style: applied AAA principle
This commit is contained in:
parent
6445d7b9ca
commit
258164bf9a
97 changed files with 823 additions and 769 deletions
|
@ -2,10 +2,10 @@
|
|||
|
||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||
|
||||
#include <LightEngine.hpp>
|
||||
#include <engine/engine.hpp>
|
||||
|
||||
// to be defined in client project
|
||||
extern Light::Application *Light::CreateApplication();
|
||||
extern Light::Application *Light::create_application();
|
||||
|
||||
// #todo: use windows specific stuff
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -20,7 +20,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
try
|
||||
{
|
||||
application = Light::CreateApplication();
|
||||
application = Light::create_application();
|
||||
lt_assert(application, "Light::Application is not intialized");
|
||||
|
||||
for (int i = 0; i < argc; i++)
|
||||
|
@ -56,7 +56,7 @@ int main(int argc, char *argv[])
|
|||
#include <engine/engine.hpp>
|
||||
|
||||
// to be defined in client project
|
||||
extern Light::Application *Light::CreateApplication();
|
||||
extern Light::Application *Light::create_application();
|
||||
|
||||
// #todo: use linux specific stuff
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -66,7 +66,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
try
|
||||
{
|
||||
application = Light::CreateApplication();
|
||||
application = Light::create_application();
|
||||
lt_assert(application, "Light::Application is not intialized");
|
||||
|
||||
application->game_loop();
|
||||
|
|
|
@ -7,29 +7,29 @@ namespace Light {
|
|||
|
||||
class Camera
|
||||
{
|
||||
private:
|
||||
glm::vec4 m_background_color = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
protected:
|
||||
glm::mat4 m_projection;
|
||||
|
||||
public:
|
||||
Camera() = default;
|
||||
|
||||
inline const glm::mat4 &GetProjection() const
|
||||
auto get_projection() const -> const glm::mat4 &
|
||||
{
|
||||
return m_projection;
|
||||
}
|
||||
|
||||
inline const glm::vec4 &GetBackgroundColor() const
|
||||
auto get_background_color() const -> const glm::vec4 &
|
||||
{
|
||||
return m_background_color;
|
||||
}
|
||||
|
||||
inline void set_background_color(const glm::vec4 &color)
|
||||
void set_background_color(const glm::vec4 &color)
|
||||
{
|
||||
m_background_color = color;
|
||||
}
|
||||
|
||||
protected:
|
||||
glm::mat4 m_projection;
|
||||
|
||||
private:
|
||||
glm::vec4 m_background_color = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
};
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -7,18 +7,6 @@ namespace Light {
|
|||
|
||||
class OrthographicCamera
|
||||
{
|
||||
private:
|
||||
glm::vec2 m_position;
|
||||
float m_aspect_ratio;
|
||||
float m_zoom_level;
|
||||
|
||||
const glm::vec3 m_up;
|
||||
|
||||
glm::mat4 m_projection;
|
||||
glm::mat4 m_view;
|
||||
|
||||
glm::vec4 m_clear_color;
|
||||
|
||||
public:
|
||||
OrthographicCamera(
|
||||
const glm::vec2 &position,
|
||||
|
@ -27,28 +15,43 @@ public:
|
|||
const glm::vec4 &clearColor = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f)
|
||||
);
|
||||
|
||||
// CAMERA //
|
||||
void calculate_view();
|
||||
|
||||
void calculate_projection();
|
||||
|
||||
void on_resize(const glm::vec2 &size);
|
||||
|
||||
inline const glm::mat4 &GetView() const
|
||||
auto get_view() const -> const glm::mat4 &
|
||||
{
|
||||
return m_view;
|
||||
}
|
||||
inline const glm::mat4 &GetProjection() const
|
||||
|
||||
auto get_projection() const -> const glm::mat4 &
|
||||
{
|
||||
return m_projection;
|
||||
}
|
||||
|
||||
inline const glm::vec4 &GetClearColor() const
|
||||
auto get_clear_color() const -> const glm::vec4 &
|
||||
{
|
||||
return m_clear_color;
|
||||
}
|
||||
|
||||
// CAMERA_CONTROLLER //
|
||||
void move(const glm::vec2 &position);
|
||||
|
||||
private:
|
||||
glm::vec2 m_position;
|
||||
|
||||
float m_aspect_ratio;
|
||||
|
||||
float m_zoom_level;
|
||||
|
||||
const glm::vec3 m_up;
|
||||
|
||||
glm::mat4 m_projection;
|
||||
|
||||
glm::mat4 m_view;
|
||||
|
||||
glm::vec4 m_clear_color;
|
||||
};
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -14,26 +14,24 @@ public:
|
|||
Perspetcive = 1
|
||||
};
|
||||
|
||||
struct OrthographicSpecification // :#todo use this
|
||||
struct OrthographicSpecification
|
||||
{
|
||||
float size;
|
||||
float nearPlane, farPlane;
|
||||
|
||||
float near_plane;
|
||||
|
||||
float far_plane;
|
||||
};
|
||||
|
||||
struct PerspectiveSpecification
|
||||
{
|
||||
float verticalFOV;
|
||||
float nearPlane, farPlane;
|
||||
float vertical_fov;
|
||||
|
||||
float near_plane;
|
||||
|
||||
float far_plane;
|
||||
};
|
||||
|
||||
private:
|
||||
OrthographicSpecification m_orthographic_specification;
|
||||
PerspectiveSpecification m_perspective_specification;
|
||||
float m_aspect_ratio;
|
||||
|
||||
ProjectionType m_projection_type;
|
||||
|
||||
public:
|
||||
SceneCamera();
|
||||
|
||||
void set_viewport_size(unsigned int width, unsigned int height);
|
||||
|
@ -41,45 +39,62 @@ public:
|
|||
void set_projection_type(ProjectionType projectionType);
|
||||
|
||||
void set_orthographic_size(float size);
|
||||
|
||||
void set_orthographic_far_plane(float farPlane);
|
||||
|
||||
void set_orthographic_near_plane(float nearPlane);
|
||||
|
||||
void set_perspective_vertical_fov(float verticalFov);
|
||||
|
||||
void set_perspective_far_plane(float farPlane);
|
||||
|
||||
void set_perspective_near_plane(float nearPlane);
|
||||
|
||||
inline float get_orthographic_size() const
|
||||
auto get_orthographic_size() const -> float
|
||||
{
|
||||
return m_orthographic_specification.size;
|
||||
}
|
||||
inline float get_orthographic_far_plane() const
|
||||
|
||||
auto get_orthographic_far_plane() const -> float
|
||||
{
|
||||
return m_orthographic_specification.farPlane;
|
||||
}
|
||||
inline float get_orthographic_near_plane() const
|
||||
{
|
||||
return m_orthographic_specification.nearPlane;
|
||||
return m_orthographic_specification.far_plane;
|
||||
}
|
||||
|
||||
inline float get_perspective_vertical_fov() const
|
||||
auto get_orthographic_near_plane() const -> float
|
||||
{
|
||||
return m_perspective_specification.verticalFOV;
|
||||
}
|
||||
inline float get_perspective_far_plane() const
|
||||
{
|
||||
return m_perspective_specification.farPlane;
|
||||
}
|
||||
inline float get_perspective_near_plane() const
|
||||
{
|
||||
return m_perspective_specification.nearPlane;
|
||||
return m_orthographic_specification.near_plane;
|
||||
}
|
||||
|
||||
inline ProjectionType get_projection_type() const
|
||||
auto get_perspective_vertical_fov() const -> float
|
||||
{
|
||||
return m_perspective_specification.vertical_fov;
|
||||
}
|
||||
|
||||
auto get_perspective_far_plane() const -> float
|
||||
{
|
||||
return m_perspective_specification.far_plane;
|
||||
}
|
||||
|
||||
auto get_perspective_near_plane() const -> float
|
||||
{
|
||||
return m_perspective_specification.near_plane;
|
||||
}
|
||||
|
||||
auto get_projection_type() const -> ProjectionType
|
||||
{
|
||||
return m_projection_type;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
OrthographicSpecification m_orthographic_specification;
|
||||
|
||||
PerspectiveSpecification m_perspective_specification;
|
||||
|
||||
float m_aspect_ratio;
|
||||
|
||||
ProjectionType m_projection_type;
|
||||
|
||||
void calculate_projection();
|
||||
};
|
||||
|
||||
|
|
|
@ -48,6 +48,6 @@ private:
|
|||
void log_debug_data();
|
||||
};
|
||||
|
||||
extern Application *CreateApplication();
|
||||
extern Application *create_application();
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -11,7 +11,9 @@ class Event;
|
|||
struct WindowProperties
|
||||
{
|
||||
std::string title;
|
||||
|
||||
glm::uvec2 size;
|
||||
|
||||
bool vsync, visible;
|
||||
};
|
||||
|
||||
|
@ -41,47 +43,49 @@ 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
|
||||
/** pass 0 for width or height for single dimension resizing */
|
||||
virtual void set_size(const glm::uvec2 &size, bool additive = false) = 0;
|
||||
|
||||
inline void close()
|
||||
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;
|
||||
|
||||
inline GraphicsContext *GetGfxContext() const
|
||||
auto get_graphics_context() const -> GraphicsContext *
|
||||
{
|
||||
return m_graphics_context.get();
|
||||
}
|
||||
|
||||
inline const WindowProperties &GetProperties() const
|
||||
auto get_properties() const -> const WindowProperties &
|
||||
{
|
||||
return m_properties;
|
||||
}
|
||||
|
||||
inline const std::string &GetTitle() const
|
||||
auto get_title() const -> const std::string &
|
||||
{
|
||||
return m_properties.title;
|
||||
}
|
||||
|
||||
inline const glm::uvec2 &get_size() const
|
||||
auto get_size() const -> const glm::uvec2 &
|
||||
{
|
||||
return m_properties.size;
|
||||
}
|
||||
|
||||
inline bool is_closed() const
|
||||
auto is_closed() const -> bool
|
||||
{
|
||||
return b_Closed;
|
||||
}
|
||||
inline bool is_v_sync() const
|
||||
|
||||
auto is_v_sync() const -> bool
|
||||
{
|
||||
return m_properties.vsync;
|
||||
}
|
||||
inline bool is_visible() const
|
||||
|
||||
auto is_visible() const -> bool
|
||||
{
|
||||
return m_properties.visible;
|
||||
}
|
||||
|
|
|
@ -18,16 +18,16 @@ class Instrumentor
|
|||
public:
|
||||
static Scope<Instrumentor> create();
|
||||
|
||||
static inline void begin_session(const std::string &outputPath)
|
||||
static void begin_session(const std::string &outputPath)
|
||||
{
|
||||
s_context->begin_session_impl(outputPath);
|
||||
}
|
||||
static inline void end_session()
|
||||
static void end_session()
|
||||
{
|
||||
s_context->end_session_impl();
|
||||
}
|
||||
|
||||
static inline void submit_scope_profile(const ScopeProfileResult &profileResult)
|
||||
static void submit_scope_profile(const ScopeProfileResult &profileResult)
|
||||
{
|
||||
s_context->submit_scope_profile_impl(profileResult);
|
||||
}
|
||||
|
|
|
@ -30,11 +30,12 @@ class logger
|
|||
public:
|
||||
static Scope<logger> create();
|
||||
|
||||
static inline Ref<spdlog::logger> get_engine_logger()
|
||||
static auto get_engine_logger() -> Ref<spdlog::logger>
|
||||
{
|
||||
return s_context->m_engine_logger;
|
||||
}
|
||||
static inline Ref<spdlog::logger> get_file_logger()
|
||||
|
||||
static auto get_file_logger() -> Ref<spdlog::logger>
|
||||
{
|
||||
return s_context->m_file_logger;
|
||||
}
|
||||
|
|
|
@ -13,20 +13,20 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
inline int get_character() const
|
||||
auto get_character() const -> int
|
||||
{
|
||||
return m_character;
|
||||
}
|
||||
|
||||
virtual std::string get_info_lt_log() const override
|
||||
auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "CharSet: " << m_character;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
event_type(SetChar);
|
||||
|
||||
event_category(InputEventCategory | KeyboardEventCategory);
|
||||
|
||||
private:
|
||||
|
|
|
@ -36,25 +36,32 @@ enum EventCategory
|
|||
MouseEventCategory = bit(3),
|
||||
};
|
||||
|
||||
#define event_type(type) \
|
||||
#define event_type(type) \
|
||||
EventType get_event_type() const override \
|
||||
{ \
|
||||
return ::Light::EventType::type; \
|
||||
{ \
|
||||
return ::Light::EventType::type; \
|
||||
}
|
||||
#define event_category(eCategory) \
|
||||
|
||||
#define event_category(eCategory) \
|
||||
inline bool has_category(EventCategory category) const override \
|
||||
{ \
|
||||
return (eCategory) & category; \
|
||||
{ \
|
||||
return (eCategory) & category; \
|
||||
}
|
||||
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
virtual EventType get_event_type() const = 0;
|
||||
virtual std::string get_info_lt_log() const = 0;
|
||||
virtual bool has_category(EventCategory category) const = 0;
|
||||
Event() = default;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, const Event &e)
|
||||
virtual ~Event() = default;
|
||||
|
||||
virtual auto get_event_type() const -> EventType = 0;
|
||||
|
||||
virtual auto get_info_lt_log() const -> std::string = 0;
|
||||
|
||||
virtual auto has_category(EventCategory category) const -> bool = 0;
|
||||
|
||||
friend auto operator<<(std::ostream &os, const Event &e) -> std::ostream &
|
||||
{
|
||||
return os << e.get_info_lt_log();
|
||||
}
|
||||
|
|
|
@ -13,12 +13,12 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
inline int get_key() const
|
||||
auto get_key() const -> int
|
||||
{
|
||||
return m_key;
|
||||
}
|
||||
|
||||
virtual std::string get_info_lt_log() const override
|
||||
virtual auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "KeyPressed: " << m_key;
|
||||
|
@ -40,18 +40,20 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
inline int get_key() const
|
||||
auto get_key() const -> int
|
||||
{
|
||||
return m_key;
|
||||
}
|
||||
|
||||
virtual std::string get_info_lt_log() const override
|
||||
virtual auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "KeyRepeated: " << m_key;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
event_type(KeyRepeated);
|
||||
|
||||
event_category(InputEventCategory | KeyboardEventCategory);
|
||||
|
||||
private:
|
||||
|
@ -65,12 +67,12 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
inline int get_key() const
|
||||
auto get_key() const -> int
|
||||
{
|
||||
return m_key;
|
||||
}
|
||||
|
||||
virtual std::string get_info_lt_log() const override
|
||||
virtual auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "KeyReleased: " << m_key;
|
||||
|
@ -78,6 +80,7 @@ public:
|
|||
}
|
||||
|
||||
event_type(KeyReleased);
|
||||
|
||||
event_category(InputEventCategory | KeyboardEventCategory);
|
||||
|
||||
private:
|
||||
|
|
|
@ -14,27 +14,30 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
inline const glm::vec2 &GetPosition() const
|
||||
auto get_position() const -> const glm::vec2 &
|
||||
{
|
||||
return m_position;
|
||||
}
|
||||
|
||||
inline float get_x() const
|
||||
auto get_x() const -> float
|
||||
{
|
||||
return m_position.x;
|
||||
}
|
||||
inline float get_y() const
|
||||
|
||||
auto get_y() const -> float
|
||||
{
|
||||
return m_position.y;
|
||||
}
|
||||
|
||||
virtual std::string get_info_lt_log() const override
|
||||
virtual auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "MouseMoved: " << m_position.x << ", " << m_position.y;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
event_type(MouseMoved);
|
||||
|
||||
event_category(InputEventCategory | MouseEventCategory);
|
||||
|
||||
private:
|
||||
|
@ -48,18 +51,20 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
inline float get_offset() const
|
||||
auto get_offset() const -> float
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
virtual std::string get_info_lt_log() const override
|
||||
virtual auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "WheelScrolled: " << m_offset;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
event_type(WheelScrolled);
|
||||
|
||||
event_category(InputEventCategory | MouseEventCategory);
|
||||
|
||||
private:
|
||||
|
@ -73,18 +78,20 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
inline int get_button() const
|
||||
auto get_button() const -> int
|
||||
{
|
||||
return m_button;
|
||||
}
|
||||
|
||||
virtual std::string get_info_lt_log() const override
|
||||
virtual auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "ButtonPressed: " << m_button;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
event_type(ButtonPressed);
|
||||
|
||||
event_category(InputEventCategory | MouseEventCategory);
|
||||
|
||||
private:
|
||||
|
@ -98,12 +105,12 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
inline int get_button() const
|
||||
auto get_button() const -> int
|
||||
{
|
||||
return m_button;
|
||||
}
|
||||
|
||||
virtual std::string get_info_lt_log() const override
|
||||
virtual auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "ButtonReleased: " << m_button;
|
||||
|
@ -111,6 +118,7 @@ public:
|
|||
}
|
||||
|
||||
event_type(ButtonReleased);
|
||||
|
||||
event_category(InputEventCategory | MouseEventCategory);
|
||||
|
||||
private:
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Light {
|
|||
class WindowClosedEvent: public Event
|
||||
{
|
||||
public:
|
||||
virtual std::string get_info_lt_log() const override
|
||||
auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
return "WindowClosedEvent";
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
const glm::ivec2 &GetPosition() const
|
||||
auto get_position() const -> const glm::ivec2 &
|
||||
{
|
||||
return m_position;
|
||||
}
|
||||
|
||||
virtual std::string get_info_lt_log() const override
|
||||
auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "WindwoMoved: " << m_position.x << ", " << m_position.y;
|
||||
|
@ -55,12 +55,12 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
const glm::uvec2 &get_size() const
|
||||
auto get_size() const -> const glm::uvec2 &
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
virtual std::string get_info_lt_log() const override
|
||||
auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "WindowResized: " << m_size.x << ", " << m_size.y;
|
||||
|
@ -78,24 +78,26 @@ private:
|
|||
class WindowLostFocusEvent: public Event
|
||||
{
|
||||
public:
|
||||
virtual std::string get_info_lt_log() const override
|
||||
auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
return "WindowLostFocus";
|
||||
}
|
||||
|
||||
event_type(WindowLostFocus);
|
||||
|
||||
event_category(WindowEventCategory);
|
||||
};
|
||||
|
||||
class WindowGainFocusEvent: public Event
|
||||
{
|
||||
public:
|
||||
virtual std::string get_info_lt_log() const override
|
||||
auto get_info_lt_log() const -> std::string override
|
||||
{
|
||||
return "WindowGainFocus";
|
||||
}
|
||||
|
||||
event_type(WindowGainFocus);
|
||||
|
||||
event_category(WindowEventCategory);
|
||||
};
|
||||
|
||||
|
|
|
@ -37,9 +37,10 @@ enum class BlendFactor : uint8_t
|
|||
class Blender
|
||||
{
|
||||
public:
|
||||
static Scope<Blender> create(Ref<SharedContext> sharedContext);
|
||||
static auto create(Ref<SharedContext> sharedContext) -> Scope<Blender>;
|
||||
|
||||
virtual void enable(BlendFactor srcFactor, BlendFactor dstFactor) = 0;
|
||||
|
||||
virtual void disable() = 0;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -11,13 +11,17 @@ enum class ConstantBufferIndex
|
|||
ViewProjection = 0u
|
||||
};
|
||||
|
||||
//========== CONSTANT_BUFFER ==========//
|
||||
class ConstantBuffer
|
||||
{
|
||||
public:
|
||||
static Scope<ConstantBuffer> create(ConstantBufferIndex index, unsigned int size, Ref<SharedContext> sharedContext);
|
||||
static auto create(
|
||||
ConstantBufferIndex index,
|
||||
unsigned int size,
|
||||
Ref<SharedContext> sharedContext
|
||||
) -> Scope<ConstantBuffer>;
|
||||
|
||||
virtual auto map() -> void * = 0;
|
||||
|
||||
virtual void* map() = 0;
|
||||
virtual void un_map() = 0;
|
||||
|
||||
virtual void bind() = 0;
|
||||
|
@ -26,33 +30,40 @@ protected:
|
|||
ConstantBuffer() = default;
|
||||
};
|
||||
|
||||
//========== VERTEX_BUFFER ==========//
|
||||
class VertexBuffer
|
||||
{
|
||||
public:
|
||||
static Ref<VertexBuffer> create(float* vertices, unsigned int stride, unsigned int count, Ref<SharedContext> sharedContext);
|
||||
static auto create(
|
||||
float *vertices,
|
||||
unsigned int stride,
|
||||
unsigned int count,
|
||||
Ref<SharedContext> sharedContext
|
||||
) -> Ref<VertexBuffer>;
|
||||
|
||||
virtual ~VertexBuffer() = default;
|
||||
|
||||
virtual void* map() = 0;
|
||||
virtual auto map() -> void * = 0;
|
||||
|
||||
virtual void un_map() = 0;
|
||||
|
||||
virtual void bind() = 0;
|
||||
virtual void bind() = 0;
|
||||
|
||||
virtual void un_bind() = 0;
|
||||
|
||||
protected:
|
||||
VertexBuffer() = default;
|
||||
};
|
||||
|
||||
//========== INDEX_BUFFER ==========//
|
||||
class IndexBuffer
|
||||
{
|
||||
public:
|
||||
static Ref<IndexBuffer> create(unsigned int* indices, unsigned int count, Ref<SharedContext> sharedContext);
|
||||
static auto create(unsigned int *indices, unsigned int count, Ref<SharedContext> sharedContext)
|
||||
-> Ref<IndexBuffer>;
|
||||
|
||||
virtual ~IndexBuffer() = default;
|
||||
|
||||
virtual void bind() = 0;
|
||||
virtual void bind() = 0;
|
||||
|
||||
virtual void un_bind() = 0;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <engine/base/base.hpp>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Light {
|
||||
|
@ -10,21 +9,28 @@ class SharedContext;
|
|||
|
||||
struct FramebufferSpecification
|
||||
{
|
||||
unsigned int width, height;
|
||||
unsigned int width;
|
||||
|
||||
unsigned int height;
|
||||
|
||||
unsigned int samples = 1;
|
||||
};
|
||||
|
||||
class Framebuffer
|
||||
{
|
||||
public:
|
||||
static Ref<Framebuffer> create(const FramebufferSpecification& specification, Ref<SharedContext> sharedContext);
|
||||
static auto create(
|
||||
const FramebufferSpecification &specification,
|
||||
Ref<SharedContext> sharedContext
|
||||
) -> Ref<Framebuffer>;
|
||||
|
||||
virtual void bind_as_target(const glm::vec4& clearColor) = 0;
|
||||
virtual void bind_as_resource() = 0;
|
||||
virtual void bind_as_target(const glm::vec4 &clearColor) = 0;
|
||||
|
||||
virtual void resize(const glm::uvec2& size) = 0;
|
||||
virtual void bind_as_resource() = 0;
|
||||
|
||||
virtual void* GetColorAttachment() = 0;
|
||||
virtual void resize(const glm::uvec2 &size) = 0;
|
||||
|
||||
virtual auto get_color_attachment() -> void * = 0;
|
||||
|
||||
protected:
|
||||
Framebuffer() = default;
|
||||
|
|
|
@ -6,7 +6,7 @@ struct GLFWwindow;
|
|||
|
||||
namespace Light {
|
||||
|
||||
class renderer;
|
||||
class Renderer;
|
||||
class resource_manager;
|
||||
class SharedContext;
|
||||
class UserInterface;
|
||||
|
@ -24,7 +24,7 @@ enum class GraphicsAPI
|
|||
class GraphicsContext
|
||||
{
|
||||
public:
|
||||
static Scope<GraphicsContext> create(GraphicsAPI api, GLFWwindow *windowHandle);
|
||||
static auto create(GraphicsAPI api, GLFWwindow *windowHandle) -> Scope<GraphicsContext>;
|
||||
|
||||
GraphicsContext(const GraphicsContext &) = delete;
|
||||
|
||||
|
@ -34,22 +34,22 @@ public:
|
|||
|
||||
virtual void log_debug_data() = 0;
|
||||
|
||||
static inline GraphicsAPI get_graphics_api()
|
||||
static GraphicsAPI get_graphics_api()
|
||||
{
|
||||
return s_context->m_graphics_api;
|
||||
}
|
||||
|
||||
static inline Ref<SharedContext> get_shared_context()
|
||||
static Ref<SharedContext> get_shared_context()
|
||||
{
|
||||
return s_context->m_shared_context;
|
||||
}
|
||||
|
||||
inline renderer *GetRenderer()
|
||||
auto get_renderer() -> Renderer *
|
||||
{
|
||||
return m_renderer.get();
|
||||
}
|
||||
|
||||
inline UserInterface *GetUserInterface()
|
||||
auto get_user_interface() -> UserInterface *
|
||||
{
|
||||
return m_user_interface.get();
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ private:
|
|||
|
||||
Scope<UserInterface> m_user_interface;
|
||||
|
||||
Scope<renderer> m_renderer;
|
||||
Scope<Renderer> m_renderer;
|
||||
};
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -12,11 +12,12 @@ class SharedContext;
|
|||
class RenderCommand
|
||||
{
|
||||
public:
|
||||
static Scope<RenderCommand> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
|
||||
static auto create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
|
||||
-> Scope<RenderCommand>;
|
||||
|
||||
RenderCommand(const RenderCommand &) = delete;
|
||||
|
||||
RenderCommand &operator=(const RenderCommand &) = delete;
|
||||
auto operator=(const RenderCommand &) -> RenderCommand & = delete;
|
||||
|
||||
virtual ~RenderCommand() = default;
|
||||
|
||||
|
|
|
@ -22,12 +22,13 @@ class SharedContext;
|
|||
class Camera;
|
||||
class WindowResizedEvent;
|
||||
|
||||
class renderer
|
||||
class Renderer
|
||||
{
|
||||
public:
|
||||
static Scope<renderer> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
|
||||
static auto create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
|
||||
-> Scope<Renderer>;
|
||||
|
||||
static inline void draw_quad(
|
||||
static void draw_quad(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec2 &size,
|
||||
const glm::vec4 &tint,
|
||||
|
@ -37,20 +38,12 @@ public:
|
|||
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
|
||||
)
|
||||
static void draw_quad(const glm::vec3 &position, const glm::vec2 &size, const glm::vec4 &tint)
|
||||
{
|
||||
s_context->draw_quad_impl(position, size, tint);
|
||||
}
|
||||
|
||||
static inline void draw_quad(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec2 &size,
|
||||
Ref<Texture> texture
|
||||
)
|
||||
static void draw_quad(const glm::vec3 &position, const glm::vec2 &size, Ref<Texture> texture)
|
||||
{
|
||||
s_context->draw_quad_impl(position, size, texture);
|
||||
}
|
||||
|
@ -70,7 +63,7 @@ public:
|
|||
s_context->draw_quad_impl(transform, texture);
|
||||
}
|
||||
|
||||
static inline void begin_scene(
|
||||
static void begin_scene(
|
||||
Camera *camera,
|
||||
const glm::mat4 &cameraTransform,
|
||||
const Ref<Framebuffer> &targetFrameBuffer = nullptr
|
||||
|
@ -78,7 +71,8 @@ public:
|
|||
{
|
||||
s_context->begin_scene_impl(camera, cameraTransform, targetFrameBuffer);
|
||||
}
|
||||
static inline void end_scene()
|
||||
|
||||
static void end_scene()
|
||||
{
|
||||
s_context->end_scene_impl();
|
||||
}
|
||||
|
@ -86,10 +80,11 @@ public:
|
|||
void on_window_resize(const WindowResizedEvent &event);
|
||||
|
||||
void begin_frame();
|
||||
|
||||
void end_frame();
|
||||
|
||||
private:
|
||||
static renderer *s_context;
|
||||
static Renderer *s_context;
|
||||
|
||||
QuadRendererProgram m_quad_renderer;
|
||||
|
||||
|
@ -109,7 +104,7 @@ private:
|
|||
|
||||
bool m_should_clear_backbuffer;
|
||||
|
||||
renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
|
||||
Renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
|
||||
|
||||
void draw_quad_impl(
|
||||
const glm::vec3 &position,
|
||||
|
|
|
@ -10,9 +10,7 @@ class Shader;
|
|||
class VertexBuffer;
|
||||
class IndexBuffer;
|
||||
class VertexLayout;
|
||||
|
||||
class OrthographicCamera;
|
||||
|
||||
class SharedContext;
|
||||
|
||||
class QuadRendererProgram: RendererProgram
|
||||
|
@ -26,7 +24,7 @@ public:
|
|||
|
||||
QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
|
||||
|
||||
bool advance();
|
||||
auto advance() -> bool;
|
||||
|
||||
void map() override;
|
||||
|
||||
|
@ -34,17 +32,17 @@ public:
|
|||
|
||||
void bind() override;
|
||||
|
||||
inline QuadVertexData *GetMapCurrent()
|
||||
auto get_map_current() -> QuadVertexData *
|
||||
{
|
||||
return m_map_current;
|
||||
}
|
||||
|
||||
inline unsigned int get_quad_count() const
|
||||
auto get_quad_count() const -> unsigned int
|
||||
{
|
||||
return m_quad_count;
|
||||
}
|
||||
|
||||
inline constexpr unsigned int get_vertex_size() const
|
||||
constexpr auto get_vertex_size() const -> unsigned int
|
||||
{
|
||||
return sizeof(QuadVertexData);
|
||||
}
|
||||
|
|
|
@ -19,12 +19,13 @@ public:
|
|||
struct TextureVertexData
|
||||
{
|
||||
glm::vec4 position;
|
||||
|
||||
glm::vec2 texcoord;
|
||||
};
|
||||
|
||||
TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
|
||||
|
||||
bool advance();
|
||||
auto advance() -> bool;
|
||||
|
||||
void map() override;
|
||||
|
||||
|
@ -32,17 +33,17 @@ public:
|
|||
|
||||
void bind() override;
|
||||
|
||||
inline TextureVertexData *GetMapCurrent()
|
||||
auto get_map_current() -> TextureVertexData *
|
||||
{
|
||||
return m_map_current;
|
||||
}
|
||||
|
||||
inline unsigned int get_quad_count() const
|
||||
auto get_quad_count() const -> unsigned int
|
||||
{
|
||||
return m_quad_count;
|
||||
}
|
||||
|
||||
inline constexpr unsigned int get_vertex_size() const
|
||||
constexpr auto get_vertex_size() const -> unsigned int
|
||||
{
|
||||
return sizeof(TextureVertexData);
|
||||
}
|
||||
|
|
|
@ -10,9 +10,7 @@ class Shader;
|
|||
class VertexBuffer;
|
||||
class IndexBuffer;
|
||||
class VertexLayout;
|
||||
|
||||
class OrthographicCamera;
|
||||
|
||||
class SharedContext;
|
||||
|
||||
class TintedTextureRendererProgram: RendererProgram
|
||||
|
@ -21,30 +19,33 @@ public:
|
|||
struct TintedTextureVertexData
|
||||
{
|
||||
glm::vec4 position;
|
||||
|
||||
glm::vec4 tint;
|
||||
|
||||
glm::vec2 texcoord;
|
||||
};
|
||||
|
||||
TintedTextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
|
||||
|
||||
bool advance();
|
||||
auto advance() -> bool;
|
||||
|
||||
void map() override;
|
||||
|
||||
void un_map() override;
|
||||
|
||||
void bind() override;
|
||||
|
||||
inline TintedTextureVertexData *GetMapCurrent()
|
||||
auto get_map_current() -> TintedTextureVertexData *
|
||||
{
|
||||
return m_map_current;
|
||||
}
|
||||
|
||||
inline unsigned int get_quad_count() const
|
||||
auto get_quad_count() const -> unsigned int
|
||||
{
|
||||
return m_quad_count;
|
||||
}
|
||||
|
||||
inline constexpr unsigned int get_vertex_size() const
|
||||
constexpr auto get_vertex_size() const -> unsigned int
|
||||
{
|
||||
return sizeof(TintedTextureVertexData);
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ public:
|
|||
GEOMETRY = 3
|
||||
};
|
||||
|
||||
static Ref<Shader> create(
|
||||
static auto create(
|
||||
BasicFileHandle vertexFile,
|
||||
BasicFileHandle pixelFile,
|
||||
Ref<SharedContext> sharedContext
|
||||
);
|
||||
) -> Ref<Shader>;
|
||||
|
||||
virtual ~Shader() = default;
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ namespace Light {
|
|||
|
||||
class SharedContext;
|
||||
|
||||
// #todo: improve textures
|
||||
class Texture
|
||||
{
|
||||
public:
|
||||
|
@ -21,15 +20,15 @@ public:
|
|||
|
||||
Texture(const Texture &) = delete;
|
||||
|
||||
Texture &operator=(const Texture &) = delete;
|
||||
auto operator=(const Texture &) -> Texture & = delete;
|
||||
|
||||
virtual ~Texture() = default;
|
||||
|
||||
virtual void bind(unsigned int slot = 0) = 0;
|
||||
|
||||
virtual void *get_texture() = 0;
|
||||
virtual auto get_texture() -> void * = 0;
|
||||
|
||||
inline const std::string &GetFilePath() const
|
||||
auto GetFilePath() const -> const std::string &
|
||||
{
|
||||
return m_file_path;
|
||||
}
|
||||
|
|
|
@ -33,12 +33,12 @@ enum class VertexElementType
|
|||
class VertexLayout
|
||||
{
|
||||
public:
|
||||
static Ref<VertexLayout> create(
|
||||
static auto create(
|
||||
Ref<VertexBuffer> vertexBuffer,
|
||||
Ref<Shader> shader,
|
||||
const std::vector<std::pair<std::string, VertexElementType>> &elements,
|
||||
Ref<SharedContext> sharedContext
|
||||
);
|
||||
) -> Ref<VertexLayout>;
|
||||
|
||||
virtual ~VertexLayout() = default;
|
||||
|
||||
|
|
|
@ -11,38 +11,39 @@ class Event;
|
|||
class Input
|
||||
{
|
||||
public:
|
||||
static Scope<Input> create();
|
||||
static auto create() -> Scope<Input>;
|
||||
|
||||
static inline void receive_user_interface_events(bool receive, bool toggle = false)
|
||||
static void receive_user_interface_events(bool receive, bool toggle = false)
|
||||
{
|
||||
s_context->receive_user_interface_events_impl(receive, toggle);
|
||||
}
|
||||
static inline void receive_game_events(bool receive, bool toggle = false)
|
||||
static void receive_game_events(bool receive, bool toggle = false)
|
||||
{
|
||||
s_context->receieve_game_events_impl(receive, toggle);
|
||||
}
|
||||
|
||||
static inline bool get_keyboard_key(int code)
|
||||
static auto get_keyboard_key(int code) -> bool
|
||||
{
|
||||
return s_context->m_keyboad_keys[code];
|
||||
}
|
||||
static inline bool get_mouse_button(int code)
|
||||
static auto get_mouse_button(int code) -> bool
|
||||
{
|
||||
return s_context->m_mouse_buttons[code];
|
||||
}
|
||||
|
||||
static inline const glm::vec2 &get_mouse_position(int code)
|
||||
static auto get_mouse_position(int code) -> const glm::vec2 &
|
||||
{
|
||||
return s_context->m_mouse_position;
|
||||
}
|
||||
|
||||
void on_event(const Event &inputEvent);
|
||||
|
||||
inline bool is_receiving_input_events() const
|
||||
auto is_receiving_input_events() const -> bool
|
||||
{
|
||||
return m_user_interface_events;
|
||||
}
|
||||
inline bool is_receiving_game_events() const
|
||||
|
||||
auto is_receiving_game_events() const -> bool
|
||||
{
|
||||
return m_game_events;
|
||||
}
|
||||
|
|
|
@ -25,9 +25,10 @@ class Layer
|
|||
{
|
||||
public:
|
||||
Layer(const std::string &name);
|
||||
|
||||
virtual ~Layer() = default;
|
||||
|
||||
const std::string &GetName() const
|
||||
auto get_name() const -> const std::string &
|
||||
{
|
||||
return m_layer_name;
|
||||
}
|
||||
|
@ -43,72 +44,72 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
bool on_event(const Event &event);
|
||||
auto on_event(const Event &event) -> bool;
|
||||
|
||||
protected:
|
||||
std::string m_layer_name;
|
||||
|
||||
virtual bool on_mouse_moved(const MouseMovedEvent &event)
|
||||
virtual auto on_mouse_moved(const MouseMovedEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_button_pressed(const ButtonPressedEvent &event)
|
||||
virtual auto on_button_pressed(const ButtonPressedEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_button_released(const ButtonReleasedEvent &event)
|
||||
virtual auto on_button_released(const ButtonReleasedEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_wheel_scrolled(const WheelScrolledEvent &event)
|
||||
virtual auto on_wheel_scrolled(const WheelScrolledEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_key_pressed(const KeyPressedEvent &event)
|
||||
virtual auto on_key_pressed(const KeyPressedEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_key_repeat(const KeyRepeatEvent &event)
|
||||
virtual auto on_key_repeat(const KeyRepeatEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_key_released(const KeyReleasedEvent &event)
|
||||
virtual auto on_key_released(const KeyReleasedEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_set_char(const SetCharEvent &event)
|
||||
virtual auto on_set_char(const SetCharEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_window_closed(const WindowClosedEvent &event)
|
||||
virtual auto on_window_closed(const WindowClosedEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_window_resized(const WindowResizedEvent &event)
|
||||
virtual auto on_window_resized(const WindowResizedEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_window_moved(const WindowMovedEvent &event)
|
||||
virtual auto on_window_moved(const WindowMovedEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_window_lost_focus(const WindowLostFocusEvent &event)
|
||||
virtual auto on_window_lost_focus(const WindowLostFocusEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool on_window_gain_focus(const WindowGainFocusEvent &event)
|
||||
virtual auto on_window_gain_focus(const WindowGainFocusEvent &event) -> bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -10,47 +10,48 @@ class Event;
|
|||
class LayerStack /* singleton */
|
||||
{
|
||||
public:
|
||||
static Scope<LayerStack> create();
|
||||
static auto create() -> Scope<LayerStack>;
|
||||
|
||||
~LayerStack();
|
||||
|
||||
// #todo: is this needed?
|
||||
template<typename t, typename... Args>
|
||||
static inline void emplace_layer(Args &&...args)
|
||||
static void emplace_layer(Args &&...args)
|
||||
{
|
||||
s_context->attach_layer_impl(new t((args)...));
|
||||
}
|
||||
|
||||
static inline void attach_layer(Layer *layer)
|
||||
static void attach_layer(Layer *layer)
|
||||
{
|
||||
s_context->attach_layer_impl(layer);
|
||||
}
|
||||
static inline void detach_layer(Layer *layer)
|
||||
|
||||
static void detach_layer(Layer *layer)
|
||||
{
|
||||
s_context->detach_layer_impl(layer);
|
||||
}
|
||||
|
||||
inline bool is_empty()
|
||||
auto is_empty() -> bool
|
||||
{
|
||||
return m_layers.empty();
|
||||
}
|
||||
|
||||
std::vector<Layer *>::iterator begin()
|
||||
auto begin() -> std::vector<Layer *>::iterator
|
||||
{
|
||||
return m_layers.begin();
|
||||
}
|
||||
|
||||
std::vector<Layer *>::iterator end()
|
||||
auto end() -> std::vector<Layer *>::iterator
|
||||
{
|
||||
return m_layers.end();
|
||||
}
|
||||
|
||||
std::vector<Layer *>::reverse_iterator rbegin()
|
||||
auto rbegin() -> std::vector<Layer *>::reverse_iterator
|
||||
{
|
||||
return m_layers.rbegin();
|
||||
}
|
||||
|
||||
std::vector<Layer *>::reverse_iterator rend()
|
||||
auto rend() -> std::vector<Layer *>::reverse_iterator
|
||||
{
|
||||
return m_layers.rend();
|
||||
}
|
||||
|
|
|
@ -7,10 +7,14 @@
|
|||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Light { namespace Math {
|
||||
namespace Light {
|
||||
namespace Math {
|
||||
|
||||
float rand(int min, int max, int decimals = 0);
|
||||
glm::vec2 rand_vec2(int min, int max, int decimals = 0);
|
||||
glm::vec3 rand_vec3(int min, int max, int decimals = 0);
|
||||
auto rand(int min, int max, int decimals = 0) -> float;
|
||||
|
||||
}}
|
||||
auto rand_vec2(int min, int max, int decimals = 0) -> glm::vec2;
|
||||
|
||||
auto rand_vec3(int min, int max, int decimals = 0) -> glm::vec3;
|
||||
|
||||
} // namespace Math
|
||||
} // namespace Light
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
void un_bind() override;
|
||||
|
||||
void *map() override;
|
||||
auto map() -> void * override;
|
||||
|
||||
void un_map() override;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
Ref<dxSharedContext> sharedContext
|
||||
);
|
||||
|
||||
inline void *GetColorAttachment() override
|
||||
auto get_color_attachment() -> void * override
|
||||
{
|
||||
return (void *)m_shader_resource_view.Get();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
|
||||
void un_bind() override;
|
||||
|
||||
inline Microsoft::WRL::ComPtr<ID3DBlob> get_vertex_blob()
|
||||
auto get_vertex_blob() -> Microsoft::WRL::ComPtr<ID3DBlob>
|
||||
{
|
||||
return m_vertex_blob;
|
||||
}
|
||||
|
|
|
@ -10,42 +10,42 @@ namespace Light {
|
|||
class dxSharedContext: public SharedContext
|
||||
{
|
||||
public:
|
||||
inline Microsoft::WRL::ComPtr<ID3D11Device> get_device()
|
||||
[[nodiscard]] auto get_device() -> Microsoft::WRL::ComPtr<ID3D11Device>
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
inline Microsoft::WRL::ComPtr<ID3D11DeviceContext> get_device_context()
|
||||
[[nodiscard]] auto get_device_context() -> Microsoft::WRL::ComPtr<ID3D11DeviceContext>
|
||||
{
|
||||
return m_deviceContext;
|
||||
}
|
||||
|
||||
inline Microsoft::WRL::ComPtr<IDXGISwapChain> get_swap_chain()
|
||||
[[nodiscard]] auto get_swap_chain() -> Microsoft::WRL::ComPtr<IDXGISwapChain>
|
||||
{
|
||||
return m_swap_chain;
|
||||
}
|
||||
|
||||
inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView> get_render_target_view()
|
||||
[[nodiscard]] auto get_render_target_view() -> Microsoft::WRL::ComPtr<ID3D11RenderTargetView>
|
||||
{
|
||||
return m_render_target_view;
|
||||
}
|
||||
|
||||
inline Microsoft::WRL::ComPtr<ID3D11Device> &GetDeviceRef()
|
||||
[[nodiscard]] auto &GetDeviceRef() -> Microsoft::WRL::ComPtr<ID3D11Device>
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
inline Microsoft::WRL::ComPtr<ID3D11DeviceContext> &GetDeviceContextRef()
|
||||
[[nodiscard]] auto &GetDeviceContextRef() -> Microsoft::WRL::ComPtr<ID3D11DeviceContext>
|
||||
{
|
||||
return m_deviceContext;
|
||||
}
|
||||
|
||||
inline Microsoft::WRL::ComPtr<IDXGISwapChain> &GetSwapChainRef()
|
||||
[[nodiscard]] auto &GetSwapChainRef() -> Microsoft::WRL::ComPtr<IDXGISwapChain>
|
||||
{
|
||||
return m_swap_chain;
|
||||
}
|
||||
|
||||
inline Microsoft::WRL::ComPtr<ID3D11RenderTargetView> &GetRenderTargetViewRef()
|
||||
[[nodiscard]] auto &GetRenderTargetViewRef() -> Microsoft::WRL::ComPtr<ID3D11RenderTargetView>
|
||||
{
|
||||
return m_render_target_view;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
|
||||
void bind() override;
|
||||
|
||||
void *map() override;
|
||||
auto map() -> void * override;
|
||||
|
||||
void un_map() override;
|
||||
|
||||
|
@ -35,7 +35,7 @@ public:
|
|||
|
||||
void un_bind() override;
|
||||
|
||||
void *map() override;
|
||||
auto map() -> void * override;
|
||||
|
||||
void un_map() override;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
|
||||
void resize(const glm::uvec2 &size) override;
|
||||
|
||||
inline void *GetColorAttachment() override
|
||||
auto get_color_attachment() -> void * override
|
||||
{
|
||||
return (void *)m_color_attachment_id;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
|
||||
void bind(unsigned int slot = 0u) override;
|
||||
|
||||
void *get_texture() override;
|
||||
auto get_texture() -> void * override;
|
||||
|
||||
private:
|
||||
unsigned int m_texture_id;
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
void un_bind() override;
|
||||
|
||||
private:
|
||||
glVertexElementDesc get_element_desc(VertexElementType type, unsigned int offset);
|
||||
auto get_element_desc(VertexElementType type, unsigned int offset) -> glVertexElementDesc;
|
||||
|
||||
unsigned int m_array_id;
|
||||
};
|
||||
|
|
|
@ -14,15 +14,15 @@ public:
|
|||
|
||||
virtual ~NativeScript() = default;
|
||||
|
||||
inline unsigned int get_uid() const
|
||||
auto get_uid() const -> unsigned int
|
||||
{
|
||||
return m_unique_identifier;
|
||||
}
|
||||
|
||||
template<typename t>
|
||||
t &GetComponent()
|
||||
auto GetComponent() -> t &
|
||||
{
|
||||
return m_entity.GetComponent<t>();
|
||||
return m_entity.get_component<t>();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -25,7 +25,7 @@ struct TransformComponent
|
|||
{
|
||||
}
|
||||
|
||||
inline glm::mat4 get_transform() const
|
||||
auto get_transform() const -> glm::mat4
|
||||
{
|
||||
return glm::translate(translation) * glm::rotate(rotation.z, glm::vec3(0.0f, 0.0f, 1.0f))
|
||||
* glm::scale(scale);
|
||||
|
|
|
@ -15,35 +15,35 @@ public:
|
|||
~Entity();
|
||||
|
||||
template<typename t, typename... Args>
|
||||
inline t &AddComponent(Args &&...args)
|
||||
auto add_component(Args &&...args) -> t &
|
||||
{
|
||||
return m_scene->m_registry.emplace<t>(m_handle, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename t>
|
||||
inline t &GetComponent()
|
||||
auto get_component() -> t &
|
||||
{
|
||||
return m_scene->m_registry.get<t>(m_handle);
|
||||
}
|
||||
|
||||
template<typename t>
|
||||
inline bool has_component()
|
||||
auto has_component() -> bool
|
||||
{
|
||||
return m_scene->m_registry.any_of<t>(m_handle);
|
||||
}
|
||||
|
||||
template<typename t>
|
||||
inline void remove_component()
|
||||
void remove_component()
|
||||
{
|
||||
m_scene->m_registry.remove<t>(m_handle);
|
||||
}
|
||||
|
||||
inline uint64_t get_uuid()
|
||||
auto get_uuid() -> uint64_t
|
||||
{
|
||||
return GetComponent<UUIDComponent>().uuid;
|
||||
return get_component<UUIDComponent>().uuid;
|
||||
}
|
||||
|
||||
inline bool is_valid() const
|
||||
auto is_valid() const -> bool
|
||||
{
|
||||
return m_handle != entt::null && m_scene != nullptr;
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ public:
|
|||
|
||||
private:
|
||||
entt::entity m_handle;
|
||||
|
||||
Scene *m_scene;
|
||||
};
|
||||
|
||||
|
|
|
@ -24,25 +24,27 @@ public:
|
|||
|
||||
void on_render(const Ref<Framebuffer> &targetFrameBuffer = nullptr);
|
||||
|
||||
Entity create_entity(
|
||||
auto create_entity(
|
||||
const std::string &name,
|
||||
const TransformComponent &transform = TransformComponent()
|
||||
);
|
||||
) -> Entity;
|
||||
|
||||
Entity get_entity_by_tag(const std::string &tag);
|
||||
auto get_entity_by_tag(const std::string &tag) -> Entity;
|
||||
|
||||
private:
|
||||
friend class Entity;
|
||||
|
||||
friend class SceneSerializer;
|
||||
|
||||
friend class SceneHierarchyPanel;
|
||||
|
||||
entt::registry m_registry;
|
||||
|
||||
Entity create_entity_with_uuid(
|
||||
auto create_entity_with_uuid(
|
||||
const std::string &name,
|
||||
UUID uuid,
|
||||
const TransformComponent &transform = TransformComponent()
|
||||
);
|
||||
) -> Entity;
|
||||
};
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -10,7 +10,7 @@ class Timer
|
|||
public:
|
||||
Timer();
|
||||
|
||||
inline float get_elapsed_time() const
|
||||
auto get_elapsed_time() const -> float
|
||||
{
|
||||
return (std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now() - m_start
|
||||
|
@ -19,7 +19,7 @@ public:
|
|||
/ 1000.;
|
||||
}
|
||||
|
||||
inline void reset()
|
||||
void reset()
|
||||
{
|
||||
m_start = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public:
|
|||
|
||||
void update();
|
||||
|
||||
inline float get_delta_time() const
|
||||
auto get_delta_time() const -> float
|
||||
{
|
||||
return m_delta_time;
|
||||
}
|
||||
|
|
|
@ -14,20 +14,21 @@ class SharedContext;
|
|||
class UserInterface /* singleton */
|
||||
{
|
||||
public:
|
||||
static Scope<UserInterface> create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
|
||||
|
||||
UserInterface(const UserInterface &) = delete;
|
||||
|
||||
UserInterface &operator=(const UserInterface &) = delete;
|
||||
|
||||
virtual ~UserInterface() = default;
|
||||
|
||||
void init(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
|
||||
static auto create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
|
||||
-> Scope<UserInterface>;
|
||||
|
||||
static void dockspace_begin();
|
||||
|
||||
static void dockspace_end();
|
||||
|
||||
UserInterface(const UserInterface &) = delete;
|
||||
|
||||
auto operator=(const UserInterface &) -> UserInterface & = delete;
|
||||
|
||||
virtual ~UserInterface() = default;
|
||||
|
||||
void init(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext);
|
||||
|
||||
virtual void platform_implementation(
|
||||
GLFWwindow *windowHandle,
|
||||
Ref<SharedContext> sharedContext
|
||||
|
@ -47,7 +48,6 @@ private:
|
|||
|
||||
void set_dark_theme_colors();
|
||||
|
||||
|
||||
ImGuiWindowFlags m_dockspace_flags;
|
||||
};
|
||||
|
||||
|
|
|
@ -17,42 +17,42 @@ public:
|
|||
|
||||
virtual void release();
|
||||
|
||||
inline uint8_t *get_data()
|
||||
auto get_data() -> uint8_t *
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
inline uint32_t get_size()
|
||||
auto get_size() -> uint32_t
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline const std::string &get_path()
|
||||
auto get_path() -> const std::string &
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
inline const std::string &get_name()
|
||||
auto get_name() -> const std::string &
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
inline const std::string &get_extension()
|
||||
auto get_extension() -> const std::string &
|
||||
{
|
||||
return m_extension;
|
||||
}
|
||||
|
||||
inline const std::string &get_name_with_extention()
|
||||
auto get_name_with_extention() -> const std::string &
|
||||
{
|
||||
return m_name + '.' + m_extension;
|
||||
}
|
||||
|
||||
inline bool is_valid() const
|
||||
auto is_valid() const -> bool
|
||||
{
|
||||
return !!m_data;
|
||||
}
|
||||
|
||||
inline operator bool() const
|
||||
operator bool() const
|
||||
{
|
||||
return is_valid();
|
||||
}
|
||||
|
@ -95,22 +95,22 @@ public:
|
|||
|
||||
void release() override;
|
||||
|
||||
inline uint32_t get_width() const
|
||||
auto get_width() const -> uint32_t
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
inline uint32_t get_height() const
|
||||
auto get_height() const -> uint32_t
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
inline uint32_t get_components() const
|
||||
auto get_components() const -> uint32_t
|
||||
{
|
||||
return m_components;
|
||||
}
|
||||
|
||||
inline uint32_t get_desired_components() const
|
||||
auto get_desired_components() const -> uint32_t
|
||||
{
|
||||
return m_desired_components;
|
||||
}
|
||||
|
@ -128,9 +128,10 @@ private:
|
|||
class FileManager
|
||||
{
|
||||
public:
|
||||
static BasicFileHandle read_text_file(const std::string &path);
|
||||
static auto read_text_file(const std::string &path) -> BasicFileHandle;
|
||||
|
||||
static ImageFileHandle read_image_file(const std::string &path, int32_t desiredComponents);
|
||||
static auto read_image_file(const std::string &path, int32_t desiredComponents)
|
||||
-> ImageFileHandle;
|
||||
};
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -11,9 +11,9 @@ class SharedContext;
|
|||
class ResourceManager
|
||||
{
|
||||
public:
|
||||
static Scope<ResourceManager> create();
|
||||
static auto create() -> Scope<ResourceManager>;
|
||||
|
||||
static inline void load_shader(
|
||||
static void load_shader(
|
||||
const std::string &name,
|
||||
const std::string &vertexPath,
|
||||
const std::string &pixelPath
|
||||
|
@ -22,7 +22,7 @@ public:
|
|||
s_context->load_shader_impl(name, vertexPath, pixelPath);
|
||||
}
|
||||
|
||||
static inline void load_texture(
|
||||
static void load_texture(
|
||||
const std::string &name,
|
||||
const std::string &path,
|
||||
unsigned int desiredComponents = 4u
|
||||
|
@ -31,17 +31,17 @@ public:
|
|||
s_context->load_texture_impl(name, path, desiredComponents);
|
||||
}
|
||||
|
||||
static inline void release_texture(const std::string &name)
|
||||
static void release_texture(const std::string &name)
|
||||
{
|
||||
s_context->release_texture_impl(name);
|
||||
}
|
||||
|
||||
static inline Ref<Shader> get_shader(const std::string &name)
|
||||
static auto get_shader(const std::string &name) -> Ref<Shader>
|
||||
{
|
||||
return s_context->m_shaders[name];
|
||||
}
|
||||
|
||||
static inline Ref<Texture> get_texture(const std::string &name)
|
||||
static auto get_texture(const std::string &name) -> Ref<Texture>
|
||||
{
|
||||
return s_context->m_textures[name];
|
||||
}
|
||||
|
|
|
@ -12,13 +12,13 @@ class SceneSerializer
|
|||
public:
|
||||
SceneSerializer(const Ref<Scene> &scene);
|
||||
|
||||
void serialize(const std::string &filePath);
|
||||
void serialize(const std::string &file_path);
|
||||
|
||||
bool deserialize(const std::string &filePath);
|
||||
auto deserialize(const std::string &file_path) -> bool;
|
||||
|
||||
void serialize_binary(const std::string &filePath);
|
||||
void serialize_binary(const std::string &file_path);
|
||||
|
||||
bool deserialize_binary(const std::string &filePath);
|
||||
auto deserialize_binary(const std::string &file_path) -> bool;
|
||||
|
||||
private:
|
||||
Ref<Scene> m_scene;
|
||||
|
|
|
@ -11,15 +11,15 @@ enum class GraphicsAPI;
|
|||
class Stringifier
|
||||
{
|
||||
public:
|
||||
static std::string glDebugMsgSeverity(unsigned int severity);
|
||||
static auto glDebugMsgSeverity(unsigned int severity) -> std::string;
|
||||
|
||||
static std::string glDebugMsgSource(unsigned int source);
|
||||
static auto glDebugMsgSource(unsigned int source) -> std::string;
|
||||
|
||||
static std::string glDebugMsgType(unsigned int type);
|
||||
static auto glDebugMsgType(unsigned int type) -> std::string;
|
||||
|
||||
static std::string spdlogLevel(unsigned int level);
|
||||
static auto spdlogLevel(unsigned int level) -> std::string;
|
||||
|
||||
static std::string graphics_api_to_string(GraphicsAPI api);
|
||||
static auto graphics_api_to_string(GraphicsAPI api) -> std::string;
|
||||
};
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -32,31 +32,31 @@ void SceneCamera::set_orthographic_size(float size)
|
|||
|
||||
void SceneCamera::set_orthographic_far_plane(float farPlane)
|
||||
{
|
||||
m_orthographic_specification.farPlane = farPlane;
|
||||
m_orthographic_specification.far_plane = farPlane;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_orthographic_near_plane(float nearPlane)
|
||||
{
|
||||
m_orthographic_specification.nearPlane = nearPlane;
|
||||
m_orthographic_specification.near_plane = nearPlane;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_perspective_vertical_fov(float verticalFOV)
|
||||
{
|
||||
m_perspective_specification.verticalFOV = verticalFOV;
|
||||
m_perspective_specification.vertical_fov = verticalFOV;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_perspective_far_plane(float farPlane)
|
||||
{
|
||||
m_perspective_specification.farPlane = farPlane;
|
||||
m_perspective_specification.far_plane = farPlane;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
void SceneCamera::set_perspective_near_plane(float nearPlane)
|
||||
{
|
||||
m_perspective_specification.nearPlane = nearPlane;
|
||||
m_perspective_specification.near_plane = nearPlane;
|
||||
calculate_projection();
|
||||
}
|
||||
|
||||
|
@ -69,17 +69,17 @@ void SceneCamera::calculate_projection()
|
|||
m_orthographic_specification.size * 0.5f * m_aspect_ratio,
|
||||
-m_orthographic_specification.size * 0.5f,
|
||||
m_orthographic_specification.size * 0.5f,
|
||||
m_orthographic_specification.farPlane,
|
||||
m_orthographic_specification.nearPlane
|
||||
m_orthographic_specification.far_plane,
|
||||
m_orthographic_specification.near_plane
|
||||
);
|
||||
}
|
||||
else // perspective
|
||||
{
|
||||
m_projection = glm::perspective(
|
||||
m_perspective_specification.verticalFOV,
|
||||
m_perspective_specification.vertical_fov,
|
||||
m_aspect_ratio,
|
||||
m_perspective_specification.nearPlane,
|
||||
m_perspective_specification.farPlane
|
||||
m_perspective_specification.near_plane,
|
||||
m_perspective_specification.far_plane
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ void Application::game_loop()
|
|||
|
||||
// log debug data
|
||||
m_logger->log_debug_data();
|
||||
m_window->GetGfxContext()->log_debug_data();
|
||||
m_window->GetGfxContext()->GetUserInterface()->log_debug_data();
|
||||
m_window->get_graphics_context()->log_debug_data();
|
||||
m_window->get_graphics_context()->get_user_interface()->log_debug_data();
|
||||
|
||||
// reveal window
|
||||
m_window->set_visibility(true);
|
||||
|
@ -59,7 +59,7 @@ void Application::game_loop()
|
|||
m_instrumentor->begin_session("Logs/ProfileResults_GameLoop.json");
|
||||
|
||||
/* game loop */
|
||||
DeltaTimer deltaTimer;
|
||||
auto delta_timer = DeltaTimer {};
|
||||
while (!m_window->is_closed())
|
||||
{
|
||||
{
|
||||
|
@ -67,29 +67,29 @@ void Application::game_loop()
|
|||
lt_profile_scope("game_loop::update");
|
||||
|
||||
for (auto it = m_layer_stack->begin(); it != m_layer_stack->end(); it++)
|
||||
(*it)->on_update(deltaTimer.get_delta_time());
|
||||
(*it)->on_update(delta_timer.get_delta_time());
|
||||
}
|
||||
|
||||
{
|
||||
// render layers
|
||||
lt_profile_scope("game_loop::Render");
|
||||
m_window->GetGfxContext()->GetRenderer()->begin_frame();
|
||||
m_window->get_graphics_context()->get_renderer()->begin_frame();
|
||||
|
||||
for (auto it = m_layer_stack->begin(); it != m_layer_stack->end(); it++)
|
||||
(*it)->on_render();
|
||||
|
||||
m_window->GetGfxContext()->GetRenderer()->end_frame();
|
||||
m_window->get_graphics_context()->get_renderer()->end_frame();
|
||||
}
|
||||
|
||||
{
|
||||
// render user interface
|
||||
lt_profile_scope("game_loop::UserInterface");
|
||||
m_window->GetGfxContext()->GetUserInterface()->begin();
|
||||
m_window->get_graphics_context()->get_user_interface()->begin();
|
||||
|
||||
for (auto it = m_layer_stack->begin(); it != m_layer_stack->end(); it++)
|
||||
(*it)->on_user_interface_update();
|
||||
|
||||
m_window->GetGfxContext()->GetUserInterface()->end();
|
||||
m_window->get_graphics_context()->get_user_interface()->end();
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -99,7 +99,7 @@ void Application::game_loop()
|
|||
}
|
||||
|
||||
/// update delta time
|
||||
deltaTimer.update();
|
||||
delta_timer.update();
|
||||
}
|
||||
|
||||
m_instrumentor->end_session(); // ProfileResults_GameLoop //
|
||||
|
@ -119,7 +119,7 @@ void Application::on_event(const Event &event)
|
|||
m_window->on_event(event);
|
||||
|
||||
if (event.get_event_type() == EventType::WindowResized)
|
||||
m_window->GetGfxContext()->GetRenderer()->on_window_resize(
|
||||
m_window->get_graphics_context()->get_renderer()->on_window_resize(
|
||||
(const WindowResizedEvent &)event
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
std::mt19937_64 UUID::s_engine = std::mt19937_64(std::random_device()());
|
||||
std::uniform_int_distribution<uint64_t> UUID::s_distribution;
|
||||
auto UUID::s_engine = std::mt19937_64(std::random_device()());
|
||||
auto UUID::s_distribution = std::uniform_int_distribution<uint64_t> {};
|
||||
|
||||
UUID::UUID(uint64_t uuid /* = -1 */): m_uuid(uuid == -1 ? s_distribution(s_engine) : uuid)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Light {
|
|||
|
||||
Instrumentor *Instrumentor::s_context = nullptr;
|
||||
|
||||
Scope<Instrumentor> Instrumentor::create()
|
||||
auto Instrumentor::create() -> Scope<Instrumentor>
|
||||
{
|
||||
return make_scope<Instrumentor>(new Instrumentor);
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ InstrumentorTimer::~InstrumentorTimer()
|
|||
m_result.start = std::chrono::time_point_cast<std::chrono::microseconds>(m_start)
|
||||
.time_since_epoch()
|
||||
.count();
|
||||
|
||||
m_result.duration = std::chrono::time_point_cast<std::chrono::microseconds>(end)
|
||||
.time_since_epoch()
|
||||
.count()
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Light {
|
|||
|
||||
logger *logger::s_context = nullptr;
|
||||
|
||||
Scope<logger> logger::create()
|
||||
auto logger::create() -> Scope<logger>
|
||||
{
|
||||
return make_scope<logger>(new logger());
|
||||
}
|
||||
|
|
|
@ -10,22 +10,23 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Scope<Blender> Blender::create(Ref<SharedContext> sharedContext)
|
||||
auto Blender::create(Ref<SharedContext> sharedContext) -> Scope<Blender>
|
||||
{
|
||||
switch (GraphicsContext::get_graphics_api())
|
||||
{
|
||||
case GraphicsAPI::OpenGL: return create_scope<glBlender>();
|
||||
|
||||
case GraphicsAPI::DirectX:
|
||||
lt_win(return create_scope<dxBlender>(std::static_pointer_cast<dxSharedContext>(sharedContext
|
||||
));)
|
||||
lt_win(return create_scope<dxBlender>(
|
||||
std::static_pointer_cast<dxSharedContext>(sharedContext)
|
||||
);)
|
||||
|
||||
default:
|
||||
lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
default
|
||||
: lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,13 +11,11 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
//================================================== CONSTANT_BUFFER
|
||||
//==================================================//
|
||||
Scope<ConstantBuffer> ConstantBuffer::create(
|
||||
auto ConstantBuffer::create(
|
||||
ConstantBufferIndex index,
|
||||
unsigned int size,
|
||||
Ref<SharedContext> sharedContext
|
||||
)
|
||||
) -> Scope<ConstantBuffer>
|
||||
{
|
||||
switch (GraphicsContext::get_graphics_api())
|
||||
{
|
||||
|
@ -30,26 +28,22 @@ Scope<ConstantBuffer> ConstantBuffer::create(
|
|||
std::static_pointer_cast<dxSharedContext>(sharedContext)
|
||||
);)
|
||||
|
||||
default:
|
||||
lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
default
|
||||
: lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
//================================================== CONSTANT_BUFFER
|
||||
//==================================================//
|
||||
|
||||
//================================================== VERTEX_BUFFER
|
||||
//==================================================//
|
||||
Ref<VertexBuffer> VertexBuffer::create(
|
||||
auto VertexBuffer::create(
|
||||
float *vertices,
|
||||
unsigned int stride,
|
||||
unsigned int count,
|
||||
Ref<SharedContext> sharedContext
|
||||
)
|
||||
) -> Ref<VertexBuffer>
|
||||
{
|
||||
switch (GraphicsContext::get_graphics_api())
|
||||
{
|
||||
|
@ -63,24 +57,21 @@ Ref<VertexBuffer> VertexBuffer::create(
|
|||
std::static_pointer_cast<dxSharedContext>(sharedContext)
|
||||
);)
|
||||
|
||||
default:
|
||||
lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
default
|
||||
: lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
//================================================== VERTEX_BUFFER
|
||||
//==================================================//
|
||||
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
Ref<IndexBuffer> IndexBuffer::create(
|
||||
auto IndexBuffer::create(
|
||||
unsigned int *indices,
|
||||
unsigned int count,
|
||||
Ref<SharedContext> sharedContext
|
||||
)
|
||||
) -> Ref<IndexBuffer>
|
||||
{
|
||||
switch (GraphicsContext::get_graphics_api())
|
||||
{
|
||||
|
@ -93,15 +84,14 @@ Ref<IndexBuffer> IndexBuffer::create(
|
|||
std::dynamic_pointer_cast<dxSharedContext>(sharedContext)
|
||||
);)
|
||||
|
||||
default:
|
||||
lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
default
|
||||
: lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Ref<Framebuffer> Framebuffer::create(
|
||||
auto Framebuffer::create(
|
||||
const FramebufferSpecification &specification,
|
||||
Ref<SharedContext> sharedContext
|
||||
)
|
||||
) -> Ref<Framebuffer>
|
||||
{
|
||||
switch (GraphicsContext::get_graphics_api())
|
||||
{
|
||||
|
@ -25,12 +25,12 @@ Ref<Framebuffer> Framebuffer::create(
|
|||
std::static_pointer_cast<dxSharedContext>(sharedContext)
|
||||
);)
|
||||
|
||||
default:
|
||||
lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
default
|
||||
: lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ GraphicsContext::~GraphicsContext()
|
|||
{
|
||||
}
|
||||
|
||||
Scope<GraphicsContext> GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle)
|
||||
auto GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle) -> Scope<GraphicsContext>
|
||||
{
|
||||
// terminate 'GraphicsContext' dependent classes
|
||||
if (s_context)
|
||||
|
@ -45,17 +45,18 @@ Scope<GraphicsContext> GraphicsContext::create(GraphicsAPI api, GLFWwindow *wind
|
|||
}
|
||||
|
||||
// create gfx context
|
||||
Scope<GraphicsContext> scopeGfx;
|
||||
auto scope_gfx = Scope<GraphicsContext> {};
|
||||
switch (api)
|
||||
{
|
||||
// opengl
|
||||
case GraphicsAPI::OpenGL:
|
||||
scopeGfx = create_scope<glGraphicsContext>(windowHandle);
|
||||
s_context = scopeGfx.get();
|
||||
scope_gfx = create_scope<glGraphicsContext>(windowHandle);
|
||||
s_context = scope_gfx.get();
|
||||
break;
|
||||
// directx
|
||||
case GraphicsAPI::DirectX:
|
||||
lt_win(scopeGfx = create_scope<dxGraphicsContext>(windowHandle); s_context = scopeGfx.get();
|
||||
lt_win(scope_gfx = create_scope<dxGraphicsContext>(windowHandle);
|
||||
s_context = scope_gfx.get();
|
||||
break;)
|
||||
|
||||
default
|
||||
|
@ -69,13 +70,13 @@ Scope<GraphicsContext> GraphicsContext::create(GraphicsAPI api, GLFWwindow *wind
|
|||
|
||||
// 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_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");
|
||||
|
||||
return std::move(scopeGfx);
|
||||
return std::move(scope_gfx);
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -10,10 +10,8 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Scope<RenderCommand> RenderCommand::create(
|
||||
GLFWwindow *windowHandle,
|
||||
Ref<SharedContext> sharedContext
|
||||
)
|
||||
auto RenderCommand::create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
|
||||
-> Scope<RenderCommand>
|
||||
{
|
||||
switch (GraphicsContext::get_graphics_api())
|
||||
{
|
||||
|
@ -24,12 +22,12 @@ Scope<RenderCommand> RenderCommand::create(
|
|||
(std::static_pointer_cast<dxSharedContext>)(sharedContext)
|
||||
);)
|
||||
|
||||
default:
|
||||
lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
default
|
||||
: lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
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_texture_renderer(LT_MAX_TEXTURE_RENDERER_VERTICES, sharedContext)
|
||||
, m_tinted_texture_renderer(LT_MAX_TINTED_TEXTURE_RENDERER_VERTICES, sharedContext)
|
||||
|
@ -39,19 +39,19 @@ renderer::renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
|
|||
m_blender->enable(BlendFactor::SRC_ALPHA, BlendFactor::INVERSE_SRC_ALPHA);
|
||||
}
|
||||
|
||||
Scope<renderer> renderer::create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
|
||||
auto Renderer::create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext) -> Scope<Renderer>
|
||||
{
|
||||
return make_scope<renderer>(new renderer(windowHandle, sharedContext));
|
||||
return make_scope<Renderer>(new Renderer(windowHandle, sharedContext));
|
||||
}
|
||||
|
||||
void renderer::on_window_resize(const WindowResizedEvent &event)
|
||||
void Renderer::on_window_resize(const WindowResizedEvent &event)
|
||||
{
|
||||
m_render_command->set_viewport(0u, 0u, event.get_size().x, event.get_size().y);
|
||||
}
|
||||
|
||||
//======================================== DRAW_QUAD ========================================//
|
||||
/* tinted textures */
|
||||
void renderer::draw_quad_impl(
|
||||
void Renderer::draw_quad_impl(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec2 &size,
|
||||
const glm::vec4 &tint,
|
||||
|
@ -67,7 +67,7 @@ void renderer::draw_quad_impl(
|
|||
}
|
||||
|
||||
/* tint */
|
||||
void renderer::draw_quad_impl(
|
||||
void Renderer::draw_quad_impl(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec2 &size,
|
||||
const glm::vec4 &tint
|
||||
|
@ -81,7 +81,7 @@ void renderer::draw_quad_impl(
|
|||
}
|
||||
|
||||
/* texture */
|
||||
void renderer::draw_quad_impl(
|
||||
void Renderer::draw_quad_impl(
|
||||
const glm::vec3 &position,
|
||||
const glm::vec2 &size,
|
||||
Ref<Texture> texture
|
||||
|
@ -96,10 +96,10 @@ void renderer::draw_quad_impl(
|
|||
//======================================== DRAW_QUAD ========================================//
|
||||
|
||||
//==================== DRAW_QUAD_TINT ====================//
|
||||
void renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint)
|
||||
void Renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint)
|
||||
{
|
||||
// locals
|
||||
QuadRendererProgram::QuadVertexData *bufferMap = m_quad_renderer.GetMapCurrent();
|
||||
QuadRendererProgram::QuadVertexData *bufferMap = m_quad_renderer.get_map_current();
|
||||
|
||||
// top left
|
||||
bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
|
||||
|
@ -127,14 +127,14 @@ void renderer::draw_quad_impl(const glm::mat4 &transform, const glm::vec4 &tint)
|
|||
//==================== DRAW_QUAD_TINT ====================//
|
||||
|
||||
//==================== DRAW_QUAD_TEXTURE ====================//
|
||||
void renderer::draw_quad_impl(const glm::mat4 &transform, Ref<Texture> texture)
|
||||
void Renderer::draw_quad_impl(const glm::mat4 &transform, Ref<Texture> texture)
|
||||
{
|
||||
// #todo: implement a proper binding
|
||||
lt_assert(texture, "Texture passed to renderer::draw_quad_impl");
|
||||
texture->bind();
|
||||
|
||||
// locals
|
||||
TextureRendererProgram::TextureVertexData *bufferMap = m_texture_renderer.GetMapCurrent();
|
||||
TextureRendererProgram::TextureVertexData *bufferMap = m_texture_renderer.get_map_current();
|
||||
|
||||
// top left
|
||||
bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
|
||||
|
@ -164,7 +164,7 @@ void renderer::draw_quad_impl(const glm::mat4 &transform, Ref<Texture> texture)
|
|||
}
|
||||
}
|
||||
|
||||
void renderer::draw_quad_impl(
|
||||
void Renderer::draw_quad_impl(
|
||||
const glm::mat4 &transform,
|
||||
const glm::vec4 &tint,
|
||||
Ref<Texture> texture
|
||||
|
@ -176,7 +176,7 @@ void renderer::draw_quad_impl(
|
|||
|
||||
// locals
|
||||
TintedTextureRendererProgram::TintedTextureVertexData *bufferMap = m_tinted_texture_renderer
|
||||
.GetMapCurrent();
|
||||
.get_map_current();
|
||||
|
||||
// top left
|
||||
bufferMap[0].position = transform * glm::vec4(-0.5f, -0.5f, 0.0f, 1.0f);
|
||||
|
@ -212,22 +212,22 @@ void renderer::draw_quad_impl(
|
|||
|
||||
//==================== DRAW_QUAD_TEXTURE ====================//
|
||||
|
||||
void renderer::begin_frame()
|
||||
void Renderer::begin_frame()
|
||||
{
|
||||
}
|
||||
|
||||
void renderer::end_frame()
|
||||
void Renderer::end_frame()
|
||||
{
|
||||
m_render_command->swap_buffers();
|
||||
m_render_command->clear_back_buffer(
|
||||
m_default_framebuffer_camera ? m_default_framebuffer_camera->GetBackgroundColor() :
|
||||
m_default_framebuffer_camera ? m_default_framebuffer_camera->get_background_color() :
|
||||
glm::vec4(0.0f)
|
||||
);
|
||||
|
||||
m_default_framebuffer_camera = nullptr;
|
||||
}
|
||||
|
||||
void renderer::begin_scene_impl(
|
||||
void Renderer::begin_scene_impl(
|
||||
Camera *camera,
|
||||
const glm::mat4 &cameraTransform,
|
||||
const Ref<Framebuffer> &targetFrameBuffer /* = nullptr */
|
||||
|
@ -237,7 +237,7 @@ void renderer::begin_scene_impl(
|
|||
m_target_framebuffer = targetFrameBuffer;
|
||||
|
||||
if (targetFrameBuffer)
|
||||
targetFrameBuffer->bind_as_target(camera->GetBackgroundColor());
|
||||
targetFrameBuffer->bind_as_target(camera->get_background_color());
|
||||
else
|
||||
{
|
||||
m_default_framebuffer_camera = camera;
|
||||
|
@ -246,7 +246,7 @@ void renderer::begin_scene_impl(
|
|||
|
||||
// update view projection buffer
|
||||
glm::mat4 *map = (glm::mat4 *)m_view_projection_buffer->map();
|
||||
map[0] = camera->GetProjection() * glm::inverse(cameraTransform);
|
||||
map[0] = camera->get_projection() * glm::inverse(cameraTransform);
|
||||
m_view_projection_buffer->un_map();
|
||||
|
||||
// map renderers
|
||||
|
@ -255,7 +255,7 @@ void renderer::begin_scene_impl(
|
|||
m_tinted_texture_renderer.map();
|
||||
}
|
||||
|
||||
void renderer::flush_scene()
|
||||
void Renderer::flush_scene()
|
||||
{
|
||||
/* tinted texture renderer */
|
||||
m_tinted_texture_renderer.un_map();
|
||||
|
@ -286,7 +286,7 @@ void renderer::flush_scene()
|
|||
m_tinted_texture_renderer.map();
|
||||
}
|
||||
|
||||
void renderer::end_scene_impl()
|
||||
void Renderer::end_scene_impl()
|
||||
{
|
||||
/* tinted texture renderer */
|
||||
m_tinted_texture_renderer.un_map();
|
||||
|
|
|
@ -38,7 +38,7 @@ QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, Ref<SharedCon
|
|||
));
|
||||
}
|
||||
|
||||
bool QuadRendererProgram::advance()
|
||||
auto QuadRendererProgram::advance() -> bool
|
||||
{
|
||||
m_map_current += 4;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ TextureRendererProgram::TextureRendererProgram(
|
|||
));
|
||||
}
|
||||
|
||||
bool TextureRendererProgram::advance()
|
||||
auto TextureRendererProgram::advance() -> bool
|
||||
{
|
||||
if (m_map_current + 4 >= m_map_end)
|
||||
{
|
||||
|
|
|
@ -43,7 +43,7 @@ TintedTextureRendererProgram::TintedTextureRendererProgram(
|
|||
));
|
||||
}
|
||||
|
||||
bool TintedTextureRendererProgram::advance()
|
||||
auto TintedTextureRendererProgram::advance() -> bool
|
||||
{
|
||||
m_map_current += 4;
|
||||
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Ref<Shader> Shader::create(
|
||||
auto Shader::create(
|
||||
BasicFileHandle vertexFile,
|
||||
BasicFileHandle pixelFile,
|
||||
Ref<SharedContext> sharedContext
|
||||
)
|
||||
) -> Ref<Shader>
|
||||
{
|
||||
// load shader source
|
||||
switch (GraphicsContext::get_graphics_api())
|
||||
|
@ -28,12 +28,12 @@ Ref<Shader> Shader::create(
|
|||
std::static_pointer_cast<dxSharedContext>(sharedContext)
|
||||
);)
|
||||
|
||||
default:
|
||||
lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
default
|
||||
: lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Ref<Texture> Texture::create(
|
||||
auto Texture::create(
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
unsigned int components,
|
||||
unsigned char *pixels,
|
||||
Ref<SharedContext> sharedContext,
|
||||
const std::string &filePath
|
||||
)
|
||||
) -> Ref<Texture>
|
||||
{
|
||||
switch (GraphicsContext::get_graphics_api())
|
||||
{
|
||||
|
@ -34,12 +34,12 @@ Ref<Texture> Texture::create(
|
|||
filePath
|
||||
);)
|
||||
|
||||
default:
|
||||
lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
default
|
||||
: lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Ref<VertexLayout> VertexLayout::create(
|
||||
auto VertexLayout::create(
|
||||
Ref<VertexBuffer> vertexBuffer,
|
||||
Ref<Shader> shader,
|
||||
const std::vector<std::pair<std::string, VertexElementType>> &elements,
|
||||
Ref<SharedContext> sharedContext
|
||||
)
|
||||
) -> Ref<VertexLayout>
|
||||
{
|
||||
switch (GraphicsContext::get_graphics_api())
|
||||
{
|
||||
|
@ -28,12 +28,12 @@ Ref<VertexLayout> VertexLayout::create(
|
|||
std::static_pointer_cast<dxSharedContext>(sharedContext)
|
||||
);)
|
||||
|
||||
default:
|
||||
lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
default
|
||||
: lt_assert(
|
||||
false,
|
||||
"Invalid/unsupported 'GraphicsAPI' {}",
|
||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
||||
);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Light {
|
|||
|
||||
Input *Input::s_context = nullptr;
|
||||
|
||||
Scope<Input> Input::create()
|
||||
auto Input::create() -> Scope<Input>
|
||||
{
|
||||
return make_scope(new Input);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ void Input::receive_user_interface_events_impl(bool receive, bool toggle /* = fa
|
|||
|
||||
void Input::receieve_game_events_impl(bool receive, bool toggle /*= false*/)
|
||||
{
|
||||
bool prev = m_game_events;
|
||||
auto prev = m_game_events;
|
||||
m_game_events = toggle ? !m_user_interface_events : receive;
|
||||
|
||||
if (m_game_events != prev)
|
||||
|
@ -59,18 +59,18 @@ void Input::restart_input_state()
|
|||
|
||||
void Input::on_event(const Event &inputEvent)
|
||||
{
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
auto &io = ImGui::GetIO();
|
||||
switch (inputEvent.get_event_type())
|
||||
{
|
||||
//** MOUSE_EVENTS **//
|
||||
case EventType::MouseMoved:
|
||||
{
|
||||
const MouseMovedEvent &event = (const MouseMovedEvent &)inputEvent;
|
||||
const auto &event = dynamic_cast<const MouseMovedEvent &>(inputEvent);
|
||||
|
||||
if (m_game_events)
|
||||
{
|
||||
m_mouse_delta = event.GetPosition() - m_mouse_position;
|
||||
m_mouse_position = event.GetPosition();
|
||||
m_mouse_delta = event.get_position() - m_mouse_position;
|
||||
m_mouse_position = event.get_position();
|
||||
}
|
||||
|
||||
if (m_user_interface_events)
|
||||
|
@ -80,7 +80,7 @@ void Input::on_event(const Event &inputEvent)
|
|||
}
|
||||
case EventType::ButtonPressed:
|
||||
{
|
||||
const ButtonPressedEvent &event = (const ButtonPressedEvent &)inputEvent;
|
||||
const auto &event = (const ButtonPressedEvent &)inputEvent;
|
||||
|
||||
if (m_game_events)
|
||||
m_mouse_buttons[event.get_button()] = true;
|
||||
|
@ -92,7 +92,7 @@ void Input::on_event(const Event &inputEvent)
|
|||
}
|
||||
case EventType::ButtonReleased:
|
||||
{
|
||||
const ButtonReleasedEvent &event = (const ButtonReleasedEvent &)inputEvent;
|
||||
const auto &event = (const ButtonReleasedEvent &)inputEvent;
|
||||
|
||||
if (m_game_events)
|
||||
m_mouse_buttons[event.get_button()] = false;
|
||||
|
@ -104,7 +104,7 @@ void Input::on_event(const Event &inputEvent)
|
|||
}
|
||||
case EventType::WheelScrolled:
|
||||
{
|
||||
const WheelScrolledEvent &event = (const WheelScrolledEvent &)inputEvent;
|
||||
const auto &event = (const WheelScrolledEvent &)inputEvent;
|
||||
|
||||
if (m_game_events)
|
||||
m_mouse_wheel_delta = event.get_offset();
|
||||
|
@ -117,7 +117,7 @@ void Input::on_event(const Event &inputEvent)
|
|||
//** KEYBOARD_EVENTS **//
|
||||
case EventType::KeyPressed:
|
||||
{
|
||||
const KeyPressedEvent &event = (const KeyPressedEvent &)inputEvent;
|
||||
const auto &event = (const KeyPressedEvent &)inputEvent;
|
||||
|
||||
if (m_game_events)
|
||||
m_keyboad_keys[event.get_key()] = true;
|
||||
|
@ -133,7 +133,7 @@ void Input::on_event(const Event &inputEvent)
|
|||
}
|
||||
case EventType::KeyReleased:
|
||||
{
|
||||
const KeyReleasedEvent &event = (const KeyReleasedEvent &)inputEvent;
|
||||
const auto &event = (const KeyReleasedEvent &)inputEvent;
|
||||
|
||||
if (m_game_events)
|
||||
m_keyboad_keys[event.get_key()] = false;
|
||||
|
@ -147,7 +147,7 @@ void Input::on_event(const Event &inputEvent)
|
|||
{
|
||||
if (m_user_interface_events)
|
||||
{
|
||||
const SetCharEvent &event = (const SetCharEvent &)inputEvent;
|
||||
const auto &event = (const SetCharEvent &)inputEvent;
|
||||
io.AddInputCharacter(event.get_character());
|
||||
}
|
||||
|
||||
|
|
|
@ -11,34 +11,23 @@ Layer::Layer(const std::string &name): m_layer_name(name)
|
|||
{
|
||||
}
|
||||
|
||||
bool Layer::on_event(const Event &event)
|
||||
auto Layer::on_event(const Event &event) -> bool
|
||||
{
|
||||
switch (event.get_event_type())
|
||||
{
|
||||
/* mouse */
|
||||
// cursor
|
||||
case EventType::MouseMoved: return on_mouse_moved((MouseMovedEvent &)event);
|
||||
// button
|
||||
case EventType::ButtonPressed: return on_button_pressed((ButtonPressedEvent &)event);
|
||||
case EventType::ButtonReleased: return on_button_released((ButtonReleasedEvent &)event);
|
||||
// wheel
|
||||
case EventType::WheelScrolled: return on_wheel_scrolled((WheelScrolledEvent &)event);
|
||||
|
||||
/* keyboard */
|
||||
// key
|
||||
case EventType::KeyPressed: return on_key_pressed((KeyPressedEvent &)event);
|
||||
case EventType::KeyRepeated: return on_key_repeat((KeyRepeatEvent &)event);
|
||||
case EventType::KeyReleased: return on_key_released((KeyReleasedEvent &)event);
|
||||
// char
|
||||
case EventType::SetChar: return on_set_char((SetCharEvent &)event);
|
||||
|
||||
/* window */
|
||||
// termination
|
||||
case EventType::WindowClosed: return on_window_closed((WindowClosedEvent &)event);
|
||||
// size/position
|
||||
case EventType::WindowResized: return on_window_resized((WindowResizedEvent &)event);
|
||||
case EventType::WindowMoved: return on_window_moved((WindowMovedEvent &)event);
|
||||
// focus
|
||||
case EventType::WindowLostFocus: return on_window_lost_focus((WindowLostFocusEvent &)event);
|
||||
case EventType::WindowGainFocus: return on_window_gain_focus((WindowGainFocusEvent &)event);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Light {
|
|||
|
||||
LayerStack *LayerStack::s_context = nullptr;
|
||||
|
||||
Scope<LayerStack> LayerStack::create()
|
||||
auto LayerStack::create() -> Scope<LayerStack>
|
||||
{
|
||||
return make_scope<LayerStack>(new LayerStack());
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ LayerStack::LayerStack(): m_layers {}, m_begin(), m_end()
|
|||
|
||||
LayerStack::~LayerStack()
|
||||
{
|
||||
for (Layer *layer : m_layers)
|
||||
for (auto *layer : m_layers)
|
||||
delete layer;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ void LayerStack::attach_layer_impl(Layer *layer)
|
|||
m_begin = m_layers.begin();
|
||||
m_end = m_layers.end();
|
||||
|
||||
lt_log(trace, "Attached [{}]", layer->GetName());
|
||||
lt_log(trace, "Attached [{}]", layer->get_name());
|
||||
}
|
||||
|
||||
void LayerStack::detach_layer_impl(Layer *layer)
|
||||
|
@ -46,7 +46,7 @@ void LayerStack::detach_layer_impl(Layer *layer)
|
|||
m_begin = m_layers.begin();
|
||||
m_end = m_layers.end();
|
||||
|
||||
lt_log(trace, "Detached [{}]", layer->GetName());
|
||||
lt_log(trace, "Detached [{}]", layer->get_name());
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -4,38 +4,38 @@
|
|||
namespace Light {
|
||||
namespace Math {
|
||||
|
||||
float rand(int min, int max, int decimals /* = 0 */)
|
||||
auto rand(int min, int max, int decimals /* = 0 */) -> float
|
||||
{
|
||||
const int dec = std::pow(10, decimals);
|
||||
const auto dec = static_cast<int>(std::pow(10, decimals));
|
||||
min *= dec;
|
||||
max *= dec;
|
||||
|
||||
return (min + (::rand() % (max)-min)) / (float)dec;
|
||||
}
|
||||
|
||||
glm::vec2 rand_vec2(int min, int max, int decimals /* = 0 */)
|
||||
auto rand_vec2(int min, int max, int decimals /* = 0 */) -> glm::vec2
|
||||
{
|
||||
const int dec = std::pow(10, decimals);
|
||||
const auto dec = static_cast<int>(std::pow(10, decimals));
|
||||
min *= dec;
|
||||
max *= dec;
|
||||
|
||||
float r1 = (min + (::rand() % (max)-min)) / (float)dec;
|
||||
float r2 = (min + (::rand() % (max)-min)) / (float)dec;
|
||||
auto r1 = (min + (::rand() % (max)-min)) / (float)dec;
|
||||
auto r2 = (min + (::rand() % (max)-min)) / (float)dec;
|
||||
|
||||
return glm::vec2(r1, r2);
|
||||
return { r1, r2 };
|
||||
}
|
||||
|
||||
glm::vec3 rand_vec3(int min, int max, int decimals /* = 0 */)
|
||||
auto rand_vec3(int min, int max, int decimals /* = 0 */) -> glm::vec3
|
||||
{
|
||||
const int dec = std::pow(10, decimals);
|
||||
const auto dec = static_cast<int>(std::pow(10, decimals));
|
||||
min *= dec;
|
||||
max *= dec;
|
||||
|
||||
float r1 = (min + (::rand() % (max - min))) / (float)dec;
|
||||
float r2 = (min + (::rand() % (max - min))) / (float)dec;
|
||||
float r3 = (min + (::rand() % (max - min))) / (float)dec;
|
||||
auto r1 = (min + (::rand() % (max - min))) / (float)dec;
|
||||
auto r2 = (min + (::rand() % (max - min))) / (float)dec;
|
||||
auto r3 = (min + (::rand() % (max - min))) / (float)dec;
|
||||
|
||||
return glm::vec3(r1, r2, r3);
|
||||
return { r1, r2, r3 };
|
||||
}
|
||||
} // namespace Math
|
||||
} // namespace Light
|
||||
|
|
|
@ -46,7 +46,7 @@ dxBlender::dxBlender(Ref<dxSharedContext> sharedContext)
|
|||
m_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||
|
||||
// create blend state
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
dxc(m_context->get_device()->CreateBlendState(&m_desc, &m_blend_state));
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ void dxBlender::enable(BlendFactor srcFactor, BlendFactor dstFactor)
|
|||
m_desc.RenderTarget[0].DestBlend = m_factor_map.at(dstFactor);
|
||||
|
||||
// re-create blind state
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
dxc(m_context->get_device()->CreateBlendState(&m_desc, &m_blend_state));
|
||||
|
||||
// bind blend state
|
||||
|
@ -71,7 +71,7 @@ void dxBlender::disable()
|
|||
m_desc.RenderTarget[0].BlendEnable = false;
|
||||
|
||||
// re-create blind state
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
dxc(m_context->get_device()->CreateBlendState(&m_desc, &m_blend_state));
|
||||
|
||||
// bind blend state
|
||||
|
|
|
@ -15,14 +15,14 @@ dxConstantBuffer::dxConstantBuffer(
|
|||
, m_map {}
|
||||
, m_index(static_cast<int>(index))
|
||||
{
|
||||
D3D11_BUFFER_DESC bDesc = {};
|
||||
auto bDesc = D3D11_BUFFER_DESC {};
|
||||
|
||||
bDesc.ByteWidth = size;
|
||||
bDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
bDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
dxc(m_context->get_device()->CreateBuffer(&bDesc, nullptr, &m_buffer));
|
||||
m_context->get_device_context()->VSSetConstantBuffers(m_index, 1u, m_buffer.GetAddressOf());
|
||||
}
|
||||
|
@ -32,10 +32,11 @@ void dxConstantBuffer::bind()
|
|||
m_context->get_device_context()->VSSetConstantBuffers(m_index, 1u, m_buffer.GetAddressOf());
|
||||
}
|
||||
|
||||
void *dxConstantBuffer::map()
|
||||
auto dxConstantBuffer::map() -> void *
|
||||
{
|
||||
m_context->get_device_context()->VSSetConstantBuffers(m_index, 1u, m_buffer.GetAddressOf());
|
||||
m_context->get_device_context()->map(m_buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_map);
|
||||
m_context->get_device_context()
|
||||
->map(m_buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_map);
|
||||
return m_map.pData;
|
||||
}
|
||||
|
||||
|
@ -43,11 +44,7 @@ void dxConstantBuffer::un_map()
|
|||
{
|
||||
m_context->get_device_context()->Unmap(m_buffer.Get(), NULL);
|
||||
}
|
||||
//======================================== CONSTANT_BUFFER
|
||||
//========================================//
|
||||
|
||||
//================================================== VERTEX_BUFFER
|
||||
//==================================================//
|
||||
dxVertexBuffer::dxVertexBuffer(
|
||||
float *vertices,
|
||||
unsigned int stride,
|
||||
|
@ -60,7 +57,7 @@ dxVertexBuffer::dxVertexBuffer(
|
|||
, m_stride(stride)
|
||||
{
|
||||
// buffer desc
|
||||
D3D11_BUFFER_DESC bDesc = {};
|
||||
auto bDesc = D3D11_BUFFER_DESC {};
|
||||
|
||||
bDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
bDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
|
@ -70,7 +67,7 @@ dxVertexBuffer::dxVertexBuffer(
|
|||
bDesc.StructureByteStride = stride;
|
||||
|
||||
// create buffer
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
dxc(m_context->get_device()->CreateBuffer(&bDesc, nullptr, &m_buffer));
|
||||
}
|
||||
|
||||
|
@ -79,9 +76,10 @@ dxVertexBuffer::~dxVertexBuffer()
|
|||
un_bind();
|
||||
}
|
||||
|
||||
void *dxVertexBuffer::map()
|
||||
auto dxVertexBuffer::map() -> void *
|
||||
{
|
||||
m_context->get_device_context()->map(m_buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_map);
|
||||
m_context->get_device_context()
|
||||
->map(m_buffer.Get(), NULL, D3D11_MAP_WRITE_DISCARD, NULL, &m_map);
|
||||
return m_map.pData;
|
||||
}
|
||||
|
||||
|
@ -92,22 +90,19 @@ void dxVertexBuffer::un_map()
|
|||
|
||||
void dxVertexBuffer::bind()
|
||||
{
|
||||
static const unsigned int offset = 0u;
|
||||
static const auto offset = unsigned int { 0u };
|
||||
m_context->get_device_context()
|
||||
->IASetVertexBuffers(0u, 1u, m_buffer.GetAddressOf(), &m_stride, &offset);
|
||||
}
|
||||
|
||||
void dxVertexBuffer::un_bind()
|
||||
{
|
||||
static const unsigned int offset = 0u;
|
||||
static ID3D11Buffer *buffer = nullptr;
|
||||
static const auto offset = unsigned int { 0u };
|
||||
static auto *buffer = (ID3D11Buffer *)(nullptr);
|
||||
|
||||
m_context->get_device_context()->IASetVertexBuffers(0u, 1u, &buffer, &m_stride, &offset);
|
||||
}
|
||||
//================================================== VERTEX_BUFFER
|
||||
//==================================================//
|
||||
|
||||
//======================================== INDEX_BUFFER ========================================//
|
||||
dxIndexBuffer::dxIndexBuffer(
|
||||
unsigned int *indices,
|
||||
unsigned int count,
|
||||
|
@ -117,20 +112,25 @@ dxIndexBuffer::dxIndexBuffer(
|
|||
, m_buffer(nullptr)
|
||||
{
|
||||
// generate indices if not provided
|
||||
bool hasIndices = !!indices;
|
||||
auto hasIndices = !!indices;
|
||||
if (!hasIndices)
|
||||
{
|
||||
// check
|
||||
if (count % 6 != 0)
|
||||
{
|
||||
lt_log(warn, "'indices' can only be null if count is multiple of 6");
|
||||
lt_log(warn, "Adding {} to 'count' -> {}", (6 - (count % 6)), count + (6 - (count % 6)));
|
||||
lt_log(
|
||||
warn,
|
||||
"Adding {} to 'count' -> {}",
|
||||
(6 - (count % 6)),
|
||||
count + (6 - (count % 6))
|
||||
);
|
||||
count = count + (6 - (count % 6));
|
||||
}
|
||||
|
||||
// create indices
|
||||
indices = new unsigned int[count];
|
||||
unsigned int offset = 0;
|
||||
auto offset = 0;
|
||||
for (unsigned int i = 0; i < count; i += 6)
|
||||
{
|
||||
indices[i + 0] = offset + 0u;
|
||||
|
@ -146,7 +146,7 @@ dxIndexBuffer::dxIndexBuffer(
|
|||
}
|
||||
|
||||
// buffer desc
|
||||
D3D11_BUFFER_DESC bDesc = {};
|
||||
auto bDesc = D3D11_BUFFER_DESC {};
|
||||
bDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
bDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
|
||||
|
@ -154,11 +154,11 @@ dxIndexBuffer::dxIndexBuffer(
|
|||
bDesc.StructureByteStride = sizeof(unsigned int);
|
||||
|
||||
// subresource data
|
||||
D3D11_SUBRESOURCE_DATA sDesc = {};
|
||||
auto sDesc = D3D11_SUBRESOURCE_DATA {};
|
||||
sDesc.pSysMem = indices;
|
||||
|
||||
// create buffer
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
dxc(m_context->get_device()->CreateBuffer(&bDesc, &sDesc, &m_buffer));
|
||||
|
||||
// delete indices
|
||||
|
@ -178,8 +178,8 @@ void dxIndexBuffer::bind()
|
|||
|
||||
void dxIndexBuffer::un_bind()
|
||||
{
|
||||
static const unsigned int offset = 0u;
|
||||
static ID3D11Buffer *buffer = nullptr;
|
||||
static const auto offset = (unsigned int) { 0u };
|
||||
static auto *buffer = (ID3D11Buffer *)(nullptr);
|
||||
|
||||
m_context->get_device_context()->IASetIndexBuffer(buffer, DXGI_FORMAT_R32_UINT, offset);
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ dxFramebuffer::dxFramebuffer(
|
|||
, m_shader_resource_view(nullptr)
|
||||
, m_depth_stencil_view(nullptr)
|
||||
{
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
|
||||
D3D11_TEXTURE2D_DESC t2dDesc = {};
|
||||
auto t2dDesc = D3D11_TEXTURE2D_DESC {};
|
||||
t2dDesc.Width = specification.width;
|
||||
t2dDesc.Height = specification.height;
|
||||
t2dDesc.MipLevels = 1;
|
||||
|
@ -31,15 +31,16 @@ dxFramebuffer::dxFramebuffer(
|
|||
t2dDesc.MiscFlags = NULL;
|
||||
dxc(m_context->get_device()->CreateTexture2D(&t2dDesc, nullptr, &m_color_attachment));
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
||||
auto srvDesc = D3D11_SHADER_RESOURCE_VIEW_DESC {};
|
||||
srvDesc.Format = t2dDesc.Format;
|
||||
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srvDesc.Texture2D.MipLevels = 1;
|
||||
srvDesc.Texture2D.MostDetailedMip = 0;
|
||||
dxc(m_context->get_device()
|
||||
->CreateShaderResourceView(m_color_attachment.Get(), &srvDesc, &m_shader_resource_view));
|
||||
->CreateShaderResourceView(m_color_attachment.Get(), &srvDesc, &m_shader_resource_view)
|
||||
);
|
||||
|
||||
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {};
|
||||
auto rtvDesc = D3D11_RENDER_TARGET_VIEW_DESC {};
|
||||
rtvDesc.Format = t2dDesc.Format;
|
||||
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
||||
rtvDesc.Texture2D.MipSlice = 0u;
|
||||
|
@ -60,7 +61,7 @@ void dxFramebuffer::bind_as_target(const glm::vec4 &clearColor)
|
|||
->OMSetRenderTargets(1u, m_render_target_view.GetAddressOf(), nullptr);
|
||||
m_context->get_device_context()->ClearRenderTargetView(m_render_target_view.Get(), color);
|
||||
|
||||
D3D11_VIEWPORT viewport;
|
||||
auto viewport = D3D11_VIEWPORT {};
|
||||
|
||||
viewport.TopLeftX = 0;
|
||||
viewport.TopLeftY = 0;
|
||||
|
@ -85,9 +86,9 @@ void dxFramebuffer::resize(const glm::uvec2 &size)
|
|||
m_specification.width = std::clamp(size.x, 1u, 16384u);
|
||||
m_specification.height = std::clamp(size.y, 1u, 16384u);
|
||||
|
||||
D3D11_TEXTURE2D_DESC textureDesc;
|
||||
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
||||
auto textureDesc = D3D11_TEXTURE2D_DESC {};
|
||||
auto rtvDesc = D3D11_RENDER_TARGET_VIEW_DESC {};
|
||||
auto srvDesc = D3D11_SHADER_RESOURCE_VIEW_DESC {};
|
||||
|
||||
m_color_attachment->GetDesc(&textureDesc);
|
||||
m_render_target_view->GetDesc(&rtvDesc);
|
||||
|
@ -96,12 +97,13 @@ void dxFramebuffer::resize(const glm::uvec2 &size)
|
|||
textureDesc.Width = m_specification.width;
|
||||
textureDesc.Height = m_specification.height;
|
||||
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
dxc(m_context->get_device()->CreateTexture2D(&textureDesc, nullptr, &m_color_attachment));
|
||||
dxc(m_context->get_device()
|
||||
->CreateRenderTargetView(m_color_attachment.Get(), &rtvDesc, &m_render_target_view));
|
||||
dxc(m_context->get_device()
|
||||
->CreateShaderResourceView(m_color_attachment.Get(), &srvDesc, &m_shader_resource_view));
|
||||
->CreateShaderResourceView(m_color_attachment.Get(), &srvDesc, &m_shader_resource_view)
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -31,10 +31,10 @@ dxGraphicsContext::dxGraphicsContext(GLFWwindow *windowHandle)
|
|||
|
||||
void dxGraphicsContext::setup_device_and_swap_chain(GLFWwindow *windowHandle)
|
||||
{
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_shared_context);
|
||||
auto context = std::static_pointer_cast<dxSharedContext>(m_shared_context);
|
||||
|
||||
// swap chain desc
|
||||
DXGI_SWAP_CHAIN_DESC sd = { 0 };
|
||||
auto sd = DXGI_SWAP_CHAIN_DESC { 0 };
|
||||
|
||||
// buffer desc
|
||||
sd.BufferDesc.Width = 1u;
|
||||
|
@ -62,7 +62,7 @@ void dxGraphicsContext::setup_device_and_swap_chain(GLFWwindow *windowHandle)
|
|||
sd.Flags = NULL;
|
||||
|
||||
// determine device flags
|
||||
UINT flags = NULL;
|
||||
auto flags = UINT { NULL };
|
||||
#ifdef LIGHT_DEBUG
|
||||
flags = D3D11_CREATE_DEVICE_DEBUG;
|
||||
#endif
|
||||
|
@ -86,13 +86,13 @@ void dxGraphicsContext::setup_device_and_swap_chain(GLFWwindow *windowHandle)
|
|||
|
||||
void dxGraphicsContext::setup_render_targets()
|
||||
{
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_shared_context);
|
||||
auto context = std::static_pointer_cast<dxSharedContext>(m_shared_context);
|
||||
|
||||
// set primitive topology
|
||||
context->get_device_context()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
|
||||
// create render target view
|
||||
Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer;
|
||||
auto backBuffer = Microsoft::WRL::ComPtr<ID3D11Resource> {};
|
||||
|
||||
dxc(context->get_swap_chain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer));
|
||||
dxc(context->get_device()
|
||||
|
@ -134,22 +134,22 @@ void dxGraphicsContext::setup_debug_interface()
|
|||
|
||||
void dxGraphicsContext::log_debug_data()
|
||||
{
|
||||
Ref<dxSharedContext> context = std::static_pointer_cast<dxSharedContext>(m_shared_context);
|
||||
auto context = std::static_pointer_cast<dxSharedContext>(m_shared_context);
|
||||
|
||||
// locals
|
||||
IDXGIDevice *DXGIDevice;
|
||||
IDXGIAdapter *DXGIAdapter;
|
||||
DXGI_ADAPTER_DESC DXGIAdapterDesc;
|
||||
auto *DXGIDevice = (IDXGIDevice *) {};
|
||||
auto *DXGIAdapter = (IDXGIAdapter *) {};
|
||||
auto *DXGIAdapterDesc = (DXGI_ADAPTER_DESC *) {};
|
||||
|
||||
context->get_device()->QueryInterface(__uuidof(IDXGIDevice), (void **)&DXGIDevice);
|
||||
DXGIDevice->GetAdapter(&DXGIAdapter);
|
||||
DXGIAdapter->GetDesc(&DXGIAdapterDesc);
|
||||
|
||||
// get the adapter's description
|
||||
char DefChar = ' ';
|
||||
auto DefChar = ' ';
|
||||
char ch[180];
|
||||
WideCharToMultiByte(CP_ACP, 0, DXGIAdapterDesc.Description, -1, ch, 180, &DefChar, NULL);
|
||||
std::string adapterDesc(ch);
|
||||
auto adapterDesc = std::string { ch };
|
||||
|
||||
// release memory
|
||||
DXGIDevice->release();
|
||||
|
|
|
@ -60,7 +60,7 @@ void dxRenderCommand::set_viewport(
|
|||
set_resolution(width, height);
|
||||
|
||||
// create viewport
|
||||
D3D11_VIEWPORT viewport;
|
||||
auto viewport = D3D11_VIEWPORT {};
|
||||
|
||||
viewport.TopLeftX = x;
|
||||
viewport.TopLeftY = y;
|
||||
|
@ -77,10 +77,10 @@ void dxRenderCommand::set_viewport(
|
|||
|
||||
void dxRenderCommand::set_resolution(unsigned int width, unsigned int height)
|
||||
{
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
|
||||
// remove render target
|
||||
ID3D11RenderTargetView *nullViews[] = { nullptr };
|
||||
auto *nullViews[] = (ID3D11RenderTargetView *) { nullptr };
|
||||
m_context->get_device_context()->OMSetRenderTargets(1u, nullViews, nullptr);
|
||||
m_context->GetRenderTargetViewRef().reset();
|
||||
|
||||
|
@ -89,7 +89,7 @@ void dxRenderCommand::set_resolution(unsigned int width, unsigned int height)
|
|||
->ResizeBuffers(0u, width, height, DXGI_FORMAT_R8G8B8A8_UNORM, NULL));
|
||||
|
||||
// create render target
|
||||
Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer = nullptr;
|
||||
auto backBuffer = Microsoft::WRL::ComPtr<ID3D11Resource> { nullptr };
|
||||
dxc(m_context->get_swap_chain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer));
|
||||
dxc(m_context->get_device()->CreateRenderTargetView(
|
||||
backBuffer.Get(),
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
namespace Light {
|
||||
|
||||
dxShader::dxShader(
|
||||
basic_file_handle vertexFile,
|
||||
basic_file_handle pixelFile,
|
||||
BasicFileHandle vertexFile,
|
||||
BasicFileHandle pixelFile,
|
||||
Ref<dxSharedContext> sharedContext
|
||||
)
|
||||
: m_context(sharedContext)
|
||||
|
@ -14,7 +14,9 @@ dxShader::dxShader(
|
|||
, m_pixel_shader(nullptr)
|
||||
, m_vertex_blob(nullptr)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<ID3DBlob> ps = nullptr, vsErr = nullptr, psErr = nullptr;
|
||||
auto ps = Microsoft::WRL::ComPtr<ID3DBlob> { nullptr };
|
||||
auto vsErr = Microsoft::WRL::ComPtr<ID3DBlob> { nullptr };
|
||||
auto psErr = Microsoft::WRL::ComPtr<ID3DBlob> { nullptr };
|
||||
|
||||
// compile shaders (we don't use dxc here because if d3_d_compile fails it throws a dxException
|
||||
// without logging the vsErr/psErr
|
||||
|
@ -50,7 +52,7 @@ dxShader::dxShader(
|
|||
lt_assert(!psErr.Get(), "Pixels shader compile error: {}", (char *)psErr->GetBufferPointer());
|
||||
|
||||
// create shaders
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
dxc(m_context->get_device()->CreateVertexShader(
|
||||
m_vertex_blob->GetBufferPointer(),
|
||||
m_vertex_blob->GetBufferSize(),
|
||||
|
@ -58,7 +60,8 @@ dxShader::dxShader(
|
|||
&m_vertex_shader
|
||||
));
|
||||
dxc(m_context->get_device()
|
||||
->CreatePixelShader(ps->GetBufferPointer(), ps->GetBufferSize(), NULL, &m_pixel_shader));
|
||||
->CreatePixelShader(ps->GetBufferPointer(), ps->GetBufferSize(), NULL, &m_pixel_shader)
|
||||
);
|
||||
}
|
||||
|
||||
dxShader::~dxShader()
|
||||
|
|
|
@ -18,7 +18,7 @@ dxTexture::dxTexture(
|
|||
, m_sampler_state(nullptr)
|
||||
{
|
||||
// texture2d desc
|
||||
D3D11_TEXTURE2D_DESC t2dDesc = {};
|
||||
auto t2dDesc = D3D11_TEXTURE2D_DESC {};
|
||||
t2dDesc.Width = width;
|
||||
t2dDesc.Height = height;
|
||||
t2dDesc.MipLevels = 0u;
|
||||
|
@ -37,7 +37,7 @@ dxTexture::dxTexture(
|
|||
t2dDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
|
||||
|
||||
// create texture
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
dxc(m_context->get_device()->CreateTexture2D(&t2dDesc, nullptr, &m_texture_2d));
|
||||
m_context->get_device_context()
|
||||
->UpdateSubresource(m_texture_2d.Get(), 0u, nullptr, pixels, width * 4u, 0u);
|
||||
|
@ -45,7 +45,7 @@ dxTexture::dxTexture(
|
|||
m_texture_2d->GetDesc(&t2dDesc);
|
||||
|
||||
// shader resource view desc
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
||||
auto srvDesc = D3D11_SHADER_RESOURCE_VIEW_DESC {};
|
||||
srvDesc.Format = t2dDesc.Format;
|
||||
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srvDesc.Texture2D.MostDetailedMip = 0u;
|
||||
|
@ -57,7 +57,7 @@ dxTexture::dxTexture(
|
|||
m_context->get_device_context()->GenerateMips(m_shader_resource_view.Get());
|
||||
|
||||
// sampler desc
|
||||
D3D11_SAMPLER_DESC sDesc = {};
|
||||
auto sDesc = D3D11_SAMPLER_DESC {};
|
||||
sDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
sDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
|
|
|
@ -16,8 +16,8 @@ void dxUserInterface::platform_implementation(
|
|||
Ref<SharedContext> sharedContext
|
||||
)
|
||||
{
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
Ref<dxSharedContext> context = std::dynamic_pointer_cast<dxSharedContext>(sharedContext);
|
||||
auto &io = ImGui::GetIO();
|
||||
auto context = std::dynamic_pointer_cast<dxSharedContext>(sharedContext);
|
||||
|
||||
ImGui_ImplWin32_Init(glfwGetWin32Window(windowHandle));
|
||||
ImGui_ImplDX11_Init(context->get_device().Get(), context->get_device_context().Get());
|
||||
|
@ -26,7 +26,7 @@ void dxUserInterface::platform_implementation(
|
|||
dxUserInterface::~dxUserInterface()
|
||||
{
|
||||
// #todo: handle this in a better way
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
auto &io = ImGui::GetIO();
|
||||
|
||||
if (io.IniFilename == "default_gui_layout.ini")
|
||||
io.IniFilename = "user_gui_layout.ini";
|
||||
|
|
|
@ -12,8 +12,7 @@ dxVertexLayout::dxVertexLayout(
|
|||
: m_context(sharedContext)
|
||||
, m_input_layout(nullptr)
|
||||
{
|
||||
// occupy space for input elements
|
||||
std::vector<D3D11_INPUT_ELEMENT_DESC> inputElementsDesc;
|
||||
auto inputElementsDesc = std::vector<D3D11_INPUT_ELEMENT_DESC> {};
|
||||
inputElementsDesc.reserve(elements.size());
|
||||
|
||||
// extract elements desc
|
||||
|
@ -28,11 +27,11 @@ dxVertexLayout::dxVertexLayout(
|
|||
0u });
|
||||
}
|
||||
|
||||
Ref<dxShader> dxpShader = std::dynamic_pointer_cast<dxShader>(shader);
|
||||
auto dxpShader = std::dynamic_pointer_cast<dxShader>(shader);
|
||||
lt_assert(dxpShader, "Failed to cast 'Shader' to 'dxShader'");
|
||||
|
||||
// create input layout (vertex layout)
|
||||
HRESULT hr;
|
||||
auto hr = HRESULT {};
|
||||
dxc(m_context->get_device()->CreateInputLayout(
|
||||
&inputElementsDesc[0],
|
||||
inputElementsDesc.size(),
|
||||
|
@ -57,7 +56,7 @@ void dxVertexLayout::un_bind()
|
|||
m_context->get_device_context()->IASetInputLayout(nullptr);
|
||||
}
|
||||
|
||||
DXGI_FORMAT dxVertexLayout::get_dxgi_format(VertexElementType type)
|
||||
auto dxVertexLayout::get_dxgi_format(VertexElementType type) -> DXGI_FORMAT
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
@ -24,9 +24,9 @@ void glConstantBuffer::bind()
|
|||
glBindBufferBase(GL_UNIFORM_BUFFER, m_index, m_buffer_id);
|
||||
}
|
||||
|
||||
void *glConstantBuffer::map()
|
||||
auto glConstantBuffer::map() -> void *
|
||||
{
|
||||
void *map = glMapNamedBuffer(m_buffer_id, GL_WRITE_ONLY);
|
||||
auto *map = glMapNamedBuffer(m_buffer_id, GL_WRITE_ONLY);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ void glVertexBuffer::un_bind()
|
|||
glBindBuffer(GL_ARRAY_BUFFER, NULL);
|
||||
}
|
||||
|
||||
void *glVertexBuffer::map()
|
||||
auto glVertexBuffer::map() -> void *
|
||||
{
|
||||
return glMapNamedBuffer(m_buffer_id, GL_WRITE_ONLY);
|
||||
}
|
||||
|
@ -74,21 +74,26 @@ void glVertexBuffer::un_map()
|
|||
glIndexBuffer::glIndexBuffer(unsigned int *indices, unsigned int count): m_buffer_id(NULL)
|
||||
{
|
||||
// generate indices if not provided
|
||||
bool hasIndices = !!indices;
|
||||
auto hasIndices = !!indices;
|
||||
if (!hasIndices)
|
||||
{
|
||||
// check
|
||||
if (count % 6 != 0)
|
||||
{
|
||||
lt_log(warn, "'indices' can only be null if count is multiple of 6");
|
||||
lt_log(warn, "Adding {} to 'count' -> {}", (6 - (count % 6)), count + (6 - (count % 6)));
|
||||
lt_log(
|
||||
warn,
|
||||
"Adding {} to 'count' -> {}",
|
||||
(6 - (count % 6)),
|
||||
count + (6 - (count % 6))
|
||||
);
|
||||
count = count + (6 - (count % 6));
|
||||
}
|
||||
|
||||
// create indices
|
||||
indices = new unsigned int[count];
|
||||
unsigned int offset = 0u;
|
||||
for (unsigned int i = 0u; i < count; i += 6u)
|
||||
auto offset = 0u;
|
||||
for (auto i = 0u; i < count; i += 6u)
|
||||
{
|
||||
indices[i + 0] = offset + 0u;
|
||||
indices[i + 1] = offset + 1u;
|
||||
|
|
|
@ -42,7 +42,6 @@ void glGraphicsContext::log_debug_data()
|
|||
void glGraphicsContext::set_debug_message_callback()
|
||||
{
|
||||
// determine log level
|
||||
// #todo: set filters from config.h
|
||||
#if defined(LIGHT_DEBUG)
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
|
||||
|
@ -89,22 +88,26 @@ void glGraphicsContext::set_debug_message_callback()
|
|||
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
lt_log(warn,
|
||||
lt_log(
|
||||
warn,
|
||||
"glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}",
|
||||
Stringifier::glDebugMsgSeverity(severity),
|
||||
Stringifier::glDebugMsgSource(source),
|
||||
Stringifier::glDebugMsgType(type),
|
||||
id);
|
||||
id
|
||||
);
|
||||
lt_log(warn, " {}", message);
|
||||
return;
|
||||
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
||||
lt_log(trace,
|
||||
lt_log(
|
||||
trace,
|
||||
"Severity: {} :: Source: {} :: Type: {} :: ID: {}",
|
||||
Stringifier::glDebugMsgSeverity(severity),
|
||||
Stringifier::glDebugMsgSource(source),
|
||||
Stringifier::glDebugMsgType(type),
|
||||
id);
|
||||
id
|
||||
);
|
||||
lt_log(trace, " {}", message);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -61,18 +61,18 @@ void glShader::un_bind()
|
|||
// // log error
|
||||
// if (result.GetCompilationStatus() != shaderc_compilation_status_success)
|
||||
// {
|
||||
// lt_log(err, "Failed to compile {} shader at {}...", stage == Shader::Stage::VERTEX ? "vertex" :
|
||||
// "pixel", file.GetPath()); lt_log(err, " {}", result.GetErrorMessage());
|
||||
// lt_log(err, "Failed to compile {} shader at {}...", stage == Shader::Stage::VERTEX ?
|
||||
// "vertex" : "pixel", file.GetPath()); lt_log(err, " {}", result.GetErrorMessage());
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
|
||||
unsigned int glShader::compile_shader(std::string source, Shader::Stage stage)
|
||||
auto glShader::compile_shader(std::string source, Shader::Stage stage) -> unsigned int
|
||||
{
|
||||
// &(address of) needs an lvalue
|
||||
const char *lvalue_source = source.c_str();
|
||||
unsigned int shader = glCreateShader(
|
||||
const auto *lvalue_source = source.c_str();
|
||||
auto shader = glCreateShader(
|
||||
stage == Shader::Stage::VERTEX ? GL_VERTEX_SHADER :
|
||||
stage == Shader::Stage::PIXEL ? GL_FRAGMENT_SHADER :
|
||||
stage == Shader::Stage::GEOMETRY ? GL_GEOMETRY_SHADER :
|
||||
|
@ -84,20 +84,22 @@ unsigned int glShader::compile_shader(std::string source, Shader::Stage stage)
|
|||
glCompileShader(shader);
|
||||
|
||||
// check
|
||||
int isCompiled = 0;
|
||||
auto isCompiled = 0;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled);
|
||||
if (isCompiled == GL_FALSE)
|
||||
{
|
||||
int logLength = 0;
|
||||
auto logLength = 0;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
|
||||
|
||||
char *errorLog = (char *)alloca(logLength);
|
||||
auto *errorLog = (char *)alloca(logLength);
|
||||
glGetShaderInfoLog(shader, logLength, &logLength, &errorLog[0]);
|
||||
|
||||
lt_log(err,
|
||||
lt_log(
|
||||
err,
|
||||
"glShader::glShader: failed to compile {} shader:\n {}",
|
||||
stage == Shader::Stage::VERTEX ? "Vertex" : "Pixel",
|
||||
errorLog);
|
||||
errorLog
|
||||
);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -105,7 +107,7 @@ unsigned int glShader::compile_shader(std::string source, Shader::Stage stage)
|
|||
#ifdef LIGHT_OPENGL_ENABLE_SHADER_INFO_LOG
|
||||
// info log
|
||||
{
|
||||
int logLength = 0;
|
||||
auto logLength = 0;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
|
||||
if (logLength)
|
||||
{
|
||||
|
|
|
@ -23,17 +23,17 @@ glTexture::glTexture(
|
|||
glTextureParameteri(m_texture_id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
// determine formats
|
||||
unsigned int format = components == 4u ? GL_RGBA :
|
||||
components == 3u ? GL_RGB :
|
||||
components == 2u ? GL_RG :
|
||||
components == 1u ? GL_RED :
|
||||
NULL;
|
||||
auto format = components == 4u ? GL_RGBA :
|
||||
components == 3u ? GL_RGB :
|
||||
components == 2u ? GL_RG :
|
||||
components == 1u ? GL_RED :
|
||||
NULL;
|
||||
|
||||
unsigned int internalFormat = format == GL_RGBA ? GL_RGBA8 :
|
||||
format == GL_RGB ? GL_RGB8 :
|
||||
format == GL_RG ? GL_RG8 :
|
||||
format == GL_RED ? GL_R8 :
|
||||
NULL;
|
||||
auto internalFormat = format == GL_RGBA ? GL_RGBA8 :
|
||||
format == GL_RGB ? GL_RGB8 :
|
||||
format == GL_RG ? GL_RG8 :
|
||||
format == GL_RED ? GL_R8 :
|
||||
NULL;
|
||||
|
||||
// check
|
||||
lt_assert(format, "Invalid number of components: {}", components);
|
||||
|
@ -67,7 +67,7 @@ void glTexture::bind(unsigned int slot /* = 0u */)
|
|||
glBindTexture(GL_TEXTURE_2D, m_texture_id);
|
||||
}
|
||||
|
||||
void *glTexture::get_texture()
|
||||
auto glTexture::get_texture() -> void *
|
||||
{
|
||||
return (void *)(intptr_t)m_texture_id;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ void glUserInterface::platform_implementation(
|
|||
glUserInterface::~glUserInterface()
|
||||
{
|
||||
// #todo: handle this in a better way
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
auto &io = ImGui::GetIO();
|
||||
|
||||
if (io.IniFilename == "default_gui_layout.ini")
|
||||
io.IniFilename = "user_gui_layout.ini";
|
||||
|
|
|
@ -18,9 +18,9 @@ glVertexLayout::glVertexLayout(
|
|||
lt_assert(!elements.empty(), "'elements' is empty");
|
||||
|
||||
// local
|
||||
std::vector<glVertexElementDesc> elementsDesc;
|
||||
auto elementsDesc = std::vector<glVertexElementDesc> {};
|
||||
elementsDesc.reserve(elements.size());
|
||||
unsigned int stride = 0u;
|
||||
auto stride = 0u;
|
||||
|
||||
// extract elements desc
|
||||
for (const auto &element : elements)
|
||||
|
@ -37,7 +37,7 @@ glVertexLayout::glVertexLayout(
|
|||
bind();
|
||||
|
||||
// enable vertex attributes
|
||||
unsigned int index = 0u;
|
||||
auto index = 0u;
|
||||
for (const auto &elementDesc : elementsDesc)
|
||||
{
|
||||
glVertexAttribPointer(
|
||||
|
@ -67,7 +67,8 @@ void glVertexLayout::un_bind()
|
|||
glBindVertexArray(NULL);
|
||||
}
|
||||
|
||||
glVertexElementDesc glVertexLayout::get_element_desc(VertexElementType type, unsigned int offset)
|
||||
auto glVertexLayout::get_element_desc(VertexElementType type, unsigned int offset)
|
||||
-> glVertexElementDesc
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
Scope<Window> Window::create(std::function<void(Event &)> callback)
|
||||
auto Window::create(std::function<void(Event &)> callback) -> Scope<Window>
|
||||
{
|
||||
return create_scope<lWindow>(callback);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ void lWindow::
|
|||
set_properties(const WindowProperties &properties, bool overrideVisibility /* = false */)
|
||||
{
|
||||
// save the visibility status and re-assign if 'overrideVisibility' is false
|
||||
bool visible = overrideVisibility ? properties.visible : m_properties.visible;
|
||||
auto visible = overrideVisibility ? properties.visible : m_properties.visible;
|
||||
m_properties = properties;
|
||||
m_properties.visible = visible;
|
||||
|
||||
|
@ -120,119 +120,102 @@ void lWindow::set_visibility(bool visible, bool toggle)
|
|||
|
||||
void lWindow::bind_glfw_events()
|
||||
{
|
||||
//============================== MOUSE_EVENTS ==============================//
|
||||
/* cursor position */
|
||||
glfwSetCursorPosCallback(m_handle, [](GLFWwindow *window, double xpos, double ypos) {
|
||||
std::function<void(Event &)> callback = *(std::function<void(Event &)> *)
|
||||
glfwGetWindowUserPointer(window);
|
||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
||||
|
||||
MouseMovedEvent event(xpos, ypos);
|
||||
auto event = MouseMovedEvent {
|
||||
static_cast<float>(xpos),
|
||||
static_cast<float>(ypos),
|
||||
};
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* mouse button */
|
||||
glfwSetMouseButtonCallback(m_handle, [](GLFWwindow *window, int button, int action, int mods) {
|
||||
std::function<void(Event &)> callback = *(std::function<void(Event &)> *)
|
||||
glfwGetWindowUserPointer(window);
|
||||
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
ButtonPressedEvent event(button);
|
||||
auto event = ButtonPressedEvent { button };
|
||||
callback(event);
|
||||
}
|
||||
else if (action == GLFW_RELEASE)
|
||||
{
|
||||
ButtonReleasedEvent event(button);
|
||||
auto event = ButtonReleasedEvent { button };
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
|
||||
/* scroll */
|
||||
glfwSetScrollCallback(m_handle, [](GLFWwindow *window, double xoffset, double yoffset) {
|
||||
std::function<void(Event &)> callback = *(std::function<void(Event &)> *)
|
||||
glfwGetWindowUserPointer(window);
|
||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
||||
|
||||
WheelScrolledEvent event(yoffset);
|
||||
auto event = WheelScrolledEvent { static_cast<float>(yoffset) };
|
||||
callback(event);
|
||||
});
|
||||
//============================== MOUSE_EVENTS ==============================//
|
||||
|
||||
//============================== KEYBOARD_EVENTS ==============================//
|
||||
/* key */
|
||||
glfwSetKeyCallback(
|
||||
m_handle,
|
||||
[](GLFWwindow *window, int key, int scancode, int action, int mods) {
|
||||
std::function<void(Event &)> callback = *(std::function<void(Event &)> *)
|
||||
glfwGetWindowUserPointer(window);
|
||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
||||
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
KeyPressedEvent event(key);
|
||||
auto event = KeyPressedEvent { key };
|
||||
callback(event);
|
||||
}
|
||||
else if (action == GLFW_RELEASE)
|
||||
{
|
||||
KeyReleasedEvent event(key);
|
||||
auto event = KeyReleasedEvent { key };
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
);
|
||||
/* char */
|
||||
|
||||
glfwSetCharCallback(m_handle, [](GLFWwindow *window, unsigned int character) {
|
||||
std::function<void(Event &)> callback = *(std::function<void(Event &)> *)
|
||||
glfwGetWindowUserPointer(window);
|
||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
||||
|
||||
SetCharEvent event(character);
|
||||
auto event = SetCharEvent { character };
|
||||
callback(event);
|
||||
});
|
||||
|
||||
//============================== KEYBOARD_EVENTS ==============================//
|
||||
|
||||
//============================== WINDOW_EVENTS ==============================//
|
||||
/* window position */
|
||||
glfwSetWindowPosCallback(m_handle, [](GLFWwindow *window, int xpos, int ypos) {
|
||||
std::function<void(Event &)> callback = *(std::function<void(Event &)> *)
|
||||
glfwGetWindowUserPointer(window);
|
||||
WindowMovedEvent event(xpos, ypos);
|
||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
||||
auto event = WindowMovedEvent { xpos, ypos };
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window size */
|
||||
glfwSetWindowSizeCallback(m_handle, [](GLFWwindow *window, int width, int height) {
|
||||
std::function<void(Event &)> callback = *(std::function<void(Event &)> *)
|
||||
glfwGetWindowUserPointer(window);
|
||||
WindowResizedEvent event(width, height);
|
||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
||||
auto event = WindowResizedEvent {
|
||||
static_cast<unsigned int>(width),
|
||||
static_cast<unsigned int>(height),
|
||||
};
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window close */
|
||||
glfwSetWindowCloseCallback(m_handle, [](GLFWwindow *window) {
|
||||
std::function<void(Event &)> callback = *(std::function<void(Event &)> *)
|
||||
glfwGetWindowUserPointer(window);
|
||||
WindowClosedEvent event;
|
||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
||||
auto event = WindowClosedEvent {};
|
||||
|
||||
callback(event);
|
||||
});
|
||||
|
||||
/* window focus */
|
||||
glfwSetWindowFocusCallback(m_handle, [](GLFWwindow *window, int focus) {
|
||||
std::function<void(Event &)> callback = *(std::function<void(Event &)> *)
|
||||
glfwGetWindowUserPointer(window);
|
||||
auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window);
|
||||
|
||||
if (focus == GLFW_TRUE)
|
||||
{
|
||||
WindowGainFocusEvent event;
|
||||
auto event = WindowGainFocusEvent {};
|
||||
callback(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowLostFocusEvent event;
|
||||
auto event = WindowLostFocusEvent {};
|
||||
callback(event);
|
||||
}
|
||||
});
|
||||
//============================== WINDOW_EVENTS ==============================//
|
||||
}
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -40,8 +40,8 @@ void Scene::on_update(float deltaTime)
|
|||
|
||||
void Scene::on_render(const Ref<Framebuffer> &targetFrameBuffer /* = nullptr */)
|
||||
{
|
||||
Camera *sceneCamera = nullptr;
|
||||
TransformComponent *sceneCameraTransform;
|
||||
auto *sceneCamera = (Camera *) {};
|
||||
auto *sceneCameraTransform = (TransformComponent *) {};
|
||||
|
||||
/* scene camera */
|
||||
{
|
||||
|
@ -59,33 +59,33 @@ void Scene::on_render(const Ref<Framebuffer> &targetFrameBuffer /* = nullptr */)
|
|||
{
|
||||
if (sceneCamera)
|
||||
{
|
||||
renderer::begin_scene(sceneCamera, *sceneCameraTransform, targetFrameBuffer);
|
||||
Renderer::begin_scene(sceneCamera, *sceneCameraTransform, targetFrameBuffer);
|
||||
|
||||
m_registry.group(entt::get<TransformComponent, SpriteRendererComponent>)
|
||||
.each([](TransformComponent &transformComp,
|
||||
SpriteRendererComponent &spriteRendererComp) {
|
||||
renderer::draw_quad(
|
||||
Renderer::draw_quad(
|
||||
transformComp,
|
||||
spriteRendererComp.tint,
|
||||
spriteRendererComp.texture
|
||||
);
|
||||
});
|
||||
|
||||
renderer::end_scene();
|
||||
Renderer::end_scene();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Entity Scene::create_entity(const std::string &name, const TransformComponent &transform)
|
||||
auto Scene::create_entity(const std::string &name, const TransformComponent &transform) -> Entity
|
||||
{
|
||||
return create_entity_with_uuid(name, UUID(), transform);
|
||||
}
|
||||
|
||||
Entity Scene::get_entity_by_tag(const std::string &tag)
|
||||
auto Scene::get_entity_by_tag(const std::string &tag) -> Entity
|
||||
{
|
||||
// TagComponent tagComp(tag);
|
||||
// entt::entity entity = entt::to_entity(m_registry, tagComp);
|
||||
Entity entity;
|
||||
auto entity = Entity {};
|
||||
|
||||
m_registry.view<TagComponent>().each([&](TagComponent &tagComp) {
|
||||
// if (tagComp.tag == tag)
|
||||
|
@ -101,16 +101,16 @@ Entity Scene::get_entity_by_tag(const std::string &tag)
|
|||
}
|
||||
}
|
||||
|
||||
Entity Scene::create_entity_with_uuid(
|
||||
auto Scene::create_entity_with_uuid(
|
||||
const std::string &name,
|
||||
UUID uuid,
|
||||
const TransformComponent &transform
|
||||
)
|
||||
) -> Entity
|
||||
{
|
||||
Entity entity { m_registry.create(), this };
|
||||
entity.AddComponent<TagComponent>(name);
|
||||
entity.AddComponent<TransformComponent>(transform);
|
||||
entity.AddComponent<UUIDComponent>(uuid);
|
||||
auto entity = Entity { m_registry.create(), this };
|
||||
entity.add_component<TagComponent>(name);
|
||||
entity.add_component<TransformComponent>(transform);
|
||||
entity.add_component<UUIDComponent>(uuid);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ DeltaTimer::DeltaTimer(): m_previous_frame(NULL), m_delta_time(60.0f / 1000.0f)
|
|||
|
||||
void DeltaTimer::update()
|
||||
{
|
||||
float currentFrame = timer.get_elapsed_time();
|
||||
auto currentFrame = timer.get_elapsed_time();
|
||||
m_delta_time = currentFrame - m_previous_frame;
|
||||
m_previous_frame = currentFrame;
|
||||
}
|
||||
|
|
|
@ -18,12 +18,10 @@ namespace Light {
|
|||
|
||||
UserInterface *UserInterface::s_context = nullptr;
|
||||
|
||||
Scope<UserInterface> UserInterface::create(
|
||||
GLFWwindow *windowHandle,
|
||||
Ref<SharedContext> sharedContext
|
||||
)
|
||||
auto UserInterface::create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
|
||||
-> Scope<UserInterface>
|
||||
{
|
||||
Scope<UserInterface> scopeUserInterface = nullptr;
|
||||
auto scopeUserInterface = Scope<UserInterface> { nullptr };
|
||||
|
||||
switch (GraphicsContext::get_graphics_api())
|
||||
{
|
||||
|
|
|
@ -27,14 +27,14 @@ void BasicFileHandle::release()
|
|||
}
|
||||
|
||||
|
||||
BasicFileHandle FileManager::read_text_file(const std::string &path)
|
||||
auto FileManager::read_text_file(const std::string &path) -> BasicFileHandle
|
||||
{
|
||||
// parse path info
|
||||
std::string name = path.substr(0, path.find('.') + -1);
|
||||
std::string extension = path.substr(path.find('.') + 1);
|
||||
auto name = path.substr(0, path.find('.') + -1);
|
||||
auto extension = path.substr(path.find('.') + 1);
|
||||
|
||||
// open file
|
||||
std::ifstream file(path.c_str(), std::ios_base::in | std::ios_base::binary);
|
||||
auto file = std::ifstream { path.c_str(), std::ios_base::in | std::ios_base::binary };
|
||||
|
||||
// check
|
||||
if (!file)
|
||||
|
@ -46,45 +46,44 @@ BasicFileHandle FileManager::read_text_file(const std::string &path)
|
|||
|
||||
// fetch file size
|
||||
file.seekg(0, std::ios::end);
|
||||
uint32_t size = file.tellg();
|
||||
auto size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
if (!size)
|
||||
lt_log(warn, "Empty text file: {}", path);
|
||||
|
||||
// read file
|
||||
uint8_t *data = new uint8_t[size];
|
||||
auto *data = new uint8_t[size];
|
||||
file.read(reinterpret_cast<char *>(data), size);
|
||||
|
||||
file.close();
|
||||
return BasicFileHandle(data, size, path, name, extension);
|
||||
return { data, static_cast<unsigned int>(size), path, name, extension };
|
||||
}
|
||||
|
||||
ImageFileHandle FileManager::read_image_file(const std::string &path, int32_t desiredComponents)
|
||||
auto FileManager::read_image_file(const std::string &path, int32_t desiredComponents)
|
||||
-> ImageFileHandle
|
||||
{
|
||||
// parse path info
|
||||
std::string name = path.substr(0, path.find('.') + -1);
|
||||
std::string extension = path.substr(path.find('.') + 1);
|
||||
auto name = path.substr(0, path.find('.') + -1);
|
||||
auto extension = path.substr(path.find('.') + 1);
|
||||
|
||||
// load image
|
||||
int32_t width = 0, height = 0, fetchedComponents = 0;
|
||||
uint8_t *pixels = stbi_load(
|
||||
path.c_str(),
|
||||
&width,
|
||||
&height,
|
||||
&fetchedComponents,
|
||||
desiredComponents
|
||||
);
|
||||
auto width = 0;
|
||||
auto height = 0;
|
||||
auto fetchedComponents = 0;
|
||||
auto *pixels = stbi_load(path.c_str(), &width, &height, &fetchedComponents, desiredComponents);
|
||||
|
||||
// check
|
||||
if (!pixels)
|
||||
lt_log(warn, "Failed to load image file: <{}>", path);
|
||||
else if (fetchedComponents != desiredComponents)
|
||||
lt_log(warn,
|
||||
lt_log(
|
||||
warn,
|
||||
"Mismatch of fetched/desired components: <{}> ({}/{})",
|
||||
name + '.' + extension,
|
||||
fetchedComponents,
|
||||
desiredComponents);
|
||||
desiredComponents
|
||||
);
|
||||
|
||||
return ImageFileHandle(
|
||||
pixels,
|
||||
|
@ -106,5 +105,4 @@ void ImageFileHandle::release()
|
|||
m_size = 0ull;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Light {
|
|||
|
||||
ResourceManager *ResourceManager::s_context = nullptr;
|
||||
|
||||
Scope<ResourceManager> ResourceManager::create()
|
||||
auto ResourceManager::create() -> Scope<ResourceManager>
|
||||
{
|
||||
return make_scope(new ResourceManager());
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ void ResourceManager::load_shader_impl(
|
|||
lt_assert(!pixelPath.empty(), "Empty 'pixelPath'");
|
||||
|
||||
// load files
|
||||
BasicFileHandle vertexFile = FileManager::read_text_file(vertexPath);
|
||||
BasicFileHandle pixelFile = FileManager::read_text_file(pixelPath);
|
||||
auto vertexFile = FileManager::read_text_file(vertexPath);
|
||||
auto pixelFile = FileManager::read_text_file(pixelPath);
|
||||
|
||||
// check
|
||||
lt_assert(vertexFile.is_valid(), "Failed to read vertex file: {}", vertexPath);
|
||||
|
@ -57,7 +57,7 @@ void ResourceManager::load_texture_impl(
|
|||
lt_assert(s_context, "Uninitliazed singleton");
|
||||
|
||||
// load file
|
||||
ImageFileHandle imgFile = FileManager::read_image_file(path, desiredComponents);
|
||||
auto imgFile = FileManager::read_image_file(path, desiredComponents);
|
||||
|
||||
// create texture
|
||||
m_textures[name] = Ref<Texture>(Texture::create(
|
||||
|
|
|
@ -8,16 +8,16 @@ namespace YAML {
|
|||
template<>
|
||||
struct convert<glm::vec3>
|
||||
{
|
||||
static Node encode(const glm::vec3 &rhs)
|
||||
static auto encode(const glm::vec3 &rhs) -> Node
|
||||
{
|
||||
Node node;
|
||||
auto node = Node {};
|
||||
node.push_back(rhs.x);
|
||||
node.push_back(rhs.y);
|
||||
node.push_back(rhs.z);
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node &node, glm::vec3 &rhs)
|
||||
static auto decode(const Node &node, glm::vec3 &rhs) -> bool
|
||||
{
|
||||
if (!node.IsSequence() || node.size() != 3)
|
||||
return false;
|
||||
|
@ -32,9 +32,9 @@ struct convert<glm::vec3>
|
|||
template<>
|
||||
struct convert<glm::vec4>
|
||||
{
|
||||
static Node encode(const glm::vec4 &rhs)
|
||||
static auto encode(const glm::vec4 &rhs) -> Node
|
||||
{
|
||||
Node node;
|
||||
auto node = Node {};
|
||||
node.push_back(rhs.x);
|
||||
node.push_back(rhs.y);
|
||||
node.push_back(rhs.z);
|
||||
|
@ -42,7 +42,7 @@ struct convert<glm::vec4>
|
|||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node &node, glm::vec4 &rhs)
|
||||
static auto decode(const Node &node, glm::vec4 &rhs) -> bool
|
||||
{
|
||||
if (!node.IsSequence() || node.size() != 4)
|
||||
return false;
|
||||
|
@ -58,14 +58,14 @@ struct convert<glm::vec4>
|
|||
|
||||
namespace Light {
|
||||
|
||||
static YAML::Emitter &operator<<(YAML::Emitter &out, const glm::vec3 &v)
|
||||
static auto operator<<(YAML::Emitter &out, const glm::vec3 &v) -> YAML::Emitter &
|
||||
{
|
||||
out << YAML::Flow;
|
||||
out << YAML::BeginSeq << v.x << v.y << v.z << YAML::EndSeq;
|
||||
return out;
|
||||
}
|
||||
|
||||
static YAML::Emitter &operator<<(YAML::Emitter &out, const glm::vec4 &v)
|
||||
static auto operator<<(YAML::Emitter &out, const glm::vec4 &v) -> YAML::Emitter &
|
||||
{
|
||||
out << YAML::Flow;
|
||||
out << YAML::BeginSeq << v.x << v.y << v.z << v.w << YAML::EndSeq;
|
||||
|
@ -78,14 +78,14 @@ SceneSerializer::SceneSerializer(const Ref<Scene> &scene): m_scene(scene)
|
|||
|
||||
void SceneSerializer::serialize(const std::string &filePath)
|
||||
{
|
||||
YAML::Emitter out;
|
||||
auto out = YAML::Emitter {};
|
||||
out << YAML::BeginMap; // Scene
|
||||
out << YAML::Key << "Scene" << YAML::Value << "Untitled";
|
||||
|
||||
out << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq;
|
||||
for (auto [entityID, storage] : m_scene->m_registry.storage())
|
||||
{
|
||||
Entity entity = { static_cast<entt::entity>(entityID), m_scene.get() };
|
||||
auto entity = Entity { static_cast<entt::entity>(entityID), m_scene.get() };
|
||||
if (!entity.is_valid())
|
||||
return;
|
||||
|
||||
|
@ -96,53 +96,53 @@ void SceneSerializer::serialize(const std::string &filePath)
|
|||
|
||||
std::filesystem::create_directories(filePath.substr(0ull, filePath.find_last_of('\\')));
|
||||
|
||||
std::ofstream fout(filePath);
|
||||
auto fout = std::ofstream { filePath };
|
||||
if (!fout.is_open())
|
||||
lt_log(trace, "Failed to create fout at: {}", filePath);
|
||||
|
||||
fout << out.c_str();
|
||||
}
|
||||
|
||||
bool SceneSerializer::deserialize(const std::string &filePath)
|
||||
auto SceneSerializer::deserialize(const std::string &filePath) -> bool
|
||||
{
|
||||
std::ifstream stream(filePath);
|
||||
std::stringstream ss;
|
||||
auto stream = std::ifstream { filePath };
|
||||
auto ss = std::stringstream {};
|
||||
ss << stream.rdbuf();
|
||||
|
||||
YAML::Node data = YAML::Load(ss.str());
|
||||
auto data = YAML::Load(ss.str());
|
||||
if (!data["Scene"])
|
||||
return false;
|
||||
|
||||
std::string sceneName = data["Scene"].as<std::string>();
|
||||
auto sceneName = data["Scene"].as<std::string>();
|
||||
lt_log(trace, "Deserializing scene: '{}'", sceneName);
|
||||
|
||||
auto entities = data["Entities"];
|
||||
if (entities)
|
||||
{
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
std::unordered_set<std::string> texturePaths;
|
||||
auto texturePaths = std::unordered_set<std::string> {};
|
||||
/* #TEMPORARY SOLUTION# */
|
||||
|
||||
|
||||
for (auto entity : entities)
|
||||
{
|
||||
uint64_t uuid = entity["entity"].as<uint64_t>(); // #todo
|
||||
auto uuid = entity["entity"].as<uint64_t>(); // #todo
|
||||
|
||||
std::string name;
|
||||
auto name = std::string {};
|
||||
auto tagComponent = entity["TagComponent"];
|
||||
if (tagComponent)
|
||||
name = tagComponent["Tag"].as<std::string>();
|
||||
|
||||
lt_log(trace, "Deserialized entity '{}' : '{}'", uuid, name);
|
||||
|
||||
Entity deserializedEntity = m_scene->create_entity_with_uuid(name, uuid);
|
||||
auto deserializedEntity = m_scene->create_entity_with_uuid(name, uuid);
|
||||
|
||||
TagComponent gg = deserializedEntity.GetComponent<TagComponent>();
|
||||
auto gg = deserializedEntity.get_component<TagComponent>();
|
||||
lt_log(trace, gg.tag);
|
||||
auto transformComponent = entity["TransformComponent"];
|
||||
if (transformComponent)
|
||||
{
|
||||
auto &entityTransforomComponent = deserializedEntity
|
||||
.GetComponent<TransformComponent>();
|
||||
.get_component<TransformComponent>();
|
||||
|
||||
entityTransforomComponent.translation = transformComponent["Translation"]
|
||||
.as<glm::vec3>();
|
||||
|
@ -155,11 +155,11 @@ bool SceneSerializer::deserialize(const std::string &filePath)
|
|||
if (spriteRendererComponent)
|
||||
{
|
||||
auto &entitySpriteRendererComponent = deserializedEntity
|
||||
.AddComponent<SpriteRendererComponent>();
|
||||
.add_component<SpriteRendererComponent>();
|
||||
entitySpriteRendererComponent.tint = spriteRendererComponent["Tint"].as<glm::vec4>(
|
||||
);
|
||||
|
||||
std::string texturePath = spriteRendererComponent["Texture"].as<std::string>();
|
||||
auto texturePath = spriteRendererComponent["Texture"].as<std::string>();
|
||||
|
||||
if (!texturePaths.contains(texturePath))
|
||||
{
|
||||
|
@ -174,7 +174,7 @@ bool SceneSerializer::deserialize(const std::string &filePath)
|
|||
auto cameraComponent = entity["CameraComponent"];
|
||||
if (cameraComponent)
|
||||
{
|
||||
auto &entityCameraComponent = deserializedEntity.AddComponent<CameraComponent>();
|
||||
auto &entityCameraComponent = deserializedEntity.add_component<CameraComponent>();
|
||||
|
||||
const auto &cameraSpecifications = cameraComponent["Camera"];
|
||||
entityCameraComponent.camera.set_projection_type(
|
||||
|
@ -220,7 +220,7 @@ void SceneSerializer::serialize_binary(const std::string &filePath)
|
|||
lt_log(err, "NO_IMPLEMENT");
|
||||
}
|
||||
|
||||
bool SceneSerializer::deserialize_binary(const std::string &filePath)
|
||||
auto SceneSerializer::deserialize_binary(const std::string &filePath) -> bool
|
||||
{
|
||||
lt_log(err, "NO_IMPLEMENT");
|
||||
return false;
|
||||
|
@ -236,7 +236,7 @@ void SceneSerializer::serialize_entity(YAML::Emitter &out, Entity entity)
|
|||
out << YAML::Key << "TagComponent";
|
||||
out << YAML::BeginMap; // tag component
|
||||
|
||||
auto &tagComponent = entity.GetComponent<TagComponent>().tag;
|
||||
auto &tagComponent = entity.get_component<TagComponent>().tag;
|
||||
out << YAML::Key << "Tag" << YAML::Value << tagComponent;
|
||||
|
||||
out << YAML::EndMap; // tag component
|
||||
|
@ -247,7 +247,7 @@ void SceneSerializer::serialize_entity(YAML::Emitter &out, Entity entity)
|
|||
out << YAML::Key << "TransformComponent";
|
||||
out << YAML::BeginMap; // transform component
|
||||
|
||||
auto &transformComponent = entity.GetComponent<TransformComponent>();
|
||||
auto &transformComponent = entity.get_component<TransformComponent>();
|
||||
|
||||
out << YAML::Key << "Translation" << YAML::Value << transformComponent.translation;
|
||||
out << YAML::Key << "Rotation" << YAML::Value << transformComponent.rotation;
|
||||
|
@ -261,7 +261,7 @@ void SceneSerializer::serialize_entity(YAML::Emitter &out, Entity entity)
|
|||
out << YAML::Key << "SpriteRendererComponent";
|
||||
out << YAML::BeginMap; // sprite renderer component;
|
||||
|
||||
auto &spriteRendererComponent = entity.GetComponent<SpriteRendererComponent>();
|
||||
auto &spriteRendererComponent = entity.get_component<SpriteRendererComponent>();
|
||||
|
||||
out << YAML::Key << "Texture" << YAML::Value
|
||||
<< spriteRendererComponent.texture->GetFilePath();
|
||||
|
@ -278,7 +278,7 @@ void SceneSerializer::serialize_entity(YAML::Emitter &out, Entity entity)
|
|||
out << YAML::Key << "CameraComponent";
|
||||
out << YAML::BeginMap; // camera component
|
||||
|
||||
auto &cameraComponent = entity.GetComponent<CameraComponent>();
|
||||
auto &cameraComponent = entity.get_component<CameraComponent>();
|
||||
|
||||
out << YAML::Key << "Camera" << YAML::Value;
|
||||
out << YAML::BeginMap; // camera
|
||||
|
@ -297,7 +297,7 @@ void SceneSerializer::serialize_entity(YAML::Emitter &out, Entity entity)
|
|||
out << YAML::Key << "ProjectionType" << YAML::Value
|
||||
<< (int)cameraComponent.camera.get_projection_type();
|
||||
out << YAML::Key << "BackgroundColor" << YAML::Value
|
||||
<< cameraComponent.camera.GetBackgroundColor();
|
||||
<< cameraComponent.camera.get_background_color();
|
||||
out << YAML::EndMap; // camera
|
||||
|
||||
out << YAML::Key << "IsPrimary" << YAML::Value << cameraComponent.isPrimary;
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
|
||||
namespace Light {
|
||||
|
||||
//============================== OPENGL ==============================//
|
||||
std::string Stringifier::glDebugMsgSeverity(unsigned int severity)
|
||||
auto Stringifier::glDebugMsgSeverity(unsigned int severity) -> std::string
|
||||
{
|
||||
switch (severity)
|
||||
{
|
||||
|
@ -18,7 +17,7 @@ std::string Stringifier::glDebugMsgSeverity(unsigned int severity)
|
|||
}
|
||||
}
|
||||
|
||||
std::string Stringifier::glDebugMsgSource(unsigned int source)
|
||||
auto Stringifier::glDebugMsgSource(unsigned int source) -> std::string
|
||||
{
|
||||
switch (source)
|
||||
{
|
||||
|
@ -32,7 +31,7 @@ std::string Stringifier::glDebugMsgSource(unsigned int source)
|
|||
}
|
||||
}
|
||||
|
||||
std::string Stringifier::glDebugMsgType(unsigned int type)
|
||||
auto Stringifier::glDebugMsgType(unsigned int type) -> std::string
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
@ -48,10 +47,8 @@ std::string Stringifier::glDebugMsgType(unsigned int type)
|
|||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
//============================== OPENGL ==============================//
|
||||
|
||||
//==================== SPDLOG ====================//
|
||||
std::string Stringifier::spdlogLevel(unsigned int level)
|
||||
auto Stringifier::spdlogLevel(unsigned int level) -> std::string
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
|
@ -65,10 +62,8 @@ std::string Stringifier::spdlogLevel(unsigned int level)
|
|||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
//==================== SPDLOG ====================//
|
||||
|
||||
//==================== GRAPHICS_API ====================//
|
||||
std::string Stringifier::graphics_api_to_string(GraphicsAPI api)
|
||||
auto Stringifier::graphics_api_to_string(GraphicsAPI api) -> std::string
|
||||
{
|
||||
switch (api)
|
||||
{
|
||||
|
@ -80,6 +75,5 @@ std::string Stringifier::graphics_api_to_string(GraphicsAPI api)
|
|||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
//==================== GRAPHICS_API ====================//
|
||||
|
||||
} // namespace Light
|
||||
|
|
|
@ -13,6 +13,7 @@ class SceneHierarchyPanel: public Panel
|
|||
{
|
||||
public:
|
||||
SceneHierarchyPanel();
|
||||
|
||||
SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel = nullptr);
|
||||
|
||||
void on_user_interface_update();
|
||||
|
|
|
@ -16,18 +16,19 @@ EditorLayer::EditorLayer(const std::string &name): Layer(name), m_scene_dir("")
|
|||
if (m_scene_dir.empty())
|
||||
{
|
||||
m_camera_entity = m_scene->create_entity("Camera");
|
||||
m_camera_entity.AddComponent<CameraComponent>(SceneCamera(), true);
|
||||
m_camera_entity.add_component<CameraComponent>(SceneCamera(), true);
|
||||
|
||||
ResourceManager::load_texture("Awesomeface", "Assets/Textures/awesomeface.png");
|
||||
Entity entity = m_scene->create_entity("Awesomeface", {});
|
||||
entity.AddComponent<SpriteRendererComponent>(
|
||||
|
||||
auto entity = Entity { m_scene->create_entity("Awesomeface", {}) };
|
||||
entity.add_component<SpriteRendererComponent>(
|
||||
ResourceManager::get_texture("Awesomeface"),
|
||||
glm::vec4 { 0.0f, 1.0f, 1.0f, 1.0f }
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneSerializer serializer(m_scene);
|
||||
auto serializer = SceneSerializer { m_scene };
|
||||
lt_assert(serializer.deserialize(m_scene_dir), "Failed to de-serialize: {}", m_scene_dir);
|
||||
|
||||
// m_camera_entity = m_scene->GetEntityByTag("Game Camera");
|
||||
|
@ -38,7 +39,7 @@ EditorLayer::~EditorLayer()
|
|||
{
|
||||
if (!m_scene_dir.empty())
|
||||
{
|
||||
SceneSerializer serializer(m_scene);
|
||||
auto serializer = SceneSerializer { m_scene };
|
||||
serializer.serialize(m_scene_dir);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +56,7 @@ void EditorLayer::on_update(float deltaTime)
|
|||
Input::get_keyboard_key(Key::W) ? 1.0f :
|
||||
0.0f;
|
||||
|
||||
auto &cameraTranslation = m_camera_entity.GetComponent<TransformComponent>().translation;
|
||||
auto &cameraTranslation = m_camera_entity.get_component<TransformComponent>().translation;
|
||||
cameraTranslation += glm::vec3(m_direction * m_speed * deltaTime, 0.0f);
|
||||
|
||||
if (Input::get_keyboard_key(Key::Escape))
|
||||
|
@ -75,22 +76,22 @@ void EditorLayer::on_user_interface_update()
|
|||
if (ImGui::Begin("Game"))
|
||||
{
|
||||
Input::receive_game_events(ImGui::IsWindowFocused());
|
||||
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
||||
auto regionAvail = ImGui::GetContentRegionAvail();
|
||||
|
||||
if (m_available_content_region_prev != regionAvail)
|
||||
{
|
||||
m_framebuffer->resize({ regionAvail.x, regionAvail.y });
|
||||
auto &camera = m_camera_entity.GetComponent<CameraComponent>().camera;
|
||||
auto &camera = m_camera_entity.get_component<CameraComponent>().camera;
|
||||
camera.set_viewport_size(regionAvail.x, regionAvail.y);
|
||||
|
||||
m_available_content_region_prev = regionAvail;
|
||||
}
|
||||
|
||||
if (GraphicsContext::get_graphics_api() == GraphicsAPI::DirectX)
|
||||
ImGui::Image(m_framebuffer->GetColorAttachment(), regionAvail);
|
||||
ImGui::Image(m_framebuffer->get_color_attachment(), regionAvail);
|
||||
else
|
||||
ImGui::Image(
|
||||
m_framebuffer->GetColorAttachment(),
|
||||
m_framebuffer->get_color_attachment(),
|
||||
regionAvail,
|
||||
ImVec2(0, 1),
|
||||
ImVec2(1, 0)
|
||||
|
|
|
@ -14,10 +14,11 @@ public:
|
|||
Mirror()
|
||||
{
|
||||
// Set window properties
|
||||
Light::WindowProperties properties;
|
||||
properties.title = "Mirror";
|
||||
properties.size = glm::uvec2(1280u, 720u);
|
||||
properties.vsync = true;
|
||||
auto properties = Light::WindowProperties {
|
||||
.title = "Mirror",
|
||||
.size = glm::uvec2(1280u, 720u),
|
||||
.vsync = true,
|
||||
};
|
||||
|
||||
m_window->set_properties(properties);
|
||||
|
||||
|
@ -26,7 +27,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
Application *CreateApplication()
|
||||
auto create_application() -> Application *
|
||||
{
|
||||
return new Mirror();
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ void AssetBrowserPanel::on_user_interface_update()
|
|||
}
|
||||
}
|
||||
|
||||
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
||||
uint32_t cellSize = m_file_size + m_file_padding;
|
||||
uint32_t columnCount = std::clamp(
|
||||
auto regionAvail = ImGui::GetContentRegionAvail();
|
||||
auto cellSize = m_file_size + m_file_padding;
|
||||
auto columnCount = std::clamp(
|
||||
static_cast<uint32_t>(std::floor(regionAvail.x / cellSize)),
|
||||
1u,
|
||||
64u
|
||||
|
@ -45,13 +45,13 @@ void AssetBrowserPanel::on_user_interface_update()
|
|||
if (ImGui::BeginTable("ContentBrowser", columnCount))
|
||||
{
|
||||
m_directory_texture->bind(0u);
|
||||
for (auto &dirEntry : std::filesystem::directory_iterator(m_current_directory))
|
||||
for (const auto &dirEntry : std::filesystem::directory_iterator(m_current_directory))
|
||||
{
|
||||
const auto &path = dirEntry.path();
|
||||
std::string extension = dirEntry.path().extension().string();
|
||||
auto extension = dirEntry.path().extension().string();
|
||||
|
||||
// TODO: Tidy up
|
||||
AssetType assetType;
|
||||
auto assetType = AssetType {};
|
||||
assetType = extension.empty() ? AssetType::Directory :
|
||||
|
||||
extension == ".txt" ? AssetType::Text :
|
||||
|
@ -102,7 +102,7 @@ void AssetBrowserPanel::on_user_interface_update()
|
|||
ImVec4 { 1.0f, 1.0f, 1.0f, 1.0f }
|
||||
))
|
||||
{
|
||||
SceneSerializer serializer(m_active_scene);
|
||||
auto serializer = SceneSerializer { m_active_scene };
|
||||
lt_log(info, "Attempting to deserialize: {}", path.string());
|
||||
serializer.deserialize(path.string());
|
||||
}
|
||||
|
|
|
@ -16,14 +16,16 @@ void PropertiesPanel::on_user_interface_update()
|
|||
{
|
||||
if (m_entity_context.has_component<TagComponent>())
|
||||
{
|
||||
auto &tagComponent = m_entity_context.GetComponent<TagComponent>();
|
||||
auto &tagComponent = m_entity_context.get_component<TagComponent>();
|
||||
|
||||
char buffer[256];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
std::strncpy(buffer, tagComponent.tag.c_str(), sizeof(buffer));
|
||||
auto buffer = std::array<char, 256> {};
|
||||
memset(buffer.data(), 0, buffer.size());
|
||||
std::strncpy(buffer.data(), tagComponent.tag.c_str(), buffer.size());
|
||||
|
||||
if (ImGui::InputText("##Tag", buffer, sizeof(buffer)))
|
||||
tagComponent.tag = std::string(buffer);
|
||||
if (ImGui::InputText("##Tag", buffer.data(), buffer.size()))
|
||||
{
|
||||
tagComponent.tag = buffer.data();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
@ -41,7 +43,7 @@ void PropertiesPanel::on_user_interface_update()
|
|||
ImGuiSelectableFlags_Disabled :
|
||||
NULL
|
||||
))
|
||||
m_entity_context.AddComponent<SpriteRendererComponent>(
|
||||
m_entity_context.add_component<SpriteRendererComponent>(
|
||||
Light::ResourceManager::get_texture("awesomeface")
|
||||
);
|
||||
|
||||
|
@ -52,7 +54,7 @@ void PropertiesPanel::on_user_interface_update()
|
|||
ImGuiSelectableFlags_Disabled :
|
||||
NULL
|
||||
))
|
||||
m_entity_context.AddComponent<CameraComponent>();
|
||||
m_entity_context.add_component<CameraComponent>();
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
@ -80,14 +82,17 @@ void PropertiesPanel::on_user_interface_update()
|
|||
[&](auto &cameraComponent) {
|
||||
auto &camera = cameraComponent.camera;
|
||||
|
||||
SceneCamera::ProjectionType projectionType = camera.get_projection_type();
|
||||
const char *projectionTypesString[] = { "Orthographic", "Perspective" };
|
||||
auto projectionType = camera.get_projection_type();
|
||||
auto projectionTypesString = std::array<const char *, 2> {
|
||||
"Orthographic",
|
||||
"Perspective",
|
||||
};
|
||||
|
||||
if (ImGui::BeginCombo("ProjectionType", projectionTypesString[(int)projectionType]))
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
const bool isSelected = (int)projectionType == i;
|
||||
const auto isSelected = (int)projectionType == i;
|
||||
if (ImGui::Selectable(projectionTypesString[i], isSelected))
|
||||
{
|
||||
projectionType = (SceneCamera::ProjectionType)i;
|
||||
|
@ -103,7 +108,9 @@ void PropertiesPanel::on_user_interface_update()
|
|||
|
||||
if (projectionType == SceneCamera::ProjectionType::Orthographic)
|
||||
{
|
||||
float orthoSize, nearPlane, farPlane;
|
||||
auto orthoSize = float {};
|
||||
auto nearPlane = float {};
|
||||
auto farPlane = float {};
|
||||
|
||||
orthoSize = camera.get_orthographic_size();
|
||||
nearPlane = camera.get_orthographic_near_plane();
|
||||
|
@ -121,7 +128,9 @@ void PropertiesPanel::on_user_interface_update()
|
|||
|
||||
else // perspective
|
||||
{
|
||||
float verticalFOV, nearPlane, farPlane;
|
||||
auto verticalFOV = float {};
|
||||
auto nearPlane = float {};
|
||||
auto farPlane = float {};
|
||||
|
||||
verticalFOV = glm::degrees(camera.get_perspective_vertical_fov());
|
||||
nearPlane = camera.get_perspective_near_plane();
|
||||
|
@ -157,7 +166,7 @@ void PropertiesPanel::draw_vec3_control(
|
|||
float columnWidth /*= 100.0f*/
|
||||
)
|
||||
{
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
auto &io = ImGui::GetIO();
|
||||
|
||||
auto boldFont = io.Fonts->Fonts[0];
|
||||
|
||||
|
@ -169,8 +178,8 @@ void PropertiesPanel::draw_vec3_control(
|
|||
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2 { 0, 0 });
|
||||
|
||||
float lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
|
||||
ImVec2 buttonSize = { lineHeight + 3.0f, lineHeight };
|
||||
auto lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
|
||||
auto buttonSize = ImVec2 { lineHeight + 3.0f, lineHeight };
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.1f, 0.15f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.9f, 0.2f, 0.2f, 1.0f));
|
||||
|
@ -229,16 +238,16 @@ void PropertiesPanel::draw_component(
|
|||
if (!entity.has_component<ComponentType>())
|
||||
return;
|
||||
|
||||
auto &component = entity.GetComponent<ComponentType>();
|
||||
auto &component = entity.get_component<ComponentType>();
|
||||
|
||||
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
|
||||
auto regionAvail = ImGui::GetContentRegionAvail();
|
||||
|
||||
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth
|
||||
| ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_AllowItemOverlap
|
||||
| ImGuiTreeNodeFlags_FramePadding;
|
||||
auto flags = ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth
|
||||
| ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_AllowItemOverlap
|
||||
| ImGuiTreeNodeFlags_FramePadding;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 4, 4 });
|
||||
float lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
|
||||
auto lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::TreeNodeEx((void *)typeid(ComponentType).hash_code(), flags, name.c_str()))
|
||||
|
|
|
@ -28,9 +28,12 @@ void SceneHierarchyPanel::on_user_interface_update()
|
|||
|
||||
for (auto entityID : m_context->m_registry.view<TagComponent>())
|
||||
{
|
||||
Entity entity(static_cast<entt::entity>(entityID), m_context.get());
|
||||
const std::string &tag = entity.GetComponent<TagComponent>();
|
||||
auto entity = Entity {
|
||||
static_cast<entt::entity>(entityID),
|
||||
m_context.get(),
|
||||
};
|
||||
|
||||
const auto &tag = entity.get_component<TagComponent>();
|
||||
draw_node(entity, tag);
|
||||
};
|
||||
}
|
||||
|
@ -48,10 +51,14 @@ void SceneHierarchyPanel::set_context(Ref<Scene> context, Ref<PropertiesPanel> p
|
|||
|
||||
void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label)
|
||||
{
|
||||
ImGuiTreeNodeFlags flags = (m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : NULL)
|
||||
| ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth;
|
||||
auto flags = (m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : NULL)
|
||||
| ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth;
|
||||
|
||||
bool expanded = ImGui::TreeNodeEx((void *)(uint64_t)(uint32_t)(entity), flags, label.c_str());
|
||||
const auto expanded = ImGui::TreeNodeEx(
|
||||
(void *)(uint64_t)(uint32_t)(entity),
|
||||
flags,
|
||||
label.c_str()
|
||||
);
|
||||
|
||||
if (ImGui::IsItemClicked())
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue