8#include "galaxy/core/ServiceLocator.hpp"
26 : m_camera {GAlAXY_BUFFER_CAMERA_INDEX}
27 , m_renderdata {GAlAXY_BUFFER_RENDERDATA_INDEX}
34 if (
m_cmds.capacity() < GALAXY_RENDERCOMMAND_INITIAL_ALLOCS)
36 m_cmds.reserve(GALAXY_RENDERCOMMAND_INITIAL_ALLOCS);
47 auto& w = core::ServiceLocator<core::Window>::ref();
48 const auto width = w.frame_width();
49 const auto height = w.frame_height();
83 m_cmds.emplace_back(std::move(command));
90 cmd.count = va.
count();
91 cmd.instances = va.instances();
93 cmd.mode = GL_TRIANGLES;
96 cmd.texture = texture.id();
97 cmd.uniforms.colour = {1.0f, 1.0f, 1.0f, opacity};
98 cmd.uniforms.entity = -1;
99 cmd.uniforms.point =
false;
100 cmd.uniforms.textured =
true;
110 cmd.count = text.
vao().count();
111 cmd.instances = text.
vao().instances();
113 cmd.mode = GL_TRIANGLES;
114 cmd.offset = text.
vao().offset();
115 cmd.vao = text.
vao().id();
117 cmd.uniforms.colour = text.
m_colour.vec4();
118 cmd.uniforms.entity = -1;
119 cmd.uniforms.point =
false;
120 cmd.uniforms.textured =
true;
131 cmd.instances = shape->
vao().instances();
133 cmd.mode = shape->
mode();
135 cmd.vao = shape->
vao().
id();
137 cmd.uniforms.colour = shape->
m_colour.vec4();
138 cmd.uniforms.entity = -1;
139 cmd.uniforms.point = shape->
mode() == GL_POINTS ? true :
false;
140 cmd.uniforms.textured =
false;
148 glActiveTexture(GL_TEXTURE0);
154 auto rtt = core::ServiceLocator<resource::Shaders>::ref().get(
"render_to_texture");
156 rtt->set_uniform(
"u_projection", target.
get_proj());
159 glDrawElements(GL_TRIANGLES, va.
count(), GL_UNSIGNED_INT, va.
offset());
161 glBindVertexArray(0);
162 glBindTexture(GL_TEXTURE_2D, 0);
169 std::sort(
m_cmds.begin(),
m_cmds.end(), [](
auto left,
auto right) ->
bool {
170 return left.layer < right.layer;
177 glActiveTexture(GL_TEXTURE0);
183 glBindTexture(GL_TEXTURE_2D, cmd.texture);
184 glBindVertexArray(cmd.vao);
185 glDrawElementsInstanced(cmd.mode, cmd.count, GL_UNSIGNED_INT, cmd.offset, cmd.instances);
196 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
197 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
219#ifdef GALAXY_WIN_PLATFORM
221#pragma warning(disable : 4244)
223 glBindFramebuffer(GL_FRAMEBUFFER, 0);
233#ifdef GALAXY_WIN_PLATFORM
240 glfwSwapBuffers(core::ServiceLocator<core::Window>::ref().handle());
245 auto& w = core::ServiceLocator<core::Window>::ref();
247 int width = window_width;
248 int height =
static_cast<int>(width / w.aspect_ratio() + 0.5f);
250 if (height > window_height)
253 height = window_height;
254 width =
static_cast<int>(height * w.aspect_ratio() + 0.5f);
258 m_viewport.x =
static_cast<float>((window_width / 2) - (width / 2));
259 m_viewport.y =
static_cast<float>((window_height / 2) - (height / 2));
void bind() const
Bind buffer.
void clear() const
Clears data from buffer.
void buffer(const unsigned int count, Object *data)
Buffer data.
void sub_buffer(const unsigned int offset, const unsigned int count, Object *data)
Sub buffer data.
void compile()
Compiles shader into GPU mem.
bool parse(const std::string &src) noexcept
Loads a combined raw shader.
void bind() const
Make active shader.
void destroy()
Destroys shader program.
Bindless OpenGL 2D Texture.
void bind() const noexcept
Bind to sampler.
Abstraction for OpenGL vertex array objects.
void bind() const
Bind this vertex array.
int count() const noexcept
Get the index count.
unsigned int id() const noexcept
Get vertex array handle.
void * offset() noexcept
Gets index offset.
Data & get_data()
Get camera view and proj.
Chromatic Aberration pass.
void bind()
Bind to draw to post processor framebuffer.
void destroy()
Cleanup used memory.
Effect * add(Args &&... args)
Add an effect to process.
void render_effects()
Draw post effects to stored framebuffer.
void render_output()
Draw finished post effects to default framebuffer (screen).
void unbind()
Unbind to draw to post processor framebuffer.
void init(const int width, const int height)
Initialize post processor and GL buffers.
Draw to an opengl texture instead of the screen.
const glm::mat4 & get_proj()
Get render texture projection.
unsigned int texture() const
Gets framebuffer texture.
void bind(bool clear=true)
Activate context.
void submit_text(Text &text, Transform &tf, const int layer)
Submit standalone text to be rendered.
meta::vector< RenderCommand > m_cmds
List of renderables to draw.
glm::vec4 m_viewport
Default framebuffer viewport.
void end_default()
Swaps buffers.
void submit_texture(const Texture2D &texture, VertexArray &va, Transform &tf, const int layer, const float opacity)
Submit a standalone texture to be rendered.
void begin_post()
Begin rendering to post process framebuffer.
void render_post()
Renders final post processing output to active framebuffer.
ShaderStorageBuffer m_renderdata
Uniform buffer storage.
void end_post()
Renders effects to post processing framebuffer and rebinds to default framebuffer.
void clear_active()
Clears currently active framebuffer.
PostProcess m_post
Post processor.
void flush()
Deletes all submitted render commands.
void submit_cmd(RenderCommand &command)
Add an entity rendering command.
void submit_camera(Camera &camera)
Set the camera to use when calling draw().
void init()
Initialize renderer.
void draw()
Draw all submitted render commands to screen.
static Renderer & ref()
Get reference to renderer singleton.
Shader m_r2d_shader
Mono render shader.
void submit_shape(Shape *shape, Transform &tf, const int layer)
Submit a standalone shape to be rendered.
void destroy()
Cleanup renderer data.
void draw_texture_to_target(RenderTexture &target, Texture *texture, VertexArray &va, Transform &tf)
Draw a texture to a render texture.
void calc_viewport(int window_width, int window_height)
Need to recalculate default framebuffer viewport.
void begin_default()
Start rendering to default framebuffer.
ShaderStorageBuffer m_camera
Camera buffer storage.
void on_window_resized(const events::WindowResized &e)
Event processing method for window size change.
Submorphological Anti Aliasing.
Colour m_colour
Used by all primitives.
VertexArray & vao()
Get vertex array object.
unsigned int mode() const
Get OpenGL rendering mode.
String of glyphs rendered with a font.
graphics::Colour m_colour
Text colour.
graphics::RenderTexture & render_texture()
Get render texture.
graphics::VertexArray & vao()
Get vertex array.
constexpr const auto r2d_frag_shader
Fragment shader for the 2d renderer.
constexpr const auto r2d_vert_shader
Vertex shader for the 2d renderer.
Data to be passed to the renderer.
Uniform data passed to shader from entity.