diff --git a/modules/engine/include/engine/core/application.hpp b/modules/engine/include/engine/core/application.hpp index 4dae09d..14d11cb 100644 --- a/modules/engine/include/engine/core/application.hpp +++ b/modules/engine/include/engine/core/application.hpp @@ -10,40 +10,39 @@ namespace Light { class Window; class Event; - class Instrumentor; -class Application /* singleton */ +class Application { -private: - static Application *s_Context; - -private: - Scope m_logger; - Scope m_instrumentor; - Scope m_layer_stack; - Scope m_input; - Scope m_resource_manager; - -protected: - Scope m_window; - public: Application(const Application &) = delete; + Application &operator=(const Application &) = delete; virtual ~Application(); void game_loop(); - // To be defined in client project - static void quit(); protected: Application(); + Scope m_window; + private: + static Application *s_context; + + Scope m_logger; + + Scope m_instrumentor; + + Scope m_layer_stack; + + Scope m_input; + + Scope m_resource_manager; + void on_event(const Event &event); void log_debug_data(); diff --git a/modules/engine/include/engine/core/uuid.hpp b/modules/engine/include/engine/core/uuid.hpp index 658cb87..95554c0 100644 --- a/modules/engine/include/engine/core/uuid.hpp +++ b/modules/engine/include/engine/core/uuid.hpp @@ -6,13 +6,6 @@ namespace Light { class UUID { -private: - static std::mt19937_64 s_Engine; - static std::uniform_int_distribution s_UniformDistribution; - -private: - uint64_t m_uuid; - public: UUID(uint64_t uuid = -1); @@ -20,6 +13,13 @@ public: { return m_uuid; } + +private: + static std::mt19937_64 s_engine; + + static std::uniform_int_distribution s_distribution; + + uint64_t m_uuid; }; } // namespace Light diff --git a/modules/engine/include/engine/core/window.hpp b/modules/engine/include/engine/core/window.hpp index 23d99bf..c0fe278 100644 --- a/modules/engine/include/engine/core/window.hpp +++ b/modules/engine/include/engine/core/window.hpp @@ -17,11 +17,6 @@ struct WindowProperties class Window { -protected: - Scope m_graphics_context; - WindowProperties m_properties; - bool b_Closed; - public: static Scope create(std::function callback); @@ -30,15 +25,15 @@ public: } Window(const Window &) = delete; + Window &operator=(const Window &) = delete; virtual ~Window() = default; - /* events */ virtual void poll_events() = 0; + virtual void on_event(const Event &event) = 0; - //======================================== SETTERS ========================================// virtual void set_properties( const WindowProperties &properties, bool affectVisibility = false @@ -47,18 +42,17 @@ public: virtual void set_title(const std::string &title) = 0; virtual void set_size(const glm::uvec2 &size, bool additive = false) = 0; // pass 0 for width or - // height for single - // dimension resizing + // height for single + // dimension resizing inline void close() { b_Closed = true; } 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 { return m_graphics_context.get(); @@ -91,9 +85,13 @@ public: { return m_properties.visible; } - //============================== GETTERS ==============================// protected: + Scope m_graphics_context; + + WindowProperties m_properties; + + bool b_Closed; }; } // namespace Light diff --git a/modules/engine/include/engine/debug/instrumentor.hpp b/modules/engine/include/engine/debug/instrumentor.hpp index 33f625d..5349a42 100644 --- a/modules/engine/include/engine/debug/instrumentor.hpp +++ b/modules/engine/include/engine/debug/instrumentor.hpp @@ -13,39 +13,36 @@ struct ScopeProfileResult uint32_t threadID; }; -// #todo: add event categories -// #todo: use ofstream in a separate thread -class Instrumentor /* singleton */ +class Instrumentor { -private: - static Instrumentor *s_Context; - -private: - std::ofstream m_output_file_stream; - - unsigned int m_current_session_count; - public: static Scope create(); 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() { - s_Context->end_session_impl(); + s_context->end_session_impl(); } static inline void submit_scope_profile(const ScopeProfileResult &profileResult) { - s_Context->submit_scope_profile_impl(profileResult); + s_context->submit_scope_profile_impl(profileResult); } private: + static Instrumentor *s_context; + + std::ofstream m_output_file_stream; + + unsigned int m_current_session_count; + Instrumentor(); void begin_session_impl(const std::string &outputPath); + void end_session_impl(); void submit_scope_profile_impl(const ScopeProfileResult &profileResult); @@ -53,13 +50,15 @@ private: class InstrumentorTimer { -private: - ScopeProfileResult m_result; - std::chrono::time_point m_start; - public: InstrumentorTimer(const std::string &scopeName); + ~InstrumentorTimer(); + +private: + ScopeProfileResult m_result; + + std::chrono::time_point m_start; }; } // namespace Light diff --git a/modules/engine/include/engine/debug/logger.hpp b/modules/engine/include/engine/debug/logger.hpp index 23d5c19..ba7f174 100644 --- a/modules/engine/include/engine/debug/logger.hpp +++ b/modules/engine/include/engine/debug/logger.hpp @@ -8,48 +8,46 @@ #define LT_LOG_FILE_LOCATION "Logs/logger.txt" #ifndef LIGHT_DIST - #define lt_log(logLevel, ...) \ - SPDLOG_LOGGER_CALL( \ + #define lt_log(logLevel, ...) \ + SPDLOG_LOGGER_CALL( \ ::Light::logger::get_engine_logger(), \ - spdlog::level::logLevel, \ - __VA_ARGS__ \ + spdlog::level::logLevel, \ + __VA_ARGS__ \ ) #else - #define lt_log(logLevel, ...) \ - SPDLOG_LOGGER_CALL( \ + #define lt_log(logLevel, ...) \ + SPDLOG_LOGGER_CALL( \ ::Light::logger::get_file_logger(), \ - spdlog::level::logLevel, \ - __VA_ARGS__ \ + spdlog::level::logLevel, \ + __VA_ARGS__ \ ) #endif namespace Light { -// #todo: extend -class logger /* singleton */ +class logger { -private: - static logger *s_Context; - -private: - Ref m_engine_logger, m_file_logger; - std::string m_log_file_path; - public: static Scope create(); static inline Ref get_engine_logger() { - return s_Context->m_engine_logger; + return s_context->m_engine_logger; } static inline Ref get_file_logger() { - return s_Context->m_file_logger; + return s_context->m_file_logger; } void log_debug_data(); private: + static logger *s_context; + + Ref m_engine_logger, m_file_logger; + + std::string m_log_file_path; + logger(); }; diff --git a/modules/engine/include/engine/events/char.hpp b/modules/engine/include/engine/events/char.hpp index 7017e02..3d6e0cc 100644 --- a/modules/engine/include/engine/events/char.hpp +++ b/modules/engine/include/engine/events/char.hpp @@ -8,9 +8,6 @@ namespace Light { class SetCharEvent: public Event { -private: - const unsigned int m_character; - public: SetCharEvent(unsigned int character): m_character(character) { @@ -27,8 +24,13 @@ public: ss << "CharSet: " << m_character; 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 diff --git a/modules/engine/include/engine/events/keyboard.hpp b/modules/engine/include/engine/events/keyboard.hpp index 6e988a8..30aa0cb 100644 --- a/modules/engine/include/engine/events/keyboard.hpp +++ b/modules/engine/include/engine/events/keyboard.hpp @@ -8,9 +8,6 @@ namespace Light { class KeyPressedEvent: public Event { -private: - const int m_key; - public: KeyPressedEvent(int key): m_key(key) { @@ -27,15 +24,17 @@ public: ss << "KeyPressed: " << m_key; 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 { -private: - const int m_key; - public: KeyRepeatEvent(int key): m_key(key) { @@ -52,15 +51,15 @@ public: ss << "KeyRepeated: " << m_key; return ss.str(); } - event_type(KeyRepeated) - event_category(InputEventCategory | KeyboardEventCategory) + event_type(KeyRepeated); + event_category(InputEventCategory | KeyboardEventCategory); + +private: + const int m_key; }; class KeyReleasedEvent: public Event { -private: - const int m_key; - public: KeyReleasedEvent(int key): m_key(key) { @@ -77,8 +76,12 @@ public: ss << "KeyReleased: " << m_key; return ss.str(); } - event_type(KeyReleased) - event_category(InputEventCategory | KeyboardEventCategory) + + event_type(KeyReleased); + event_category(InputEventCategory | KeyboardEventCategory); + +private: + const int m_key; }; } // namespace Light diff --git a/modules/engine/include/engine/events/mouse.hpp b/modules/engine/include/engine/events/mouse.hpp index fd28ea4..29bb3f7 100644 --- a/modules/engine/include/engine/events/mouse.hpp +++ b/modules/engine/include/engine/events/mouse.hpp @@ -9,9 +9,6 @@ namespace Light { class MouseMovedEvent: public Event { -private: - const glm::vec2 m_position; - public: MouseMovedEvent(float x, float y): m_position(x, y) { @@ -37,15 +34,15 @@ public: ss << "MouseMoved: " << m_position.x << ", " << m_position.y; return ss.str(); } - event_type(MouseMoved) - event_category(InputEventCategory | MouseEventCategory) + event_type(MouseMoved); + event_category(InputEventCategory | MouseEventCategory); + +private: + const glm::vec2 m_position; }; class WheelScrolledEvent: public Event { -private: - const float m_offset; - public: WheelScrolledEvent(float offset): m_offset(offset) { @@ -62,15 +59,15 @@ public: ss << "WheelScrolled: " << m_offset; return ss.str(); } - event_type(WheelScrolled) - event_category(InputEventCategory | MouseEventCategory) + event_type(WheelScrolled); + event_category(InputEventCategory | MouseEventCategory); + +private: + const float m_offset; }; class ButtonPressedEvent: public Event { -private: - const int m_button; - public: ButtonPressedEvent(int button): m_button(button) { @@ -87,15 +84,15 @@ public: ss << "ButtonPressed: " << m_button; return ss.str(); } - event_type(ButtonPressed) - event_category(InputEventCategory | MouseEventCategory) + event_type(ButtonPressed); + event_category(InputEventCategory | MouseEventCategory); + +private: + const int m_button; }; class ButtonReleasedEvent: public Event { -private: - const int m_button; - public: ButtonReleasedEvent(int button): m_button(button) { @@ -112,8 +109,12 @@ public: ss << "ButtonReleased: " << m_button; return ss.str(); } - event_type(ButtonReleased) - event_category(InputEventCategory | MouseEventCategory) + + event_type(ButtonReleased); + event_category(InputEventCategory | MouseEventCategory); + +private: + const int m_button; }; } // namespace Light diff --git a/modules/engine/include/engine/events/window.hpp b/modules/engine/include/engine/events/window.hpp index 916044f..29d24e4 100644 --- a/modules/engine/include/engine/events/window.hpp +++ b/modules/engine/include/engine/events/window.hpp @@ -14,15 +14,14 @@ public: { return "WindowClosedEvent"; } - event_type(WindowClosed) - event_category(WindowEventCategory) + + event_type(WindowClosed); + + event_category(WindowEventCategory); }; class WindowMovedEvent: public Event { -private: - const glm::ivec2 m_position; - public: WindowMovedEvent(int x, int y): m_position(x, y) { @@ -40,15 +39,17 @@ public: 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 { -private: - const glm::uvec2 m_size; - public: WindowResizedEvent(unsigned int width, unsigned int height): m_size(width, height) { @@ -65,8 +66,13 @@ public: ss << "WindowResized: " << m_size.x << ", " << m_size.y; 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 @@ -76,8 +82,9 @@ public: { return "WindowLostFocus"; } - event_type(WindowLostFocus) - event_category(WindowEventCategory) + + event_type(WindowLostFocus); + event_category(WindowEventCategory); }; class WindowGainFocusEvent: public Event @@ -87,8 +94,9 @@ public: { return "WindowGainFocus"; } - event_type(WindowGainFocus) - event_category(WindowEventCategory) + + event_type(WindowGainFocus); + event_category(WindowEventCategory); }; } // namespace Light diff --git a/modules/engine/include/engine/graphics/blender.hpp b/modules/engine/include/engine/graphics/blender.hpp index 10e81a4..560b6dc 100644 --- a/modules/engine/include/engine/graphics/blender.hpp +++ b/modules/engine/include/engine/graphics/blender.hpp @@ -40,7 +40,7 @@ public: static Scope create(Ref sharedContext); virtual void enable(BlendFactor srcFactor, BlendFactor dstFactor) = 0; - virtual void disable() = 0; + virtual void disable() = 0; protected: Blender() = default; diff --git a/modules/engine/include/engine/graphics/graphics_context.hpp b/modules/engine/include/engine/graphics/graphics_context.hpp index 1997e19..ba0c3af 100644 --- a/modules/engine/include/engine/graphics/graphics_context.hpp +++ b/modules/engine/include/engine/graphics/graphics_context.hpp @@ -9,9 +9,7 @@ namespace Light { class renderer; class resource_manager; class SharedContext; - class UserInterface; - class WindowResizedEvent; enum class GraphicsAPI @@ -19,41 +17,56 @@ enum class GraphicsAPI Default = 0, OpenGL, DirectX, - Vulkan, // :#todo - Metal // :#todo + Vulkan, + Metal }; -class GraphicsContext /* singleton */ +class GraphicsContext { -private: - static GraphicsContext* s_Context; - -private: - Scope m_user_interface; - Scope m_renderer; - -protected: - GraphicsAPI m_graphics_api; - Ref m_shared_context = nullptr; - public: - static Scope create(GraphicsAPI api, GLFWwindow* windowHandle); + static Scope create(GraphicsAPI api, GLFWwindow *windowHandle); - GraphicsContext(const GraphicsContext&) = delete; - GraphicsContext& operator=(const GraphicsContext&) = delete; + GraphicsContext(const GraphicsContext &) = delete; + + GraphicsContext &operator=(const GraphicsContext &) = delete; virtual ~GraphicsContext(); virtual void log_debug_data() = 0; - static inline GraphicsAPI get_graphics_api() { return s_Context->m_graphics_api; } - static inline Ref get_shared_context() { return s_Context->m_shared_context; } + static inline GraphicsAPI get_graphics_api() + { + return s_context->m_graphics_api; + } - inline renderer* GetRenderer() { return m_renderer.get(); } - inline UserInterface* GetUserInterface() { return m_user_interface.get(); } + static inline Ref get_shared_context() + { + return s_context->m_shared_context; + } + + inline renderer *GetRenderer() + { + return m_renderer.get(); + } + + inline UserInterface *GetUserInterface() + { + return m_user_interface.get(); + } protected: GraphicsContext() = default; + + GraphicsAPI m_graphics_api; + + Ref m_shared_context = nullptr; + +private: + static GraphicsContext *s_context; + + Scope m_user_interface; + + Scope m_renderer; }; } // namespace Light diff --git a/modules/engine/include/engine/graphics/render_command.hpp b/modules/engine/include/engine/graphics/render_command.hpp index 74c66fb..963fa87 100644 --- a/modules/engine/include/engine/graphics/render_command.hpp +++ b/modules/engine/include/engine/graphics/render_command.hpp @@ -15,14 +15,17 @@ public: static Scope create(GLFWwindow *windowHandle, Ref sharedContext); RenderCommand(const RenderCommand &) = delete; + RenderCommand &operator=(const RenderCommand &) = delete; virtual ~RenderCommand() = default; virtual void swap_buffers() = 0; + virtual void clear_back_buffer(const glm::vec4 &clearColor) = 0; virtual void draw(unsigned int count) = 0; + virtual void draw_indexed(unsigned int count) = 0; virtual void default_target_framebuffer() = 0; diff --git a/modules/engine/include/engine/graphics/renderer.hpp b/modules/engine/include/engine/graphics/renderer.hpp index 569a4bb..16b219f 100644 --- a/modules/engine/include/engine/graphics/renderer.hpp +++ b/modules/engine/include/engine/graphics/renderer.hpp @@ -18,34 +18,12 @@ class ConstantBuffer; class Framebuffer; class RenderCommand; class Texture; - class SharedContext; - class Camera; - class WindowResizedEvent; 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 m_view_projection_buffer; - - Scope m_render_command; - Scope m_blender; - - Camera *m_default_framebuffer_camera; - Ref m_target_framebuffer; - - bool m_should_clear_backbuffer; - public: static Scope create(GLFWwindow *windowHandle, Ref sharedContext); @@ -56,36 +34,40 @@ public: Ref texture ) { - s_Context->draw_quad_impl(position, size, tint, texture); + s_context->draw_quad_impl(position, size, tint, texture); } + static inline void draw_quad( const glm::vec3 &position, const glm::vec2 &size, 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( const glm::vec3 &position, const glm::vec2 &size, Ref 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) { - 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) { - s_Context->draw_quad_impl(transform, tint); + s_context->draw_quad_impl(transform, tint); } + static void draw_quad(const glm::mat4 &transform, Ref texture) { - s_Context->draw_quad_impl(transform, texture); + s_context->draw_quad_impl(transform, texture); } static inline void begin_scene( @@ -94,11 +76,11 @@ public: const Ref &targetFrameBuffer = nullptr ) { - s_Context->begin_scene_impl(camera, cameraTransform, targetFrameBuffer); + s_context->begin_scene_impl(camera, cameraTransform, targetFrameBuffer); } static inline void end_scene() { - s_Context->end_scene_impl(); + s_context->end_scene_impl(); } void on_window_resize(const WindowResizedEvent &event); @@ -107,6 +89,26 @@ public: void end_frame(); private: + static renderer *s_context; + + QuadRendererProgram m_quad_renderer; + + TextureRendererProgram m_texture_renderer; + + TintedTextureRendererProgram m_tinted_texture_renderer; + + Scope m_view_projection_buffer; + + Scope m_render_command; + + Scope m_blender; + + Camera *m_default_framebuffer_camera; + + Ref m_target_framebuffer; + + bool m_should_clear_backbuffer; + renderer(GLFWwindow *windowHandle, Ref sharedContext); void draw_quad_impl( @@ -115,11 +117,15 @@ private: const glm::vec4 &tint, Ref 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, Ref texture); void draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint, Ref texture); + void draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint); + void draw_quad_impl(const glm::mat4 &transform, Ref texture); void begin_scene_impl( @@ -127,7 +133,9 @@ private: const glm::mat4 &cameraTransform, const Ref &targetFrameBuffer = nullptr ); + void flush_scene(); + void end_scene_impl(); }; diff --git a/modules/engine/include/engine/graphics/renderer_programs/quad.hpp b/modules/engine/include/engine/graphics/renderer_programs/quad.hpp index dd39332..88fb684 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/quad.hpp +++ b/modules/engine/include/engine/graphics/renderer_programs/quad.hpp @@ -24,24 +24,12 @@ public: glm::vec4 tint; }; -private: - Ref m_shader; - Ref m_vertex_buffer; - Ref m_index_buffer; - Ref 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); bool advance(); void map() override; + void un_map() override; void bind() override; @@ -50,14 +38,33 @@ public: { return m_map_current; } + inline unsigned int get_quad_count() const { return m_quad_count; } + inline constexpr unsigned int get_vertex_size() const { return sizeof(QuadVertexData); } + +private: + Ref m_shader; + + Ref m_vertex_buffer; + + Ref m_index_buffer; + + Ref 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 diff --git a/modules/engine/include/engine/graphics/renderer_programs/renderer_program.hpp b/modules/engine/include/engine/graphics/renderer_programs/renderer_program.hpp index 719ac26..3ff0c5c 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/renderer_program.hpp +++ b/modules/engine/include/engine/graphics/renderer_programs/renderer_program.hpp @@ -8,7 +8,8 @@ class OrthographicCamera; class RendererProgram { - virtual void map() = 0; + virtual void map() = 0; + virtual void un_map() = 0; virtual void bind() = 0; diff --git a/modules/engine/include/engine/graphics/renderer_programs/texture.hpp b/modules/engine/include/engine/graphics/renderer_programs/texture.hpp index 3790dd5..2fdf891 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/texture.hpp +++ b/modules/engine/include/engine/graphics/renderer_programs/texture.hpp @@ -10,9 +10,7 @@ class Shader; class VertexBuffer; class IndexBuffer; class VertexLayout; - class OrthographicCamera; - class SharedContext; class TextureRendererProgram: RendererProgram @@ -24,24 +22,12 @@ public: glm::vec2 texcoord; }; -private: - Ref m_shader; - Ref m_vertex_buffer; - Ref m_index_buffer; - Ref 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); bool advance(); void map() override; + void un_map() override; void bind() override; @@ -60,6 +46,23 @@ public: { return sizeof(TextureVertexData); } + +private: + Ref m_shader; + + Ref m_vertex_buffer; + + Ref m_index_buffer; + + Ref 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 diff --git a/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp b/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp index 1c861cb..bb15f7f 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp +++ b/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp @@ -25,19 +25,6 @@ public: glm::vec2 texcoord; }; -private: - Ref m_shader; - Ref m_vertex_buffer; - Ref m_index_buffer; - Ref 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); bool advance(); @@ -61,6 +48,23 @@ public: { return sizeof(TintedTextureVertexData); } + +private: + Ref m_shader; + + Ref m_vertex_buffer; + + Ref m_index_buffer; + + Ref 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 diff --git a/modules/engine/include/engine/graphics/shader.hpp b/modules/engine/include/engine/graphics/shader.hpp index 89613ba..3b817cb 100644 --- a/modules/engine/include/engine/graphics/shader.hpp +++ b/modules/engine/include/engine/graphics/shader.hpp @@ -19,16 +19,16 @@ public: GEOMETRY = 3 }; -public: static Ref create( - basic_file_handle vertexFile, - basic_file_handle pixelFile, + BasicFileHandle vertexFile, + BasicFileHandle pixelFile, Ref sharedContext ); virtual ~Shader() = default; virtual void bind() = 0; + virtual void un_bind() = 0; protected: diff --git a/modules/engine/include/engine/graphics/texture.hpp b/modules/engine/include/engine/graphics/texture.hpp index be3b7ea..68fd194 100644 --- a/modules/engine/include/engine/graphics/texture.hpp +++ b/modules/engine/include/engine/graphics/texture.hpp @@ -10,24 +10,34 @@ class SharedContext; class Texture { public: - static Ref create(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, Ref sharedContext, const std::string& filePath); + static Ref create( + unsigned int width, + unsigned int height, + unsigned int components, + unsigned char *pixels, + Ref sharedContext, + const std::string &filePath + ); - Texture(const Texture&) = delete; - Texture& operator=(const Texture&) = delete; + Texture(const Texture &) = delete; + + Texture &operator=(const Texture &) = delete; virtual ~Texture() = default; virtual void bind(unsigned int slot = 0) = 0; - virtual void* get_texture() = 0; + virtual void *get_texture() = 0; - inline const std::string& GetFilePath() const { return m_file_path; } - -protected: - Texture(const std::string& filePath); + inline const std::string &GetFilePath() const + { + return m_file_path; + } protected: std::string m_file_path; + + Texture(const std::string &filePath); }; } // namespace Light diff --git a/modules/engine/include/engine/graphics/vertex_layout.hpp b/modules/engine/include/engine/graphics/vertex_layout.hpp index dcf8c2a..1e7fa64 100644 --- a/modules/engine/include/engine/graphics/vertex_layout.hpp +++ b/modules/engine/include/engine/graphics/vertex_layout.hpp @@ -6,7 +6,6 @@ namespace Light { class VertexBuffer; class Shader; - class SharedContext; enum class VertexElementType @@ -42,9 +41,9 @@ public: ); virtual ~VertexLayout() = default; - ; virtual void bind() = 0; + virtual void un_bind() = 0; protected: diff --git a/modules/engine/include/engine/input/input.hpp b/modules/engine/include/engine/input/input.hpp index a1ed6fb..e68132d 100644 --- a/modules/engine/include/engine/input/input.hpp +++ b/modules/engine/include/engine/input/input.hpp @@ -8,46 +8,32 @@ namespace Light { class Event; -class Input /* singleton */ +class Input { -private: - static Input *s_Context; - -private: - std::array m_keyboad_keys; - std::array 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: static Scope create(); 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) { - s_Context->receieve_game_events_impl(receive, toggle); + s_context->receieve_game_events_impl(receive, toggle); } 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) { - 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); @@ -62,9 +48,26 @@ public: } private: + static Input *s_context; + + std::array m_keyboad_keys; + + std::array 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(); void receive_user_interface_events_impl(bool receive, bool toggle = false); + void receieve_game_events_impl(bool receive, bool toggle = false); void restart_input_state(); diff --git a/modules/engine/include/engine/layer/layer.hpp b/modules/engine/include/engine/layer/layer.hpp index 42a1b47..953054c 100644 --- a/modules/engine/include/engine/layer/layer.hpp +++ b/modules/engine/include/engine/layer/layer.hpp @@ -11,16 +11,10 @@ class MouseMovedEvent; class ButtonPressedEvent; class ButtonReleasedEvent; class WheelScrolledEvent; - -// keyboard -// key class KeyPressedEvent; class KeyRepeatEvent; class KeyReleasedEvent; -// char class SetCharEvent; - -// window class WindowClosedEvent; class WindowResizedEvent; class WindowMovedEvent; @@ -29,19 +23,15 @@ class WindowGainFocusEvent; class Layer { -protected: - std::string m_layer_name; - public: Layer(const std::string &name); virtual ~Layer() = default; - inline const std::string &GetName() const + const std::string &GetName() const { return m_layer_name; } - /* update */ virtual void on_update(float deltaTime) { } @@ -56,67 +46,68 @@ public: bool on_event(const Event &event); protected: - /* mouse */ - // cursor + std::string m_layer_name; + virtual bool on_mouse_moved(const MouseMovedEvent &event) { return false; } - // button + virtual bool on_button_pressed(const ButtonPressedEvent &event) { return false; } + virtual bool on_button_released(const ButtonReleasedEvent &event) { return false; } - // wheel + virtual bool on_wheel_scrolled(const WheelScrolledEvent &event) { return false; } - /* keyboard */ - // key virtual bool on_key_pressed(const KeyPressedEvent &event) { return false; } + virtual bool on_key_repeat(const KeyRepeatEvent &event) { return false; } + virtual bool on_key_released(const KeyReleasedEvent &event) { return false; } - // char + virtual bool on_set_char(const SetCharEvent &event) { return false; } - /* window */ - // termination virtual bool on_window_closed(const WindowClosedEvent &event) { return false; } - // size/position + virtual bool on_window_resized(const WindowResizedEvent &event) { return false; } + virtual bool on_window_moved(const WindowMovedEvent &event) { return false; } - // focus + virtual bool on_window_lost_focus(const WindowLostFocusEvent &event) { return false; } + virtual bool on_window_gain_focus(const WindowGainFocusEvent &event) { return false; diff --git a/modules/engine/include/engine/layer/layer_stack.hpp b/modules/engine/include/engine/layer/layer_stack.hpp index b99f44c..4e2ea28 100644 --- a/modules/engine/include/engine/layer/layer_stack.hpp +++ b/modules/engine/include/engine/layer/layer_stack.hpp @@ -5,20 +5,10 @@ namespace Light { class Layer; - class Event; class LayerStack /* singleton */ { -private: - static LayerStack *s_Context; - -private: - std::vector m_layers; - - std::vector::iterator m_begin; - std::vector::iterator m_end; - public: static Scope create(); @@ -28,16 +18,16 @@ public: template 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) { - s_Context->attach_layer_impl(layer); + s_context->attach_layer_impl(layer); } static inline void detach_layer(Layer *layer) { - s_Context->detach_layer_impl(layer); + s_context->detach_layer_impl(layer); } inline bool is_empty() @@ -49,23 +39,35 @@ public: { return m_layers.begin(); } + std::vector::iterator end() { return m_layers.end(); } + std::vector::reverse_iterator rbegin() { return m_layers.rbegin(); } + std::vector::reverse_iterator rend() { return m_layers.rend(); } private: + static LayerStack *s_context; + + std::vector m_layers; + + std::vector::iterator m_begin; + + std::vector::iterator m_end; + LayerStack(); void attach_layer_impl(Layer *layer); + void detach_layer_impl(Layer *layer); }; diff --git a/modules/engine/include/engine/platform/graphics/directx/blender.hpp b/modules/engine/include/engine/platform/graphics/directx/blender.hpp index cdc5265..54f3313 100644 --- a/modules/engine/include/engine/platform/graphics/directx/blender.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/blender.hpp @@ -11,6 +11,13 @@ class dxSharedContext; class dxBlender: public Blender { +public: + dxBlender(Ref sharedContext); + + void enable(BlendFactor srcFactor, BlendFactor dstFactor) override; + + void disable() override; + private: Ref m_context; @@ -19,12 +26,6 @@ private: Microsoft::WRL::ComPtr m_blend_state; D3D11_BLEND_DESC m_desc; - -public: - dxBlender(Ref sharedContext); - - void enable(BlendFactor srcFactor, BlendFactor dstFactor) override; - void disable() override; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/directx/buffers.hpp b/modules/engine/include/engine/platform/graphics/directx/buffers.hpp index cd00d79..eab79c3 100644 --- a/modules/engine/include/engine/platform/graphics/directx/buffers.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/buffers.hpp @@ -9,17 +9,8 @@ namespace Light { class dxSharedContext; -//========== CONSTANT_BUFFER ==========// class dxConstantBuffer: public ConstantBuffer { -private: - Ref m_context; - - Microsoft::WRL::ComPtr m_buffer; - D3D11_MAPPED_SUBRESOURCE m_map; - - unsigned int m_index; - public: dxConstantBuffer( ConstantBufferIndex index, @@ -30,20 +21,21 @@ public: void bind() override; void *map() override; - void un_map() override; -}; -//========== VERTEX_BUFFER ==========// -class dxVertexBuffer: public VertexBuffer -{ + void un_map() override; + private: Ref m_context; Microsoft::WRL::ComPtr m_buffer; + D3D11_MAPPED_SUBRESOURCE m_map; - unsigned int m_stride; + unsigned int m_index; +}; +class dxVertexBuffer: public VertexBuffer +{ public: dxVertexBuffer( float *vertices, @@ -51,29 +43,42 @@ public: unsigned int count, Ref sharedContext ); + ~dxVertexBuffer(); void bind() override; + void un_bind() override; void *map() override; - void un_map() override; -}; -//========== INDEX_BUFFER ==========// -class dxIndexBuffer: public IndexBuffer -{ + void un_map() override; + private: Ref m_context; Microsoft::WRL::ComPtr m_buffer; + D3D11_MAPPED_SUBRESOURCE m_map; + + unsigned int m_stride; +}; + +class dxIndexBuffer: public IndexBuffer +{ public: dxIndexBuffer(unsigned int *indices, unsigned int count, Ref sharedContext); + ~dxIndexBuffer(); void bind() override; + void un_bind() override; + +private: + Ref m_context; + + Microsoft::WRL::ComPtr m_buffer; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp b/modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp index d9c1747..80b7037 100644 --- a/modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp @@ -11,17 +11,6 @@ class dxSharedContext; class dxFramebuffer: public Framebuffer { -private: - Ref m_context; - - FramebufferSpecification m_specification; - - Microsoft::WRL::ComPtr m_render_target_view; - Microsoft::WRL::ComPtr m_color_attachment; - Microsoft::WRL::ComPtr m_depth_stencil_attachment; - Microsoft::WRL::ComPtr m_shader_resource_view; - Microsoft::WRL::ComPtr m_depth_stencil_view; - public: dxFramebuffer( const FramebufferSpecification &specification, @@ -34,9 +23,25 @@ public: } void bind_as_target(const glm::vec4 &clearColor) override; + void bind_as_resource() override; void resize(const glm::uvec2 &size) override; + +private: + Ref m_context; + + FramebufferSpecification m_specification; + + Microsoft::WRL::ComPtr m_render_target_view; + + Microsoft::WRL::ComPtr m_color_attachment; + + Microsoft::WRL::ComPtr m_depth_stencil_attachment; + + Microsoft::WRL::ComPtr m_shader_resource_view; + + Microsoft::WRL::ComPtr m_depth_stencil_view; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/directx/graphics_context.hpp b/modules/engine/include/engine/platform/graphics/directx/graphics_context.hpp index f237d41..da7a9f7 100644 --- a/modules/engine/include/engine/platform/graphics/directx/graphics_context.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/graphics_context.hpp @@ -11,19 +11,20 @@ namespace Light { class dxGraphicsContext: public GraphicsContext { -private: - GLFWwindow *m_window_handle; - - Microsoft::WRL::ComPtr m_debug_interface; - public: dxGraphicsContext(GLFWwindow *windowHandle); virtual void log_debug_data() override; private: + GLFWwindow *m_window_handle; + + Microsoft::WRL::ComPtr m_debug_interface; + void setup_device_and_swap_chain(GLFWwindow *windowHandle); + void setup_render_targets(); + void setup_debug_interface(); }; diff --git a/modules/engine/include/engine/platform/graphics/directx/render_command.hpp b/modules/engine/include/engine/platform/graphics/directx/render_command.hpp index 87df731..ca14789 100644 --- a/modules/engine/include/engine/platform/graphics/directx/render_command.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/render_command.hpp @@ -11,16 +11,15 @@ class dxSharedContext; class dxRenderCommand: public RenderCommand { -private: - Ref m_context; - public: dxRenderCommand(Ref sharedContext); virtual void swap_buffers() override; + virtual void clear_back_buffer(const glm::vec4 &clearColor) override; virtual void draw(unsigned int count) override; + virtual void draw_indexed(unsigned int count) override; virtual void default_target_framebuffer() override; @@ -33,6 +32,8 @@ public: ) override; private: + Ref m_context; + void set_resolution(unsigned int width, unsigned int height); }; diff --git a/modules/engine/include/engine/platform/graphics/directx/shader.hpp b/modules/engine/include/engine/platform/graphics/directx/shader.hpp index aaba07c..3baff09 100644 --- a/modules/engine/include/engine/platform/graphics/directx/shader.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/shader.hpp @@ -12,29 +12,32 @@ class dxSharedContext; class dxShader: public Shader { -private: - Ref m_context; - - Microsoft::WRL::ComPtr m_vertex_shader; - Microsoft::WRL::ComPtr m_pixel_shader; - - Microsoft::WRL::ComPtr m_vertex_blob; - public: dxShader( - basic_file_handle vertexFile, - basic_file_handle pixelFile, + BasicFileHandle vertexFile, + BasicFileHandle pixelFile, Ref sharedContext ); + ~dxShader(); void bind() override; + void un_bind() override; inline Microsoft::WRL::ComPtr get_vertex_blob() { return m_vertex_blob; } + +private: + Ref m_context; + + Microsoft::WRL::ComPtr m_vertex_shader; + + Microsoft::WRL::ComPtr m_pixel_shader; + + Microsoft::WRL::ComPtr m_vertex_blob; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/directx/shared_context.hpp b/modules/engine/include/engine/platform/graphics/directx/shared_context.hpp index 72cb851..8cbeb03 100644 --- a/modules/engine/include/engine/platform/graphics/directx/shared_context.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/shared_context.hpp @@ -9,25 +9,22 @@ namespace Light { class dxSharedContext: public SharedContext { -private: - Microsoft::WRL::ComPtr m_device = nullptr; - Microsoft::WRL::ComPtr m_deviceContext = nullptr; - Microsoft::WRL::ComPtr m_swap_chain = nullptr; - Microsoft::WRL::ComPtr m_render_target_view = nullptr; - public: inline Microsoft::WRL::ComPtr get_device() { return m_device; } + inline Microsoft::WRL::ComPtr get_device_context() { return m_deviceContext; } + inline Microsoft::WRL::ComPtr get_swap_chain() { return m_swap_chain; } + inline Microsoft::WRL::ComPtr get_render_target_view() { return m_render_target_view; @@ -37,18 +34,30 @@ public: { return m_device; } + inline Microsoft::WRL::ComPtr &GetDeviceContextRef() { return m_deviceContext; } + inline Microsoft::WRL::ComPtr &GetSwapChainRef() { return m_swap_chain; } + inline Microsoft::WRL::ComPtr &GetRenderTargetViewRef() { return m_render_target_view; } + +private: + Microsoft::WRL::ComPtr m_device = nullptr; + + Microsoft::WRL::ComPtr m_deviceContext = nullptr; + + Microsoft::WRL::ComPtr m_swap_chain = nullptr; + + Microsoft::WRL::ComPtr m_render_target_view = nullptr; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/directx/texture.hpp b/modules/engine/include/engine/platform/graphics/directx/texture.hpp index b3f770c..f708926 100644 --- a/modules/engine/include/engine/platform/graphics/directx/texture.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/texture.hpp @@ -11,13 +11,6 @@ class dxSharedContext; class dxTexture: public Texture { -private: - Ref m_context; - - Microsoft::WRL::ComPtr m_texture_2d; - Microsoft::WRL::ComPtr m_shader_resource_view; - Microsoft::WRL::ComPtr m_sampler_state; - public: dxTexture( unsigned int width, @@ -29,6 +22,15 @@ public: ); void bind(unsigned int slot = 0u) override; + +private: + Ref m_context; + + Microsoft::WRL::ComPtr m_texture_2d; + + Microsoft::WRL::ComPtr m_shader_resource_view; + + Microsoft::WRL::ComPtr m_sampler_state; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/directx/user_interface.hpp b/modules/engine/include/engine/platform/graphics/directx/user_interface.hpp index dd4409c..ba6ba41 100644 --- a/modules/engine/include/engine/platform/graphics/directx/user_interface.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/user_interface.hpp @@ -15,12 +15,14 @@ class dxUserInterface: public UserInterface { public: dxUserInterface() = default; + ~dxUserInterface(); void platform_implementation(GLFWwindow *windowHandle, Ref sharedContext) override; void begin() override; + void end() override; void log_debug_data() override; diff --git a/modules/engine/include/engine/platform/graphics/directx/vertex_layout.hpp b/modules/engine/include/engine/platform/graphics/directx/vertex_layout.hpp index b8e126d..c2b91d8 100644 --- a/modules/engine/include/engine/platform/graphics/directx/vertex_layout.hpp +++ b/modules/engine/include/engine/platform/graphics/directx/vertex_layout.hpp @@ -8,29 +8,29 @@ namespace Light { class Shader; - class dxSharedContext; class dxVertexLayout: public VertexLayout { -private: - Ref m_context; - - Microsoft::WRL::ComPtr m_input_layout; - public: dxVertexLayout( Ref shader, const std::vector> &elements, Ref sharedContext ); + ~dxVertexLayout(); void bind() override; + void un_bind() override; private: DXGI_FORMAT get_dxgi_format(VertexElementType type); + + Ref m_context; + + Microsoft::WRL::ComPtr m_input_layout; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/opengl/blender.hpp b/modules/engine/include/engine/platform/graphics/opengl/blender.hpp index 3cc8122..3e02e63 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/blender.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/blender.hpp @@ -7,14 +7,15 @@ namespace Light { class glBlender: public Blender { -private: - std::unordered_map m_factor_map; - public: glBlender(); void enable(BlendFactor srcFactor, BlendFactor dstFactor) override; + void disable() override; + +private: + std::unordered_map m_factor_map; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/opengl/buffers.hpp b/modules/engine/include/engine/platform/graphics/opengl/buffers.hpp index a2a0a22..41d983e 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/buffers.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/buffers.hpp @@ -5,52 +5,57 @@ namespace Light { -//========== CONSTANT_BUFFER ==========// class glConstantBuffer: public ConstantBuffer { -private: - unsigned int m_buffer_id; - unsigned int m_index; - public: glConstantBuffer(ConstantBufferIndex index, unsigned int size); + ~glConstantBuffer(); void bind() override; void *map() override; - void un_map() override; -}; -//========== VERTEX_BUFFER ==========// -class glVertexBuffer: public VertexBuffer -{ + void un_map() override; + private: unsigned int m_buffer_id; + unsigned int m_index; +}; + +class glVertexBuffer: public VertexBuffer +{ public: glVertexBuffer(float *vertices, unsigned int stride, unsigned int count); + ~glVertexBuffer(); void bind() override; + void un_bind() override; void *map() override; - void un_map() override; -}; -//========== INDEX_BUFFER ==========// -class glIndexBuffer: public IndexBuffer -{ + void un_map() override; + private: unsigned int m_buffer_id; +}; +class glIndexBuffer: public IndexBuffer +{ public: glIndexBuffer(unsigned int *indices, unsigned int count); + ~glIndexBuffer(); void bind() override; + void un_bind() override; + +private: + unsigned int m_buffer_id; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp b/modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp index 51bff64..4cb2f22 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp @@ -7,17 +7,13 @@ namespace Light { 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: glFramebuffer(const FramebufferSpecification &specification); + ~glFramebuffer(); void bind_as_target(const glm::vec4 &clearColor) override; + void bind_as_resource() override; void resize(const glm::uvec2 &size) override; @@ -26,6 +22,15 @@ public: { 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 diff --git a/modules/engine/include/engine/platform/graphics/opengl/graphics_context.hpp b/modules/engine/include/engine/platform/graphics/opengl/graphics_context.hpp index 412e92e..70eb8e7 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/graphics_context.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/graphics_context.hpp @@ -9,15 +9,14 @@ namespace Light { class glGraphicsContext: public GraphicsContext { -private: - GLFWwindow *m_window_handle; - public: glGraphicsContext(GLFWwindow *windowHandle); void log_debug_data() override; private: + GLFWwindow *m_window_handle; + void set_debug_message_callback(); }; diff --git a/modules/engine/include/engine/platform/graphics/opengl/render_command.hpp b/modules/engine/include/engine/platform/graphics/opengl/render_command.hpp index e2c2bed..74fa34b 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/render_command.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/render_command.hpp @@ -9,22 +9,24 @@ namespace Light { class glRenderCommand: public RenderCommand { -private: - GLFWwindow *m_window_handle; - public: glRenderCommand(GLFWwindow *windowHandle); void swap_buffers() override; + void clear_back_buffer(const glm::vec4 &clearColor) override; void draw(unsigned int count) override; + void draw_indexed(unsigned int count) override; void default_target_framebuffer() override; void set_viewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height) override; + +private: + GLFWwindow *m_window_handle; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/opengl/shader.hpp b/modules/engine/include/engine/platform/graphics/opengl/shader.hpp index 5757814..f43d811 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/shader.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/shader.hpp @@ -8,20 +8,19 @@ namespace Light { class glShader: public Shader { -private: - unsigned int m_shader_id; - public: - glShader(basic_file_handle vertexFile, basic_file_handle pixelFile); + glShader(BasicFileHandle vertexFile, BasicFileHandle pixelFile); + ~glShader(); void bind() override; + void un_bind() override; private: - // shaderc::SpvCompilationResult compile_glsl(basic_file_handle file, Shader::Stage stage); - unsigned int compile_shader(std::string source, Shader::Stage stage); + + unsigned int m_shader_id; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/opengl/texture.hpp b/modules/engine/include/engine/platform/graphics/opengl/texture.hpp index 58d0302..a5b818a 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/texture.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/texture.hpp @@ -7,16 +7,23 @@ namespace Light { class glTexture: public Texture { -private: - unsigned int m_texture_id; - 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(); void bind(unsigned int slot = 0u) override; - void* get_texture() override; + void *get_texture() override; + +private: + unsigned int m_texture_id; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/opengl/user_interface.hpp b/modules/engine/include/engine/platform/graphics/opengl/user_interface.hpp index 59640b8..986b4cc 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/user_interface.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/user_interface.hpp @@ -9,20 +9,22 @@ namespace Light { class glUserInterface: public UserInterface { -private: - GLFWwindow *m_window_handle; - public: glUserInterface() = default; + ~glUserInterface(); void platform_implementation(GLFWwindow *windowHandle, Ref sharedContext) override; void begin() override; + void end() override; void log_debug_data() override; + +private: + GLFWwindow *m_window_handle; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp b/modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp index deb3d6f..ce0b664 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp +++ b/modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp @@ -10,28 +10,32 @@ class VertexBuffer; struct glVertexElementDesc { unsigned int type; + unsigned int count; + unsigned int typeSize; + unsigned int offset; }; class glVertexLayout: public VertexLayout { -private: - unsigned int m_array_id; - public: glVertexLayout( Ref buffer, const std::vector> &elements ); + ~glVertexLayout(); void bind() override; + void un_bind() override; private: glVertexElementDesc get_element_desc(VertexElementType type, unsigned int offset); + + unsigned int m_array_id; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/os/linux/l_window.hpp b/modules/engine/include/engine/platform/os/linux/l_window.hpp index 3bd9d05..203eb01 100644 --- a/modules/engine/include/engine/platform/os/linux/l_window.hpp +++ b/modules/engine/include/engine/platform/os/linux/l_window.hpp @@ -12,20 +12,15 @@ class WindowResizedEvent; class lWindow: public Window { -private: - GLFWwindow *m_handle; - - std::function m_event_callback; - public: lWindow(std::function callback); + ~lWindow(); - /* events */ void poll_events() override; + void on_event(const Event &event) override; - //======================================== SETTERS ========================================// void set_properties(const WindowProperties &properties, bool overrideVisibility = false) override; @@ -34,10 +29,14 @@ public: void set_size(const glm::uvec2 &size, bool additive = false) override; void set_v_sync(bool vsync, bool toggle = false) override; + void set_visibility(bool visible, bool toggle = false) override; - //======================================== SETTERS ========================================// private: + GLFWwindow *m_handle; + + std::function m_event_callback; + void on_window_resize(const WindowResizedEvent &event); void bind_glfw_events(); diff --git a/modules/engine/include/engine/platform/os/windows/w_window.hpp b/modules/engine/include/engine/platform/os/windows/w_window.hpp index 0d1ff9a..7ac1c00 100644 --- a/modules/engine/include/engine/platform/os/windows/w_window.hpp +++ b/modules/engine/include/engine/platform/os/windows/w_window.hpp @@ -12,20 +12,15 @@ class WindowResizedEvent; class wWindow: public Window { -private: - GLFWwindow *m_handle; - - std::function m_event_callback; - public: wWindow(std::function callback); + ~wWindow(); - /* events */ void poll_events() override; + void on_event(const Event &event) override; - //======================================== SETTERS ========================================// void set_properties(const WindowProperties &properties, bool overrideVisibility = false) override; @@ -34,10 +29,14 @@ public: void set_size(const glm::uvec2 &size, bool additive = false) override; void set_v_sync(bool vsync, bool toggle = false) override; + void set_visibility(bool visible, bool toggle = false) override; - //======================================== SETTERS ========================================// private: + GLFWwindow *m_handle; + + std::function m_event_callback; + void on_window_resize(const WindowResizedEvent &event); void bind_glfw_events(); diff --git a/modules/engine/include/engine/scene/components/camera.hpp b/modules/engine/include/engine/scene/components/camera.hpp index 3a3a1d0..b5c25d3 100644 --- a/modules/engine/include/engine/scene/components/camera.hpp +++ b/modules/engine/include/engine/scene/components/camera.hpp @@ -8,10 +8,8 @@ namespace Light { struct CameraComponent { - SceneCamera camera; - bool isPrimary; - CameraComponent() = default; + CameraComponent(const CameraComponent &) = default; CameraComponent(SceneCamera _camera, bool _isPrimary = false) @@ -24,6 +22,10 @@ struct CameraComponent { return camera; } + + SceneCamera camera; + + bool isPrimary; }; } // namespace Light diff --git a/modules/engine/include/engine/scene/components/native_script.hpp b/modules/engine/include/engine/scene/components/native_script.hpp index 78e205a..0be3aac 100644 --- a/modules/engine/include/engine/scene/components/native_script.hpp +++ b/modules/engine/include/engine/scene/components/native_script.hpp @@ -7,9 +7,8 @@ namespace Light { struct NativeScriptComponent { - NativeScript *instance; - NativeScript *(*CreateInstance)(); + void (*DestroyInstance)(NativeScriptComponent *); template @@ -23,6 +22,8 @@ struct NativeScriptComponent nsc->instance = nullptr; }; } + + NativeScript *instance; }; } // namespace Light diff --git a/modules/engine/include/engine/scene/components/scriptable_entity.hpp b/modules/engine/include/engine/scene/components/scriptable_entity.hpp index 43e6fe7..8da9b00 100644 --- a/modules/engine/include/engine/scene/components/scriptable_entity.hpp +++ b/modules/engine/include/engine/scene/components/scriptable_entity.hpp @@ -7,14 +7,11 @@ namespace Light { class NativeScript { +public: friend class Scene; -private: - Entity m_entity; - unsigned int m_unique_identifier = 0; // :#todo - -public: NativeScript() = default; + virtual ~NativeScript() = default; inline unsigned int get_uid() const @@ -32,12 +29,19 @@ protected: virtual void on_create() { } + virtual void on_destroy() { } + virtual void on_update(float ts) { } + +private: + Entity m_entity; + + unsigned int m_unique_identifier = 0; // :#todo }; } // namespace Light diff --git a/modules/engine/include/engine/scene/components/sprite_renderer.hpp b/modules/engine/include/engine/scene/components/sprite_renderer.hpp index e44db62..2c9af24 100644 --- a/modules/engine/include/engine/scene/components/sprite_renderer.hpp +++ b/modules/engine/include/engine/scene/components/sprite_renderer.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace Light { @@ -8,10 +9,8 @@ class Texture; struct SpriteRendererComponent { - Ref texture; - glm::vec4 tint; - SpriteRendererComponent() = default; + SpriteRendererComponent(const SpriteRendererComponent &) = default; SpriteRendererComponent( @@ -27,6 +26,10 @@ struct SpriteRendererComponent { return texture; } + + Ref texture; + + glm::vec4 tint; }; } // namespace Light diff --git a/modules/engine/include/engine/scene/components/tag.hpp b/modules/engine/include/engine/scene/components/tag.hpp index 63d2bd7..4612936 100644 --- a/modules/engine/include/engine/scene/components/tag.hpp +++ b/modules/engine/include/engine/scene/components/tag.hpp @@ -6,9 +6,8 @@ namespace Light { struct TagComponent { - std::string tag = "Unnamed"; - TagComponent() = default; + TagComponent(const TagComponent &) = default; TagComponent(const std::string &_tag): tag(_tag) @@ -19,10 +18,13 @@ struct TagComponent { return tag; } + operator const std::string &() const { return tag; } + + std::string tag = "Unnamed"; }; } // namespace Light diff --git a/modules/engine/include/engine/scene/components/transform.hpp b/modules/engine/include/engine/scene/components/transform.hpp index 7778f86..64a9505 100644 --- a/modules/engine/include/engine/scene/components/transform.hpp +++ b/modules/engine/include/engine/scene/components/transform.hpp @@ -11,10 +11,6 @@ namespace Light { struct TransformComponent { - glm::vec3 translation; - glm::vec3 scale; - glm::vec3 rotation; - TransformComponent(const TransformComponent &) = default; TransformComponent( @@ -39,6 +35,12 @@ struct TransformComponent { return get_transform(); } + + glm::vec3 translation; + + glm::vec3 scale; + + glm::vec3 rotation; }; } // namespace Light diff --git a/modules/engine/include/engine/scene/components/uuid.hpp b/modules/engine/include/engine/scene/components/uuid.hpp index 9bae8fc..6eee4ef 100644 --- a/modules/engine/include/engine/scene/components/uuid.hpp +++ b/modules/engine/include/engine/scene/components/uuid.hpp @@ -7,12 +7,13 @@ namespace Light { struct UUIDComponent { - UUID uuid; - UUIDComponent(UUID _uuid): uuid(_uuid) { } + UUIDComponent(const UUIDComponent &) = default; + + UUID uuid; }; } // namespace Light diff --git a/modules/engine/include/engine/scene/entity.hpp b/modules/engine/include/engine/scene/entity.hpp index 3231f68..d4f4dfb 100644 --- a/modules/engine/include/engine/scene/entity.hpp +++ b/modules/engine/include/engine/scene/entity.hpp @@ -9,10 +9,6 @@ namespace Light { class Entity { -private: - entt::entity m_handle; - Scene *m_scene; - public: Entity(entt::entity handle = entt::null, Scene *registry = nullptr); @@ -56,6 +52,10 @@ public: { return (uint32_t)m_handle; } + +private: + entt::entity m_handle; + Scene *m_scene; }; } // namespace Light diff --git a/modules/engine/include/engine/scene/scene.hpp b/modules/engine/include/engine/scene/scene.hpp index f89b12d..7b8f859 100644 --- a/modules/engine/include/engine/scene/scene.hpp +++ b/modules/engine/include/engine/scene/scene.hpp @@ -9,26 +9,19 @@ namespace Light { class Entity; - class Framebuffer; class Scene { -private: - friend class Entity; - friend class SceneSerializer; - friend class SceneHierarchyPanel; - -private: - entt::registry m_registry; - public: Scene(); + ~Scene(); void on_create(); void on_update(float deltaTime); + void on_render(const Ref &targetFrameBuffer = nullptr); Entity create_entity( @@ -39,6 +32,12 @@ public: Entity get_entity_by_tag(const std::string &tag); private: + friend class Entity; + friend class SceneSerializer; + friend class SceneHierarchyPanel; + + entt::registry m_registry; + Entity create_entity_with_uuid( const std::string &name, UUID uuid, diff --git a/modules/engine/include/engine/time/timer.hpp b/modules/engine/include/engine/time/timer.hpp index 7d826d1..8bcd9df 100644 --- a/modules/engine/include/engine/time/timer.hpp +++ b/modules/engine/include/engine/time/timer.hpp @@ -7,9 +7,6 @@ namespace Light { class Timer { -private: - std::chrono::time_point m_start; - public: Timer(); @@ -26,16 +23,13 @@ public: { m_start = std::chrono::steady_clock::now(); } + +private: + std::chrono::time_point m_start; }; class DeltaTimer { -private: - Timer timer; - - float m_previous_frame; - float m_delta_time; - public: DeltaTimer(); @@ -45,6 +39,13 @@ public: { return m_delta_time; } + +private: + Timer timer; + + float m_previous_frame; + + float m_delta_time; }; } // namespace Light diff --git a/modules/engine/include/engine/user_interface/user_interface.hpp b/modules/engine/include/engine/user_interface/user_interface.hpp index 7c204bc..41b867d 100644 --- a/modules/engine/include/engine/user_interface/user_interface.hpp +++ b/modules/engine/include/engine/user_interface/user_interface.hpp @@ -8,22 +8,16 @@ struct GLFWwindow; namespace Light { class Event; - class SharedContext; // #todo: fix the UserIntreface mess!! class UserInterface /* singleton */ { -private: - static UserInterface *s_Context; - -private: - ImGuiWindowFlags m_dockspace_flags; - public: static Scope create(GLFWwindow *windowHandle, Ref sharedContext); UserInterface(const UserInterface &) = delete; + UserInterface &operator=(const UserInterface &) = delete; virtual ~UserInterface() = default; @@ -31,6 +25,7 @@ public: void init(GLFWwindow *windowHandle, Ref sharedContext); static void dockspace_begin(); + static void dockspace_end(); virtual void platform_implementation( @@ -39,6 +34,7 @@ public: ) = 0; virtual void begin() = 0; + virtual void end() = 0; virtual void log_debug_data() = 0; @@ -47,7 +43,12 @@ protected: UserInterface(); private: + static UserInterface *s_context; + void set_dark_theme_colors(); + + + ImGuiWindowFlags m_dockspace_flags; }; } // namespace Light diff --git a/modules/engine/include/engine/utils/file_manager.hpp b/modules/engine/include/engine/utils/file_manager.hpp index 124c9c6..d996116 100644 --- a/modules/engine/include/engine/utils/file_manager.hpp +++ b/modules/engine/include/engine/utils/file_manager.hpp @@ -4,10 +4,10 @@ namespace Light { -class basic_file_handle +class BasicFileHandle { public: - basic_file_handle( + BasicFileHandle( uint8_t *data = nullptr, uint32_t size = 0ull, const std::string &path = "", @@ -17,30 +17,32 @@ public: virtual void release(); - // getters - inline uint8_t *GetData() + inline uint8_t *get_data() { return m_data; } + inline uint32_t get_size() { return m_size; } - inline const std::string &GetPath() + inline const std::string &get_path() { return m_path; } - inline const std::string &GetName() + + inline const std::string &get_name() { return m_name; } - inline const std::string &GetExtension() + + inline const std::string &get_extension() { return m_extension; } - inline const std::string &GetNameWithExtension() + inline const std::string &get_name_with_extention() { return m_name + '.' + m_extension; } @@ -50,7 +52,6 @@ public: return !!m_data; } - // operators inline operator bool() const { return is_valid(); @@ -59,16 +60,21 @@ public: protected: // made protected for custom free(): uint8_t *m_data; + uint32_t m_size; 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: - image_file_handle( + ImageFileHandle( uint8_t *data, uint32_t size, const std::string &path, @@ -79,7 +85,7 @@ public: uint32_t components, uint32_t desiredComponents ) - : basic_file_handle(data, size, path, name, extension) + : BasicFileHandle(data, size, path, name, extension) , m_width(width) , m_height(height) , m_components(components) @@ -89,33 +95,42 @@ public: void release() override; - // getters inline uint32_t get_width() const { return m_width; } + inline uint32_t get_height() const { return m_height; } + inline uint32_t get_components() const { return m_components; } + inline uint32_t get_desired_components() const { return m_desired_components; } 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 { public: - static basic_file_handle read_text_file(const std::string &path); - static image_file_handle read_image_file(const std::string &path, int32_t desiredComponents); + static BasicFileHandle read_text_file(const std::string &path); + + static ImageFileHandle read_image_file(const std::string &path, int32_t desiredComponents); }; } // namespace Light diff --git a/modules/engine/include/engine/utils/resource_manager.hpp b/modules/engine/include/engine/utils/resource_manager.hpp index 9c91150..f03d426 100644 --- a/modules/engine/include/engine/utils/resource_manager.hpp +++ b/modules/engine/include/engine/utils/resource_manager.hpp @@ -6,29 +6,20 @@ namespace Light { class Shader; class Texture; - class SharedContext; -class ResourceManager /* singleton */ +class ResourceManager { -private: - static ResourceManager *s_Context; - -private: - std::unordered_map> m_shaders; - std::unordered_map> m_textures; - public: static Scope create(); - // #todo: add geometry shader support static inline void load_shader( const std::string &name, const std::string &vertexPath, 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( @@ -37,24 +28,31 @@ public: 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) { - s_Context->release_texture_impl(name); + s_context->release_texture_impl(name); } static inline Ref get_shader(const std::string &name) { - return s_Context->m_shaders[name]; + return s_context->m_shaders[name]; } + static inline Ref get_texture(const std::string &name) { - return s_Context->m_textures[name]; + return s_context->m_textures[name]; } private: + static ResourceManager *s_context; + + std::unordered_map> m_shaders; + + std::unordered_map> m_textures; + ResourceManager(); void load_shader_impl( diff --git a/modules/engine/include/engine/utils/serializer.hpp b/modules/engine/include/engine/utils/serializer.hpp index 2a28ea7..583afba 100644 --- a/modules/engine/include/engine/utils/serializer.hpp +++ b/modules/engine/include/engine/utils/serializer.hpp @@ -13,16 +13,17 @@ public: SceneSerializer(const Ref &scene); void serialize(const std::string &filePath); + bool deserialize(const std::string &filePath); void serialize_binary(const std::string &filePath); + bool deserialize_binary(const std::string &filePath); -private: - void serialize_entity(YAML::Emitter &out, Entity entity); - private: Ref m_scene; + + void serialize_entity(YAML::Emitter &out, Entity entity); }; diff --git a/modules/engine/include/engine/utils/stringifier.hpp b/modules/engine/include/engine/utils/stringifier.hpp index ed85487..13f1dea 100644 --- a/modules/engine/include/engine/utils/stringifier.hpp +++ b/modules/engine/include/engine/utils/stringifier.hpp @@ -12,7 +12,9 @@ class Stringifier { public: static std::string glDebugMsgSeverity(unsigned int severity); + static std::string glDebugMsgSource(unsigned int source); + static std::string glDebugMsgType(unsigned int type); static std::string spdlogLevel(unsigned int level); diff --git a/modules/engine/src/core/application.cpp b/modules/engine/src/core/application.cpp index 38484f2..fa58e15 100644 --- a/modules/engine/src/core/application.cpp +++ b/modules/engine/src/core/application.cpp @@ -11,7 +11,7 @@ namespace Light { -Application *Application::s_Context = nullptr; +Application *Application::s_context = nullptr; Application::Application() : m_instrumentor(nullptr) @@ -19,8 +19,8 @@ Application::Application() , m_input(nullptr) , m_window(nullptr) { - lt_assert(!s_Context, "Repeated singleton construction"); - s_Context = this; + lt_assert(!s_context, "Repeated singleton construction"); + s_context = this; m_logger = logger::create(); log_debug_data(); @@ -108,7 +108,7 @@ void Application::game_loop() void Application::quit() { - s_Context->m_window->close(); + s_context->m_window->close(); } void Application::on_event(const Event &event) diff --git a/modules/engine/src/core/uuid.cpp b/modules/engine/src/core/uuid.cpp index cc50e70..2f52c10 100644 --- a/modules/engine/src/core/uuid.cpp +++ b/modules/engine/src/core/uuid.cpp @@ -2,10 +2,10 @@ namespace Light { -std::mt19937_64 UUID::s_Engine = std::mt19937_64(std::random_device()()); -std::uniform_int_distribution UUID::s_UniformDistribution; +std::mt19937_64 UUID::s_engine = std::mt19937_64(std::random_device()()); +std::uniform_int_distribution 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) { } diff --git a/modules/engine/src/debug/instrumentor.cpp b/modules/engine/src/debug/instrumentor.cpp index 626252c..2034804 100644 --- a/modules/engine/src/debug/instrumentor.cpp +++ b/modules/engine/src/debug/instrumentor.cpp @@ -2,7 +2,7 @@ namespace Light { -Instrumentor *Instrumentor::s_Context = nullptr; +Instrumentor *Instrumentor::s_context = nullptr; Scope Instrumentor::create() { @@ -13,10 +13,10 @@ Instrumentor::Instrumentor(): m_current_session_count(0u) { // #todo: maintenance lt_assert( - !s_Context, + !s_context, "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) diff --git a/modules/engine/src/debug/logger.cpp b/modules/engine/src/debug/logger.cpp index 545921f..98a9c69 100644 --- a/modules/engine/src/debug/logger.cpp +++ b/modules/engine/src/debug/logger.cpp @@ -4,7 +4,7 @@ namespace Light { -logger *logger::s_Context = nullptr; +logger *logger::s_context = nullptr; Scope logger::create() { @@ -16,8 +16,8 @@ logger::logger() , m_file_logger(nullptr) , m_log_file_path(LT_LOG_FILE_LOCATION) { - lt_assert(!s_Context, "An instance of 'logger' already exists, do not construct this class!"); - s_Context = this; + lt_assert(!s_context, "An instance of 'logger' already exists, do not construct this class!"); + s_context = this; // set spdlog pattern // create loggers diff --git a/modules/engine/src/graphics/graphics_context.cpp b/modules/engine/src/graphics/graphics_context.cpp index 51348b9..1484bca 100644 --- a/modules/engine/src/graphics/graphics_context.cpp +++ b/modules/engine/src/graphics/graphics_context.cpp @@ -15,7 +15,7 @@ namespace Light { -GraphicsContext *GraphicsContext::s_Context = nullptr; +GraphicsContext *GraphicsContext::s_context = nullptr; GraphicsContext::~GraphicsContext() { @@ -24,12 +24,12 @@ GraphicsContext::~GraphicsContext() Scope GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle) { // terminate 'GraphicsContext' dependent classes - if (s_Context) + if (s_context) { - s_Context->m_renderer.reset(); - s_Context->m_user_interface.reset(); + s_context->m_renderer.reset(); + s_context->m_user_interface.reset(); - delete s_Context; + delete s_context; } // determine the default api @@ -51,29 +51,29 @@ Scope GraphicsContext::create(GraphicsAPI api, GLFWwindow *wind // opengl case GraphicsAPI::OpenGL: scopeGfx = create_scope(windowHandle); - s_Context = scopeGfx.get(); + s_context = scopeGfx.get(); break; // directx case GraphicsAPI::DirectX: - lt_win(scopeGfx = create_scope(windowHandle); s_Context = scopeGfx.get(); + lt_win(scopeGfx = create_scope(windowHandle); s_context = scopeGfx.get(); break;) - default: - lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - Stringifier::graphics_api_to_string(api) - ); + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + Stringifier::graphics_api_to_string(api) + ); return nullptr; } // create 'GraphicsContext' dependent classes - 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_user_interface = UserInterface::create(windowHandle, s_context->m_shared_context); + s_context->m_renderer = renderer::create(windowHandle, s_context->m_shared_context); // check - 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_user_interface, "Failed to create UserInterface"); + lt_assert(s_context->m_renderer, "Failed to create renderer"); return std::move(scopeGfx); } diff --git a/modules/engine/src/graphics/renderer.cpp b/modules/engine/src/graphics/renderer.cpp index 42be5b5..c8f3c4d 100644 --- a/modules/engine/src/graphics/renderer.cpp +++ b/modules/engine/src/graphics/renderer.cpp @@ -12,7 +12,7 @@ namespace Light { -renderer *renderer::s_Context = nullptr; +renderer *renderer::s_context = nullptr; renderer::renderer(GLFWwindow *windowHandle, Ref sharedContext) : m_quad_renderer(LT_MAX_QUAD_RENDERER_VERTICES, sharedContext) @@ -25,8 +25,8 @@ renderer::renderer(GLFWwindow *windowHandle, Ref sharedContext) , m_target_framebuffer(nullptr) , m_should_clear_backbuffer(false) { - lt_assert(!s_Context, "An instance of 'renderer' already exists, do not construct this class!"); - s_Context = this; + lt_assert(!s_context, "An instance of 'renderer' already exists, do not construct this class!"); + s_context = this; m_view_projection_buffer = ConstantBuffer::create( ConstantBufferIndex::ViewProjection, @@ -67,7 +67,11 @@ void renderer::draw_quad_impl( } /* 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( 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 */ -void renderer::draw_quad_impl(const glm::vec3 &position, const glm::vec2 &size, Ref texture) +void renderer::draw_quad_impl( + const glm::vec3 &position, + const glm::vec2 &size, + Ref texture +) { draw_quad( glm::translate(glm::mat4(1.0f), position) @@ -147,13 +155,20 @@ void renderer::draw_quad_impl(const glm::mat4 &transform, Ref texture) // 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(); } } -void renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint, Ref texture) +void renderer::draw_quad_impl( + const glm::mat4 &transform, + const glm::vec4 &tint, + Ref texture +) { // #todo: implement a proper binding 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 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(); } @@ -203,7 +221,7 @@ void renderer::end_frame() m_render_command->swap_buffers(); m_render_command->clear_back_buffer( m_default_framebuffer_camera ? m_default_framebuffer_camera->GetBackgroundColor() : - glm::vec4(0.0f) + glm::vec4(0.0f) ); m_default_framebuffer_camera = nullptr; diff --git a/modules/engine/src/graphics/shader.cpp b/modules/engine/src/graphics/shader.cpp index 0bd0942..e437a54 100644 --- a/modules/engine/src/graphics/shader.cpp +++ b/modules/engine/src/graphics/shader.cpp @@ -11,8 +11,8 @@ namespace Light { Ref Shader::create( - basic_file_handle vertexFile, - basic_file_handle pixelFile, + BasicFileHandle vertexFile, + BasicFileHandle pixelFile, Ref sharedContext ) { diff --git a/modules/engine/src/input/input.cpp b/modules/engine/src/input/input.cpp index 38ff46a..8b936d9 100644 --- a/modules/engine/src/input/input.cpp +++ b/modules/engine/src/input/input.cpp @@ -8,7 +8,7 @@ namespace Light { -Input *Input::s_Context = nullptr; +Input *Input::s_context = nullptr; Scope Input::create() { @@ -25,10 +25,10 @@ Input::Input() , m_game_events(true) { lt_assert( - !s_Context, + !s_context, "Input::Input: an instance of 'Input' already exists, do not construct this class!" ); - s_Context = this; + s_context = this; restart_input_state(); } diff --git a/modules/engine/src/layer/layer_stack.cpp b/modules/engine/src/layer/layer_stack.cpp index 31e114c..f9dd28e 100644 --- a/modules/engine/src/layer/layer_stack.cpp +++ b/modules/engine/src/layer/layer_stack.cpp @@ -7,7 +7,7 @@ namespace Light { -LayerStack *LayerStack::s_Context = nullptr; +LayerStack *LayerStack::s_context = nullptr; Scope LayerStack::create() { @@ -17,9 +17,9 @@ Scope LayerStack::create() LayerStack::LayerStack(): m_layers {}, m_begin(), m_end() { lt_assert( - !s_Context, + !s_context, "An instance of 'LayerStack' already exists, do not construct this class!" - ) s_Context + ) s_context = this; } diff --git a/modules/engine/src/platform/graphics/opengl/shader.cpp b/modules/engine/src/platform/graphics/opengl/shader.cpp index 2ccc7a0..b60d65e 100644 --- a/modules/engine/src/platform/graphics/opengl/shader.cpp +++ b/modules/engine/src/platform/graphics/opengl/shader.cpp @@ -6,13 +6,13 @@ 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 m_shader_id = glCreateProgram(); - std::string vertexSource(vertexFile.GetData(), vertexFile.GetData() + vertexFile.get_size()); - std::string pixelSource(pixelFile.GetData(), pixelFile.GetData() + pixelFile.get_size()); + std::string vertexSource(vertexFile.get_data(), vertexFile.get_data() + vertexFile.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 pixelShader = compile_shader(pixelSource, Shader::Stage::PIXEL); diff --git a/modules/engine/src/user_interface/user_interface.cpp b/modules/engine/src/user_interface/user_interface.cpp index 6ceac29..936a972 100644 --- a/modules/engine/src/user_interface/user_interface.cpp +++ b/modules/engine/src/user_interface/user_interface.cpp @@ -16,7 +16,7 @@ namespace Light { -UserInterface *UserInterface::s_Context = nullptr; +UserInterface *UserInterface::s_context = nullptr; Scope UserInterface::create( GLFWwindow *windowHandle, @@ -52,11 +52,11 @@ UserInterface::UserInterface() ) { lt_assert( - !s_Context, + !s_context, "UserInterface::UserInterface: an instance of 'UserInterface' already exists, do not " "construct this class!" ); - s_Context = this; + s_context = this; } void UserInterface::init(GLFWwindow *windowHandle, Ref sharedContext) @@ -129,7 +129,7 @@ void UserInterface::dockspace_begin() ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 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); ImGuiStyle &style = ImGui::GetStyle(); diff --git a/modules/engine/src/utils/file_manager.cpp b/modules/engine/src/utils/file_manager.cpp index d021298..955f14b 100644 --- a/modules/engine/src/utils/file_manager.cpp +++ b/modules/engine/src/utils/file_manager.cpp @@ -4,7 +4,7 @@ namespace Light { -basic_file_handle::basic_file_handle( +BasicFileHandle::BasicFileHandle( uint8_t *data, uint32_t size, 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; 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 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(data), size); 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 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, desiredComponents); - return image_file_handle( + return ImageFileHandle( pixels, width * height, 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(m_data)); m_data = nullptr; diff --git a/modules/engine/src/utils/resource_manager.cpp b/modules/engine/src/utils/resource_manager.cpp index 8af4d36..4cb2577 100644 --- a/modules/engine/src/utils/resource_manager.cpp +++ b/modules/engine/src/utils/resource_manager.cpp @@ -6,7 +6,7 @@ namespace Light { -ResourceManager *ResourceManager::s_Context = nullptr; +ResourceManager *ResourceManager::s_context = nullptr; Scope ResourceManager::create() { @@ -15,8 +15,8 @@ Scope ResourceManager::create() ResourceManager::ResourceManager(): m_shaders {}, m_textures {} { - lt_assert(!s_Context, "Repeated singleton construction"); - s_Context = this; + lt_assert(!s_context, "Repeated singleton construction"); + s_context = this; } void ResourceManager::load_shader_impl( @@ -26,13 +26,13 @@ void ResourceManager::load_shader_impl( ) { // check - lt_assert(s_Context, "Uninitliazed singleton"); + lt_assert(s_context, "Uninitliazed singleton"); lt_assert(!vertexPath.empty(), "Empty 'vertexPath'"); lt_assert(!pixelPath.empty(), "Empty 'pixelPath'"); // load files - basic_file_handle vertexFile = FileManager::read_text_file(vertexPath); - basic_file_handle pixelFile = FileManager::read_text_file(pixelPath); + BasicFileHandle vertexFile = FileManager::read_text_file(vertexPath); + BasicFileHandle pixelFile = FileManager::read_text_file(pixelPath); // check lt_assert(vertexFile.is_valid(), "Failed to read vertex file: {}", vertexPath); @@ -54,17 +54,17 @@ void ResourceManager::load_texture_impl( unsigned int desiredComponents /* = 4u */ ) { - lt_assert(s_Context, "Uninitliazed singleton"); + lt_assert(s_context, "Uninitliazed singleton"); // load file - image_file_handle imgFile = FileManager::read_image_file(path, desiredComponents); + ImageFileHandle imgFile = FileManager::read_image_file(path, desiredComponents); // create texture m_textures[name] = Ref(Texture::create( imgFile.get_width(), imgFile.get_height(), imgFile.get_components(), - imgFile.GetData(), + imgFile.get_data(), GraphicsContext::get_shared_context(), path ));