style: fix access specifier ordering

This commit is contained in:
light7734 2025-07-05 16:07:51 +03:30
parent ff56283c19
commit 6445d7b9ca
Signed by: light7734
GPG key ID: 8C30176798F1A6BA
72 changed files with 740 additions and 587 deletions

View file

@ -10,40 +10,39 @@ namespace Light {
class Window; class Window;
class Event; class Event;
class Instrumentor; class Instrumentor;
class Application /* singleton */ class Application
{ {
private:
static Application *s_Context;
private:
Scope<logger> m_logger;
Scope<Instrumentor> m_instrumentor;
Scope<LayerStack> m_layer_stack;
Scope<Input> m_input;
Scope<ResourceManager> m_resource_manager;
protected:
Scope<Window> m_window;
public: public:
Application(const Application &) = delete; Application(const Application &) = delete;
Application &operator=(const Application &) = delete; Application &operator=(const Application &) = delete;
virtual ~Application(); virtual ~Application();
void game_loop(); void game_loop();
// To be defined in client project
static void quit(); static void quit();
protected: protected:
Application(); Application();
Scope<Window> m_window;
private: private:
static Application *s_context;
Scope<logger> m_logger;
Scope<Instrumentor> m_instrumentor;
Scope<LayerStack> m_layer_stack;
Scope<Input> m_input;
Scope<ResourceManager> m_resource_manager;
void on_event(const Event &event); void on_event(const Event &event);
void log_debug_data(); void log_debug_data();

View file

@ -6,13 +6,6 @@ namespace Light {
class UUID class UUID
{ {
private:
static std::mt19937_64 s_Engine;
static std::uniform_int_distribution<uint64_t> s_UniformDistribution;
private:
uint64_t m_uuid;
public: public:
UUID(uint64_t uuid = -1); UUID(uint64_t uuid = -1);
@ -20,6 +13,13 @@ public:
{ {
return m_uuid; return m_uuid;
} }
private:
static std::mt19937_64 s_engine;
static std::uniform_int_distribution<uint64_t> s_distribution;
uint64_t m_uuid;
}; };
} // namespace Light } // namespace Light

View file

@ -17,11 +17,6 @@ struct WindowProperties
class Window class Window
{ {
protected:
Scope<GraphicsContext> m_graphics_context;
WindowProperties m_properties;
bool b_Closed;
public: public:
static Scope<Window> create(std::function<void(Event &)> callback); static Scope<Window> create(std::function<void(Event &)> callback);
@ -30,15 +25,15 @@ public:
} }
Window(const Window &) = delete; Window(const Window &) = delete;
Window &operator=(const Window &) = delete; Window &operator=(const Window &) = delete;
virtual ~Window() = default; virtual ~Window() = default;
/* events */
virtual void poll_events() = 0; virtual void poll_events() = 0;
virtual void on_event(const Event &event) = 0; virtual void on_event(const Event &event) = 0;
//======================================== SETTERS ========================================//
virtual void set_properties( virtual void set_properties(
const WindowProperties &properties, const WindowProperties &properties,
bool affectVisibility = false bool affectVisibility = false
@ -55,10 +50,9 @@ public:
b_Closed = true; b_Closed = true;
} }
virtual void set_v_sync(bool vsync, bool toggle = false) = 0; virtual void set_v_sync(bool vsync, bool toggle = false) = 0;
virtual void set_visibility(bool visible, bool toggle = false) = 0;
//======================================== SETTERS ========================================//
//============================== GETTERS ==============================// virtual void set_visibility(bool visible, bool toggle = false) = 0;
inline GraphicsContext *GetGfxContext() const inline GraphicsContext *GetGfxContext() const
{ {
return m_graphics_context.get(); return m_graphics_context.get();
@ -91,9 +85,13 @@ public:
{ {
return m_properties.visible; return m_properties.visible;
} }
//============================== GETTERS ==============================//
protected: protected:
Scope<GraphicsContext> m_graphics_context;
WindowProperties m_properties;
bool b_Closed;
}; };
} // namespace Light } // namespace Light

View file

@ -13,39 +13,36 @@ struct ScopeProfileResult
uint32_t threadID; uint32_t threadID;
}; };
// #todo: add event categories class Instrumentor
// #todo: use ofstream in a separate thread
class Instrumentor /* singleton */
{ {
private:
static Instrumentor *s_Context;
private:
std::ofstream m_output_file_stream;
unsigned int m_current_session_count;
public: public:
static Scope<Instrumentor> create(); static Scope<Instrumentor> create();
static inline void begin_session(const std::string &outputPath) static inline void begin_session(const std::string &outputPath)
{ {
s_Context->begin_session_impl(outputPath); s_context->begin_session_impl(outputPath);
} }
static inline void end_session() static inline void end_session()
{ {
s_Context->end_session_impl(); s_context->end_session_impl();
} }
static inline void submit_scope_profile(const ScopeProfileResult &profileResult) static inline void submit_scope_profile(const ScopeProfileResult &profileResult)
{ {
s_Context->submit_scope_profile_impl(profileResult); s_context->submit_scope_profile_impl(profileResult);
} }
private: private:
static Instrumentor *s_context;
std::ofstream m_output_file_stream;
unsigned int m_current_session_count;
Instrumentor(); Instrumentor();
void begin_session_impl(const std::string &outputPath); void begin_session_impl(const std::string &outputPath);
void end_session_impl(); void end_session_impl();
void submit_scope_profile_impl(const ScopeProfileResult &profileResult); void submit_scope_profile_impl(const ScopeProfileResult &profileResult);
@ -53,13 +50,15 @@ private:
class InstrumentorTimer class InstrumentorTimer
{ {
private:
ScopeProfileResult m_result;
std::chrono::time_point<std::chrono::steady_clock> m_start;
public: public:
InstrumentorTimer(const std::string &scopeName); InstrumentorTimer(const std::string &scopeName);
~InstrumentorTimer(); ~InstrumentorTimer();
private:
ScopeProfileResult m_result;
std::chrono::time_point<std::chrono::steady_clock> m_start;
}; };
} // namespace Light } // namespace Light

View file

@ -25,31 +25,29 @@
namespace Light { namespace Light {
// #todo: extend class logger
class logger /* singleton */
{ {
private:
static logger *s_Context;
private:
Ref<spdlog::logger> m_engine_logger, m_file_logger;
std::string m_log_file_path;
public: public:
static Scope<logger> create(); static Scope<logger> create();
static inline Ref<spdlog::logger> get_engine_logger() static inline Ref<spdlog::logger> get_engine_logger()
{ {
return s_Context->m_engine_logger; return s_context->m_engine_logger;
} }
static inline Ref<spdlog::logger> get_file_logger() static inline Ref<spdlog::logger> get_file_logger()
{ {
return s_Context->m_file_logger; return s_context->m_file_logger;
} }
void log_debug_data(); void log_debug_data();
private: private:
static logger *s_context;
Ref<spdlog::logger> m_engine_logger, m_file_logger;
std::string m_log_file_path;
logger(); logger();
}; };

View file

@ -8,9 +8,6 @@ namespace Light {
class SetCharEvent: public Event class SetCharEvent: public Event
{ {
private:
const unsigned int m_character;
public: public:
SetCharEvent(unsigned int character): m_character(character) SetCharEvent(unsigned int character): m_character(character)
{ {
@ -27,8 +24,13 @@ public:
ss << "CharSet: " << m_character; ss << "CharSet: " << m_character;
return ss.str(); return ss.str();
} }
event_type(SetChar)
event_category(InputEventCategory | KeyboardEventCategory)
event_type(SetChar);
event_category(InputEventCategory | KeyboardEventCategory);
private:
const unsigned int m_character;
}; };
} // namespace Light } // namespace Light

View file

@ -8,9 +8,6 @@ namespace Light {
class KeyPressedEvent: public Event class KeyPressedEvent: public Event
{ {
private:
const int m_key;
public: public:
KeyPressedEvent(int key): m_key(key) KeyPressedEvent(int key): m_key(key)
{ {
@ -27,15 +24,17 @@ public:
ss << "KeyPressed: " << m_key; ss << "KeyPressed: " << m_key;
return ss.str(); return ss.str();
} }
event_type(KeyPressed)
event_category(InputEventCategory | KeyboardEventCategory) event_type(KeyPressed);
event_category(InputEventCategory | KeyboardEventCategory);
private:
const int m_key;
}; };
class KeyRepeatEvent: public Event class KeyRepeatEvent: public Event
{ {
private:
const int m_key;
public: public:
KeyRepeatEvent(int key): m_key(key) KeyRepeatEvent(int key): m_key(key)
{ {
@ -52,15 +51,15 @@ public:
ss << "KeyRepeated: " << m_key; ss << "KeyRepeated: " << m_key;
return ss.str(); return ss.str();
} }
event_type(KeyRepeated) event_type(KeyRepeated);
event_category(InputEventCategory | KeyboardEventCategory) event_category(InputEventCategory | KeyboardEventCategory);
private:
const int m_key;
}; };
class KeyReleasedEvent: public Event class KeyReleasedEvent: public Event
{ {
private:
const int m_key;
public: public:
KeyReleasedEvent(int key): m_key(key) KeyReleasedEvent(int key): m_key(key)
{ {
@ -77,8 +76,12 @@ public:
ss << "KeyReleased: " << m_key; ss << "KeyReleased: " << m_key;
return ss.str(); return ss.str();
} }
event_type(KeyReleased)
event_category(InputEventCategory | KeyboardEventCategory) event_type(KeyReleased);
event_category(InputEventCategory | KeyboardEventCategory);
private:
const int m_key;
}; };
} // namespace Light } // namespace Light

View file

@ -9,9 +9,6 @@ namespace Light {
class MouseMovedEvent: public Event class MouseMovedEvent: public Event
{ {
private:
const glm::vec2 m_position;
public: public:
MouseMovedEvent(float x, float y): m_position(x, y) MouseMovedEvent(float x, float y): m_position(x, y)
{ {
@ -37,15 +34,15 @@ public:
ss << "MouseMoved: " << m_position.x << ", " << m_position.y; ss << "MouseMoved: " << m_position.x << ", " << m_position.y;
return ss.str(); return ss.str();
} }
event_type(MouseMoved) event_type(MouseMoved);
event_category(InputEventCategory | MouseEventCategory) event_category(InputEventCategory | MouseEventCategory);
private:
const glm::vec2 m_position;
}; };
class WheelScrolledEvent: public Event class WheelScrolledEvent: public Event
{ {
private:
const float m_offset;
public: public:
WheelScrolledEvent(float offset): m_offset(offset) WheelScrolledEvent(float offset): m_offset(offset)
{ {
@ -62,15 +59,15 @@ public:
ss << "WheelScrolled: " << m_offset; ss << "WheelScrolled: " << m_offset;
return ss.str(); return ss.str();
} }
event_type(WheelScrolled) event_type(WheelScrolled);
event_category(InputEventCategory | MouseEventCategory) event_category(InputEventCategory | MouseEventCategory);
private:
const float m_offset;
}; };
class ButtonPressedEvent: public Event class ButtonPressedEvent: public Event
{ {
private:
const int m_button;
public: public:
ButtonPressedEvent(int button): m_button(button) ButtonPressedEvent(int button): m_button(button)
{ {
@ -87,15 +84,15 @@ public:
ss << "ButtonPressed: " << m_button; ss << "ButtonPressed: " << m_button;
return ss.str(); return ss.str();
} }
event_type(ButtonPressed) event_type(ButtonPressed);
event_category(InputEventCategory | MouseEventCategory) event_category(InputEventCategory | MouseEventCategory);
private:
const int m_button;
}; };
class ButtonReleasedEvent: public Event class ButtonReleasedEvent: public Event
{ {
private:
const int m_button;
public: public:
ButtonReleasedEvent(int button): m_button(button) ButtonReleasedEvent(int button): m_button(button)
{ {
@ -112,8 +109,12 @@ public:
ss << "ButtonReleased: " << m_button; ss << "ButtonReleased: " << m_button;
return ss.str(); return ss.str();
} }
event_type(ButtonReleased)
event_category(InputEventCategory | MouseEventCategory) event_type(ButtonReleased);
event_category(InputEventCategory | MouseEventCategory);
private:
const int m_button;
}; };
} // namespace Light } // namespace Light

View file

@ -14,15 +14,14 @@ public:
{ {
return "WindowClosedEvent"; return "WindowClosedEvent";
} }
event_type(WindowClosed)
event_category(WindowEventCategory) event_type(WindowClosed);
event_category(WindowEventCategory);
}; };
class WindowMovedEvent: public Event class WindowMovedEvent: public Event
{ {
private:
const glm::ivec2 m_position;
public: public:
WindowMovedEvent(int x, int y): m_position(x, y) WindowMovedEvent(int x, int y): m_position(x, y)
{ {
@ -40,15 +39,17 @@ public:
return ss.str(); return ss.str();
; ;
} }
event_type(WindowMoved)
event_category(WindowEventCategory) event_type(WindowMoved);
event_category(WindowEventCategory);
private:
const glm::ivec2 m_position;
}; };
class WindowResizedEvent: public Event class WindowResizedEvent: public Event
{ {
private:
const glm::uvec2 m_size;
public: public:
WindowResizedEvent(unsigned int width, unsigned int height): m_size(width, height) WindowResizedEvent(unsigned int width, unsigned int height): m_size(width, height)
{ {
@ -65,8 +66,13 @@ public:
ss << "WindowResized: " << m_size.x << ", " << m_size.y; ss << "WindowResized: " << m_size.x << ", " << m_size.y;
return ss.str(); return ss.str();
} }
event_type(WindowResized)
event_category(WindowEventCategory) event_type(WindowResized);
event_category(WindowEventCategory);
private:
const glm::uvec2 m_size;
}; };
class WindowLostFocusEvent: public Event class WindowLostFocusEvent: public Event
@ -76,8 +82,9 @@ public:
{ {
return "WindowLostFocus"; return "WindowLostFocus";
} }
event_type(WindowLostFocus)
event_category(WindowEventCategory) event_type(WindowLostFocus);
event_category(WindowEventCategory);
}; };
class WindowGainFocusEvent: public Event class WindowGainFocusEvent: public Event
@ -87,8 +94,9 @@ public:
{ {
return "WindowGainFocus"; return "WindowGainFocus";
} }
event_type(WindowGainFocus)
event_category(WindowEventCategory) event_type(WindowGainFocus);
event_category(WindowEventCategory);
}; };
} // namespace Light } // namespace Light

