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