2025-07-05 13:28:41 +03:30
|
|
|
#pragma once
|
|
|
|
|
2025-07-10 13:29:03 +03:30
|
|
|
//
|
|
|
|
#include <renderer/blender.hpp>
|
|
|
|
#include <renderer/buffers.hpp>
|
|
|
|
#include <renderer/render_command.hpp>
|
|
|
|
#include <renderer/renderer.hpp>
|
|
|
|
///
|
|
|
|
|
|
|
|
#include <renderer/renderer_programs/quad.hpp>
|
|
|
|
#include <renderer/renderer_programs/texture.hpp>
|
|
|
|
#include <renderer/renderer_programs/tinted_texture.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;
|
2025-07-10 13:29:03 +03:30
|
|
|
class Shader;
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-06 14:02:50 +03:30
|
|
|
class Renderer
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
|
|
|
public:
|
2025-07-10 13:29:03 +03:30
|
|
|
struct CreateInfo
|
|
|
|
{
|
|
|
|
Ref<Shader> quad_renderer_shader;
|
|
|
|
|
|
|
|
Ref<Shader> texture_renderer_shader;
|
|
|
|
|
|
|
|
Ref<Shader> tinted_texture_renderer_shader;
|
|
|
|
};
|
|
|
|
|
|
|
|
static auto create(
|
|
|
|
GLFWwindow *window_handle,
|
|
|
|
Ref<SharedContext> shared_context,
|
|
|
|
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(
|
2025-07-05 13:28:41 +03:30
|
|
|
const glm::vec3 &position,
|
|
|
|
const glm::vec2 &size,
|
|
|
|
const glm::vec4 &tint,
|
|
|
|
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
|
|
|
|
2025-07-06 14:02:50 +03:30
|
|
|
static void draw_quad(const glm::vec3 &position, const glm::vec2 &size, const glm::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
|
|
|
|
2025-07-06 14:02:50 +03:30
|
|
|
static void draw_quad(const glm::vec3 &position, const glm::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
|
|
|
}
|
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
static void draw_quad(const glm::mat4 &transform, const glm::vec4 &tint, Ref<Texture> texture)
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
2025-07-06 16:52:50 +03:30
|
|
|
s_context->draw_quad_impl(transform, tint, std::move(texture));
|
2025-07-05 13:28:41 +03:30
|
|
|
}
|
2025-07-05 16:07:51 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
static void draw_quad(const glm::mat4 &transform, const glm::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
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
static void draw_quad(const glm::mat4 &transform, Ref<Texture> texture)
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
2025-07-06 16:52:50 +03:30
|
|
|
s_context->draw_quad_impl(transform, std::move(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 glm::mat4 &cameraTransform,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void on_window_resize(const WindowResizedEvent &event);
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void begin_frame();
|
2025-07-06 14:02:50 +03:30
|
|
|
|
2025-07-05 15:36:53 +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
|
|
|
|
|
|
|
QuadRendererProgram m_quad_renderer;
|
|
|
|
|
|
|
|
TextureRendererProgram m_texture_renderer;
|
|
|
|
|
|
|
|
TintedTextureRendererProgram m_tinted_texture_renderer;
|
|
|
|
|
|
|
|
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
|
|
|
|
2025-07-10 13:29:03 +03:30
|
|
|
Renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext, CreateInfo create_info);
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void draw_quad_impl(
|
2025-07-05 13:28:41 +03:30
|
|
|
const glm::vec3 &position,
|
|
|
|
const glm::vec2 &size,
|
|
|
|
const glm::vec4 &tint,
|
|
|
|
Ref<Texture> texture
|
|
|
|
);
|
2025-07-05 16:07:51 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint);
|
2025-07-05 16:07:51 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void draw_quad_impl(const glm::vec3 &position, const glm::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 glm::mat4 &transform,
|
|
|
|
const glm::vec4 &tint,
|
|
|
|
const Ref<Texture> &texture
|
|
|
|
);
|
2025-07-05 16:07:51 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint);
|
2025-07-05 16:07:51 +03:30
|
|
|
|
2025-07-06 16:52:50 +03:30
|
|
|
void draw_quad_impl(const glm::mat4 &transform, const Ref<Texture> &texture);
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void begin_scene_impl(
|
2025-07-05 13:28:41 +03:30
|
|
|
Camera *camera,
|
|
|
|
const glm::mat4 &cameraTransform,
|
|
|
|
const Ref<Framebuffer> &targetFrameBuffer = nullptr
|
|
|
|
);
|
2025-07-05 16:07:51 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void flush_scene();
|
2025-07-05 16:07:51 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void end_scene_impl();
|
2025-07-05 13:28:41 +03:30
|
|
|
};
|
|
|
|
|
2025-07-11 00:05:48 +03:30
|
|
|
} // namespace lt
|