View file

@ -9,9 +9,7 @@ namespace Light {
class renderer; class renderer;
class resource_manager; class resource_manager;
class SharedContext; class SharedContext;
class UserInterface; class UserInterface;
class WindowResizedEvent; class WindowResizedEvent;
enum class GraphicsAPI enum class GraphicsAPI
@ -19,41 +17,56 @@ enum class GraphicsAPI
Default = 0, Default = 0,
OpenGL, OpenGL,
DirectX, DirectX,
Vulkan, // :#todo Vulkan,
Metal // :#todo Metal
}; };
class GraphicsContext /* singleton */ class GraphicsContext
{ {
private:
static GraphicsContext* s_Context;
private:
Scope<UserInterface> m_user_interface;
Scope<renderer> m_renderer;
protected:
GraphicsAPI m_graphics_api;
Ref<SharedContext> m_shared_context = nullptr;
public: public:
static Scope<GraphicsContext> create(GraphicsAPI api, GLFWwindow *windowHandle); static Scope<GraphicsContext> create(GraphicsAPI api, GLFWwindow *windowHandle);
GraphicsContext(const GraphicsContext &) = delete; GraphicsContext(const GraphicsContext &) = delete;
GraphicsContext &operator=(const GraphicsContext &) = delete; GraphicsContext &operator=(const GraphicsContext &) = delete;
virtual ~GraphicsContext(); virtual ~GraphicsContext();
virtual void log_debug_data() = 0; virtual void log_debug_data() = 0;
static inline GraphicsAPI get_graphics_api() { return s_Context->m_graphics_api; } static inline GraphicsAPI get_graphics_api()
static inline Ref<SharedContext> get_shared_context() { return s_Context->m_shared_context; } {
return s_context->m_graphics_api;
}
inline renderer* GetRenderer() { return m_renderer.get(); } static inline Ref<SharedContext> get_shared_context()
inline UserInterface* GetUserInterface() { return m_user_interface.get(); } {
return s_context->m_shared_context;
}
inline renderer *GetRenderer()
{
return m_renderer.get();
}
inline UserInterface *GetUserInterface()
{
return m_user_interface.get();
}
protected: protected:
GraphicsContext() = default; GraphicsContext() = default;
GraphicsAPI m_graphics_api;
Ref<SharedContext> m_shared_context = nullptr;
private:
static GraphicsContext *s_context;
Scope<UserInterface> m_user_interface;
Scope<renderer> m_renderer;
}; };
} // namespace Light } // namespace Light

View file

@ -15,14 +15,17 @@ public:
static Scope<RenderCommand> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext); static Scope<RenderCommand> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
RenderCommand(const RenderCommand &) = delete; RenderCommand(const RenderCommand &) = delete;
RenderCommand &operator=(const RenderCommand &) = delete; RenderCommand &operator=(const RenderCommand &) = delete;
virtual ~RenderCommand() = default; virtual ~RenderCommand() = default;
virtual void swap_buffers() = 0; virtual void swap_buffers() = 0;
virtual void clear_back_buffer(const glm::vec4 &clearColor) = 0; virtual void clear_back_buffer(const glm::vec4 &clearColor) = 0;
virtual void draw(unsigned int count) = 0; virtual void draw(unsigned int count) = 0;
virtual void draw_indexed(unsigned int count) = 0; virtual void draw_indexed(unsigned int count) = 0;
virtual void default_target_framebuffer() = 0; virtual void default_target_framebuffer() = 0;

View file

@ -18,34 +18,12 @@ class ConstantBuffer;
class Framebuffer; class Framebuffer;
class RenderCommand; class RenderCommand;
class Texture; class Texture;
class SharedContext; class SharedContext;
class Camera; class Camera;
class WindowResizedEvent; class WindowResizedEvent;
class renderer class renderer
{ {
private:
static renderer *s_Context;
// renderer programs
QuadRendererProgram m_quad_renderer;
TextureRendererProgram m_texture_renderer;
TintedTextureRendererProgram m_tinted_texture_renderer;
// constant buffers
Scope<ConstantBuffer> m_view_projection_buffer;
Scope<RenderCommand> m_render_command;
Scope<Blender> m_blender;
Camera *m_default_framebuffer_camera;
Ref<Framebuffer> m_target_framebuffer;
bool m_should_clear_backbuffer;
public: public:
static Scope<renderer> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext); static Scope<renderer> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
@ -56,36 +34,40 @@ public:
Ref<Texture> texture Ref<Texture> texture
) )
{ {
s_Context->draw_quad_impl(position, size, tint, texture); s_context->draw_quad_impl(position, size, tint, texture);
} }
static inline void draw_quad( static inline void draw_quad(
const glm::vec3 &position, const glm::vec3 &position,
const glm::vec2 &size, const glm::vec2 &size,
const glm::vec4 &tint const glm::vec4 &tint
) )
{ {
s_Context->draw_quad_impl(position, size, tint); s_context->draw_quad_impl(position, size, tint);
} }
static inline void draw_quad( static inline void draw_quad(
const glm::vec3 &position, const glm::vec3 &position,
const glm::vec2 &size, const glm::vec2 &size,
Ref<Texture> texture Ref<Texture> texture
) )
{ {
s_Context->draw_quad_impl(position, size, texture); s_context->draw_quad_impl(position, size, texture);
} }
static void draw_quad(const glm::mat4 &transform, const glm::vec4 &tint, Ref<Texture> texture) static void draw_quad(const glm::mat4 &transform, const glm::vec4 &tint, Ref<Texture> texture)
{ {
s_Context->draw_quad_impl(transform, tint, texture); s_context->draw_quad_impl(transform, tint, texture);
} }
static void draw_quad(const glm::mat4 &transform, const glm::vec4 &tint) static void draw_quad(const glm::mat4 &transform, const glm::vec4 &tint)
{ {
s_Context->draw_quad_impl(transform, tint); s_context->draw_quad_impl(transform, tint);
} }
static void draw_quad(const glm::mat4 &transform, Ref<Texture> texture) static void draw_quad(const glm::mat4 &transform, Ref<Texture> texture)
{ {
s_Context->draw_quad_impl(transform, texture); s_context->draw_quad_impl(transform, texture);
} }
static inline void begin_scene( static inline void begin_scene(
@ -94,11 +76,11 @@ public:
const Ref<Framebuffer> &targetFrameBuffer = nullptr const Ref<Framebuffer> &targetFrameBuffer = nullptr
) )
{ {
s_Context->begin_scene_impl(camera, cameraTransform, targetFrameBuffer); s_context->begin_scene_impl(camera, cameraTransform, targetFrameBuffer);
} }
static inline void end_scene() static inline void end_scene()
{ {
s_Context->end_scene_impl(); s_context->end_scene_impl();
} }
void on_window_resize(const WindowResizedEvent &event); void on_window_resize(const WindowResizedEvent &event);
@ -107,6 +89,26 @@ public:
void end_frame(); void end_frame();
private: private:
static renderer *s_context;
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;
Camera *m_default_framebuffer_camera;
Ref<Framebuffer> m_target_framebuffer;
bool m_should_clear_backbuffer;
renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext); renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
void draw_quad_impl( void draw_quad_impl(
@ -115,11 +117,15 @@ private:
const glm::vec4 &tint, const glm::vec4 &tint,
Ref<Texture> texture Ref<Texture> texture
); );
void draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint); void draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint);
void draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, Ref<Texture> texture); void draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, Ref<Texture> texture);
void draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint, Ref<Texture> texture); void draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint, Ref<Texture> texture);
void draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint); void draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint);
void draw_quad_impl(const glm::mat4 &transform, Ref<Texture> texture); void draw_quad_impl(const glm::mat4 &transform, Ref<Texture> texture);
void begin_scene_impl( void begin_scene_impl(
@ -127,7 +133,9 @@ private:
const glm::mat4 &cameraTransform, const glm::mat4 &cameraTransform,
const Ref<Framebuffer> &targetFrameBuffer = nullptr const Ref<Framebuffer> &targetFrameBuffer = nullptr
); );
void flush_scene(); void flush_scene();
void end_scene_impl(); void end_scene_impl();
}; };

View file

