light/modules/renderer/public/renderer.hpp

176 lines
3.8 KiB
C++
Raw Normal View History

2025-07-05 13:28:41 +03:30
#pragma once
#include <math/mat4.hpp>
#include <math/vec3.hpp>
#include <math/vec4.hpp>
#include <renderer/blender.hpp>
#include <renderer/buffers.hpp>
#include <renderer/render_command.hpp>
#include <renderer/renderer.hpp>
2025-07-06 16:52:50 +03:30
#include <utility>
2025-07-05 13:28:41 +03:30
2025-07-06 16:52:50 +03:30
#define LT_MAX_QUAD_RENDERER_VERTICES (1028u * 4u)
#define LT_MAX_TEXTURE_RENDERER_VERTICES (1028u * 4u)
#define LT_MAX_TINTED_TEXTURE_RENDERER_VERTICES (1028u * 4u)
2025-07-05 13:28:41 +03:30
struct GLFWwindow;
2025-07-11 00:05:48 +03:30
namespace lt {
2025-07-05 13:28:41 +03:30
class ConstantBuffer;
class Framebuffer;
class RenderCommand;
class Texture;
class SharedContext;
class Camera;
class WindowResizedEvent;
class Shader;
2025-07-05 13:28:41 +03:30
class TintedTextureRendererProgram;
class QuadRendererProgram;
class TextureRendererProgram;
2025-07-06 14:02:50 +03:30
class Renderer
2025-07-05 13:28:41 +03:30
{
public:
struct CreateInfo
{
Ref<Shader> quad_renderer_shader;
Ref<Shader> texture_renderer_shader;
Ref<Shader> tinted_texture_renderer_shader;
};
static auto create(
GLFWwindow *windowHandle,
Ref<SharedContext> sharedContext,
CreateInfo create_info
) -> Scope<Renderer>;
2025-07-05 13:28:41 +03:30
2025-07-06 14:02:50 +03:30
static void draw_quad(
const math::vec3 &position,
const math::vec2 &size,
const math::vec4 &tint,
2025-07-05 13:28:41 +03:30
Ref<Texture> texture
)
{
2025-07-06 16:52:50 +03:30
s_context->draw_quad_impl(position, size, tint, std::move(texture));
2025-07-05 13:28:41 +03:30
}
2025-07-05 16:07:51 +03:30
static void draw_quad(
const math::vec3 &position,
const math::vec2 &size,
const math::vec4 &tint
)
2025-07-05 13:28:41 +03:30
{
2025-07-05 16:07:51 +03:30
s_context->draw_quad_impl(position, size, tint);
2025-07-05 13:28:41 +03:30
}
2025-07-05 16:07:51 +03:30
static void draw_quad(const math::vec3 &position, const math::vec2 &size, Ref<Texture> texture)
2025-07-05 13:28:41 +03:30
{
2025-07-06 16:52:50 +03:30
s_context->draw_quad_impl(position, size, std::move(texture));
2025-07-05 13:28:41 +03:30
}
static void draw_quad(
const math::mat4 &transform,
const math::vec4 &tint,
const Ref<Texture> &texture
)
2025-07-05 13:28:41 +03:30
{
s_context->draw_quad_impl(transform, tint, texture);
2025-07-05 13:28:41 +03:30
}
2025-07-05 16:07:51 +03:30
static void draw_quad(const math::mat4 &transform, const math::vec4 &tint)
2025-07-05 13:28:41 +03:30
{
2025-07-05 16:07:51 +03:30
s_context->draw_quad_impl(transform, tint);
2025-07-05 13:28:41 +03:30
}
2025-07-05 16:07:51 +03:30
static void draw_quad(const math::mat4 &transform, const Ref<Texture> &texture)
2025-07-05 13:28:41 +03:30
{
s_context->draw_quad_impl(transform, texture);
2025-07-05 13:28:41 +03:30
}
2025-07-06 14:02:50 +03:30
static void begin_scene(
2025-07-05 13:28:41 +03:30
Camera *camera,
const math::mat4 &cameraTransform,
2025-07-05 13:28:41 +03:30
const Ref<Framebuffer> &targetFrameBuffer = nullptr
)
{
2025-07-05 16:07:51 +03:30
s_context->begin_scene_impl(camera, cameraTransform, targetFrameBuffer);
2025-07-05 13:28:41 +03:30
}
2025-07-06 14:02:50 +03:30
static void end_scene()
2025-07-05 13:28:41 +03:30
{
2025-07-05 16:07:51 +03:30
s_context->end_scene_impl();
2025-07-05 13:28:41 +03:30
}
~Renderer();
void on_window_resize(const WindowResizedEvent &event);
2025-07-05 13:28:41 +03:30
void begin_frame();
2025-07-06 14:02:50 +03:30
void end_frame();
2025-07-05 13:28:41 +03:30
private:
2025-07-06 14:02:50 +03:30
static Renderer *s_context;
2025-07-05 16:07:51 +03:30
Scope<QuadRendererProgram> m_quad_renderer;
2025-07-05 16:07:51 +03:30
Scope<TextureRendererProgram> m_texture_renderer;
2025-07-05 16:07:51 +03:30
Scope<TintedTextureRendererProgram> m_tinted_texture_renderer;
2025-07-05 16:07:51 +03:30
Scope<ConstantBuffer> m_view_projection_buffer;
Scope<RenderCommand> m_render_command;
Scope<Blender> m_blender;
2025-07-06 16:52:50 +03:30
Camera *m_default_framebuffer_camera { nullptr };
2025-07-05 16:07:51 +03:30
Ref<Framebuffer> m_target_framebuffer;
2025-07-06 16:52:50 +03:30
bool m_should_clear_backbuffer { false };
2025-07-05 16:07:51 +03:30
Renderer(
GLFWwindow *window_handle,
const Ref<SharedContext> &shared_context,
CreateInfo create_info
);
2025-07-05 13:28:41 +03:30
void draw_quad_impl(
const math::vec3 &position,
const math::vec2 &size,
const math::vec4 &tint,
2025-07-05 13:28:41 +03:30
Ref<Texture> texture
);
2025-07-05 16:07:51 +03:30
void draw_quad_impl(const math::vec3 &position, const math::vec2 &size, const math::vec4 &tint);
2025-07-05 16:07:51 +03:30
void draw_quad_impl(const math::vec3 &position, const math::vec2 &size, Ref<Texture> texture);
2025-07-05 13:28:41 +03:30
2025-07-06 16:52:50 +03:30
void draw_quad_impl(
const math::mat4 &transform,
const math::vec4 &tint,
2025-07-06 16:52:50 +03:30
const Ref<Texture> &texture
);
2025-07-05 16:07:51 +03:30
void draw_quad_impl(const math::mat4 &transform, const math::vec4 &tint);
2025-07-05 16:07:51 +03:30
void draw_quad_impl(const math::mat4 &transform, const Ref<Texture> &texture);
2025-07-05 13:28:41 +03:30
void begin_scene_impl(
2025-07-05 13:28:41 +03:30
Camera *camera,
const math::mat4 &cameraTransform,
2025-07-05 13:28:41 +03:30
const Ref<Framebuffer> &targetFrameBuffer = nullptr
);
2025-07-05 16:07:51 +03:30
void flush_scene();
2025-07-05 16:07:51 +03:30
void end_scene_impl();
2025-07-05 13:28:41 +03:30
};
2025-07-11 00:05:48 +03:30
} // namespace lt