refactor: fix some static analysis
This commit is contained in:
parent
345dddcf11
commit
310d8d3579
25 changed files with 200 additions and 271 deletions
|
@ -25,7 +25,6 @@ if(NOT WIN32)
|
|||
input/input.cpp
|
||||
layer/layer.cpp
|
||||
layer/layer_stack.cpp
|
||||
math/random.cpp
|
||||
platform/graphics/opengl/blender.cpp
|
||||
platform/graphics/opengl/buffers.cpp
|
||||
platform/graphics/opengl/framebuffers.cpp
|
||||
|
@ -70,7 +69,6 @@ else()
|
|||
input/input.cpp
|
||||
layer/layer.cpp
|
||||
layer/layer_stack.cpp
|
||||
math/random.cpp
|
||||
platform/graphics/directx/blender.cpp
|
||||
platform/graphics/directx/buffers.cpp
|
||||
platform/graphics/directx/framebuffers.cpp
|
||||
|
|
|
@ -9,32 +9,42 @@ namespace Light {
|
|||
class Window;
|
||||
class Event;
|
||||
|
||||
extern Scope<class Application> create_application();
|
||||
|
||||
class Application
|
||||
{
|
||||
public:
|
||||
Application(const Application &) = delete;
|
||||
|
||||
Application &operator=(const Application &) = delete;
|
||||
Application(Application &&) = delete;
|
||||
|
||||
auto operator=(const Application &) -> Application & = delete;
|
||||
|
||||
auto operator=(Application &&) -> Application & = delete;
|
||||
|
||||
virtual ~Application();
|
||||
|
||||
void game_loop();
|
||||
|
||||
[[nodiscard]] auto get_window() -> Window &
|
||||
{
|
||||
return *m_window;
|
||||
}
|
||||
|
||||
static void quit();
|
||||
|
||||
protected:
|
||||
Application();
|
||||
|
||||
Scope<Window> m_window;
|
||||
|
||||
private:
|
||||
static Application *s_instance;
|
||||
|
||||
void on_event(const Event &event);
|
||||
|
||||
void log_debug_data();
|
||||
|
||||
Scope<Window> m_window;
|
||||
|
||||
static Application *s_instance;
|
||||
};
|
||||
|
||||
extern Light::Scope<Application> create_application();
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -47,9 +47,6 @@
|
|||
// third party
|
||||
#include <imgui.h>
|
||||
|
||||
// math
|
||||
#include <engine/math/random.hpp>
|
||||
|
||||
// scene
|
||||
#include <engine/scene/components.hpp>
|
||||
#include <engine/scene/entity.hpp>
|
||||
|
|
|
@ -16,14 +16,15 @@ class SharedContext;
|
|||
class QuadRendererProgram: RendererProgram
|
||||
{
|
||||
public:
|
||||
virtual ~QuadRendererProgram() = default;
|
||||
virtual ~QuadRendererProgram() = default;
|
||||
struct QuadVertexData
|
||||
{
|
||||
glm::vec4 position;
|
||||
|
||||
glm::vec4 tint;
|
||||
};
|
||||
|
||||
QuadRendererProgram(unsigned int maxVertices, const Ref<SharedContext>& sharedContext);
|
||||
QuadRendererProgram(unsigned int maxVertices, const Ref<SharedContext> &sharedContext);
|
||||
|
||||
auto advance() -> bool;
|
||||
|
||||
|
@ -35,7 +36,7 @@ virtual ~QuadRendererProgram() = default;
|
|||
|
||||
auto get_map_current() -> QuadVertexData *
|
||||
{
|
||||
return m_map_current;
|
||||
return &m_map[m_idx];
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_quad_count() const -> unsigned int
|
||||
|
@ -57,9 +58,9 @@ private:
|
|||
|
||||
Ref<VertexLayout> m_vertex_layout;
|
||||
|
||||
QuadVertexData *m_map_current = nullptr;
|
||||
std::span<QuadVertexData> m_map;
|
||||
|
||||
QuadVertexData *m_map_end = nullptr;
|
||||
size_t m_idx {};
|
||||
|
||||
unsigned int m_quad_count = 0u;
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ class SharedContext;
|
|||
class TextureRendererProgram: RendererProgram
|
||||
{
|
||||
public:
|
||||
virtual ~TextureRendererProgram() = default;
|
||||
~TextureRendererProgram() override = default;
|
||||
|
||||
struct TextureVertexData
|
||||
{
|
||||
glm::vec4 position;
|
||||
|
@ -24,7 +25,7 @@ virtual ~TextureRendererProgram() = default;
|
|||
glm::vec2 texcoord;
|
||||
};
|
||||
|
||||
TextureRendererProgram(unsigned int maxVertices, const Ref<SharedContext>& sharedContext);
|
||||
TextureRendererProgram(unsigned int maxVertices, const Ref<SharedContext> &sharedContext);
|
||||
|
||||
auto advance() -> bool;
|
||||
|
||||
|
@ -36,7 +37,7 @@ virtual ~TextureRendererProgram() = default;
|
|||
|
||||
auto get_map_current() -> TextureVertexData *
|
||||
{
|
||||
return m_map_current;
|
||||
return &m_map[m_idx];
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_quad_count() const -> unsigned int
|
||||
|
@ -58,11 +59,11 @@ private:
|
|||
|
||||
Ref<VertexLayout> m_vertex_layout;
|
||||
|
||||
TextureVertexData *m_map_current = nullptr;
|
||||
std::span<TextureVertexData> m_map;
|
||||
|
||||
TextureVertexData *m_map_end = nullptr;
|
||||
size_t m_idx {};
|
||||
|
||||
unsigned int m_quad_count{0u};
|
||||
unsigned int m_quad_count { 0u };
|
||||
|
||||
unsigned int m_max_vertices;
|
||||
};
|
||||
|
|
|
@ -16,7 +16,7 @@ class SharedContext;
|
|||
class TintedTextureRendererProgram: RendererProgram
|
||||
{
|
||||
public:
|
||||
virtual ~TintedTextureRendererProgram() = default;
|
||||
virtual ~TintedTextureRendererProgram() = default;
|
||||
struct TintedTextureVertexData
|
||||
{
|
||||
glm::vec4 position;
|
||||
|
@ -26,7 +26,7 @@ virtual ~TintedTextureRendererProgram() = default;
|
|||
glm::vec2 texcoord;
|
||||
};
|
||||
|
||||
TintedTextureRendererProgram(unsigned int maxVertices, const Ref<SharedContext>& sharedContext);
|
||||
TintedTextureRendererProgram(unsigned int maxVertices, const Ref<SharedContext> &sharedContext);
|
||||
|
||||
auto advance() -> bool;
|
||||
|
||||
|
@ -38,7 +38,7 @@ virtual ~TintedTextureRendererProgram() = default;
|
|||
|
||||
auto get_map_current() -> TintedTextureVertexData *
|
||||
{
|
||||
return m_map_current;
|
||||
return &m_map[m_idx];
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_quad_count() const -> unsigned int
|
||||
|
@ -60,11 +60,11 @@ private:
|
|||
|
||||
Ref<VertexLayout> m_vertex_layout;
|
||||
|
||||
TintedTextureVertexData *m_map_current = nullptr;
|
||||
std::span<TintedTextureVertexData> m_map;
|
||||
|
||||
TintedTextureVertexData *m_map_end = nullptr;
|
||||
size_t m_idx {};
|
||||
|
||||
unsigned int m_quad_count{0u};
|
||||
unsigned int m_quad_count { 0u };
|
||||
|
||||
unsigned int m_max_vertices;
|
||||
};
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// #todo: make proper math stuff
|
||||
|
||||
// this is a temporary header file to extend the glm math
|
||||
// light engine will either have it's own math library or extend upon the glm
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
|
||||
namespace Light::Math {
|
||||
|
||||
auto rand(int min, int max, int decimals = 0) -> float;
|
||||
|
||||
auto rand_vec2(int min, int max, int decimals = 0) -> glm::vec2;
|
||||
|
||||
auto rand_vec3(int min, int max, int decimals = 0) -> glm::vec3;
|
||||
|
||||
} // namespace Light::Math
|
||||
|
|
@ -12,8 +12,6 @@ class Entity
|
|||
public:
|
||||
Entity(entt::entity handle = entt::null, Scene *scene = nullptr);
|
||||
|
||||
~Entity();
|
||||
|
||||
template<typename t, typename... Args>
|
||||
auto add_component(Args &&...args) -> t &
|
||||
{
|
||||
|
|
|
@ -14,10 +14,6 @@ class Framebuffer;
|
|||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene();
|
||||
|
||||
~Scene();
|
||||
|
||||
void on_create();
|
||||
|
||||
void on_update(float deltaTime);
|
||||
|
|
|
@ -12,11 +12,12 @@ public:
|
|||
|
||||
[[nodiscard]] auto get_elapsed_time() const -> float
|
||||
{
|
||||
return (std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now() - m_start
|
||||
)
|
||||
.count())
|
||||
/ 1000.;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::milliseconds;
|
||||
using std::chrono::steady_clock;
|
||||
|
||||
auto rep = duration_cast<milliseconds>(steady_clock::now() - m_start).count();
|
||||
return static_cast<float>(rep) / 1000.f;
|
||||
}
|
||||
|
||||
void reset()
|
||||
|
@ -28,24 +29,4 @@ private:
|
|||
std::chrono::time_point<std::chrono::steady_clock> m_start;
|
||||
};
|
||||
|
||||
class DeltaTimer
|
||||
{
|
||||
public:
|
||||
DeltaTimer();
|
||||
|
||||
void update();
|
||||
|
||||
[[nodiscard]] auto get_delta_time() const -> float
|
||||
{
|
||||
return m_delta_time;
|
||||
}
|
||||
|
||||
private:
|
||||
Timer timer;
|
||||
|
||||
float m_previous_frame;
|
||||
|
||||
float m_delta_time;
|
||||
};
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -6,15 +6,15 @@ namespace Light {
|
|||
|
||||
OrthographicCamera::OrthographicCamera(
|
||||
const glm::vec2 &position,
|
||||
float aspectRatio,
|
||||
float zoomLevel,
|
||||
const glm::vec4 &clearColor /* = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f) */
|
||||
float aspect_ratio,
|
||||
float zoom_level,
|
||||
const glm::vec4 &clear_color /* = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f) */
|
||||
)
|
||||
: m_up(0.0f, 1.0f, 0.0f)
|
||||
, m_position(position)
|
||||
, m_aspect_ratio(aspectRatio)
|
||||
, m_zoom_level(zoomLevel)
|
||||
, m_clear_color(clearColor)
|
||||
, m_aspect_ratio(aspect_ratio)
|
||||
, m_zoom_level(zoom_level)
|
||||
, m_clear_color(clear_color)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -4,23 +4,25 @@
|
|||
namespace Light {
|
||||
|
||||
SceneCamera::SceneCamera()
|
||||
: m_orthographic_specification { .size=1000.0f, .near_plane=-1.0f, .far_plane=10000.0f }
|
||||
, m_perspective_specification { .vertical_fov=glm::radians(45.0f), .near_plane=0.01f, .far_plane=10000.0f }
|
||||
: m_orthographic_specification { .size = 1000.0f, .near_plane = -1.0f, .far_plane = 10000.0f }
|
||||
, m_perspective_specification { .vertical_fov = glm::radians(45.0f),
|
||||
.near_plane = 0.01f,
|
||||
.far_plane = 10000.0f }
|
||||
, m_aspect_ratio(16.0f / 9.0f)
|
||||
|
||||
|
||||
{
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_viewport_size(unsigned int width, unsigned int height)
|
||||
{
|
||||
m_aspect_ratio = width / (float)height;
|
||||
m_aspect_ratio = static_cast<float>(width) / static_cast<float>(height);
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_projection_type(ProjectionType projectionType)
|
||||
void SceneCamera::set_projection_type(ProjectionType projection_type)
|
||||
{
|
||||
m_projection_type = projectionType;
|
||||
m_projection_type = projection_type;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
|
@ -30,33 +32,33 @@ void SceneCamera::set_orthographic_size(float size)
|
|||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_orthographic_far_plane(float farPlane)
|
||||
void SceneCamera::set_orthographic_far_plane(float far_plane)
|
||||
{
|
||||
m_orthographic_specification.far_plane = farPlane;
|
||||
m_orthographic_specification.far_plane = far_plane;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_orthographic_near_plane(float nearPlane)
|
||||
void SceneCamera::set_orthographic_near_plane(float near_plane)
|
||||
{
|
||||
m_orthographic_specification.near_plane = nearPlane;
|
||||
m_orthographic_specification.near_plane = near_plane;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_perspective_vertical_fov(float verticalFOV)
|
||||
void SceneCamera::set_perspective_vertical_fov(float vertical_fov)
|
||||
{
|
||||
m_perspective_specification.vertical_fov = verticalFOV;
|
||||
m_perspective_specification.vertical_fov = vertical_fov;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_perspective_far_plane(float farPlane)
|
||||
void SceneCamera::set_perspective_far_plane(float far_plane)
|
||||
{
|
||||
m_perspective_specification.far_plane = farPlane;
|
||||
m_perspective_specification.far_plane = far_plane;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_perspective_near_plane(float nearPlane)
|
||||
void SceneCamera::set_perspective_near_plane(float near_plane)
|
||||
{
|
||||
m_perspective_specification.near_plane = nearPlane;
|
||||
m_perspective_specification.near_plane = near_plane;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#include <engine/core/window.hpp>
|
||||
#include <engine/debug/instrumentor.hpp>
|
||||
#include <engine/events/event.hpp>
|
||||
#include <engine/events/keyboard.hpp>
|
||||
#include <engine/events/window.hpp>
|
||||
#include <engine/graphics/graphics_context.hpp>
|
||||
#include <engine/graphics/render_command.hpp>
|
||||
#include <engine/graphics/renderer.hpp>
|
||||
|
@ -48,7 +50,7 @@ void Application::game_loop()
|
|||
Instrumentor::begin_session("Logs/ProfileResults_GameLoop.json");
|
||||
|
||||
/* game loop */
|
||||
auto delta_timer = DeltaTimer {};
|
||||
auto timer = Timer {};
|
||||
while (!m_window->is_closed())
|
||||
{
|
||||
{
|
||||
|
@ -57,8 +59,11 @@ void Application::game_loop()
|
|||
|
||||
for (auto &it : LayerStack::instance())
|
||||
{
|
||||
it->on_update(delta_timer.get_delta_time());
|
||||
it->on_update(timer.get_elapsed_time());
|
||||
}
|
||||
|
||||
// TODO: each layer should have their own "delta time"
|
||||
timer.reset();
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -92,9 +97,6 @@ void Application::game_loop()
|
|||
lt_profile_scope("game_loop::Events");
|
||||
m_window->poll_events();
|
||||
}
|
||||
|
||||
/// update delta time
|
||||
delta_timer.update();
|
||||
}
|
||||
|
||||
Instrumentor::end_session();
|
||||
|
@ -116,7 +118,7 @@ void Application::on_event(const Event &event)
|
|||
if (event.get_event_type() == EventType::WindowResized)
|
||||
{
|
||||
m_window->get_graphics_context()->get_renderer()->on_window_resize(
|
||||
(const WindowResizedEvent &)event
|
||||
dynamic_cast<const WindowResizedEvent &>(event)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,24 +98,24 @@ void Renderer::draw_quad_impl(
|
|||
//==================== DRAW_QUAD_TINT ====================//
|
||||
void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint)
|
||||
{
|
||||
// locals
|
||||
QuadRendererProgram::QuadVertexData *bufferMap = m_quad_renderer.get_map_current();
|
||||
auto map = std::span<QuadRendererProgram::QuadVertexData> { m_quad_renderer.get_map_current(),
|
||||
4 };
|
||||
|
||||
// top left
|
||||
bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
|
||||
bufferMap[0].tint = tint;
|
||||
map[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
|
||||
map[0].tint = tint;
|
||||
|
||||
// top right
|
||||
bufferMap[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f);
|
||||
bufferMap[1].tint = tint;
|
||||
map[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f);
|
||||
map[1].tint = tint;
|
||||
|
||||
// bottom right
|
||||
bufferMap[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f);
|
||||
bufferMap[2].tint = tint;
|
||||
map[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f);
|
||||
map[2].tint = tint;
|
||||
|
||||
// bottom left
|
||||
bufferMap[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f);
|
||||
bufferMap[3].tint = tint;
|
||||
map[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f);
|
||||
map[3].tint = tint;
|
||||
|
||||
// advance
|
||||
if (!m_quad_renderer.advance())
|
||||
|
@ -124,33 +124,32 @@ void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint)
|
|||
flush_scene();
|
||||
}
|
||||
}
|
||||
//==================== DRAW_QUAD_TINT ====================//
|
||||
|
||||
//==================== DRAW_QUAD_TEXTURE ====================//
|
||||
void Renderer::draw_quad_impl(const glm::mat4 &transform, const Ref<Texture> &texture)
|
||||
{
|
||||
// #todo: implement a proper binding
|
||||
lt_assert(texture, "Texture passed to renderer::draw_quad_impl");
|
||||
texture->bind();
|
||||
|
||||
// locals
|
||||
TextureRendererProgram::TextureVertexData *bufferMap = m_texture_renderer.get_map_current();
|
||||
texture->bind();
|
||||
auto map = std::span<TextureRendererProgram::TextureVertexData> {
|
||||
m_texture_renderer.get_map_current(),
|
||||
4
|
||||
};
|
||||
|
||||
// top left
|
||||
bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
|
||||
bufferMap[0].texcoord = { 0.0f, 0.0f };
|
||||
map[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
|
||||
map[0].texcoord = { 0.0f, 0.0f };
|
||||
|
||||
// top right
|
||||
bufferMap[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f);
|
||||
bufferMap[1].texcoord = { 1.0f, 0.0f };
|
||||
map[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f);
|
||||
map[1].texcoord = { 1.0f, 0.0f };
|
||||
|
||||
// bottom right
|
||||
bufferMap[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f);
|
||||
bufferMap[2].texcoord = { 1.0f, 1.0f };
|
||||
map[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f);
|
||||
map[2].texcoord = { 1.0f, 1.0f };
|
||||
|
||||
// bottom left
|
||||
bufferMap[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f);
|
||||
bufferMap[3].texcoord = { 0.0f, 1.0f };
|
||||
map[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f);
|
||||
map[3].texcoord = { 0.0f, 1.0f };
|
||||
|
||||
// advance
|
||||
if (!m_texture_renderer.advance())
|
||||
|
@ -166,35 +165,34 @@ void Renderer::draw_quad_impl(
|
|||
const Ref<Texture> &texture
|
||||
)
|
||||
{
|
||||
// #todo: implement a proper binding
|
||||
lt_assert(texture, "Texture passed to renderer::draw_quad_impl");
|
||||
texture->bind();
|
||||
|
||||
// locals
|
||||
TintedTextureRendererProgram::TintedTextureVertexData *bufferMap = m_tinted_texture_renderer
|
||||
.get_map_current();
|
||||
texture->bind();
|
||||
auto map = std::span<TintedTextureRendererProgram::TintedTextureVertexData> {
|
||||
m_tinted_texture_renderer.get_map_current(),
|
||||
4
|
||||
};
|
||||
|
||||
// top left
|
||||
bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
|
||||
bufferMap[0].tint = tint;
|
||||
bufferMap[0].texcoord = { 0.0f, 0.0f };
|
||||
map[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
|
||||
map[0].tint = tint;
|
||||
map[0].texcoord = { 0.0f, 0.0f };
|
||||
|
||||
// top right
|
||||
bufferMap[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f);
|
||||
bufferMap[1].tint = tint;
|
||||
bufferMap[1].texcoord = { 1.0f, 0.0f };
|
||||
map[1].position = transform * glm::vec4(0.5f, -0.5f, 0.0f, 1.0f);
|
||||
map[1].tint = tint;
|
||||
map[1].texcoord = { 1.0f, 0.0f };
|
||||
|
||||
// bottom right
|
||||
bufferMap[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f);
|
||||
bufferMap[2].tint = tint;
|
||||
bufferMap[2].texcoord = { 1.0f, 1.0f };
|
||||
map[2].position = transform * glm::vec4(0.5f, 0.5f, 0.0f, 1.0f);
|
||||
map[2].tint = tint;
|
||||
map[2].texcoord = { 1.0f, 1.0f };
|
||||
|
||||
// bottom left
|
||||
bufferMap[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f);
|
||||
bufferMap[3].tint = tint;
|
||||
bufferMap[3].texcoord = { 0.0f, 1.0f };
|
||||
map[3].position = transform * glm::vec4(-0.5f, 0.5f, 0.0f, 1.0f);
|
||||
map[3].tint = tint;
|
||||
map[3].texcoord = { 0.0f, 1.0f };
|
||||
|
||||
// advance
|
||||
if (!m_tinted_texture_renderer.advance())
|
||||
{
|
||||
log_wrn("Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES);
|
||||
|
@ -202,8 +200,6 @@ void Renderer::draw_quad_impl(
|
|||
}
|
||||
}
|
||||
|
||||
//==================== DRAW_QUAD_TEXTURE ====================//
|
||||
|
||||
void Renderer::begin_frame()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -7,12 +7,14 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, const Ref<SharedContext>& sharedContext)
|
||||
QuadRendererProgram::QuadRendererProgram(
|
||||
unsigned int max_vertices,
|
||||
const Ref<SharedContext> &shared_context
|
||||
)
|
||||
: m_shader(nullptr)
|
||||
, m_index_buffer(nullptr)
|
||||
, m_vertex_layout(nullptr)
|
||||
,
|
||||
m_max_vertices(maxVertices)
|
||||
, m_max_vertices(max_vertices)
|
||||
{
|
||||
// #todo: don't use relative path
|
||||
ResourceManager::load_shader(
|
||||
|
@ -23,24 +25,23 @@ QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, const Ref<Sha
|
|||
|
||||
m_shader = ResourceManager::get_shader("LT_ENGINE_RESOURCES_QUAD_SHADER");
|
||||
m_vertex_buffer = Ref<VertexBuffer>(
|
||||
VertexBuffer::create(nullptr, sizeof(QuadVertexData), maxVertices, sharedContext)
|
||||
VertexBuffer::create(nullptr, sizeof(QuadVertexData), max_vertices, shared_context)
|
||||
);
|
||||
m_index_buffer = Ref<IndexBuffer>(
|
||||
IndexBuffer::create(nullptr, (maxVertices / 4) * 6, sharedContext)
|
||||
IndexBuffer::create(nullptr, (max_vertices / 4) * 6, shared_context)
|
||||
);
|
||||
m_vertex_layout = Ref<VertexLayout>(VertexLayout::create(
|
||||
m_vertex_buffer,
|
||||
m_shader,
|
||||
{ { "POSITION", VertexElementType::Float4 }, { "COLOR", VertexElementType::Float4 } },
|
||||
sharedContext
|
||||
shared_context
|
||||
));
|
||||
}
|
||||
|
||||
auto QuadRendererProgram::advance() -> bool
|
||||
{
|
||||
m_map_current += 4;
|
||||
|
||||
if (m_map_current >= m_map_end)
|
||||
m_idx += 4;
|
||||
if (m_idx >= m_map.size())
|
||||
{
|
||||
log_wrn("'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices);
|
||||
return false;
|
||||
|
@ -52,15 +53,19 @@ auto QuadRendererProgram::advance() -> bool
|
|||
|
||||
void QuadRendererProgram::map()
|
||||
{
|
||||
m_quad_count = 0u;
|
||||
m_map = std::span<QuadVertexData> {
|
||||
static_cast<QuadRendererProgram::QuadVertexData *>(m_vertex_buffer->map()),
|
||||
m_max_vertices,
|
||||
};
|
||||
|
||||
m_map_current = (QuadRendererProgram::QuadVertexData *)m_vertex_buffer->map();
|
||||
m_map_end = m_map_current + m_max_vertices;
|
||||
m_quad_count = 0u;
|
||||
m_idx = {};
|
||||
}
|
||||
|
||||
void QuadRendererProgram::un_map()
|
||||
{
|
||||
m_vertex_buffer->un_map();
|
||||
m_idx = {};
|
||||
}
|
||||
|
||||
void QuadRendererProgram::bind()
|
||||
|
|
|
@ -8,14 +8,13 @@
|
|||
namespace Light {
|
||||
|
||||
TextureRendererProgram::TextureRendererProgram(
|
||||
unsigned int maxVertices,
|
||||
const Ref<SharedContext>& sharedContext
|
||||
unsigned int max_vertices,
|
||||
const Ref<SharedContext> &shared_context
|
||||
)
|
||||
: m_shader(nullptr)
|
||||
, m_index_buffer(nullptr)
|
||||
, m_vertex_layout(nullptr)
|
||||
,
|
||||
m_max_vertices(maxVertices)
|
||||
, m_max_vertices(max_vertices)
|
||||
{
|
||||
// #todo: don't use relative path
|
||||
ResourceManager::load_shader(
|
||||
|
@ -26,38 +25,41 @@ TextureRendererProgram::TextureRendererProgram(
|
|||
|
||||
m_shader = ResourceManager::get_shader("LT_ENGINE_RESOURCES_TEXTURE_SHADER");
|
||||
m_vertex_buffer = Ref<VertexBuffer>(
|
||||
VertexBuffer::create(nullptr, sizeof(TextureVertexData), maxVertices, sharedContext)
|
||||
VertexBuffer::create(nullptr, sizeof(TextureVertexData), max_vertices, shared_context)
|
||||
);
|
||||
m_index_buffer = Ref<IndexBuffer>(
|
||||
IndexBuffer::create(nullptr, (maxVertices / 4) * 6, sharedContext)
|
||||
IndexBuffer::create(nullptr, (max_vertices / 4) * 6, shared_context)
|
||||
);
|
||||
m_vertex_layout = Ref<VertexLayout>(VertexLayout::create(
|
||||
m_vertex_buffer,
|
||||
m_shader,
|
||||
{ { "POSITION", VertexElementType::Float4 }, { "TEXCOORD", VertexElementType::Float2 } },
|
||||
sharedContext
|
||||
shared_context
|
||||
));
|
||||
}
|
||||
|
||||
auto TextureRendererProgram::advance() -> bool
|
||||
{
|
||||
if (m_map_current + 4 >= m_map_end)
|
||||
m_idx += 4;
|
||||
if (m_idx >= m_map.size())
|
||||
{
|
||||
log_wrn("'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_map_current += 4;
|
||||
m_quad_count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextureRendererProgram::map()
|
||||
{
|
||||
m_quad_count = 0u;
|
||||
m_map = std::span<TextureVertexData> {
|
||||
static_cast<TextureVertexData *>(m_vertex_buffer->map()),
|
||||
m_max_vertices,
|
||||
};
|
||||
|
||||
m_map_current = (TextureRendererProgram::TextureVertexData *)m_vertex_buffer->map();
|
||||
m_map_end = m_map_current + m_max_vertices;
|
||||
m_quad_count = 0u;
|
||||
m_idx = {};
|
||||
}
|
||||
|
||||
void TextureRendererProgram::un_map()
|
||||
|
|
|
@ -8,14 +8,13 @@
|
|||
namespace Light {
|
||||
|
||||
TintedTextureRendererProgram::TintedTextureRendererProgram(
|
||||
unsigned int maxVertices,
|
||||
const Ref<SharedContext>& sharedContext
|
||||
unsigned int max_vertices,
|
||||
const Ref<SharedContext> &shared_context
|
||||
)
|
||||
: m_shader(nullptr)
|
||||
, m_index_buffer(nullptr)
|
||||
, m_vertex_layout(nullptr)
|
||||
,
|
||||
m_max_vertices(maxVertices)
|
||||
, m_max_vertices(max_vertices)
|
||||
{
|
||||
// #todo: don't use relative path
|
||||
ResourceManager::load_shader(
|
||||
|
@ -26,10 +25,10 @@ TintedTextureRendererProgram::TintedTextureRendererProgram(
|
|||
|
||||
m_shader = ResourceManager::get_shader("LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER");
|
||||
m_vertex_buffer = Ref<VertexBuffer>(
|
||||
VertexBuffer::create(nullptr, sizeof(TintedTextureVertexData), maxVertices, sharedContext)
|
||||
VertexBuffer::create(nullptr, sizeof(TintedTextureVertexData), max_vertices, shared_context)
|
||||
);
|
||||
m_index_buffer = Ref<IndexBuffer>(
|
||||
IndexBuffer::create(nullptr, (maxVertices / 4) * 6, sharedContext)
|
||||
IndexBuffer::create(nullptr, (max_vertices / 4) * 6, shared_context)
|
||||
);
|
||||
m_vertex_layout = Ref<VertexLayout>(VertexLayout::create(
|
||||
m_vertex_buffer,
|
||||
|
@ -37,15 +36,14 @@ TintedTextureRendererProgram::TintedTextureRendererProgram(
|
|||
{ { "POSITION", VertexElementType::Float4 },
|
||||
{ "TINT", VertexElementType::Float4 },
|
||||
{ "TEXCOORD", VertexElementType::Float2 } },
|
||||
sharedContext
|
||||
shared_context
|
||||
));
|
||||
}
|
||||
|
||||
auto TintedTextureRendererProgram::advance() -> bool
|
||||
{
|
||||
m_map_current += 4;
|
||||
|
||||
if (m_map_current >= m_map_end)
|
||||
m_idx += 4;
|
||||
if (m_idx >= m_map.size())
|
||||
{
|
||||
log_wrn("'VertexBuffer' map went beyond 'MaxVertices': {}", m_max_vertices);
|
||||
return false;
|
||||
|
@ -57,10 +55,13 @@ auto TintedTextureRendererProgram::advance() -> bool
|
|||
|
||||
void TintedTextureRendererProgram::map()
|
||||
{
|
||||
m_quad_count = 0u;
|
||||
m_map = std::span<TintedTextureVertexData> {
|
||||
static_cast<TintedTextureVertexData *>(m_vertex_buffer->map()),
|
||||
m_max_vertices,
|
||||
};
|
||||
|
||||
m_map_current = (TintedTextureRendererProgram::TintedTextureVertexData *)m_vertex_buffer->map();
|
||||
m_map_end = m_map_current + m_max_vertices;
|
||||
m_quad_count = 0u;
|
||||
m_idx = {};
|
||||
}
|
||||
|
||||
void TintedTextureRendererProgram::un_map()
|
||||
|
|
|
@ -156,6 +156,7 @@ void Input::on_event(const Event &inputEvent)
|
|||
|
||||
return;
|
||||
}
|
||||
default: log_trc("Dropped event");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,21 +15,32 @@ auto Layer::on_event(const Event &event) -> bool
|
|||
{
|
||||
switch (event.get_event_type())
|
||||
{
|
||||
case EventType::MouseMoved: return on_mouse_moved((MouseMovedEvent &)event);
|
||||
case EventType::ButtonPressed: return on_button_pressed((ButtonPressedEvent &)event);
|
||||
case EventType::ButtonReleased: return on_button_released((ButtonReleasedEvent &)event);
|
||||
case EventType::WheelScrolled: return on_wheel_scrolled((WheelScrolledEvent &)event);
|
||||
case EventType::MouseMoved: return on_mouse_moved(dynamic_cast<const MouseMovedEvent &>(event));
|
||||
case EventType::ButtonPressed:
|
||||
return on_button_pressed(dynamic_cast<const ButtonPressedEvent &>(event));
|
||||
case EventType::ButtonReleased:
|
||||
return on_button_released(dynamic_cast<const ButtonReleasedEvent &>(event));
|
||||
case EventType::WheelScrolled:
|
||||
return on_wheel_scrolled(dynamic_cast<const WheelScrolledEvent &>(event));
|
||||
|
||||
case EventType::KeyPressed: return on_key_pressed((KeyPressedEvent &)event);
|
||||
case EventType::KeyRepeated: return on_key_repeat((KeyRepeatEvent &)event);
|
||||
case EventType::KeyReleased: return on_key_released((KeyReleasedEvent &)event);
|
||||
case EventType::SetChar: return on_set_char((SetCharEvent &)event);
|
||||
case EventType::KeyPressed: return on_key_pressed(dynamic_cast<const KeyPressedEvent &>(event));
|
||||
case EventType::KeyRepeated: return on_key_repeat(dynamic_cast<const KeyRepeatEvent &>(event));
|
||||
case EventType::KeyReleased:
|
||||
return on_key_released(dynamic_cast<const KeyReleasedEvent &>(event));
|
||||
case EventType::SetChar: return on_set_char(dynamic_cast<const SetCharEvent &>(event));
|
||||
|
||||
case EventType::WindowClosed: return on_window_closed((WindowClosedEvent &)event);
|
||||
case EventType::WindowResized: return on_window_resized((WindowResizedEvent &)event);
|
||||
case EventType::WindowMoved: return on_window_moved((WindowMovedEvent &)event);
|
||||
case EventType::WindowLostFocus: return on_window_lost_focus((WindowLostFocusEvent &)event);
|
||||
case EventType::WindowGainFocus: return on_window_gain_focus((WindowGainFocusEvent &)event);
|
||||
case EventType::WindowClosed:
|
||||
return on_window_closed(dynamic_cast<const WindowClosedEvent &>(event));
|
||||
case EventType::WindowResized:
|
||||
return on_window_resized(dynamic_cast<const WindowResizedEvent &>(event));
|
||||
case EventType::WindowMoved:
|
||||
return on_window_moved(dynamic_cast<const WindowMovedEvent &>(event));
|
||||
case EventType::WindowLostFocus:
|
||||
return on_window_lost_focus(dynamic_cast<const WindowLostFocusEvent &>(event));
|
||||
case EventType::WindowGainFocus:
|
||||
return on_window_gain_focus(dynamic_cast<const WindowGainFocusEvent &>(event));
|
||||
|
||||
default: lt_assert(false, "Invalid event: {}", event.get_info_lt_log());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
#include <cmath>
|
||||
#include <engine/math/random.hpp>
|
||||
|
||||
|
||||
namespace Light::Math {
|
||||
|
||||
auto rand(int min, int max, int decimals /* = 0 */) -> float
|
||||
{
|
||||
const auto dec = static_cast<int>(std::pow(10, decimals));
|
||||
min *= dec;
|
||||
max *= dec;
|
||||
|
||||
return (min + (::rand() % (max)-min)) / (float)dec;
|
||||
}
|
||||
|
||||
auto rand_vec2(int min, int max, int decimals /* = 0 */) -> glm::vec2
|
||||
{
|
||||
const auto dec = static_cast<int>(std::pow(10, decimals));
|
||||
min *= dec;
|
||||
max *= dec;
|
||||
|
||||
auto r1 = (min + (::rand() % (max)-min)) / (float)dec;
|
||||
auto r2 = (min + (::rand() % (max)-min)) / (float)dec;
|
||||
|
||||
return { r1, r2 };
|
||||
}
|
||||
|
||||
auto rand_vec3(int min, int max, int decimals /* = 0 */) -> glm::vec3
|
||||
{
|
||||
const auto dec = static_cast<int>(std::pow(10, decimals));
|
||||
min *= dec;
|
||||
max *= dec;
|
||||
|
||||
auto r1 = (min + (::rand() % (max - min))) / (float)dec;
|
||||
auto r2 = (min + (::rand() % (max - min))) / (float)dec;
|
||||
auto r3 = (min + (::rand() % (max - min))) / (float)dec;
|
||||
|
||||
return { r1, r2, r3 };
|
||||
}
|
||||
} // namespace Light::Math
|
||||
|
|
@ -7,7 +7,4 @@ Entity::Entity(entt::entity handle, Scene *scene): m_handle(handle), m_scene(sce
|
|||
{
|
||||
}
|
||||
|
||||
Entity::~Entity()
|
||||
= default;
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -6,13 +6,6 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Scene::Scene()
|
||||
{
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
= default;
|
||||
|
||||
void Scene::on_create()
|
||||
{
|
||||
/* native scripts */
|
||||
|
|
|
@ -6,15 +6,4 @@ Timer::Timer(): m_start(std::chrono::steady_clock::now())
|
|||
{
|
||||
}
|
||||
|
||||
DeltaTimer::DeltaTimer(): m_previous_frame(NULL), m_delta_time(60.0f / 1000.0f)
|
||||
{
|
||||
}
|
||||
|
||||
void DeltaTimer::update()
|
||||
{
|
||||
auto currentFrame = timer.get_elapsed_time();
|
||||
m_delta_time = currentFrame - m_previous_frame;
|
||||
m_previous_frame = currentFrame;
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -15,6 +15,12 @@
|
|||
#include <imgui.h>
|
||||
#include <utility>
|
||||
|
||||
|
||||
inline ImGuiDockNodeFlags_ operator|(ImGuiDockNodeFlags_ a, ImGuiDockNodeFlags_ b)
|
||||
{
|
||||
return static_cast<ImGuiDockNodeFlags_>(std::to_underlying(a) | std::to_underlying(b));
|
||||
}
|
||||
|
||||
namespace Light {
|
||||
|
||||
UserInterface *UserInterface::s_context = nullptr;
|
||||
|
@ -44,11 +50,13 @@ auto UserInterface::create(GLFWwindow *windowHandle, Ref<SharedContext> sharedCo
|
|||
}
|
||||
|
||||
UserInterface::UserInterface()
|
||||
// NOLINTBEGIN
|
||||
: m_dockspace_flags(
|
||||
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar
|
||||
| ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
|
||||
| ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus
|
||||
)
|
||||
// NOLINTEND
|
||||
{
|
||||
lt_assert(
|
||||
!s_context,
|
||||
|
@ -66,13 +74,13 @@ void UserInterface::init(GLFWwindow *windowHandle, Ref<SharedContext> sharedCont
|
|||
|
||||
// configure io
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
// NOLINTBEGIN
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
||||
|
||||
io.ConfigFlags |= ImGuiBackendFlags_PlatformHasViewports;
|
||||
io.ConfigFlags |= ImGuiBackendFlags_RendererHasViewports;
|
||||
// NOLINTEND
|
||||
|
||||
// #todo: handle this in a better way
|
||||
if (std::filesystem::exists("user_gui_layout.ini"))
|
||||
|
@ -117,8 +125,9 @@ void UserInterface::dockspace_begin()
|
|||
ImGui::DockSpace(
|
||||
ImGui::GetID("MyDockSpace"),
|
||||
ImVec2(0.0f, 0.0f),
|
||||
ImGuiDockNodeFlags_None | ImGuiWindowFlags_NoBackground
|
||||
ImGuiDockNodeFlags_None | ImGuiWindowFlags_NoBackground // NOLINT
|
||||
);
|
||||
|
||||
style.WindowMinSize.x = minWinSizeX;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,28 +8,28 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
class Mirror: public Light::Application
|
||||
class Mirror: public Application
|
||||
{
|
||||
public:
|
||||
Mirror()
|
||||
{
|
||||
// Set window properties
|
||||
auto properties = Light::WindowProperties {
|
||||
auto properties = WindowProperties {
|
||||
.title = "Mirror",
|
||||
.size = glm::uvec2(1280u, 720u),
|
||||
.vsync = true,
|
||||
};
|
||||
|
||||
m_window->set_properties(properties);
|
||||
get_window().set_properties(properties);
|
||||
|
||||
// Attach the sandbox layer
|
||||
LayerStack::emplace_layer<EditorLayer>("MirrorLayer");
|
||||
}
|
||||
};
|
||||
|
||||
auto create_application() -> Light::Scope<Application>
|
||||
auto create_application() -> Scope<Application>
|
||||
{
|
||||
return Light::create_scope<Mirror>();
|
||||
return create_scope<Mirror>();
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
Loading…
Add table
Reference in a new issue