@ -24,24 +24,12 @@ public:
glm::vec4 tint; glm::vec4 tint;
}; };
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
QuadVertexData *m_map_current = nullptr;
QuadVertexData *m_map_end = nullptr;
unsigned int m_quad_count = 0u;
unsigned int m_max_vertices = 0u;
public:
QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext); QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
bool advance(); bool advance();
void map() override; void map() override;
void un_map() override; void un_map() override;
void bind() override; void bind() override;
@ -50,14 +38,33 @@ public:
{ {
return m_map_current; return m_map_current;
} }
inline unsigned int get_quad_count() const inline unsigned int get_quad_count() const
{ {
return m_quad_count; return m_quad_count;
} }
inline constexpr unsigned int get_vertex_size() const inline constexpr unsigned int get_vertex_size() const
{ {
return sizeof(QuadVertexData); return sizeof(QuadVertexData);
} }
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
QuadVertexData *m_map_current = nullptr;
QuadVertexData *m_map_end = nullptr;
unsigned int m_quad_count = 0u;
unsigned int m_max_vertices = 0u;
}; };
} // namespace Light } // namespace Light

View file

@ -9,6 +9,7 @@ class OrthographicCamera;
class RendererProgram class RendererProgram
{ {
virtual void map() = 0; virtual void map() = 0;
virtual void un_map() = 0; virtual void un_map() = 0;
virtual void bind() = 0; virtual void bind() = 0;

View file

@ -10,9 +10,7 @@ class Shader;
class VertexBuffer; class VertexBuffer;
class IndexBuffer; class IndexBuffer;
class VertexLayout; class VertexLayout;
class OrthographicCamera; class OrthographicCamera;
class SharedContext; class SharedContext;
class TextureRendererProgram: RendererProgram class TextureRendererProgram: RendererProgram
@ -24,24 +22,12 @@ public:
glm::vec2 texcoord; glm::vec2 texcoord;
}; };
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
TextureVertexData *m_map_current = nullptr;
TextureVertexData *m_map_end = nullptr;
unsigned int m_quad_count;
unsigned int m_max_vertices;
public:
TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext); TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
bool advance(); bool advance();
void map() override; void map() override;
void un_map() override; void un_map() override;
void bind() override; void bind() override;
@ -60,6 +46,23 @@ public:
{ {
return sizeof(TextureVertexData); return sizeof(TextureVertexData);
} }
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
TextureVertexData *m_map_current = nullptr;
TextureVertexData *m_map_end = nullptr;
unsigned int m_quad_count;
unsigned int m_max_vertices;
}; };
} // namespace Light } // namespace Light

View file

@ -25,19 +25,6 @@ public:
glm::vec2 texcoord; glm::vec2 texcoord;
}; };
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
TintedTextureVertexData *m_map_current = nullptr;
TintedTextureVertexData *m_map_end = nullptr;
unsigned int m_quad_count;
unsigned int m_max_vertices;
public:
TintedTextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext); TintedTextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
bool advance(); bool advance();
@ -61,6 +48,23 @@ public:
{ {
return sizeof(TintedTextureVertexData); return sizeof(TintedTextureVertexData);
} }
private:
Ref<Shader> m_shader;
Ref<VertexBuffer> m_vertex_buffer;
Ref<IndexBuffer> m_index_buffer;
Ref<VertexLayout> m_vertex_layout;
TintedTextureVertexData *m_map_current = nullptr;
TintedTextureVertexData *m_map_end = nullptr;
unsigned int m_quad_count;
unsigned int m_max_vertices;
}; };
} // namespace Light } // namespace Light

View file

@ -19,16 +19,16 @@ public:
GEOMETRY = 3 GEOMETRY = 3
}; };
public:
static Ref<Shader> create( static Ref<Shader> create(
basic_file_handle vertexFile, BasicFileHandle vertexFile,
basic_file_handle pixelFile, BasicFileHandle pixelFile,
Ref<SharedContext> sharedContext Ref<SharedContext> sharedContext
); );
virtual ~Shader() = default; virtual ~Shader() = default;
virtual void bind() = 0; virtual void bind() = 0;
virtual void un_bind() = 0; virtual void un_bind() = 0;
protected: protected:

View file

@ -10,9 +10,17 @@ class SharedContext;
class Texture class Texture
{ {
public: public:
static Ref<Texture> create(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, Ref<SharedContext> sharedContext, const std::string& filePath); static Ref<Texture> create(
unsigned int width,
unsigned int height,
unsigned int components,
unsigned char *pixels,
Ref<SharedContext> sharedContext,
const std::string &filePath
);
Texture(const Texture &) = delete; Texture(const Texture &) = delete;
Texture &operator=(const Texture &) = delete; Texture &operator=(const Texture &) = delete;
virtual ~Texture() = default; virtual ~Texture() = default;
@ -21,13 +29,15 @@ public:
virtual void *get_texture() = 0; virtual void *get_texture() = 0;
inline const std::string& GetFilePath() const { return m_file_path; } inline const std::string &GetFilePath() const
{
protected: return m_file_path;
Texture(const std::string& filePath); }
protected: protected:
std::string m_file_path; std::string m_file_path;
Texture(const std::string &filePath);
}; };
} // namespace Light } // namespace Light

View file

@ -6,7 +6,6 @@ namespace Light {
class VertexBuffer; class VertexBuffer;
class Shader; class Shader;
class SharedContext; class SharedContext;
enum class VertexElementType enum class VertexElementType
@ -42,9 +41,9 @@ public:
); );
virtual ~VertexLayout() = default; virtual ~VertexLayout() = default;
;
virtual void bind() = 0; virtual void bind() = 0;
virtual void un_bind() = 0; virtual void un_bind() = 0;
protected: protected:

View file

@ -8,46 +8,32 @@ namespace Light {
class Event; class Event;
class Input /* singleton */ class Input
{ {
private:
static Input *s_Context;
private:
std::array<bool, 348> m_keyboad_keys;
std::array<bool, 8> m_mouse_buttons;
glm::vec2 m_mouse_position;
glm::vec2 m_mouse_delta;
float m_mouse_wheel_delta;
bool m_user_interface_events;
bool m_game_events;
public: public:
static Scope<Input> create(); static Scope<Input> create();
static inline void receive_user_interface_events(bool receive, bool toggle = false) static inline void receive_user_interface_events(bool receive, bool toggle = false)
{ {
s_Context->receive_user_interface_events_impl(receive, toggle); s_context->receive_user_interface_events_impl(receive, toggle);
} }
static inline void receive_game_events(bool receive, bool toggle = false) static inline void receive_game_events(bool receive, bool toggle = false)
{ {
s_Context->receieve_game_events_impl(receive, toggle); s_context->receieve_game_events_impl(receive, toggle);
} }
static inline bool get_keyboard_key(int code) static inline bool get_keyboard_key(int code)
{ {
return s_Context->m_keyboad_keys[code]; return s_context->m_keyboad_keys[code];
} }
static inline bool get_mouse_button(int code) static inline bool get_mouse_button(int code)
{ {
return s_Context->m_mouse_buttons[code]; return s_context->m_mouse_buttons[code];
} }
static inline const glm::vec2 &GetMousePosition(int code) static inline const glm::vec2 &get_mouse_position(int code)
{ {
return s_Context->m_mouse_position; return s_context->m_mouse_position;
} }
void on_event(const Event &inputEvent); void on_event(const Event &inputEvent);
@ -62,9 +48,26 @@ public:
} }
private: private:
static Input *s_context;
std::array<bool, 348> m_keyboad_keys;
std::array<bool, 8> m_mouse_buttons;
glm::vec2 m_mouse_position;
glm::vec2 m_mouse_delta;
float m_mouse_wheel_delta;
bool m_user_interface_events;
bool m_game_events;
Input(); Input();
void receive_user_interface_events_impl(bool receive, bool toggle = false); void receive_user_interface_events_impl(bool receive, bool toggle = false);
void receieve_game_events_impl(bool receive, bool toggle = false); void receieve_game_events_impl(bool receive, bool toggle = false);
void restart_input_state(); void restart_input_state();

View file

@ -11,16 +11,10 @@ class MouseMovedEvent;
class ButtonPressedEvent; class ButtonPressedEvent;
class ButtonReleasedEvent; class ButtonReleasedEvent;
class WheelScrolledEvent; class WheelScrolledEvent;
// keyboard
// key
class KeyPressedEvent; class KeyPressedEvent;
class KeyRepeatEvent; class KeyRepeatEvent;
class KeyReleasedEvent; class KeyReleasedEvent;
// char
class SetCharEvent; class SetCharEvent;
// window
class WindowClosedEvent; class WindowClosedEvent;
class WindowResizedEvent; class WindowResizedEvent;
class WindowMovedEvent; class WindowMovedEvent;
@ -29,19 +23,15 @@ class WindowGainFocusEvent;
class Layer class Layer
{ {
protected:
std::string m_layer_name;
public: public:
Layer(const std::string &name); Layer(const std::string &name);
virtual ~Layer() = default; virtual ~Layer() = default;
inline const std::string &GetName() const const std::string &GetName() const
{ {
return m_layer_name; return m_layer_name;
} }
/* update */
virtual void on_update(float deltaTime) virtual void on_update(float deltaTime)
{ {
} }
@ -56,67 +46,68 @@ public:
bool on_event(const Event &event); bool on_event(const Event &event);
protected: protected:
/* mouse */ std::string m_layer_name;
// cursor
virtual bool on_mouse_moved(const MouseMovedEvent &event) virtual bool on_mouse_moved(const MouseMovedEvent &event)
{ {
return false; return false;
} }
// button
virtual bool on_button_pressed(const ButtonPressedEvent &event) virtual bool on_button_pressed(const ButtonPressedEvent &event)
{ {
return false; return false;
} }
virtual bool on_button_released(const ButtonReleasedEvent &event) virtual bool on_button_released(const ButtonReleasedEvent &event)
{ {
return false; return false;
} }
// wheel
virtual bool on_wheel_scrolled(const WheelScrolledEvent &event) virtual bool on_wheel_scrolled(const WheelScrolledEvent &event)
{ {
return false; return false;
} }
/* keyboard */
// key
virtual bool on_key_pressed(const KeyPressedEvent &event) virtual bool on_key_pressed(const KeyPressedEvent &event)
{ {
return false; return false;
} }
virtual bool on_key_repeat(const KeyRepeatEvent &event) virtual bool on_key_repeat(const KeyRepeatEvent &event)
{ {
return false; return false;
} }
virtual bool on_key_released(const KeyReleasedEvent &event) virtual bool on_key_released(const KeyReleasedEvent &event)
{ {
return false; return false;
} }
// char
virtual bool on_set_char(const SetCharEvent &event) virtual bool on_set_char(const SetCharEvent &event)
{ {
return false; return false;
} }
/* window */
// termination
virtual bool on_window_closed(const WindowClosedEvent &event) virtual bool on_window_closed(const WindowClosedEvent &event)
{ {
return false; return false;
} }
// size/position
virtual bool on_window_resized(const WindowResizedEvent &event) virtual bool on_window_resized(const WindowResizedEvent &event)
{ {
return false; return false;
} }
virtual bool on_window_moved(const WindowMovedEvent &event) virtual bool on_window_moved(const WindowMovedEvent &event)
{ {
return false; return false;
} }
// focus
virtual bool on_window_lost_focus(const WindowLostFocusEvent &event) virtual bool on_window_lost_focus(const WindowLostFocusEvent &event)
{ {
return false; return false;
} }
virtual bool on_window_gain_focus(const WindowGainFocusEvent &event) virtual bool on_window_gain_focus(const WindowGainFocusEvent &event)
{ {
return false; return false;

View file

@ -5,20 +5,10 @@
namespace Light { namespace Light {
class Layer; class Layer;
class Event; class Event;
class LayerStack /* singleton */ class LayerStack /* singleton */
{ {
private:
static LayerStack *s_Context;
private:
std::vector<Layer *> m_layers;
std::vector<Layer *>::iterator m_begin;
std::vector<Layer *>::iterator m_end;
public: public:
static Scope<LayerStack> create(); static Scope<LayerStack> create();
@ -28,16 +18,16 @@ public:
template<typename t, typename... Args> template<typename t, typename... Args>
static inline void emplace_layer(Args &&...args) static inline void emplace_layer(Args &&...args)
{ {
s_Context->attach_layer_impl(new t((args)...)); s_context->attach_layer_impl(new t((args)...));
} }
static inline void attach_layer(Layer *layer) static inline void attach_layer(Layer *layer)
{ {
s_Context->attach_layer_impl(layer); s_context->attach_layer_impl(layer);
} }
static inline void detach_layer(Layer *layer) static inline void detach_layer(Layer *layer)
{ {
s_Context->detach_layer_impl(layer); s_context->detach_layer_impl(layer);
} }
inline bool is_empty() inline bool is_empty()
@ -49,23 +39,35 @@ public:
{ {
return m_layers.begin(); return m_layers.begin();
} }
std::vector<Layer *>::iterator end() std::vector<Layer *>::iterator end()
{ {
return m_layers.end(); return m_layers.end();
} }
std::vector<Layer *>::reverse_iterator rbegin() std::vector<Layer *>::reverse_iterator rbegin()
{ {
return m_layers.rbegin(); return m_layers.rbegin();
} }
std::vector<Layer *>::reverse_iterator rend() std::vector<Layer *>::reverse_iterator rend()
{ {
return m_layers.rend(); return m_layers.rend();
} }
private: private:
static LayerStack *s_context;
std::vector<Layer *> m_layers;
std::vector<Layer *>::iterator m_begin;
std::vector<Layer *>::iterator m_end;
LayerStack(); LayerStack();
void attach_layer_impl(Layer *layer); void attach_layer_impl(Layer *layer);
void detach_layer_impl(Layer *layer); void detach_layer_impl(Layer *layer);
}; };

View file

@ -11,6 +11,13 @@ class dxSharedContext;
class dxBlender: public Blender class dxBlender: public Blender
{ {
public:
dxBlender(Ref<dxSharedContext> sharedContext);
void enable(BlendFactor srcFactor, BlendFactor dstFactor) override;
void disable() override;
private: private:
Ref<dxSharedContext> m_context; Ref<dxSharedContext> m_context;
@ -19,12 +26,6 @@ private:
Microsoft::WRL::ComPtr<ID3D11BlendState> m_blend_state; Microsoft::WRL::ComPtr<ID3D11BlendState> m_blend_state;
D3D11_BLEND_DESC m_desc; D3D11_BLEND_DESC m_desc;
public:
dxBlender(Ref<dxSharedContext> sharedContext);
void enable(BlendFactor srcFactor, BlendFactor dstFactor) override;
void disable() override;
}; };
} // namespace Light } // namespace Light

View file

@ -9,17 +9,8 @@ namespace Light {
class dxSharedContext; class dxSharedContext;
//========== CONSTANT_BUFFER ==========//
class dxConstantBuffer: public ConstantBuffer class dxConstantBuffer: public ConstantBuffer
{ {
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer;
D3D11_MAPPED_SUBRESOURCE m_map;
unsigned int m_index;
public: public:
dxConstantBuffer( dxConstantBuffer(
ConstantBufferIndex index, ConstantBufferIndex index,
@ -30,20 +21,21 @@ public:
void bind() override; void bind() override;
void *map() override; void *map() override;
void un_map() override;
};
//========== VERTEX_BUFFER ==========// void un_map() override;
class dxVertexBuffer: public VertexBuffer
{
private: private:
Ref<dxSharedContext> m_context; Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer; Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer;
D3D11_MAPPED_SUBRESOURCE m_map; D3D11_MAPPED_SUBRESOURCE m_map;
unsigned int m_stride; unsigned int m_index;
};
class dxVertexBuffer: public VertexBuffer
{
public: public:
dxVertexBuffer( dxVertexBuffer(
float *vertices, float *vertices,
@ -51,29 +43,42 @@ public:
unsigned int count, unsigned int count,
Ref<dxSharedContext> sharedContext Ref<dxSharedContext> sharedContext
); );
~dxVertexBuffer(); ~dxVertexBuffer();
void bind() override; void bind() override;
void un_bind() override; void un_bind() override;
void *map() override; void *map() override;
void un_map() override;
};
//========== INDEX_BUFFER ==========// void un_map() override;
class dxIndexBuffer: public IndexBuffer
{
private: private:
Ref<dxSharedContext> m_context; Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer; Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer;
D3D11_MAPPED_SUBRESOURCE m_map;
unsigned int m_stride;
};
class dxIndexBuffer: public IndexBuffer
{
public: public:
dxIndexBuffer(unsigned int *indices, unsigned int count, Ref<dxSharedContext> sharedContext); dxIndexBuffer(unsigned int *indices, unsigned int count, Ref<dxSharedContext> sharedContext);
~dxIndexBuffer(); ~dxIndexBuffer();
void bind() override; void bind() override;
void un_bind() override; void un_bind() override;
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_buffer;
}; };
} // namespace Light } // namespace Light

View file

@ -11,17 +11,6 @@ class dxSharedContext;
class dxFramebuffer: public Framebuffer class dxFramebuffer: public Framebuffer
{ {
private:
Ref<dxSharedContext> m_context;
FramebufferSpecification m_specification;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_render_target_view;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_color_attachment;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_depth_stencil_attachment;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_shader_resource_view;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depth_stencil_view;
public: public:
dxFramebuffer( dxFramebuffer(
const FramebufferSpecification &specification, const FramebufferSpecification &specification,
@ -34,9 +23,25 @@ public:
} }
void bind_as_target(const glm::vec4 &clearColor) override; void bind_as_target(const glm::vec4 &clearColor) override;
void bind_as_resource() override; void bind_as_resource() override;
void resize(const glm::uvec2 &size) override; void resize(const glm::uvec2 &size) override;
private:
Ref<dxSharedContext> m_context;
FramebufferSpecification m_specification;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_render_target_view;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_color_attachment;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_depth_stencil_attachment;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_shader_resource_view;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depth_stencil_view;
}; };
} // namespace Light } // namespace Light

View file

@ -11,19 +11,20 @@ namespace Light {
class dxGraphicsContext: public GraphicsContext class dxGraphicsContext: public GraphicsContext
{ {
private:
GLFWwindow *m_window_handle;
Microsoft::WRL::ComPtr<ID3D11Debug> m_debug_interface;
public: public:
dxGraphicsContext(GLFWwindow *windowHandle); dxGraphicsContext(GLFWwindow *windowHandle);
virtual void log_debug_data() override; virtual void log_debug_data() override;
private: private:
GLFWwindow *m_window_handle;
Microsoft::WRL::ComPtr<ID3D11Debug> m_debug_interface;
void setup_device_and_swap_chain(GLFWwindow *windowHandle); void setup_device_and_swap_chain(GLFWwindow *windowHandle);
void setup_render_targets(); void setup_render_targets();
void setup_debug_interface(); void setup_debug_interface();
}; };

View file

@ -11,16 +11,15 @@ class dxSharedContext;
class dxRenderCommand: public RenderCommand class dxRenderCommand: public RenderCommand
{ {
private:
Ref<dxSharedContext> m_context;
public: public:
dxRenderCommand(Ref<dxSharedContext> sharedContext); dxRenderCommand(Ref<dxSharedContext> sharedContext);
virtual void swap_buffers() override; virtual void swap_buffers() override;
virtual void clear_back_buffer(const glm::vec4 &clearColor) override; virtual void clear_back_buffer(const glm::vec4 &clearColor) override;
virtual void draw(unsigned int count) override; virtual void draw(unsigned int count) override;
virtual void draw_indexed(unsigned int count) override; virtual void draw_indexed(unsigned int count) override;
virtual void default_target_framebuffer() override; virtual void default_target_framebuffer() override;
@ -33,6 +32,8 @@ public:
) override; ) override;
private: private:
Ref<dxSharedContext> m_context;
void set_resolution(unsigned int width, unsigned int height); void set_resolution(unsigned int width, unsigned int height);
}; };

View file

@ -12,29 +12,32 @@ class dxSharedContext;
class dxShader: public Shader class dxShader: public Shader
{ {
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertex_shader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixel_shader;
Microsoft::WRL::ComPtr<ID3DBlob> m_vertex_blob;
public: public:
dxShader( dxShader(
basic_file_handle vertexFile, BasicFileHandle vertexFile,
basic_file_handle pixelFile, BasicFileHandle pixelFile,
Ref<dxSharedContext> sharedContext Ref<dxSharedContext> sharedContext
); );
~dxShader(); ~dxShader();
void bind() override; void bind() override;
void un_bind() override; void un_bind() override;
inline Microsoft::WRL::ComPtr<ID3DBlob> get_vertex_blob() inline Microsoft::WRL::ComPtr<ID3DBlob> get_vertex_blob()
{ {
return m_vertex_blob; return m_vertex_blob;
} }
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertex_shader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixel_shader;
Microsoft::WRL::ComPtr<ID3DBlob> m_vertex_blob;
}; };
} // namespace Light } // namespace Light

View file

@ -9,25 +9,22 @@ namespace Light {
class dxSharedContext: public SharedContext class dxSharedContext: public SharedContext
{ {
private:
Microsoft::WRL::ComPtr<ID3D11Device> m_device = nullptr;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_deviceContext = nullptr;
Microsoft::WRL::ComPtr<IDXGISwapChain> m_swap_chain = nullptr;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_render_target_view = nullptr;
public: public:
inline Microsoft::WRL::ComPtr<ID3D11Device> get_device() inline Microsoft::WRL::ComPtr<ID3D11Device> get_device()
{ {
return m_device; return m_device;
} }
inline Microsoft::WRL::ComPtr<ID3D11DeviceContext> get_device_context() inline Microsoft::WRL::ComPtr<ID3D11DeviceContext> get_device_context()
{ {
return m_deviceContext; return m_deviceContext;
} }
inline Microsoft::WRL::ComPtr<IDXGISwapChain> get_swap_chain() inline Microsoft::WRL::ComPtr<IDXGISwapChain> get_swap_chain()
{ {
return m_swap_chain; return m_swap_chain;
} }
inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView> get_render_target_view() inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView> get_render_target_view()
{ {
return m_render_target_view; return m_render_target_view;
@ -37,18 +34,30 @@ public:
{ {
return m_device; return m_device;
} }
inline Microsoft::WRL::ComPtr<ID3D11DeviceContext> &GetDeviceContextRef() inline Microsoft::WRL::ComPtr<ID3D11DeviceContext> &GetDeviceContextRef()
{ {
return m_deviceContext; return m_deviceContext;
} }
inline Microsoft::WRL::ComPtr<IDXGISwapChain> &GetSwapChainRef() inline Microsoft::WRL::ComPtr<IDXGISwapChain> &GetSwapChainRef()
{ {
return m_swap_chain; return m_swap_chain;
} }
inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView> &GetRenderTargetViewRef() inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView> &GetRenderTargetViewRef()
{ {
return m_render_target_view; return m_render_target_view;
} }
private:
Microsoft::WRL::ComPtr<ID3D11Device> m_device = nullptr;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_deviceContext = nullptr;
Microsoft::WRL::ComPtr<IDXGISwapChain> m_swap_chain = nullptr;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_render_target_view = nullptr;
}; };
} // namespace Light } // namespace Light

View file

@ -11,13 +11,6 @@ class dxSharedContext;
class dxTexture: public Texture class dxTexture: public Texture
{ {
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture_2d;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_shader_resource_view;
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_sampler_state;
public: public:
dxTexture( dxTexture(
unsigned int width, unsigned int width,
@ -29,6 +22,15 @@ public:
); );
void bind(unsigned int slot = 0u) override; void bind(unsigned int slot = 0u) override;
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture_2d;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_shader_resource_view;
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_sampler_state;
}; };
} // namespace Light } // namespace Light

View file

@ -15,12 +15,14 @@ class dxUserInterface: public UserInterface
{ {
public: public:
dxUserInterface() = default; dxUserInterface() = default;
~dxUserInterface(); ~dxUserInterface();
void platform_implementation(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext) void platform_implementation(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
override; override;
void begin() override; void begin() override;
void end() override; void end() override;
void log_debug_data() override; void log_debug_data() override;

View file

@ -8,29 +8,29 @@
namespace Light { namespace Light {
class Shader; class Shader;
class dxSharedContext; class dxSharedContext;
class dxVertexLayout: public VertexLayout class dxVertexLayout: public VertexLayout
{ {
private:
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_input_layout;
public: public:
dxVertexLayout( dxVertexLayout(
Ref<Shader> shader, Ref<Shader> shader,
const std::vector<std::pair<std::string, VertexElementType>> &elements, const std::vector<std::pair<std::string, VertexElementType>> &elements,
Ref<dxSharedContext> sharedContext Ref<dxSharedContext> sharedContext
); );
~dxVertexLayout(); ~dxVertexLayout();
void bind() override; void bind() override;
void un_bind() override; void un_bind() override;
private: private:
DXGI_FORMAT get_dxgi_format(VertexElementType type); DXGI_FORMAT get_dxgi_format(VertexElementType type);
Ref<dxSharedContext> m_context;
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_input_layout;
}; };
} // namespace Light } // namespace Light

View file

@ -7,14 +7,15 @@ namespace Light {
class glBlender: public Blender class glBlender: public Blender
{ {
private:
std::unordered_map<BlendFactor, unsigned int> m_factor_map;
public: public:
glBlender(); glBlender();
void enable(BlendFactor srcFactor, BlendFactor dstFactor) override; void enable(BlendFactor srcFactor, BlendFactor dstFactor) override;
void disable() override; void disable() override;
private:
std::unordered_map<BlendFactor, unsigned int> m_factor_map;
}; };
} // namespace Light } // namespace Light

View file

@ -5,52 +5,57 @@
namespace Light { namespace Light {
//========== CONSTANT_BUFFER ==========//
class glConstantBuffer: public ConstantBuffer class glConstantBuffer: public ConstantBuffer
{ {
private:
unsigned int m_buffer_id;
unsigned int m_index;
public: public:
glConstantBuffer(ConstantBufferIndex index, unsigned int size); glConstantBuffer(ConstantBufferIndex index, unsigned int size);
~glConstantBuffer(); ~glConstantBuffer();
void bind() override; void bind() override;
void *map() override; void *map() override;
void un_map() override;
};
//========== VERTEX_BUFFER ==========// void un_map() override;
class glVertexBuffer: public VertexBuffer
{
private: private:
unsigned int m_buffer_id; unsigned int m_buffer_id;
unsigned int m_index;
};
class glVertexBuffer: public VertexBuffer
{
public: public:
glVertexBuffer(float *vertices, unsigned int stride, unsigned int count); glVertexBuffer(float *vertices, unsigned int stride, unsigned int count);
~glVertexBuffer(); ~glVertexBuffer();
void bind() override; void bind() override;
void un_bind() override; void un_bind() override;
void *map() override; void *map() override;
void un_map() override;
};
//========== INDEX_BUFFER ==========// void un_map() override;
class glIndexBuffer: public IndexBuffer
{
private: private:
unsigned int m_buffer_id; unsigned int m_buffer_id;
};
class glIndexBuffer: public IndexBuffer
{
public: public:
glIndexBuffer(unsigned int *indices, unsigned int count); glIndexBuffer(unsigned int *indices, unsigned int count);
~glIndexBuffer(); ~glIndexBuffer();
void bind() override; void bind() override;
void un_bind() override; void un_bind() override;
private:
unsigned int m_buffer_id;
}; };
} // namespace Light } // namespace Light

View file

@ -7,17 +7,13 @@ namespace Light {
class glFramebuffer: public Framebuffer class glFramebuffer: public Framebuffer
{ {
private:
FramebufferSpecification m_specification;
unsigned int m_buffer_id;
unsigned int m_color_attachment_id, m_depth_stencil_attachment_id;
public: public:
glFramebuffer(const FramebufferSpecification &specification); glFramebuffer(const FramebufferSpecification &specification);
~glFramebuffer(); ~glFramebuffer();
void bind_as_target(const glm::vec4 &clearColor) override; void bind_as_target(const glm::vec4 &clearColor) override;
void bind_as_resource() override; void bind_as_resource() override;
void resize(const glm::uvec2 &size) override; void resize(const glm::uvec2 &size) override;
@ -26,6 +22,15 @@ public:
{ {
return (void *)m_color_attachment_id; return (void *)m_color_attachment_id;
} }
private:
FramebufferSpecification m_specification;
unsigned int m_buffer_id;
unsigned int m_color_attachment_id;
unsigned int m_depth_stencil_attachment_id;
}; };
} // namespace Light } // namespace Light

View file

@ -9,15 +9,14 @@ namespace Light {
class glGraphicsContext: public GraphicsContext class glGraphicsContext: public GraphicsContext
{ {
private:
GLFWwindow *m_window_handle;
public: public:
glGraphicsContext(GLFWwindow *windowHandle); glGraphicsContext(GLFWwindow *windowHandle);
void log_debug_data() override; void log_debug_data() override;
private: private:
GLFWwindow *m_window_handle;
void set_debug_message_callback(); void set_debug_message_callback();
}; };

View file

@ -9,22 +9,24 @@ namespace Light {
class glRenderCommand: public RenderCommand class glRenderCommand: public RenderCommand
{ {
private:
GLFWwindow *m_window_handle;
public: public:
glRenderCommand(GLFWwindow *windowHandle); glRenderCommand(GLFWwindow *windowHandle);
void swap_buffers() override; void swap_buffers() override;
void clear_back_buffer(const glm::vec4 &clearColor) override; void clear_back_buffer(const glm::vec4 &clearColor) override;
void draw(unsigned int count) override; void draw(unsigned int count) override;
void draw_indexed(unsigned int count) override; void draw_indexed(unsigned int count) override;
void default_target_framebuffer() override; void default_target_framebuffer() override;
void set_viewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height) void set_viewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
override; override;
private:
GLFWwindow *m_window_handle;
}; };
} // namespace Light } // namespace Light

View file

@ -8,20 +8,19 @@ namespace Light {
class glShader: public Shader class glShader: public Shader
{ {
private:
unsigned int m_shader_id;
public: public:
glShader(basic_file_handle vertexFile, basic_file_handle pixelFile); glShader(BasicFileHandle vertexFile, BasicFileHandle pixelFile);
~glShader(); ~glShader();
void bind() override; void bind() override;
void un_bind() override; void un_bind() override;
private: private:
// shaderc::SpvCompilationResult compile_glsl(basic_file_handle file, Shader::Stage stage);
unsigned int compile_shader(std::string source, Shader::Stage stage); unsigned int compile_shader(std::string source, Shader::Stage stage);
unsigned int m_shader_id;
}; };
} // namespace Light } // namespace Light

View file

@ -7,16 +7,23 @@ namespace Light {
class glTexture: public Texture class glTexture: public Texture
{ {
private:
unsigned int m_texture_id;
public: public:
glTexture(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, const std::string& filePath); glTexture(
unsigned int width,
unsigned int height,
unsigned int components,
unsigned char *pixels,
const std::string &filePath
);
~glTexture(); ~glTexture();
void bind(unsigned int slot = 0u) override; void bind(unsigned int slot = 0u) override;
void *get_texture() override; void *get_texture() override;
private:
unsigned int m_texture_id;
}; };
} // namespace Light } // namespace Light

View file

@ -9,20 +9,22 @@ namespace Light {
class glUserInterface: public UserInterface class glUserInterface: public UserInterface
{ {
private:
GLFWwindow *m_window_handle;
public: public:
glUserInterface() = default; glUserInterface() = default;
~glUserInterface(); ~glUserInterface();
void platform_implementation(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext) void platform_implementation(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
override; override;
void begin() override; void begin() override;
void end() override; void end() override;
void log_debug_data() override; void log_debug_data() override;
private:
GLFWwindow *m_window_handle;
}; };
} // namespace Light } // namespace Light

View file

@ -10,28 +10,32 @@ class VertexBuffer;
struct glVertexElementDesc struct glVertexElementDesc
{ {
unsigned int type; unsigned int type;
unsigned int count; unsigned int count;
unsigned int typeSize; unsigned int typeSize;
unsigned int offset; unsigned int offset;
}; };
class glVertexLayout: public VertexLayout class glVertexLayout: public VertexLayout
{ {
private:
unsigned int m_array_id;
public: public:
glVertexLayout( glVertexLayout(
Ref<VertexBuffer> buffer, Ref<VertexBuffer> buffer,
const std::vector<std::pair<std::string, VertexElementType>> &elements const std::vector<std::pair<std::string, VertexElementType>> &elements
); );
~glVertexLayout(); ~glVertexLayout();
void bind() override; void bind() override;
void un_bind() override; void un_bind() override;
private: private:
glVertexElementDesc get_element_desc(VertexElementType type, unsigned int offset); glVertexElementDesc get_element_desc(VertexElementType type, unsigned int offset);
unsigned int m_array_id;
}; };
} // namespace Light } // namespace Light

View file

@ -12,20 +12,15 @@ class WindowResizedEvent;
class lWindow: public Window class lWindow: public Window
{ {
private:
GLFWwindow *m_handle;
std::function<void(Event &)> m_event_callback;
public: public:
lWindow(std::function<void(Event &)> callback); lWindow(std::function<void(Event &)> callback);
~lWindow(); ~lWindow();
/* events */
void poll_events() override; void poll_events() override;
void on_event(const Event &event) override; void on_event(const Event &event) override;
//======================================== SETTERS ========================================//
void set_properties(const WindowProperties &properties, bool overrideVisibility = false) void set_properties(const WindowProperties &properties, bool overrideVisibility = false)
override; override;
@ -34,10 +29,14 @@ public:
void set_size(const glm::uvec2 &size, bool additive = false) override; void set_size(const glm::uvec2 &size, bool additive = false) override;
void set_v_sync(bool vsync, bool toggle = false) override; void set_v_sync(bool vsync, bool toggle = false) override;
void set_visibility(bool visible, bool toggle = false) override; void set_visibility(bool visible, bool toggle = false) override;
//======================================== SETTERS ========================================//
private: private:
GLFWwindow *m_handle;
std::function<void(Event &)> m_event_callback;
void on_window_resize(const WindowResizedEvent &event); void on_window_resize(const WindowResizedEvent &event);
void bind_glfw_events(); void bind_glfw_events();

View file

@ -12,20 +12,15 @@ class WindowResizedEvent;
class wWindow: public Window class wWindow: public Window
{ {
private:
GLFWwindow *m_handle;
std::function<void(Event &)> m_event_callback;
public: public:
wWindow(std::function<void(Event &)> callback); wWindow(std::function<void(Event &)> callback);
~wWindow(); ~wWindow();
/* events */
void poll_events() override; void poll_events() override;
void on_event(const Event &event) override; void on_event(const Event &event) override;
//======================================== SETTERS ========================================//
void set_properties(const WindowProperties &properties, bool overrideVisibility = false) void set_properties(const WindowProperties &properties, bool overrideVisibility = false)
override; override;
@ -34,10 +29,14 @@ public:
void set_size(const glm::uvec2 &size, bool additive = false) override; void set_size(const glm::uvec2 &size, bool additive = false) override;
void set_v_sync(bool vsync, bool toggle = false) override; void set_v_sync(bool vsync, bool toggle = false) override;
void set_visibility(bool visible, bool toggle = false) override; void set_visibility(bool visible, bool toggle = false) override;
//======================================== SETTERS ========================================//
private: private:
GLFWwindow *m_handle;
std::function<void(Event &)> m_event_callback;
void on_window_resize(const WindowResizedEvent &event); void on_window_resize(const WindowResizedEvent &event);
void bind_glfw_events(); void bind_glfw_events();

View file

@ -8,10 +8,8 @@ namespace Light {
struct CameraComponent struct CameraComponent
{ {
SceneCamera camera;
bool isPrimary;
CameraComponent() = default; CameraComponent() = default;
CameraComponent(const CameraComponent &) = default; CameraComponent(const CameraComponent &) = default;
CameraComponent(SceneCamera _camera, bool _isPrimary = false) CameraComponent(SceneCamera _camera, bool _isPrimary = false)
@ -24,6 +22,10 @@ struct CameraComponent
{ {
return camera; return camera;
} }
SceneCamera camera;
bool isPrimary;
}; };
} // namespace Light } // namespace Light

View file

@ -7,9 +7,8 @@ namespace Light {
struct NativeScriptComponent struct NativeScriptComponent
{ {
NativeScript *instance;
NativeScript *(*CreateInstance)(); NativeScript *(*CreateInstance)();
void (*DestroyInstance)(NativeScriptComponent *); void (*DestroyInstance)(NativeScriptComponent *);
template<typename t> template<typename t>
@ -23,6 +22,8 @@ struct NativeScriptComponent
nsc->instance = nullptr; nsc->instance = nullptr;
}; };
} }
NativeScript *instance;
}; };
} // namespace Light } // namespace Light

View file

@ -7,14 +7,11 @@ namespace Light {
class NativeScript class NativeScript
{ {
public:
friend class Scene; friend class Scene;
private:
Entity m_entity;
unsigned int m_unique_identifier = 0; // :#todo
public:
NativeScript() = default; NativeScript() = default;
virtual ~NativeScript() = default; virtual ~NativeScript() = default;
inline unsigned int get_uid() const inline unsigned int get_uid() const
@ -32,12 +29,19 @@ protected:
virtual void on_create() virtual void on_create()
{ {
} }
virtual void on_destroy() virtual void on_destroy()
{ {
} }
virtual void on_update(float ts) virtual void on_update(float ts)
{ {
} }
private:
Entity m_entity;
unsigned int m_unique_identifier = 0; // :#todo
}; };
} // namespace Light } // namespace Light

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <engine/base/base.hpp> #include <engine/base/base.hpp>
#include <glm/glm.hpp>
namespace Light { namespace Light {
@ -8,10 +9,8 @@ class Texture;
struct SpriteRendererComponent struct SpriteRendererComponent
{ {
Ref<Texture> texture;
glm::vec4 tint;
SpriteRendererComponent() = default; SpriteRendererComponent() = default;
SpriteRendererComponent(const SpriteRendererComponent &) = default; SpriteRendererComponent(const SpriteRendererComponent &) = default;
SpriteRendererComponent( SpriteRendererComponent(
@ -27,6 +26,10 @@ struct SpriteRendererComponent
{ {
return texture; return texture;
} }
Ref<Texture> texture;
glm::vec4 tint;
}; };
} // namespace Light } // namespace Light

View file

@ -6,9 +6,8 @@ namespace Light {
struct TagComponent struct TagComponent
{ {
std::string tag = "Unnamed";
TagComponent() = default; TagComponent() = default;
TagComponent(const TagComponent &) = default; TagComponent(const TagComponent &) = default;
TagComponent(const std::string &_tag): tag(_tag) TagComponent(const std::string &_tag): tag(_tag)
@ -19,10 +18,13 @@ struct TagComponent
{ {
return tag; return tag;
} }
operator const std::string &() const operator const std::string &() const
{ {
return tag; return tag;
} }
std::string tag = "Unnamed";
}; };
} // namespace Light } // namespace Light

View file

@ -11,10 +11,6 @@ namespace Light {
struct TransformComponent struct TransformComponent
{ {
glm::vec3 translation;
glm::vec3 scale;
glm::vec3 rotation;
TransformComponent(const TransformComponent &) = default; TransformComponent(const TransformComponent &) = default;
TransformComponent( TransformComponent(
@ -39,6 +35,12 @@ struct TransformComponent
{ {
return get_transform(); return get_transform();
} }
glm::vec3 translation;
glm::vec3 scale;
glm::vec3 rotation;
}; };
} // namespace Light } // namespace Light

View file

@ -7,12 +7,13 @@ namespace Light {
struct UUIDComponent struct UUIDComponent
{ {
UUID uuid;
UUIDComponent(UUID _uuid): uuid(_uuid) UUIDComponent(UUID _uuid): uuid(_uuid)
{ {
} }
UUIDComponent(const UUIDComponent &) = default; UUIDComponent(const UUIDComponent &) = default;
UUID uuid;
}; };
} // namespace Light } // namespace Light

View file

@ -9,10 +9,6 @@ namespace Light {
class Entity class Entity
{ {
private:
entt::entity m_handle;
Scene *m_scene;
public: public:
Entity(entt::entity handle = entt::null, Scene *registry = nullptr); Entity(entt::entity handle = entt::null, Scene *registry = nullptr);
@ -56,6 +52,10 @@ public:
{ {
return (uint32_t)m_handle; return (uint32_t)m_handle;
} }
private:
entt::entity m_handle;
Scene *m_scene;
}; };
} // namespace Light } // namespace Light

View file

@ -9,26 +9,19 @@
namespace Light { namespace Light {
class Entity; class Entity;
class Framebuffer; class Framebuffer;
class Scene class Scene
{ {
private:
friend class Entity;
friend class SceneSerializer;
friend class SceneHierarchyPanel;
private:
entt::registry m_registry;
public: public:
Scene(); Scene();
~Scene(); ~Scene();
void on_create(); void on_create();
void on_update(float deltaTime); void on_update(float deltaTime);
void on_render(const Ref<Framebuffer> &targetFrameBuffer = nullptr); void on_render(const Ref<Framebuffer> &targetFrameBuffer = nullptr);
Entity create_entity( Entity create_entity(
@ -39,6 +32,12 @@ public:
Entity get_entity_by_tag(const std::string &tag); Entity get_entity_by_tag(const std::string &tag);
private: private:
friend class Entity;
friend class SceneSerializer;
friend class SceneHierarchyPanel;
entt::registry m_registry;
Entity create_entity_with_uuid( Entity create_entity_with_uuid(
const std::string &name, const std::string &name,
UUID uuid, UUID uuid,

View file

@ -7,9 +7,6 @@ namespace Light {
class Timer class Timer
{ {
private:
std::chrono::time_point<std::chrono::steady_clock> m_start;
public: public:
Timer(); Timer();
@ -26,16 +23,13 @@ public:
{ {
m_start = std::chrono::steady_clock::now(); m_start = std::chrono::steady_clock::now();
} }
private:
std::chrono::time_point<std::chrono::steady_clock> m_start;
}; };
class DeltaTimer class DeltaTimer
{ {
private:
Timer timer;
float m_previous_frame;
float m_delta_time;
public: public:
DeltaTimer(); DeltaTimer();
@ -45,6 +39,13 @@ public:
{ {
return m_delta_time; return m_delta_time;
} }
private:
Timer timer;
float m_previous_frame;
float m_delta_time;
}; };
} // namespace Light } // namespace Light

View file

@ -8,22 +8,16 @@ struct GLFWwindow;
namespace Light { namespace Light {
class Event; class Event;
class SharedContext; class SharedContext;
// #todo: fix the UserIntreface mess!! // #todo: fix the UserIntreface mess!!
class UserInterface /* singleton */ class UserInterface /* singleton */
{ {
private:
static UserInterface *s_Context;
private:
ImGuiWindowFlags m_dockspace_flags;
public: public:
static Scope<UserInterface> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext); static Scope<UserInterface> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
UserInterface(const UserInterface &) = delete; UserInterface(const UserInterface &) = delete;
UserInterface &operator=(const UserInterface &) = delete; UserInterface &operator=(const UserInterface &) = delete;
virtual ~UserInterface() = default; virtual ~UserInterface() = default;
@ -31,6 +25,7 @@ public:
void init(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext); void init(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
static void dockspace_begin(); static void dockspace_begin();
static void dockspace_end(); static void dockspace_end();
virtual void platform_implementation( virtual void platform_implementation(
@ -39,6 +34,7 @@ public:
) = 0; ) = 0;
virtual void begin() = 0; virtual void begin() = 0;
virtual void end() = 0; virtual void end() = 0;
virtual void log_debug_data() = 0; virtual void log_debug_data() = 0;
@ -47,7 +43,12 @@ protected:
UserInterface(); UserInterface();
private: private:
static UserInterface *s_context;
void set_dark_theme_colors(); void set_dark_theme_colors();
ImGuiWindowFlags m_dockspace_flags;
}; };
} // namespace Light } // namespace Light

View file

@ -4,10 +4,10 @@
namespace Light { namespace Light {
class basic_file_handle class BasicFileHandle
{ {
public: public:
basic_file_handle( BasicFileHandle(
uint8_t *data = nullptr, uint8_t *data = nullptr,
uint32_t size = 0ull, uint32_t size = 0ull,
const std::string &path = "", const std::string &path = "",
@ -17,30 +17,32 @@ public:
virtual void release(); virtual void release();
// getters inline uint8_t *get_data()
inline uint8_t *GetData()
{ {
return m_data; return m_data;
} }
inline uint32_t get_size() inline uint32_t get_size()
{ {
return m_size; return m_size;
} }
inline const std::string &GetPath() inline const std::string &get_path()
{ {
return m_path; return m_path;
} }
inline const std::string &GetName()
inline const std::string &get_name()
{ {
return m_name; return m_name;
} }
inline const std::string &GetExtension()
inline const std::string &get_extension()
{ {
return m_extension; return m_extension;
} }
inline const std::string &GetNameWithExtension() inline const std::string &get_name_with_extention()
{ {
return m_name + '.' + m_extension; return m_name + '.' + m_extension;
} }
@ -50,7 +52,6 @@ public:
return !!m_data; return !!m_data;
} }
// operators
inline operator bool() const inline operator bool() const
{ {
return is_valid(); return is_valid();
@ -59,16 +60,21 @@ public:
protected: protected:
// made protected for custom free(): // made protected for custom free():
uint8_t *m_data; uint8_t *m_data;
uint32_t m_size; uint32_t m_size;
private: private:
const std::string m_path, m_name, m_extension; const std::string m_path;
const std::string m_name;
const std::string m_extension;
}; };
class image_file_handle: public basic_file_handle class ImageFileHandle: public BasicFileHandle
{ {
public: public:
image_file_handle( ImageFileHandle(
uint8_t *data, uint8_t *data,
uint32_t size, uint32_t size,
const std::string &path, const std::string &path,
@ -79,7 +85,7 @@ public:
uint32_t components, uint32_t components,
uint32_t desiredComponents uint32_t desiredComponents
) )
: basic_file_handle(data, size, path, name, extension) : BasicFileHandle(data, size, path, name, extension)
, m_width(width) , m_width(width)
, m_height(height) , m_height(height)
, m_components(components) , m_components(components)
@ -89,33 +95,42 @@ public:
void release() override; void release() override;
// getters
inline uint32_t get_width() const inline uint32_t get_width() const
{ {
return m_width; return m_width;
} }
inline uint32_t get_height() const inline uint32_t get_height() const
{ {
return m_height; return m_height;
} }
inline uint32_t get_components() const inline uint32_t get_components() const
{ {
return m_components; return m_components;
} }
inline uint32_t get_desired_components() const inline uint32_t get_desired_components() const
{ {
return m_desired_components; return m_desired_components;
} }
private: private:
uint32_t m_width, m_height, m_components, m_desired_components; uint32_t m_width;
uint32_t m_height;
uint32_t m_components;
uint32_t m_desired_components;
}; };
class FileManager class FileManager
{ {
public: public:
static basic_file_handle read_text_file(const std::string &path); static BasicFileHandle read_text_file(const std::string &path);
static image_file_handle read_image_file(const std::string &path, int32_t desiredComponents);
static ImageFileHandle read_image_file(const std::string &path, int32_t desiredComponents);
}; };
} // namespace Light } // namespace Light

View file

@ -6,29 +6,20 @@ namespace Light {
class Shader; class Shader;
class Texture; class Texture;
class SharedContext; class SharedContext;
class ResourceManager /* singleton */ class ResourceManager
{ {
private:
static ResourceManager *s_Context;
private:
std::unordered_map<std::string, Ref<Shader>> m_shaders;
std::unordered_map<std::string, Ref<Texture>> m_textures;
public: public:
static Scope<ResourceManager> create(); static Scope<ResourceManager> create();
// #todo: add geometry shader support
static inline void load_shader( static inline void load_shader(
const std::string &name, const std::string &name,
const std::string &vertexPath, const std::string &vertexPath,
const std::string &pixelPath const std::string &pixelPath
) )
{ {
s_Context->load_shader_impl(name, vertexPath, pixelPath); s_context->load_shader_impl(name, vertexPath, pixelPath);
} }
static inline void load_texture( static inline void load_texture(
@ -37,24 +28,31 @@ public:
unsigned int desiredComponents = 4u unsigned int desiredComponents = 4u
) )
{ {
s_Context->load_texture_impl(name, path, desiredComponents); s_context->load_texture_impl(name, path, desiredComponents);
} }
static inline void release_texture(const std::string &name) static inline void release_texture(const std::string &name)
{ {
s_Context->release_texture_impl(name); s_context->release_texture_impl(name);
} }
static inline Ref<Shader> get_shader(const std::string &name) static inline Ref<Shader> get_shader(const std::string &name)
{ {
return s_Context->m_shaders[name]; return s_context->m_shaders[name];
} }
static inline Ref<Texture> get_texture(const std::string &name) static inline Ref<Texture> get_texture(const std::string &name)
{ {
return s_Context->m_textures[name]; return s_context->m_textures[name];
} }
private: private:
static ResourceManager *s_context;
std::unordered_map<std::string, Ref<Shader>> m_shaders;
std::unordered_map<std::string, Ref<Texture>> m_textures;
ResourceManager(); ResourceManager();
void load_shader_impl( void load_shader_impl(

View file

@ -13,16 +13,17 @@ public:
SceneSerializer(const Ref<Scene> &scene); SceneSerializer(const Ref<Scene> &scene);
void serialize(const std::string &filePath); void serialize(const std::string &filePath);
bool deserialize(const std::string &filePath); bool deserialize(const std::string &filePath);
void serialize_binary(const std::string &filePath); void serialize_binary(const std::string &filePath);
bool deserialize_binary(const std::string &filePath); bool deserialize_binary(const std::string &filePath);
private:
void serialize_entity(YAML::Emitter &out, Entity entity);
private: private:
Ref<Scene> m_scene; Ref<Scene> m_scene;
void serialize_entity(YAML::Emitter &out, Entity entity);
}; };

View file

@ -12,7 +12,9 @@ class Stringifier
{ {
public: public:
static std::string glDebugMsgSeverity(unsigned int severity); static std::string glDebugMsgSeverity(unsigned int severity);
static std::string glDebugMsgSource(unsigned int source); static std::string glDebugMsgSource(unsigned int source);
static std::string glDebugMsgType(unsigned int type); static std::string glDebugMsgType(unsigned int type);
static std::string spdlogLevel(unsigned int level); static std::string spdlogLevel(unsigned int level);

View file

@ -11,7 +11,7 @@
namespace Light { namespace Light {
Application *Application::s_Context = nullptr; Application *Application::s_context = nullptr;
Application::Application() Application::Application()
: m_instrumentor(nullptr) : m_instrumentor(nullptr)
@ -19,8 +19,8 @@ Application::Application()
, m_input(nullptr) , m_input(nullptr)
, m_window(nullptr) , m_window(nullptr)
{ {
lt_assert(!s_Context, "Repeated singleton construction"); lt_assert(!s_context, "Repeated singleton construction");
s_Context = this; s_context = this;
m_logger = logger::create(); m_logger = logger::create();
log_debug_data(); log_debug_data();
@ -108,7 +108,7 @@ void Application::game_loop()
void Application::quit() void Application::quit()
{ {
s_Context->m_window->close(); s_context->m_window->close();
} }
void Application::on_event(const Event &event) void Application::on_event(const Event &event)

View file

@ -2,10 +2,10 @@
namespace Light { namespace Light {
std::mt19937_64 UUID::s_Engine = std::mt19937_64(std::random_device()()); std::mt19937_64 UUID::s_engine = std::mt19937_64(std::random_device()());
std::uniform_int_distribution<uint64_t> UUID::s_UniformDistribution; std::uniform_int_distribution<uint64_t> UUID::s_distribution;
UUID::UUID(uint64_t uuid /* = -1 */): m_uuid(uuid == -1 ? s_UniformDistribution(s_Engine) : uuid) UUID::UUID(uint64_t uuid /* = -1 */): m_uuid(uuid == -1 ? s_distribution(s_engine) : uuid)
{ {
} }

View file

@ -2,7 +2,7 @@
namespace Light { namespace Light {
Instrumentor *Instrumentor::s_Context = nullptr; Instrumentor *Instrumentor::s_context = nullptr;
Scope<Instrumentor> Instrumentor::create() Scope<Instrumentor> Instrumentor::create()
{ {
@ -13,10 +13,10 @@ Instrumentor::Instrumentor(): m_current_session_count(0u)
{ {
// #todo: maintenance // #todo: maintenance
lt_assert( lt_assert(
!s_Context, !s_context,
"An instance of 'Instrumentor' already exists, do not construct this class!" "An instance of 'Instrumentor' already exists, do not construct this class!"
); );
s_Context = this; s_context = this;
} }
void Instrumentor::begin_session_impl(const std::string &outputPath) void Instrumentor::begin_session_impl(const std::string &outputPath)

View file

@ -4,7 +4,7 @@
namespace Light { namespace Light {
logger *logger::s_Context = nullptr; logger *logger::s_context = nullptr;
Scope<logger> logger::create() Scope<logger> logger::create()
{ {
@ -16,8 +16,8 @@ logger::logger()
, m_file_logger(nullptr) , m_file_logger(nullptr)
, m_log_file_path(LT_LOG_FILE_LOCATION) , m_log_file_path(LT_LOG_FILE_LOCATION)
{ {
lt_assert(!s_Context, "An instance of 'logger' already exists, do not construct this class!"); lt_assert(!s_context, "An instance of 'logger' already exists, do not construct this class!");
s_Context = this; s_context = this;
// set spdlog pattern // set spdlog pattern
// create loggers // create loggers

View file

@ -15,7 +15,7 @@
namespace Light { namespace Light {
GraphicsContext *GraphicsContext::s_Context = nullptr; GraphicsContext *GraphicsContext::s_context = nullptr;
GraphicsContext::~GraphicsContext() GraphicsContext::~GraphicsContext()
{ {
@ -24,12 +24,12 @@ GraphicsContext::~GraphicsContext()
Scope<GraphicsContext> GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle) Scope<GraphicsContext> GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle)
{ {
// terminate 'GraphicsContext' dependent classes // terminate 'GraphicsContext' dependent classes
if (s_Context) if (s_context)
{ {
s_Context->m_renderer.reset(); s_context->m_renderer.reset();
s_Context->m_user_interface.reset(); s_context->m_user_interface.reset();
delete s_Context; delete s_context;
} }
// determine the default api // determine the default api
@ -51,15 +51,15 @@ Scope<GraphicsContext> GraphicsContext::create(GraphicsAPI api, GLFWwindow *wind
// opengl // opengl
case GraphicsAPI::OpenGL: case GraphicsAPI::OpenGL:
scopeGfx = create_scope<glGraphicsContext>(windowHandle); scopeGfx = create_scope<glGraphicsContext>(windowHandle);
s_Context = scopeGfx.get(); s_context = scopeGfx.get();
break; break;
// directx // directx
case GraphicsAPI::DirectX: case GraphicsAPI::DirectX:
lt_win(scopeGfx = create_scope<dxGraphicsContext>(windowHandle); s_Context = scopeGfx.get(); lt_win(scopeGfx = create_scope<dxGraphicsContext>(windowHandle); s_context = scopeGfx.get();
break;) break;)
default: default
lt_assert( : lt_assert(
false, false,
"Invalid/unsupported 'GraphicsAPI' {}", "Invalid/unsupported 'GraphicsAPI' {}",
Stringifier::graphics_api_to_string(api) Stringifier::graphics_api_to_string(api)
@ -68,12 +68,12 @@ Scope<GraphicsContext> GraphicsContext::create(GraphicsAPI api, GLFWwindow *wind
} }
// create 'GraphicsContext' dependent classes // create 'GraphicsContext' dependent classes
s_Context->m_user_interface = UserInterface::create(windowHandle, s_Context->m_shared_context); s_context->m_user_interface = UserInterface::create(windowHandle, s_context->m_shared_context);
s_Context->m_renderer = renderer::create(windowHandle, s_Context->m_shared_context); s_context->m_renderer = renderer::create(windowHandle, s_context->m_shared_context);
// check // check
lt_assert(s_Context->m_user_interface, "Failed to create UserInterface"); lt_assert(s_context->m_user_interface, "Failed to create UserInterface");
lt_assert(s_Context->m_renderer, "Failed to create renderer"); lt_assert(s_context->m_renderer, "Failed to create renderer");
return std::move(scopeGfx); return std::move(scopeGfx);
} }

View file

@ -12,7 +12,7 @@
namespace Light { namespace Light {
renderer *renderer::s_Context = nullptr; renderer *renderer::s_context = nullptr;
renderer::renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext) renderer::renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
: m_quad_renderer(LT_MAX_QUAD_RENDERER_VERTICES, sharedContext) : m_quad_renderer(LT_MAX_QUAD_RENDERER_VERTICES, sharedContext)
@ -25,8 +25,8 @@ renderer::renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
, m_target_framebuffer(nullptr) , m_target_framebuffer(nullptr)
, m_should_clear_backbuffer(false) , m_should_clear_backbuffer(false)
{ {
lt_assert(!s_Context, "An instance of 'renderer' already exists, do not construct this class!"); lt_assert(!s_context, "An instance of 'renderer' already exists, do not construct this class!");
s_Context = this; s_context = this;
m_view_projection_buffer = ConstantBuffer::create( m_view_projection_buffer = ConstantBuffer::create(
ConstantBufferIndex::ViewProjection, ConstantBufferIndex::ViewProjection,
@ -67,7 +67,11 @@ void renderer::draw_quad_impl(
} }
/* tint */ /* tint */
void renderer::draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint) void renderer::draw_quad_impl(
const glm::vec3 &position,
const glm::vec2 &size,
const glm::vec4 &tint
)
{ {
draw_quad( draw_quad(
glm::translate(glm::mat4(1.0f), position) glm::translate(glm::mat4(1.0f), position)
@ -77,7 +81,11 @@ void renderer::draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size,
} }
/* texture */ /* texture */
void renderer::draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, Ref<Texture> texture) void renderer::draw_quad_impl(
const glm::vec3 &position,
const glm::vec2 &size,
Ref<Texture> texture
)
{ {
draw_quad( draw_quad(
glm::translate(glm::mat4(1.0f), position) glm::translate(glm::mat4(1.0f), position)
@ -147,13 +155,20 @@ void renderer::draw_quad_impl(const glm::mat4 &transform, Ref<Texture> texture)
// advance // advance
if (!m_texture_renderer.advance()) if (!m_texture_renderer.advance())
{ {
lt_log(warn, "Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES lt_log(
warn,
"Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}",
LT_MAX_TEXTURE_RENDERER_VERTICES
); );
flush_scene(); flush_scene();
} }
} }
void renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint, Ref<Texture> texture) void renderer::draw_quad_impl(
const glm::mat4 &transform,
const glm::vec4 &tint,
Ref<Texture> texture
)
{ {
// #todo: implement a proper binding // #todo: implement a proper binding
lt_assert(texture, "Texture passed to renderer::draw_quad_impl"); lt_assert(texture, "Texture passed to renderer::draw_quad_impl");
@ -186,7 +201,10 @@ void renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint,
// advance // advance
if (!m_tinted_texture_renderer.advance()) if (!m_tinted_texture_renderer.advance())
{ {
lt_log(warn, "Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}", LT_MAX_TEXTURE_RENDERER_VERTICES lt_log(
warn,
"Exceeded LT_MAX_TEXTURE_RENDERER_VERTICES: {}",
LT_MAX_TEXTURE_RENDERER_VERTICES
); );
flush_scene(); flush_scene();
} }

View file

@ -11,8 +11,8 @@
namespace Light { namespace Light {
Ref<Shader> Shader::create( Ref<Shader> Shader::create(
basic_file_handle vertexFile, BasicFileHandle vertexFile,
basic_file_handle pixelFile, BasicFileHandle pixelFile,
Ref<SharedContext> sharedContext Ref<SharedContext> sharedContext
) )
{ {

View file

@ -8,7 +8,7 @@
namespace Light { namespace Light {
Input *Input::s_Context = nullptr; Input *Input::s_context = nullptr;
Scope<Input> Input::create() Scope<Input> Input::create()
{ {
@ -25,10 +25,10 @@ Input::Input()
, m_game_events(true) , m_game_events(true)
{ {
lt_assert( lt_assert(
!s_Context, !s_context,
"Input::Input: an instance of 'Input' already exists, do not construct this class!" "Input::Input: an instance of 'Input' already exists, do not construct this class!"
); );
s_Context = this; s_context = this;
restart_input_state(); restart_input_state();
} }

View file

@ -7,7 +7,7 @@
namespace Light { namespace Light {
LayerStack *LayerStack::s_Context = nullptr; LayerStack *LayerStack::s_context = nullptr;
Scope<LayerStack> LayerStack::create() Scope<LayerStack> LayerStack::create()
{ {
@ -17,9 +17,9 @@ Scope<LayerStack> LayerStack::create()
LayerStack::LayerStack(): m_layers {}, m_begin(), m_end() LayerStack::LayerStack(): m_layers {}, m_begin(), m_end()
{ {
lt_assert( lt_assert(
!s_Context, !s_context,
"An instance of 'LayerStack' already exists, do not construct this class!" "An instance of 'LayerStack' already exists, do not construct this class!"
) s_Context ) s_context
= this; = this;
} }

View file

@ -6,13 +6,13 @@
namespace Light { namespace Light {
glShader::glShader(basic_file_handle vertexFile, basic_file_handle pixelFile): m_shader_id(0u) glShader::glShader(BasicFileHandle vertexFile, BasicFileHandle pixelFile): m_shader_id(0u)
{ {
// create // create
m_shader_id = glCreateProgram(); m_shader_id = glCreateProgram();
std::string vertexSource(vertexFile.GetData(), vertexFile.GetData() + vertexFile.get_size()); std::string vertexSource(vertexFile.get_data(), vertexFile.get_data() + vertexFile.get_size());
std::string pixelSource(pixelFile.GetData(), pixelFile.GetData() + pixelFile.get_size()); std::string pixelSource(pixelFile.get_data(), pixelFile.get_data() + pixelFile.get_size());
unsigned int vertexShader = compile_shader(vertexSource, Shader::Stage::VERTEX); unsigned int vertexShader = compile_shader(vertexSource, Shader::Stage::VERTEX);
unsigned int pixelShader = compile_shader(pixelSource, Shader::Stage::PIXEL); unsigned int pixelShader = compile_shader(pixelSource, Shader::Stage::PIXEL);

View file

@ -16,7 +16,7 @@
namespace Light { namespace Light {
UserInterface *UserInterface::s_Context = nullptr; UserInterface *UserInterface::s_context = nullptr;
Scope<UserInterface> UserInterface::create( Scope<UserInterface> UserInterface::create(
GLFWwindow *windowHandle, GLFWwindow *windowHandle,
@ -52,11 +52,11 @@ UserInterface::UserInterface()
) )
{ {
lt_assert( lt_assert(
!s_Context, !s_context,
"UserInterface::UserInterface: an instance of 'UserInterface' already exists, do not " "UserInterface::UserInterface: an instance of 'UserInterface' already exists, do not "
"construct this class!" "construct this class!"
); );
s_Context = this; s_context = this;
} }
void UserInterface::init(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext) void UserInterface::init(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
@ -129,7 +129,7 @@ void UserInterface::dockspace_begin()
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("Dockspace", (bool *)0, s_Context->m_dockspace_flags); ImGui::Begin("Dockspace", (bool *)0, s_context->m_dockspace_flags);
ImGui::PopStyleVar(3); ImGui::PopStyleVar(3);
ImGuiStyle &style = ImGui::GetStyle(); ImGuiStyle &style = ImGui::GetStyle();

View file

@ -4,7 +4,7 @@
namespace Light { namespace Light {
basic_file_handle::basic_file_handle( BasicFileHandle::BasicFileHandle(
uint8_t *data, uint8_t *data,
uint32_t size, uint32_t size,
const std::string &path, const std::string &path,
@ -19,7 +19,7 @@ basic_file_handle::basic_file_handle(
{ {
} }
void basic_file_handle::release() void BasicFileHandle::release()
{ {
delete m_data; delete m_data;
m_data = nullptr; m_data = nullptr;
@ -27,7 +27,7 @@ void basic_file_handle::release()
} }
basic_file_handle FileManager::read_text_file(const std::string &path) BasicFileHandle FileManager::read_text_file(const std::string &path)
{ {
// parse path info // parse path info
std::string name = path.substr(0, path.find('.') + -1); std::string name = path.substr(0, path.find('.') + -1);
@ -57,10 +57,10 @@ basic_file_handle FileManager::read_text_file(const std::string &path)
file.read(reinterpret_cast<char *>(data), size); file.read(reinterpret_cast<char *>(data), size);
file.close(); file.close();
return basic_file_handle(data, size, path, name, extension); return BasicFileHandle(data, size, path, name, extension);
} }
image_file_handle FileManager::read_image_file(const std::string &path, int32_t desiredComponents) ImageFileHandle FileManager::read_image_file(const std::string &path, int32_t desiredComponents)
{ {
// parse path info // parse path info
std::string name = path.substr(0, path.find('.') + -1); std::string name = path.substr(0, path.find('.') + -1);
@ -86,7 +86,7 @@ image_file_handle FileManager::read_image_file(const std::string &path, int32_t
fetchedComponents, fetchedComponents,
desiredComponents); desiredComponents);
return image_file_handle( return ImageFileHandle(
pixels, pixels,
width * height, width * height,
path, path,
@ -99,7 +99,7 @@ image_file_handle FileManager::read_image_file(const std::string &path, int32_t
); );
} }
void image_file_handle::release() void ImageFileHandle::release()
{ {
stbi_image_free(reinterpret_cast<void *>(m_data)); stbi_image_free(reinterpret_cast<void *>(m_data));
m_data = nullptr; m_data = nullptr;

View file

@ -6,7 +6,7 @@
namespace Light { namespace Light {
ResourceManager *ResourceManager::s_Context = nullptr; ResourceManager *ResourceManager::s_context = nullptr;
Scope<ResourceManager> ResourceManager::create() Scope<ResourceManager> ResourceManager::create()
{ {
@ -15,8 +15,8 @@ Scope<ResourceManager> ResourceManager::create()
ResourceManager::ResourceManager(): m_shaders {}, m_textures {} ResourceManager::ResourceManager(): m_shaders {}, m_textures {}
{ {
lt_assert(!s_Context, "Repeated singleton construction"); lt_assert(!s_context, "Repeated singleton construction");
s_Context = this; s_context = this;
} }
void ResourceManager::load_shader_impl( void ResourceManager::load_shader_impl(
@ -26,13 +26,13 @@ void ResourceManager::load_shader_impl(
) )
{ {
// check // check
lt_assert(s_Context, "Uninitliazed singleton"); lt_assert(s_context, "Uninitliazed singleton");
lt_assert(!vertexPath.empty(), "Empty 'vertexPath'"); lt_assert(!vertexPath.empty(), "Empty 'vertexPath'");
lt_assert(!pixelPath.empty(), "Empty 'pixelPath'"); lt_assert(!pixelPath.empty(), "Empty 'pixelPath'");
// load files // load files
basic_file_handle vertexFile = FileManager::read_text_file(vertexPath); BasicFileHandle vertexFile = FileManager::read_text_file(vertexPath);
basic_file_handle pixelFile = FileManager::read_text_file(pixelPath); BasicFileHandle pixelFile = FileManager::read_text_file(pixelPath);
// check // check
lt_assert(vertexFile.is_valid(), "Failed to read vertex file: {}", vertexPath); lt_assert(vertexFile.is_valid(), "Failed to read vertex file: {}", vertexPath);
@ -54,17 +54,17 @@ void ResourceManager::load_texture_impl(
unsigned int desiredComponents /* = 4u */ unsigned int desiredComponents /* = 4u */
) )
{ {
lt_assert(s_Context, "Uninitliazed singleton"); lt_assert(s_context, "Uninitliazed singleton");
// load file // load file
image_file_handle imgFile = FileManager::read_image_file(path, desiredComponents); ImageFileHandle imgFile = FileManager::read_image_file(path, desiredComponents);
// create texture // create texture
m_textures[name] = Ref<Texture>(Texture::create( m_textures[name] = Ref<Texture>(Texture::create(
imgFile.get_width(), imgFile.get_width(),
imgFile.get_height(), imgFile.get_height(),
imgFile.get_components(), imgFile.get_components(),
imgFile.GetData(), imgFile.get_data(),
GraphicsContext::get_shared_context(), GraphicsContext::get_shared_context(),
path path
)); ));