Style: Rename *.h -> *.hpp
This commit is contained in:
parent
dcedb1799c
commit
acbed604bb
211 changed files with 3803 additions and 3937 deletions
|
@ -59,7 +59,7 @@ target_link_libraries(
|
||||||
PRIVATE imgui)
|
PRIVATE imgui)
|
||||||
|
|
||||||
# Precompiled headers
|
# Precompiled headers
|
||||||
target_precompile_headers(Engine PUBLIC ${ENGINE_DIR}src/Engine/ltpch.h)
|
target_precompile_headers(Engine PUBLIC ${ENGINE_DIR}src/Engine/ltpch.hpp)
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
set_property(DIRECTORY ${CMAE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Mirror)
|
set_property(DIRECTORY ${CMAE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Mirror)
|
||||||
|
|
|
@ -90,22 +90,22 @@ constexpr std::unique_ptr<T> MakeScope(T* rawPointer)
|
||||||
//========== ESSENTIAL_HEADERS ==========//
|
//========== ESSENTIAL_HEADERS ==========//
|
||||||
/* config */
|
/* config */
|
||||||
#ifndef LIGHT_CONFIG_H
|
#ifndef LIGHT_CONFIG_H
|
||||||
#include "Base/Config.h"
|
#include "Base/Config.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* debug */
|
/* debug */
|
||||||
#ifndef LIGHT_LOGGER_H
|
#ifndef LIGHT_LOGGER_H
|
||||||
#include "Debug/Logger.h"
|
#include "Debug/Logger.hpp"
|
||||||
#endif
|
#endif
|
||||||
#include "Debug/Exceptions.h"
|
#include "Debug/Exceptions.hpp"
|
||||||
|
|
||||||
/* portables */
|
/* portables */
|
||||||
#ifndef LIGHT_DEBUG_TRAP_H
|
#ifndef LIGHT_DEBUG_TRAP_H
|
||||||
#include "Base/Portables/DebugTrap.h"
|
#include "Base/Portables/DebugTrap.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* utility */
|
/* utility */
|
||||||
#ifndef LIGHT_STRINGIFIER_H
|
#ifndef LIGHT_STRINGIFIER_H
|
||||||
#include "Utility/Stringifier.h"
|
#include "Utility/Stringifier.hpp"
|
||||||
#endif
|
#endif
|
||||||
//========== ESSENTIAL_HEADERS ==========//
|
//========== ESSENTIAL_HEADERS ==========//
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||||
|
|
||||||
#include <LightEngine.h>
|
#include <LightEngine.hpp>
|
||||||
|
|
||||||
// to be defined in client project
|
// to be defined in client project
|
||||||
extern Light::Application* Light::CreateApplication(std::string execName, std::vector<std::string> args);
|
extern Light::Application* Light::CreateApplication(std::string execName, std::vector<std::string> args);
|
||||||
|
@ -53,7 +53,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
#elif defined(LIGHT_PLATFORM_LINUX)
|
#elif defined(LIGHT_PLATFORM_LINUX)
|
||||||
|
|
||||||
#include <LightEngine.h>
|
#include <LightEngine.hpp>
|
||||||
|
|
||||||
// to be defined in client project
|
// to be defined in client project
|
||||||
extern Light::Application* Light::CreateApplication();
|
extern Light::Application* Light::CreateApplication();
|
|
@ -2,7 +2,7 @@
|
||||||
#ifndef LIGHT_DEBUG_TRAP_H
|
#ifndef LIGHT_DEBUG_TRAP_H
|
||||||
#define LIGHT_DEBUG_TRAP_H
|
#define LIGHT_DEBUG_TRAP_H
|
||||||
|
|
||||||
#include "Base/Base.h"
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
// https://github.com/nemequ/portable-snippets/tree/master/debug-trap
|
// https://github.com/nemequ/portable-snippets/tree/master/debug-trap
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "Camera.h"
|
#include "Camera.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Camera
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
glm::vec4 m_BackgroundColor = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
glm::mat4 m_Projection;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Camera() = default;
|
|
||||||
|
|
||||||
inline const glm::mat4& GetProjection() const { return m_Projection; }
|
|
||||||
|
|
||||||
inline const glm::vec4& GetBackgroundColor() const { return m_BackgroundColor; }
|
|
||||||
|
|
||||||
inline void SetBackgroundColor(const glm::vec4& color) { m_BackgroundColor = color; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
27
Engine/src/Engine/Camera/Camera.hpp
Normal file
27
Engine/src/Engine/Camera/Camera.hpp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Camera
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
glm::vec4 m_BackgroundColor = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
glm::mat4 m_Projection;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Camera() = default;
|
||||||
|
|
||||||
|
inline const glm::mat4& GetProjection() const { return m_Projection; }
|
||||||
|
|
||||||
|
inline const glm::vec4& GetBackgroundColor() const { return m_BackgroundColor; }
|
||||||
|
|
||||||
|
inline void SetBackgroundColor(const glm::vec4& color) { m_BackgroundColor = color; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,42 +1,38 @@
|
||||||
#include "OrthographicCamera.h"
|
#include "OrthographicCamera.hpp"
|
||||||
|
|
||||||
#include <glm/matrix.hpp>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/matrix.hpp>
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
OrthographicCamera::OrthographicCamera(const glm::vec2& position, float aspectRatio, float zoomLevel, const glm::vec4& clearColor /* = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f) */)
|
OrthographicCamera::OrthographicCamera(const glm::vec2& position, float aspectRatio, float zoomLevel, const glm::vec4& clearColor /* = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f) */)
|
||||||
: m_Up(0.0f, 1.0f, 0.0f),
|
: m_Up(0.0f, 1.0f, 0.0f), m_Position(position), m_AspectRatio(aspectRatio), m_ZoomLevel(zoomLevel), m_ClearColor(clearColor)
|
||||||
m_Position(position),
|
{
|
||||||
m_AspectRatio(aspectRatio),
|
|
||||||
m_ZoomLevel(zoomLevel),
|
|
||||||
m_ClearColor(clearColor)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void OrthographicCamera::CalculateView()
|
|
||||||
{
|
|
||||||
m_View = glm::lookAt(glm::vec3(m_Position, 100.0f), glm::vec3(m_Position, 0.0f), m_Up);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OrthographicCamera::CalculateProjection()
|
|
||||||
{
|
|
||||||
m_Projection = glm::ortho(-m_ZoomLevel * m_AspectRatio,
|
|
||||||
+m_ZoomLevel * m_AspectRatio,
|
|
||||||
-m_ZoomLevel,
|
|
||||||
+m_ZoomLevel,
|
|
||||||
FLT_MAX, FLT_MIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OrthographicCamera::OnResize(const glm::vec2& size)
|
|
||||||
{
|
|
||||||
m_AspectRatio = size.x / size.y;
|
|
||||||
CalculateProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OrthographicCamera::Move(const glm::vec2& position)
|
|
||||||
{
|
|
||||||
m_Position += position;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OrthographicCamera::CalculateView()
|
||||||
|
{
|
||||||
|
m_View = glm::lookAt(glm::vec3(m_Position, 100.0f), glm::vec3(m_Position, 0.0f), m_Up);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OrthographicCamera::CalculateProjection()
|
||||||
|
{
|
||||||
|
m_Projection = glm::ortho(-m_ZoomLevel * m_AspectRatio,
|
||||||
|
+m_ZoomLevel * m_AspectRatio,
|
||||||
|
-m_ZoomLevel,
|
||||||
|
+m_ZoomLevel,
|
||||||
|
FLT_MAX, FLT_MIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OrthographicCamera::OnResize(const glm::vec2& size)
|
||||||
|
{
|
||||||
|
m_AspectRatio = size.x / size.y;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OrthographicCamera::Move(const glm::vec2& position)
|
||||||
|
{
|
||||||
|
m_Position += position;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,41 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class OrthographicCamera
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
glm::vec2 m_Position;
|
|
||||||
float m_AspectRatio;
|
|
||||||
float m_ZoomLevel;
|
|
||||||
|
|
||||||
const glm::vec3 m_Up;
|
|
||||||
|
|
||||||
glm::mat4 m_Projection;
|
|
||||||
glm::mat4 m_View;
|
|
||||||
|
|
||||||
glm::vec4 m_ClearColor;
|
|
||||||
|
|
||||||
public:
|
|
||||||
OrthographicCamera(const glm::vec2& position, float aspectRatio, float zoomLevel, const glm::vec4& clearColor = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f));
|
|
||||||
|
|
||||||
// CAMERA //
|
|
||||||
void CalculateView();
|
|
||||||
void CalculateProjection();
|
|
||||||
|
|
||||||
void OnResize(const glm::vec2& size);
|
|
||||||
|
|
||||||
inline const glm::mat4& GetView() const { return m_View; }
|
|
||||||
inline const glm::mat4& GetProjection() const { return m_Projection; }
|
|
||||||
|
|
||||||
inline const glm::vec4& GetClearColor() const { return m_ClearColor; }
|
|
||||||
|
|
||||||
// CAMERA_CONTROLLER //
|
|
||||||
void Move(const glm::vec2& position);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
41
Engine/src/Engine/Camera/OrthographicCamera.hpp
Normal file
41
Engine/src/Engine/Camera/OrthographicCamera.hpp
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class OrthographicCamera
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
glm::vec2 m_Position;
|
||||||
|
float m_AspectRatio;
|
||||||
|
float m_ZoomLevel;
|
||||||
|
|
||||||
|
const glm::vec3 m_Up;
|
||||||
|
|
||||||
|
glm::mat4 m_Projection;
|
||||||
|
glm::mat4 m_View;
|
||||||
|
|
||||||
|
glm::vec4 m_ClearColor;
|
||||||
|
|
||||||
|
public:
|
||||||
|
OrthographicCamera(const glm::vec2& position, float aspectRatio, float zoomLevel, const glm::vec4& clearColor = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f));
|
||||||
|
|
||||||
|
// CAMERA //
|
||||||
|
void CalculateView();
|
||||||
|
void CalculateProjection();
|
||||||
|
|
||||||
|
void OnResize(const glm::vec2& size);
|
||||||
|
|
||||||
|
inline const glm::mat4& GetView() const { return m_View; }
|
||||||
|
inline const glm::mat4& GetProjection() const { return m_Projection; }
|
||||||
|
|
||||||
|
inline const glm::vec4& GetClearColor() const { return m_ClearColor; }
|
||||||
|
|
||||||
|
// CAMERA_CONTROLLER //
|
||||||
|
void Move(const glm::vec2& position);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,84 +1,81 @@
|
||||||
#include "SceneCamera.h"
|
#include "SceneCamera.hpp"
|
||||||
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
SceneCamera::SceneCamera()
|
SceneCamera::SceneCamera()
|
||||||
: m_OrthographicSpecification{ 1000.0f, -1.0f, 10000.0f },
|
: m_OrthographicSpecification { 1000.0f, -1.0f, 10000.0f }, m_PerspectiveSpecification { glm::radians(45.0f), 0.01f, 10000.0f }, m_AspectRatio(16.0f / 9.0f), m_ProjectionType(ProjectionType::Orthographic)
|
||||||
m_PerspectiveSpecification{ glm::radians(45.0f), 0.01f, 10000.0f },
|
{
|
||||||
m_AspectRatio(16.0f / 9.0f),
|
CalculateProjection();
|
||||||
m_ProjectionType(ProjectionType::Orthographic)
|
|
||||||
{
|
|
||||||
CalculateProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneCamera::SetViewportSize(unsigned int width, unsigned int height)
|
|
||||||
{
|
|
||||||
m_AspectRatio = width / (float)height;
|
|
||||||
CalculateProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneCamera::SetProjectionType(ProjectionType projectionType)
|
|
||||||
{
|
|
||||||
m_ProjectionType = projectionType;
|
|
||||||
CalculateProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneCamera::SetOrthographicSize(float size)
|
|
||||||
{
|
|
||||||
m_OrthographicSpecification.size = size;
|
|
||||||
CalculateProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneCamera::SetOrthographicFarPlane(float farPlane)
|
|
||||||
{
|
|
||||||
m_OrthographicSpecification.farPlane = farPlane;
|
|
||||||
CalculateProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneCamera::SetOrthographicNearPlane(float nearPlane)
|
|
||||||
{
|
|
||||||
m_OrthographicSpecification.nearPlane = nearPlane;
|
|
||||||
CalculateProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneCamera::SetPerspectiveVerticalFOV(float verticalFOV)
|
|
||||||
{
|
|
||||||
m_PerspectiveSpecification.verticalFOV = verticalFOV;
|
|
||||||
CalculateProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneCamera::SetPerspectiveFarPlane(float farPlane)
|
|
||||||
{
|
|
||||||
m_PerspectiveSpecification.farPlane = farPlane;
|
|
||||||
CalculateProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneCamera::SetPerspectiveNearPlane(float nearPlane)
|
|
||||||
{
|
|
||||||
m_PerspectiveSpecification.nearPlane = nearPlane;
|
|
||||||
CalculateProjection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneCamera::CalculateProjection()
|
|
||||||
{
|
|
||||||
if(m_ProjectionType == ProjectionType::Orthographic)
|
|
||||||
{
|
|
||||||
m_Projection = glm::ortho(-m_OrthographicSpecification.size * 0.5f * m_AspectRatio,
|
|
||||||
m_OrthographicSpecification.size * 0.5f * m_AspectRatio,
|
|
||||||
-m_OrthographicSpecification.size * 0.5f,
|
|
||||||
m_OrthographicSpecification.size * 0.5f,
|
|
||||||
m_OrthographicSpecification.farPlane,
|
|
||||||
m_OrthographicSpecification.nearPlane);
|
|
||||||
}
|
|
||||||
else // perspective
|
|
||||||
{
|
|
||||||
m_Projection = glm::perspective(m_PerspectiveSpecification.verticalFOV,
|
|
||||||
m_AspectRatio,
|
|
||||||
m_PerspectiveSpecification.nearPlane,
|
|
||||||
m_PerspectiveSpecification.farPlane);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetViewportSize(unsigned int width, unsigned int height)
|
||||||
|
{
|
||||||
|
m_AspectRatio = width / (float)height;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetProjectionType(ProjectionType projectionType)
|
||||||
|
{
|
||||||
|
m_ProjectionType = projectionType;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetOrthographicSize(float size)
|
||||||
|
{
|
||||||
|
m_OrthographicSpecification.size = size;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetOrthographicFarPlane(float farPlane)
|
||||||
|
{
|
||||||
|
m_OrthographicSpecification.farPlane = farPlane;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetOrthographicNearPlane(float nearPlane)
|
||||||
|
{
|
||||||
|
m_OrthographicSpecification.nearPlane = nearPlane;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetPerspectiveVerticalFOV(float verticalFOV)
|
||||||
|
{
|
||||||
|
m_PerspectiveSpecification.verticalFOV = verticalFOV;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetPerspectiveFarPlane(float farPlane)
|
||||||
|
{
|
||||||
|
m_PerspectiveSpecification.farPlane = farPlane;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::SetPerspectiveNearPlane(float nearPlane)
|
||||||
|
{
|
||||||
|
m_PerspectiveSpecification.nearPlane = nearPlane;
|
||||||
|
CalculateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneCamera::CalculateProjection()
|
||||||
|
{
|
||||||
|
if (m_ProjectionType == ProjectionType::Orthographic)
|
||||||
|
{
|
||||||
|
m_Projection = glm::ortho(-m_OrthographicSpecification.size * 0.5f * m_AspectRatio,
|
||||||
|
m_OrthographicSpecification.size * 0.5f * m_AspectRatio,
|
||||||
|
-m_OrthographicSpecification.size * 0.5f,
|
||||||
|
m_OrthographicSpecification.size * 0.5f,
|
||||||
|
m_OrthographicSpecification.farPlane,
|
||||||
|
m_OrthographicSpecification.nearPlane);
|
||||||
|
}
|
||||||
|
else // perspective
|
||||||
|
{
|
||||||
|
m_Projection = glm::perspective(m_PerspectiveSpecification.verticalFOV,
|
||||||
|
m_AspectRatio,
|
||||||
|
m_PerspectiveSpecification.nearPlane,
|
||||||
|
m_PerspectiveSpecification.farPlane);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,65 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Camera.h"
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class SceneCamera : public Camera
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum class ProjectionType
|
|
||||||
{
|
|
||||||
Orthographic = 0,
|
|
||||||
Perspetcive = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct OrthographicSpecification // :#todo use this
|
|
||||||
{
|
|
||||||
float size;
|
|
||||||
float nearPlane, farPlane;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PerspectiveSpecification
|
|
||||||
{
|
|
||||||
float verticalFOV;
|
|
||||||
float nearPlane, farPlane;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
OrthographicSpecification m_OrthographicSpecification;
|
|
||||||
PerspectiveSpecification m_PerspectiveSpecification;
|
|
||||||
float m_AspectRatio;
|
|
||||||
|
|
||||||
ProjectionType m_ProjectionType;
|
|
||||||
|
|
||||||
public:
|
|
||||||
SceneCamera();
|
|
||||||
|
|
||||||
void SetViewportSize(unsigned int width, unsigned int height);
|
|
||||||
|
|
||||||
void SetProjectionType(ProjectionType projectionType);
|
|
||||||
|
|
||||||
void SetOrthographicSize(float size);
|
|
||||||
void SetOrthographicFarPlane(float farPlane);
|
|
||||||
void SetOrthographicNearPlane(float nearPlane);
|
|
||||||
|
|
||||||
void SetPerspectiveVerticalFOV(float verticalFov);
|
|
||||||
void SetPerspectiveFarPlane(float farPlane);
|
|
||||||
void SetPerspectiveNearPlane(float nearPlane);
|
|
||||||
|
|
||||||
inline float GetOrthographicSize() const { return m_OrthographicSpecification.size; }
|
|
||||||
inline float GetOrthographicFarPlane() const { return m_OrthographicSpecification.farPlane; }
|
|
||||||
inline float GetOrthographicNearPlane() const { return m_OrthographicSpecification.nearPlane; }
|
|
||||||
|
|
||||||
inline float GetPerspectiveVerticalFOV() const { return m_PerspectiveSpecification.verticalFOV; }
|
|
||||||
inline float GetPerspectiveFarPlane() const { return m_PerspectiveSpecification.farPlane; }
|
|
||||||
inline float GetPerspectiveNearPlane() const { return m_PerspectiveSpecification.nearPlane; }
|
|
||||||
|
|
||||||
inline ProjectionType GetProjectionType() const { return m_ProjectionType; }
|
|
||||||
private:
|
|
||||||
void CalculateProjection();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
65
Engine/src/Engine/Camera/SceneCamera.hpp
Normal file
65
Engine/src/Engine/Camera/SceneCamera.hpp
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "Camera.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class SceneCamera: public Camera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum class ProjectionType
|
||||||
|
{
|
||||||
|
Orthographic = 0,
|
||||||
|
Perspetcive = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
struct OrthographicSpecification // :#todo use this
|
||||||
|
{
|
||||||
|
float size;
|
||||||
|
float nearPlane, farPlane;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PerspectiveSpecification
|
||||||
|
{
|
||||||
|
float verticalFOV;
|
||||||
|
float nearPlane, farPlane;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
OrthographicSpecification m_OrthographicSpecification;
|
||||||
|
PerspectiveSpecification m_PerspectiveSpecification;
|
||||||
|
float m_AspectRatio;
|
||||||
|
|
||||||
|
ProjectionType m_ProjectionType;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SceneCamera();
|
||||||
|
|
||||||
|
void SetViewportSize(unsigned int width, unsigned int height);
|
||||||
|
|
||||||
|
void SetProjectionType(ProjectionType projectionType);
|
||||||
|
|
||||||
|
void SetOrthographicSize(float size);
|
||||||
|
void SetOrthographicFarPlane(float farPlane);
|
||||||
|
void SetOrthographicNearPlane(float nearPlane);
|
||||||
|
|
||||||
|
void SetPerspectiveVerticalFOV(float verticalFov);
|
||||||
|
void SetPerspectiveFarPlane(float farPlane);
|
||||||
|
void SetPerspectiveNearPlane(float nearPlane);
|
||||||
|
|
||||||
|
inline float GetOrthographicSize() const { return m_OrthographicSpecification.size; }
|
||||||
|
inline float GetOrthographicFarPlane() const { return m_OrthographicSpecification.farPlane; }
|
||||||
|
inline float GetOrthographicNearPlane() const { return m_OrthographicSpecification.nearPlane; }
|
||||||
|
|
||||||
|
inline float GetPerspectiveVerticalFOV() const { return m_PerspectiveSpecification.verticalFOV; }
|
||||||
|
inline float GetPerspectiveFarPlane() const { return m_PerspectiveSpecification.farPlane; }
|
||||||
|
inline float GetPerspectiveNearPlane() const { return m_PerspectiveSpecification.nearPlane; }
|
||||||
|
|
||||||
|
inline ProjectionType GetProjectionType() const { return m_ProjectionType; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void CalculateProjection();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,14 +1,14 @@
|
||||||
#include "Application.h"
|
#include "Application.hpp"
|
||||||
|
|
||||||
#include "Debug/Instrumentor.h"
|
#include "Debug/Instrumentor.hpp"
|
||||||
#include "Events/Event.h"
|
#include "Events/Event.hpp"
|
||||||
#include "Graphics/GraphicsContext.h"
|
#include "Graphics/GraphicsContext.hpp"
|
||||||
#include "Graphics/RenderCommand.h"
|
#include "Graphics/RenderCommand.hpp"
|
||||||
#include "Graphics/Renderer.h"
|
#include "Graphics/Renderer.hpp"
|
||||||
#include "Layer/Layer.h"
|
#include "Layer/Layer.hpp"
|
||||||
#include "Time/Timer.h"
|
#include "Time/Timer.hpp"
|
||||||
#include "UserInterface/UserInterface.h"
|
#include "UserInterface/UserInterface.hpp"
|
||||||
#include "Window.h"
|
#include "Window.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include "Debug/Instrumentor.h"
|
|
||||||
|
|
||||||
#include "Input/Input.h"
|
|
||||||
|
|
||||||
#include "Layer/LayerStack.h"
|
|
||||||
|
|
||||||
#include "Utility/ResourceManager.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Window;
|
|
||||||
class Event;
|
|
||||||
|
|
||||||
class Instrumentor;
|
|
||||||
|
|
||||||
class Application /* singleton */
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
static Application* s_Context;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Scope<Logger> m_Logger;
|
|
||||||
Scope<Instrumentor> m_Instrumentor;
|
|
||||||
Scope<LayerStack> m_LayerStack;
|
|
||||||
Scope<Input> m_Input;
|
|
||||||
Scope<ResourceManager> m_ResourceManager;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Scope<Window> m_Window;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Application(const Application&) = delete;
|
|
||||||
Application& operator=(const Application&) = delete;
|
|
||||||
|
|
||||||
virtual ~Application();
|
|
||||||
|
|
||||||
void GameLoop();
|
|
||||||
|
|
||||||
// To be defined in client project
|
|
||||||
|
|
||||||
static void Quit();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Application(std::string execName, std::vector<std::string> args);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void OnEvent(const Event& event);
|
|
||||||
|
|
||||||
void LogDebugData();
|
|
||||||
};
|
|
||||||
|
|
||||||
extern Application* CreateApplication(std::string execName, std::vector<std::string> args);
|
|
||||||
|
|
||||||
}
|
|
54
Engine/src/Engine/Core/Application.hpp
Normal file
54
Engine/src/Engine/Core/Application.hpp
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "Debug/Instrumentor.hpp"
|
||||||
|
#include "Input/Input.hpp"
|
||||||
|
#include "Layer/LayerStack.hpp"
|
||||||
|
#include "Utility/ResourceManager.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Window;
|
||||||
|
class Event;
|
||||||
|
|
||||||
|
class Instrumentor;
|
||||||
|
|
||||||
|
class Application /* singleton */
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static Application* s_Context;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Scope<Logger> m_Logger;
|
||||||
|
Scope<Instrumentor> m_Instrumentor;
|
||||||
|
Scope<LayerStack> m_LayerStack;
|
||||||
|
Scope<Input> m_Input;
|
||||||
|
Scope<ResourceManager> m_ResourceManager;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Scope<Window> m_Window;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Application(const Application&) = delete;
|
||||||
|
Application& operator=(const Application&) = delete;
|
||||||
|
|
||||||
|
virtual ~Application();
|
||||||
|
|
||||||
|
void GameLoop();
|
||||||
|
|
||||||
|
// To be defined in client project
|
||||||
|
|
||||||
|
static void Quit();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Application(std::string execName, std::vector<std::string> args);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void OnEvent(const Event& event);
|
||||||
|
|
||||||
|
void LogDebugData();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Application* CreateApplication(std::string execName, std::vector<std::string> args);
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,13 +1,14 @@
|
||||||
#include "ltpch.h"
|
#include "UUID.hpp"
|
||||||
#include "UUID.h"
|
|
||||||
|
#include "ltpch.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
std::mt19937_64 UUID::s_Engine = std::mt19937_64(std::random_device()());
|
std::mt19937_64 UUID::s_Engine = std::mt19937_64(std::random_device()());
|
||||||
std::uniform_int_distribution<uint64_t> UUID::s_UniformDistribution;
|
std::uniform_int_distribution<uint64_t> UUID::s_UniformDistribution;
|
||||||
|
|
||||||
UUID::UUID(uint64_t uuid /* = -1 */)
|
UUID::UUID(uint64_t uuid /* = -1 */)
|
||||||
: m_UUID(uuid == -1 ? s_UniformDistribution(s_Engine) : uuid)
|
: m_UUID(uuid == -1 ? s_UniformDistribution(s_Engine) : uuid)
|
||||||
{
|
{
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace Light
|
|
@ -1,75 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Event;
|
|
||||||
|
|
||||||
class GraphicsContext;
|
|
||||||
|
|
||||||
struct WindowProperties
|
|
||||||
{
|
|
||||||
std::string title;
|
|
||||||
glm::uvec2 size;
|
|
||||||
bool vsync, visible;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Window
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
Scope<GraphicsContext> m_GraphicsContext;
|
|
||||||
WindowProperties m_Properties;
|
|
||||||
bool b_Closed;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static Scope<Window> Create(std::function<void(Event&)> callback);
|
|
||||||
|
|
||||||
Window()
|
|
||||||
: m_GraphicsContext(nullptr),
|
|
||||||
m_Properties{},
|
|
||||||
b_Closed(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Window(const Window&) = delete;
|
|
||||||
Window& operator=(const Window&) = delete;
|
|
||||||
|
|
||||||
virtual ~Window() = default;
|
|
||||||
|
|
||||||
/* events */
|
|
||||||
virtual void PollEvents() = 0;
|
|
||||||
virtual void OnEvent(const Event& event) = 0;
|
|
||||||
|
|
||||||
//======================================== SETTERS ========================================//
|
|
||||||
virtual void SetProperties(const WindowProperties& properties, bool affectVisibility = false) = 0;
|
|
||||||
|
|
||||||
virtual void SetTitle(const std::string& title) = 0;
|
|
||||||
|
|
||||||
virtual void SetSize(const glm::uvec2& size, bool additive = false) = 0; // pass 0 for width or height for single dimension resizing
|
|
||||||
|
|
||||||
inline void Close() { b_Closed = true; }
|
|
||||||
virtual void SetVSync(bool vsync, bool toggle = false) = 0;
|
|
||||||
virtual void SetVisibility(bool visible, bool toggle = false) = 0;
|
|
||||||
//======================================== SETTERS ========================================//
|
|
||||||
|
|
||||||
//============================== GETTERS ==============================//
|
|
||||||
inline GraphicsContext* GetGfxContext() const { return m_GraphicsContext.get(); }
|
|
||||||
|
|
||||||
inline const WindowProperties& GetProperties() const { return m_Properties; }
|
|
||||||
|
|
||||||
inline const std::string& GetTitle() const { return m_Properties.title; }
|
|
||||||
|
|
||||||
inline const glm::uvec2& GetSize() const { return m_Properties.size; }
|
|
||||||
|
|
||||||
inline bool IsClosed() const { return b_Closed; }
|
|
||||||
inline bool IsVSync() const { return m_Properties.vsync; }
|
|
||||||
inline bool IsVisible() const { return m_Properties.visible; }
|
|
||||||
//============================== GETTERS ==============================//
|
|
||||||
|
|
||||||
protected:
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
73
Engine/src/Engine/Core/Window.hpp
Normal file
73
Engine/src/Engine/Core/Window.hpp
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Event;
|
||||||
|
|
||||||
|
class GraphicsContext;
|
||||||
|
|
||||||
|
struct WindowProperties
|
||||||
|
{
|
||||||
|
std::string title;
|
||||||
|
glm::uvec2 size;
|
||||||
|
bool vsync, visible;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Window
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
Scope<GraphicsContext> m_GraphicsContext;
|
||||||
|
WindowProperties m_Properties;
|
||||||
|
bool b_Closed;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Scope<Window> Create(std::function<void(Event&)> callback);
|
||||||
|
|
||||||
|
Window()
|
||||||
|
: m_GraphicsContext(nullptr), m_Properties {}, b_Closed(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Window(const Window&) = delete;
|
||||||
|
Window& operator=(const Window&) = delete;
|
||||||
|
|
||||||
|
virtual ~Window() = default;
|
||||||
|
|
||||||
|
/* events */
|
||||||
|
virtual void PollEvents() = 0;
|
||||||
|
virtual void OnEvent(const Event& event) = 0;
|
||||||
|
|
||||||
|
//======================================== SETTERS ========================================//
|
||||||
|
virtual void SetProperties(const WindowProperties& properties, bool affectVisibility = false) = 0;
|
||||||
|
|
||||||
|
virtual void SetTitle(const std::string& title) = 0;
|
||||||
|
|
||||||
|
virtual void SetSize(const glm::uvec2& size, bool additive = false) = 0; // pass 0 for width or height for single dimension resizing
|
||||||
|
|
||||||
|
inline void Close() { b_Closed = true; }
|
||||||
|
virtual void SetVSync(bool vsync, bool toggle = false) = 0;
|
||||||
|
virtual void SetVisibility(bool visible, bool toggle = false) = 0;
|
||||||
|
//======================================== SETTERS ========================================//
|
||||||
|
|
||||||
|
//============================== GETTERS ==============================//
|
||||||
|
inline GraphicsContext* GetGfxContext() const { return m_GraphicsContext.get(); }
|
||||||
|
|
||||||
|
inline const WindowProperties& GetProperties() const { return m_Properties; }
|
||||||
|
|
||||||
|
inline const std::string& GetTitle() const { return m_Properties.title; }
|
||||||
|
|
||||||
|
inline const glm::uvec2& GetSize() const { return m_Properties.size; }
|
||||||
|
|
||||||
|
inline bool IsClosed() const { return b_Closed; }
|
||||||
|
inline bool IsVSync() const { return m_Properties.vsync; }
|
||||||
|
inline bool IsVisible() const { return m_Properties.visible; }
|
||||||
|
//============================== GETTERS ==============================//
|
||||||
|
|
||||||
|
protected:
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,6 +1,6 @@
|
||||||
#include "Exceptions.h"
|
#include "Exceptions.hpp"
|
||||||
|
|
||||||
#include "Utility/Stringifier.h"
|
#include "Utility/Stringifier.hpp"
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "Instrumentor.h"
|
#include "Instrumentor.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <ostream>
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
struct ScopeProfileResult
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
long long start, duration;
|
|
||||||
uint32_t threadID;
|
|
||||||
};
|
|
||||||
|
|
||||||
// #todo: add event categories
|
|
||||||
// #todo: use ofstream in a separate thread
|
|
||||||
class Instrumentor /* singleton */
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
static Instrumentor* s_Context;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::ofstream m_OutputFileStream;
|
|
||||||
|
|
||||||
unsigned int m_CurrentSessionCount;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static Scope<Instrumentor> Create();
|
|
||||||
|
|
||||||
static inline void BeginSession(const std::string& outputPath) { s_Context->BeginSessionImpl(outputPath); }
|
|
||||||
static inline void EndSession() { s_Context->EndSessionImpl(); }
|
|
||||||
|
|
||||||
static inline void SubmitScopeProfile(const ScopeProfileResult& profileResult) { s_Context->SubmitScopeProfileImpl(profileResult); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Instrumentor();
|
|
||||||
|
|
||||||
void BeginSessionImpl(const std::string& outputPath);
|
|
||||||
void EndSessionImpl();
|
|
||||||
|
|
||||||
void SubmitScopeProfileImpl(const ScopeProfileResult& profileResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
class InstrumentorTimer
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ScopeProfileResult m_Result;
|
|
||||||
std::chrono::time_point<std::chrono::steady_clock> m_Start;
|
|
||||||
|
|
||||||
public:
|
|
||||||
InstrumentorTimer(const std::string& scopeName);
|
|
||||||
~InstrumentorTimer();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* scope */
|
|
||||||
#define LT_PROFILE_SCOPE(name) LT_PROFILE_SCOPE_NO_REDIFINITION(name, __LINE__)
|
|
||||||
#define LT_PROFILE_SCOPE_NO_REDIFINITION(name, line) LT_PROFILE_SCOPE_NO_REDIFINITION2(name, line)
|
|
||||||
#define LT_PROFILE_SCOPE_NO_REDIFINITION2(name, line) InstrumentorTimer timer##line(name)
|
|
||||||
|
|
||||||
/* function */
|
|
||||||
#define LT_PROFILE_FUNCTION LT_PROFILE_SCOPE(__FUNCSIG__)
|
|
||||||
|
|
||||||
/* session */
|
|
||||||
#define LT_PROFILE_BEGIN_SESSION(outputPath) ::Light::Instrumentor::BeginSession(outputPath)
|
|
||||||
#define LT_PROFILE_END_SESSION() ::Light::Instrumentor::EndSession()
|
|
70
Engine/src/Engine/Debug/Instrumentor.hpp
Normal file
70
Engine/src/Engine/Debug/Instrumentor.hpp
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <fstream>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
struct ScopeProfileResult
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
long long start, duration;
|
||||||
|
uint32_t threadID;
|
||||||
|
};
|
||||||
|
|
||||||
|
// #todo: add event categories
|
||||||
|
// #todo: use ofstream in a separate thread
|
||||||
|
class Instrumentor /* singleton */
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static Instrumentor* s_Context;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::ofstream m_OutputFileStream;
|
||||||
|
|
||||||
|
unsigned int m_CurrentSessionCount;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Scope<Instrumentor> Create();
|
||||||
|
|
||||||
|
static inline void BeginSession(const std::string& outputPath) { s_Context->BeginSessionImpl(outputPath); }
|
||||||
|
static inline void EndSession() { s_Context->EndSessionImpl(); }
|
||||||
|
|
||||||
|
static inline void SubmitScopeProfile(const ScopeProfileResult& profileResult) { s_Context->SubmitScopeProfileImpl(profileResult); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Instrumentor();
|
||||||
|
|
||||||
|
void BeginSessionImpl(const std::string& outputPath);
|
||||||
|
void EndSessionImpl();
|
||||||
|
|
||||||
|
void SubmitScopeProfileImpl(const ScopeProfileResult& profileResult);
|
||||||
|
};
|
||||||
|
|
||||||
|
class InstrumentorTimer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
ScopeProfileResult m_Result;
|
||||||
|
std::chrono::time_point<std::chrono::steady_clock> m_Start;
|
||||||
|
|
||||||
|
public:
|
||||||
|
InstrumentorTimer(const std::string& scopeName);
|
||||||
|
~InstrumentorTimer();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
||||||
|
|
||||||
|
/* scope */
|
||||||
|
#define LT_PROFILE_SCOPE(name) LT_PROFILE_SCOPE_NO_REDIFINITION(name, __LINE__)
|
||||||
|
#define LT_PROFILE_SCOPE_NO_REDIFINITION(name, line) LT_PROFILE_SCOPE_NO_REDIFINITION2(name, line)
|
||||||
|
#define LT_PROFILE_SCOPE_NO_REDIFINITION2(name, line) InstrumentorTimer timer##line(name)
|
||||||
|
|
||||||
|
/* function */
|
||||||
|
#define LT_PROFILE_FUNCTION LT_PROFILE_SCOPE(__FUNCSIG__)
|
||||||
|
|
||||||
|
/* session */
|
||||||
|
#define LT_PROFILE_BEGIN_SESSION(outputPath) ::Light::Instrumentor::BeginSession(outputPath)
|
||||||
|
#define LT_PROFILE_END_SESSION() ::Light::Instrumentor::EndSession()
|
|
@ -1,4 +1,4 @@
|
||||||
#include "Logger.h"
|
#include "Logger.hpp"
|
||||||
|
|
||||||
#include <spdlog/sinks/basic_file_sink.h>
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#ifndef LIGHT_LOGGER_H
|
#ifndef LIGHT_LOGGER_H
|
||||||
#define LIGHT_LOGGER_H
|
#define LIGHT_LOGGER_H
|
||||||
|
|
||||||
#include "Base/Base.h"
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Event.h"
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class SetCharEvent : public Event
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const unsigned int m_Character;
|
|
||||||
|
|
||||||
public:
|
|
||||||
SetCharEvent(unsigned int character)
|
|
||||||
: m_Character(character)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int GetCharacter() const { return m_Character; }
|
|
||||||
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "CharSet: " << m_Character;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
EVENT_TYPE(SetChar)
|
|
||||||
EVENT_CATEGORY(InputEventCategory | KeyboardEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
33
Engine/src/Engine/Events/CharEvent.hpp
Normal file
33
Engine/src/Engine/Events/CharEvent.hpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "Event.hpp"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class SetCharEvent: public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const unsigned int m_Character;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SetCharEvent(unsigned int character)
|
||||||
|
: m_Character(character)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int GetCharacter() const { return m_Character; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "CharSet: " << m_Character;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(SetChar)
|
||||||
|
EVENT_CATEGORY(InputEventCategory | KeyboardEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,46 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
enum class EventType
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
|
|
||||||
// input
|
|
||||||
MouseMoved, WheelScrolled, ButtonPressed, ButtonReleased,
|
|
||||||
KeyPressed, KeyRepeated, KeyReleased,
|
|
||||||
SetChar,
|
|
||||||
|
|
||||||
// window
|
|
||||||
WindowMoved, WindowResized, WindowClosed, WindowLostFocus, WindowGainFocus,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum EventCategory
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
|
|
||||||
WindowEventCategory = BIT(0),
|
|
||||||
InputEventCategory = BIT(1),
|
|
||||||
KeyboardEventCategory = BIT(2),
|
|
||||||
MouseEventCategory = BIT(3),
|
|
||||||
};
|
|
||||||
|
|
||||||
#define EVENT_TYPE(type) EventType GetEventType() const override { return ::Light::EventType:: type; }
|
|
||||||
#define EVENT_CATEGORY(eCategory) inline bool HasCategory(EventCategory category) const override { return (eCategory) & category; }
|
|
||||||
|
|
||||||
class Event
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual EventType GetEventType() const = 0;
|
|
||||||
virtual std::string GetInfoLog() const = 0;
|
|
||||||
virtual bool HasCategory(EventCategory category) const = 0;
|
|
||||||
|
|
||||||
friend std::ostream & operator<<(std::ostream & os, const Event& e)
|
|
||||||
{
|
|
||||||
return os << e.GetInfoLog();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
57
Engine/src/Engine/Events/Event.hpp
Normal file
57
Engine/src/Engine/Events/Event.hpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
enum class EventType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
|
||||||
|
// input
|
||||||
|
MouseMoved,
|
||||||
|
WheelScrolled,
|
||||||
|
ButtonPressed,
|
||||||
|
ButtonReleased,
|
||||||
|
KeyPressed,
|
||||||
|
KeyRepeated,
|
||||||
|
KeyReleased,
|
||||||
|
SetChar,
|
||||||
|
|
||||||
|
// window
|
||||||
|
WindowMoved,
|
||||||
|
WindowResized,
|
||||||
|
WindowClosed,
|
||||||
|
WindowLostFocus,
|
||||||
|
WindowGainFocus,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum EventCategory
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
|
||||||
|
WindowEventCategory = BIT(0),
|
||||||
|
InputEventCategory = BIT(1),
|
||||||
|
KeyboardEventCategory = BIT(2),
|
||||||
|
MouseEventCategory = BIT(3),
|
||||||
|
};
|
||||||
|
|
||||||
|
#define EVENT_TYPE(type) \
|
||||||
|
EventType GetEventType() const override { return ::Light::EventType::type; }
|
||||||
|
#define EVENT_CATEGORY(eCategory) \
|
||||||
|
inline bool HasCategory(EventCategory category) const override { return (eCategory)&category; }
|
||||||
|
|
||||||
|
class Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual EventType GetEventType() const = 0;
|
||||||
|
virtual std::string GetInfoLog() const = 0;
|
||||||
|
virtual bool HasCategory(EventCategory category) const = 0;
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const Event& e)
|
||||||
|
{
|
||||||
|
return os << e.GetInfoLog();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,80 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Event.h"
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class KeyPressedEvent : public Event
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const int m_Key;
|
|
||||||
|
|
||||||
public:
|
|
||||||
KeyPressedEvent(int key)
|
|
||||||
: m_Key(key)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int GetKey() const { return m_Key; }
|
|
||||||
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "KeyPressed: " << m_Key;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
EVENT_TYPE(KeyPressed)
|
|
||||||
EVENT_CATEGORY(InputEventCategory | KeyboardEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
class KeyRepeatEvent : public Event
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const int m_Key;
|
|
||||||
|
|
||||||
public:
|
|
||||||
KeyRepeatEvent(int key)
|
|
||||||
: m_Key(key)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int GetKey() const { return m_Key; }
|
|
||||||
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "KeyRepeated: " << m_Key;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
EVENT_TYPE(KeyRepeated)
|
|
||||||
EVENT_CATEGORY(InputEventCategory | KeyboardEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
class KeyReleasedEvent : public Event
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const int m_Key;
|
|
||||||
|
|
||||||
public:
|
|
||||||
KeyReleasedEvent(int key)
|
|
||||||
: m_Key(key)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int GetKey() const { return m_Key; }
|
|
||||||
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "KeyReleased: " << m_Key;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
EVENT_TYPE(KeyReleased)
|
|
||||||
EVENT_CATEGORY(InputEventCategory | KeyboardEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
79
Engine/src/Engine/Events/KeyboardEvents.hpp
Normal file
79
Engine/src/Engine/Events/KeyboardEvents.hpp
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "Event.hpp"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class KeyPressedEvent: public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int m_Key;
|
||||||
|
|
||||||
|
public:
|
||||||
|
KeyPressedEvent(int key)
|
||||||
|
: m_Key(key)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int GetKey() const { return m_Key; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "KeyPressed: " << m_Key;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(KeyPressed)
|
||||||
|
EVENT_CATEGORY(InputEventCategory | KeyboardEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
class KeyRepeatEvent: public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int m_Key;
|
||||||
|
|
||||||
|
public:
|
||||||
|
KeyRepeatEvent(int key)
|
||||||
|
: m_Key(key)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int GetKey() const { return m_Key; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "KeyRepeated: " << m_Key;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(KeyRepeated)
|
||||||
|
EVENT_CATEGORY(InputEventCategory | KeyboardEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
class KeyReleasedEvent: public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int m_Key;
|
||||||
|
|
||||||
|
public:
|
||||||
|
KeyReleasedEvent(int key)
|
||||||
|
: m_Key(key)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int GetKey() const { return m_Key; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "KeyReleased: " << m_Key;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(KeyReleased)
|
||||||
|
EVENT_CATEGORY(InputEventCategory | KeyboardEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,108 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Event.h"
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class MouseMovedEvent : public Event
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const glm::vec2 m_Position;
|
|
||||||
|
|
||||||
public:
|
|
||||||
MouseMovedEvent(float x, float y)
|
|
||||||
: m_Position(x, y)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const glm::vec2& GetPosition() const { return m_Position; }
|
|
||||||
|
|
||||||
inline float GetX() const { return m_Position.x; }
|
|
||||||
inline float GetY() const { return m_Position.y; }
|
|
||||||
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "MouseMoved: " << m_Position.x << ", " << m_Position.y;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
EVENT_TYPE(MouseMoved)
|
|
||||||
EVENT_CATEGORY(InputEventCategory | MouseEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
class WheelScrolledEvent : public Event
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const float m_Offset;
|
|
||||||
|
|
||||||
public:
|
|
||||||
WheelScrolledEvent(float offset)
|
|
||||||
: m_Offset(offset)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float GetOffset() const { return m_Offset; }
|
|
||||||
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "WheelScrolled: " << m_Offset;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
EVENT_TYPE(WheelScrolled)
|
|
||||||
EVENT_CATEGORY(InputEventCategory | MouseEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
class ButtonPressedEvent : public Event
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const int m_Button;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ButtonPressedEvent(int button)
|
|
||||||
: m_Button(button)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int GetButton() const { return m_Button; }
|
|
||||||
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "ButtonPressed: " << m_Button;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
EVENT_TYPE(ButtonPressed)
|
|
||||||
EVENT_CATEGORY(InputEventCategory | MouseEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
class ButtonReleasedEvent : public Event
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const int m_Button;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ButtonReleasedEvent(int button)
|
|
||||||
: m_Button(button)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int GetButton() const { return m_Button; }
|
|
||||||
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "ButtonReleased: " << m_Button;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
EVENT_TYPE(ButtonReleased)
|
|
||||||
EVENT_CATEGORY(InputEventCategory | MouseEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
106
Engine/src/Engine/Events/MouseEvents.hpp
Normal file
106
Engine/src/Engine/Events/MouseEvents.hpp
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "Event.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class MouseMovedEvent: public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const glm::vec2 m_Position;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MouseMovedEvent(float x, float y)
|
||||||
|
: m_Position(x, y)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const glm::vec2& GetPosition() const { return m_Position; }
|
||||||
|
|
||||||
|
inline float GetX() const { return m_Position.x; }
|
||||||
|
inline float GetY() const { return m_Position.y; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "MouseMoved: " << m_Position.x << ", " << m_Position.y;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(MouseMoved)
|
||||||
|
EVENT_CATEGORY(InputEventCategory | MouseEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
class WheelScrolledEvent: public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const float m_Offset;
|
||||||
|
|
||||||
|
public:
|
||||||
|
WheelScrolledEvent(float offset)
|
||||||
|
: m_Offset(offset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float GetOffset() const { return m_Offset; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "WheelScrolled: " << m_Offset;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(WheelScrolled)
|
||||||
|
EVENT_CATEGORY(InputEventCategory | MouseEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
class ButtonPressedEvent: public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int m_Button;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ButtonPressedEvent(int button)
|
||||||
|
: m_Button(button)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int GetButton() const { return m_Button; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "ButtonPressed: " << m_Button;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(ButtonPressed)
|
||||||
|
EVENT_CATEGORY(InputEventCategory | MouseEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
class ButtonReleasedEvent: public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int m_Button;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ButtonReleasedEvent(int button)
|
||||||
|
: m_Button(button)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int GetButton() const { return m_Button; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "ButtonReleased: " << m_Button;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(ButtonReleased)
|
||||||
|
EVENT_CATEGORY(InputEventCategory | MouseEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,92 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Event.h"
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class WindowClosedEvent : public Event
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
return "WindowClosedEvent";
|
|
||||||
}
|
|
||||||
EVENT_TYPE(WindowClosed)
|
|
||||||
EVENT_CATEGORY(WindowEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
class WindowMovedEvent : public Event
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const glm::ivec2 m_Position;
|
|
||||||
|
|
||||||
public:
|
|
||||||
WindowMovedEvent(int x, int y)
|
|
||||||
: m_Position(x, y)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::ivec2& GetPosition() const{ return m_Position; }
|
|
||||||
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "WindwoMoved: " << m_Position.x << ", " << m_Position.y;
|
|
||||||
return ss.str();
|
|
||||||
; }
|
|
||||||
EVENT_TYPE(WindowMoved)
|
|
||||||
EVENT_CATEGORY(WindowEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
class WindowResizedEvent : public Event
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const glm::uvec2 m_Size;
|
|
||||||
|
|
||||||
public:
|
|
||||||
WindowResizedEvent(unsigned int width, unsigned int height)
|
|
||||||
: m_Size(width, height)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::uvec2& GetSize() const { return m_Size; }
|
|
||||||
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "WindowResized: " << m_Size.x << ", " << m_Size.y;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
EVENT_TYPE(WindowResized)
|
|
||||||
EVENT_CATEGORY(WindowEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
class WindowLostFocusEvent : public Event
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
return "WindowLostFocus";
|
|
||||||
}
|
|
||||||
EVENT_TYPE(WindowLostFocus)
|
|
||||||
EVENT_CATEGORY(WindowEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
class WindowGainFocusEvent : public Event
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual std::string GetInfoLog() const override
|
|
||||||
{
|
|
||||||
return "WindowGainFocus";
|
|
||||||
}
|
|
||||||
EVENT_TYPE(WindowGainFocus)
|
|
||||||
EVENT_CATEGORY(WindowEventCategory)
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
91
Engine/src/Engine/Events/WindowEvents.hpp
Normal file
91
Engine/src/Engine/Events/WindowEvents.hpp
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "Event.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class WindowClosedEvent: public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
return "WindowClosedEvent";
|
||||||
|
}
|
||||||
|
EVENT_TYPE(WindowClosed)
|
||||||
|
EVENT_CATEGORY(WindowEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
class WindowMovedEvent: public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const glm::ivec2 m_Position;
|
||||||
|
|
||||||
|
public:
|
||||||
|
WindowMovedEvent(int x, int y)
|
||||||
|
: m_Position(x, y)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const glm::ivec2& GetPosition() const { return m_Position; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "WindwoMoved: " << m_Position.x << ", " << m_Position.y;
|
||||||
|
return ss.str();
|
||||||
|
;
|
||||||
|
}
|
||||||
|
EVENT_TYPE(WindowMoved)
|
||||||
|
EVENT_CATEGORY(WindowEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
class WindowResizedEvent: public Event
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const glm::uvec2 m_Size;
|
||||||
|
|
||||||
|
public:
|
||||||
|
WindowResizedEvent(unsigned int width, unsigned int height)
|
||||||
|
: m_Size(width, height)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const glm::uvec2& GetSize() const { return m_Size; }
|
||||||
|
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "WindowResized: " << m_Size.x << ", " << m_Size.y;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
EVENT_TYPE(WindowResized)
|
||||||
|
EVENT_CATEGORY(WindowEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
class WindowLostFocusEvent: public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
return "WindowLostFocus";
|
||||||
|
}
|
||||||
|
EVENT_TYPE(WindowLostFocus)
|
||||||
|
EVENT_CATEGORY(WindowEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
class WindowGainFocusEvent: public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual std::string GetInfoLog() const override
|
||||||
|
{
|
||||||
|
return "WindowGainFocus";
|
||||||
|
}
|
||||||
|
EVENT_TYPE(WindowGainFocus)
|
||||||
|
EVENT_CATEGORY(WindowEventCategory)
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,13 +1,13 @@
|
||||||
#include "Blender.h"
|
#include "Blender.hpp"
|
||||||
|
|
||||||
#include "OpenGL/glBlender.h"
|
#include "OpenGL/glBlender.hpp"
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||||
#include "DirectX/dxBlender.h"
|
#include "DirectX/dxBlender.hpp"
|
||||||
#include "DirectX/dxSharedContext.h"
|
#include "DirectX/dxSharedContext.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "GraphicsContext.h"
|
#include "GraphicsContext.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
enum class BlendFactor : uint8_t
|
|
||||||
{
|
|
||||||
// constants
|
|
||||||
ZERO, ONE,
|
|
||||||
|
|
||||||
// source
|
|
||||||
SRC_COLOR,
|
|
||||||
INVERSE_SRC_COLOR,
|
|
||||||
|
|
||||||
SRC_ALPHA,
|
|
||||||
INVERSE_SRC_ALPHA,
|
|
||||||
|
|
||||||
// destination
|
|
||||||
DST_COLOR,
|
|
||||||
INVERSE_DST_COLOR,
|
|
||||||
|
|
||||||
DST_ALPHA,
|
|
||||||
INVERSE_DST_ALPHA,
|
|
||||||
|
|
||||||
// source1
|
|
||||||
SRC1_COLOR,
|
|
||||||
INVERSE_SRC1_COLOR,
|
|
||||||
|
|
||||||
SRC1_ALPHA,
|
|
||||||
INVERSE_SRC1_ALPHA,
|
|
||||||
};
|
|
||||||
|
|
||||||
class Blender
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Scope<Blender> Create(Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
virtual void Enable(BlendFactor srcFactor, BlendFactor dstFactor) = 0;
|
|
||||||
virtual void Disable() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Blender() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
49
Engine/src/Engine/Graphics/Blender.hpp
Normal file
49
Engine/src/Engine/Graphics/Blender.hpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
enum class BlendFactor : uint8_t
|
||||||
|
{
|
||||||
|
// constants
|
||||||
|
ZERO,
|
||||||
|
ONE,
|
||||||
|
|
||||||
|
// source
|
||||||
|
SRC_COLOR,
|
||||||
|
INVERSE_SRC_COLOR,
|
||||||
|
|
||||||
|
SRC_ALPHA,
|
||||||
|
INVERSE_SRC_ALPHA,
|
||||||
|
|
||||||
|
// destination
|
||||||
|
DST_COLOR,
|
||||||
|
INVERSE_DST_COLOR,
|
||||||
|
|
||||||
|
DST_ALPHA,
|
||||||
|
INVERSE_DST_ALPHA,
|
||||||
|
|
||||||
|
// source1
|
||||||
|
SRC1_COLOR,
|
||||||
|
INVERSE_SRC1_COLOR,
|
||||||
|
|
||||||
|
SRC1_ALPHA,
|
||||||
|
INVERSE_SRC1_ALPHA,
|
||||||
|
};
|
||||||
|
|
||||||
|
class Blender
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Scope<Blender> Create(Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
virtual void Enable(BlendFactor srcFactor, BlendFactor dstFactor) = 0;
|
||||||
|
virtual void Disable() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Blender() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,14 +1,14 @@
|
||||||
#include "Buffers.h"
|
#include "Buffers.hpp"
|
||||||
|
|
||||||
#include "OpenGL/glBuffers.h"
|
#include "OpenGL/glBuffers.hpp"
|
||||||
#include "SharedContext.h"
|
#include "SharedContext.hpp"
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||||
#include "DirectX/dxBuffers.h"
|
#include "DirectX/dxBuffers.hpp"
|
||||||
#include "DirectX/dxSharedContext.h"
|
#include "DirectX/dxSharedContext.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "GraphicsContext.h"
|
#include "GraphicsContext.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
enum class ConstantBufferIndex
|
|
||||||
{
|
|
||||||
ViewProjection = 0u
|
|
||||||
};
|
|
||||||
|
|
||||||
//========== CONSTANT_BUFFER ==========//
|
|
||||||
class ConstantBuffer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Scope<ConstantBuffer> Create(ConstantBufferIndex index, unsigned int size, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
virtual void* Map() = 0;
|
|
||||||
virtual void UnMap() = 0;
|
|
||||||
|
|
||||||
virtual void Bind() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
ConstantBuffer() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
//========== VERTEX_BUFFER ==========//
|
|
||||||
class VertexBuffer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Ref<VertexBuffer> Create(float* vertices, unsigned int stride, unsigned int count, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
virtual ~VertexBuffer() = default;
|
|
||||||
|
|
||||||
virtual void* Map() = 0;
|
|
||||||
virtual void UnMap() = 0;
|
|
||||||
|
|
||||||
virtual void Bind() = 0;
|
|
||||||
virtual void UnBind() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
VertexBuffer() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
//========== INDEX_BUFFER ==========//
|
|
||||||
class IndexBuffer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Ref<IndexBuffer> Create(unsigned int* indices, unsigned int count, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
virtual ~IndexBuffer() = default;
|
|
||||||
|
|
||||||
virtual void Bind() = 0;
|
|
||||||
virtual void UnBind() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
IndexBuffer() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
62
Engine/src/Engine/Graphics/Buffers.hpp
Normal file
62
Engine/src/Engine/Graphics/Buffers.hpp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
enum class ConstantBufferIndex
|
||||||
|
{
|
||||||
|
ViewProjection = 0u
|
||||||
|
};
|
||||||
|
|
||||||
|
//========== CONSTANT_BUFFER ==========//
|
||||||
|
class ConstantBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Scope<ConstantBuffer> Create(ConstantBufferIndex index, unsigned int size, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
virtual void* Map() = 0;
|
||||||
|
virtual void UnMap() = 0;
|
||||||
|
|
||||||
|
virtual void Bind() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ConstantBuffer() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
//========== VERTEX_BUFFER ==========//
|
||||||
|
class VertexBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Ref<VertexBuffer> Create(float* vertices, unsigned int stride, unsigned int count, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
virtual ~VertexBuffer() = default;
|
||||||
|
|
||||||
|
virtual void* Map() = 0;
|
||||||
|
virtual void UnMap() = 0;
|
||||||
|
|
||||||
|
virtual void Bind() = 0;
|
||||||
|
virtual void UnBind() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
VertexBuffer() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
//========== INDEX_BUFFER ==========//
|
||||||
|
class IndexBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Ref<IndexBuffer> Create(unsigned int* indices, unsigned int count, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
virtual ~IndexBuffer() = default;
|
||||||
|
|
||||||
|
virtual void Bind() = 0;
|
||||||
|
virtual void UnBind() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
IndexBuffer() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,13 +1,13 @@
|
||||||
#include "Framebuffer.h"
|
#include "Framebuffer.hpp"
|
||||||
|
|
||||||
#include "OpenGL/glFramebuffer.h"
|
#include "OpenGL/glFramebuffer.hpp"
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||||
#include "DirectX/dxFramebuffer.h"
|
#include "DirectX/dxFramebuffer.hpp"
|
||||||
#include "DirectX/dxSharedContext.h"
|
#include "DirectX/dxSharedContext.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "GraphicsContext.h"
|
#include "GraphicsContext.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
struct FramebufferSpecification
|
|
||||||
{
|
|
||||||
unsigned int width, height;
|
|
||||||
unsigned int samples = 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Framebuffer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Ref<Framebuffer> Create(const FramebufferSpecification& specification, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
virtual void BindAsTarget(const glm::vec4& clearColor) = 0;
|
|
||||||
virtual void BindAsResource() = 0;
|
|
||||||
|
|
||||||
virtual void Resize(const glm::uvec2& size) = 0;
|
|
||||||
|
|
||||||
virtual void* GetColorAttachment() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Framebuffer() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
33
Engine/src/Engine/Graphics/Framebuffer.hpp
Normal file
33
Engine/src/Engine/Graphics/Framebuffer.hpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
struct FramebufferSpecification
|
||||||
|
{
|
||||||
|
unsigned int width, height;
|
||||||
|
unsigned int samples = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Framebuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Ref<Framebuffer> Create(const FramebufferSpecification& specification, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
virtual void BindAsTarget(const glm::vec4& clearColor) = 0;
|
||||||
|
virtual void BindAsResource() = 0;
|
||||||
|
|
||||||
|
virtual void Resize(const glm::uvec2& size) = 0;
|
||||||
|
|
||||||
|
virtual void* GetColorAttachment() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Framebuffer() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,18 +1,18 @@
|
||||||
#include "GraphicsContext.h"
|
#include "GraphicsContext.hpp"
|
||||||
|
|
||||||
#include "OpenGL/glGraphicsContext.h"
|
#include "OpenGL/glGraphicsContext.hpp"
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||||
#include "DirectX/dxGraphicsContext.h"
|
#include "DirectX/dxGraphicsContext.hpp"
|
||||||
#include "DirectX/dxSharedContext.h"
|
#include "DirectX/dxSharedContext.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Blender.h" // required for forward declaration
|
#include "Blender.hpp" // required for forward declaration
|
||||||
#include "Buffers.h" // required for forward declaration
|
#include "Buffers.hpp" // required for forward declaration
|
||||||
#include "RenderCommand.h" // required for forward declaration
|
#include "RenderCommand.hpp" // required for forward declaration
|
||||||
#include "Renderer.h" // required for forward declaration
|
#include "Renderer.hpp" // required for forward declaration
|
||||||
#include "UserInterface/UserInterface.h" // required for forward declaration
|
#include "UserInterface/UserInterface.hpp" // required for forward declaration
|
||||||
#include "Utility/ResourceManager.h" // required for forward declaration
|
#include "Utility/ResourceManager.hpp" // required for forward declaration
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
struct GLFWwindow;
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Renderer;
|
|
||||||
class ResourceManager;
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
class UserInterface;
|
|
||||||
|
|
||||||
class WindowResizedEvent;
|
|
||||||
|
|
||||||
enum class GraphicsAPI
|
|
||||||
{
|
|
||||||
Default = 0,
|
|
||||||
OpenGL,
|
|
||||||
DirectX,
|
|
||||||
Vulkan, // :#todo
|
|
||||||
Metal // :#todo
|
|
||||||
};
|
|
||||||
|
|
||||||
class GraphicsContext /* singleton */
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
static GraphicsContext* s_Context;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Scope<UserInterface> m_UserInterface;
|
|
||||||
Scope<Renderer> m_Renderer;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
GraphicsAPI m_GraphicsAPI;
|
|
||||||
Ref<SharedContext> m_SharedContext = nullptr;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static Scope<GraphicsContext> Create(GraphicsAPI api, GLFWwindow* windowHandle);
|
|
||||||
|
|
||||||
GraphicsContext(const GraphicsContext&) = delete;
|
|
||||||
GraphicsContext& operator=(const GraphicsContext&) = delete;
|
|
||||||
|
|
||||||
virtual ~GraphicsContext();
|
|
||||||
|
|
||||||
virtual void LogDebugData() = 0;
|
|
||||||
|
|
||||||
static inline GraphicsAPI GetGraphicsAPI() { return s_Context->m_GraphicsAPI; }
|
|
||||||
static inline Ref<SharedContext> GetSharedContext() { return s_Context->m_SharedContext; }
|
|
||||||
|
|
||||||
inline Renderer* GetRenderer() { return m_Renderer.get(); }
|
|
||||||
inline UserInterface* GetUserInterface() { return m_UserInterface.get(); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
GraphicsContext() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
59
Engine/src/Engine/Graphics/GraphicsContext.hpp
Normal file
59
Engine/src/Engine/Graphics/GraphicsContext.hpp
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
struct GLFWwindow;
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Renderer;
|
||||||
|
class ResourceManager;
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
class UserInterface;
|
||||||
|
|
||||||
|
class WindowResizedEvent;
|
||||||
|
|
||||||
|
enum class GraphicsAPI
|
||||||
|
{
|
||||||
|
Default = 0,
|
||||||
|
OpenGL,
|
||||||
|
DirectX,
|
||||||
|
Vulkan, // :#todo
|
||||||
|
Metal // :#todo
|
||||||
|
};
|
||||||
|
|
||||||
|
class GraphicsContext /* singleton */
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static GraphicsContext* s_Context;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Scope<UserInterface> m_UserInterface;
|
||||||
|
Scope<Renderer> m_Renderer;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
GraphicsAPI m_GraphicsAPI;
|
||||||
|
Ref<SharedContext> m_SharedContext = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Scope<GraphicsContext> Create(GraphicsAPI api, GLFWwindow* windowHandle);
|
||||||
|
|
||||||
|
GraphicsContext(const GraphicsContext&) = delete;
|
||||||
|
GraphicsContext& operator=(const GraphicsContext&) = delete;
|
||||||
|
|
||||||
|
virtual ~GraphicsContext();
|
||||||
|
|
||||||
|
virtual void LogDebugData() = 0;
|
||||||
|
|
||||||
|
static inline GraphicsAPI GetGraphicsAPI() { return s_Context->m_GraphicsAPI; }
|
||||||
|
static inline Ref<SharedContext> GetSharedContext() { return s_Context->m_SharedContext; }
|
||||||
|
|
||||||
|
inline Renderer* GetRenderer() { return m_Renderer.get(); }
|
||||||
|
inline UserInterface* GetUserInterface() { return m_UserInterface.get(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
GraphicsContext() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,13 +1,13 @@
|
||||||
#include "RenderCommand.h"
|
#include "RenderCommand.hpp"
|
||||||
|
|
||||||
#include "OpenGL/glRenderCommand.h"
|
#include "OpenGL/glRenderCommand.hpp"
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||||
#include "DirectX/dxRenderCommand.h"
|
#include "DirectX/dxRenderCommand.hpp"
|
||||||
#include "DirectX/dxSharedContext.h"
|
#include "DirectX/dxSharedContext.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "GraphicsContext.h"
|
#include "GraphicsContext.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
struct GLFWwindow;
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
class RenderCommand
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Scope<RenderCommand> Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
RenderCommand(const RenderCommand&) = delete;
|
|
||||||
RenderCommand& operator=(const RenderCommand&) = delete;
|
|
||||||
|
|
||||||
virtual ~RenderCommand() = default;
|
|
||||||
|
|
||||||
virtual void SwapBuffers() = 0;
|
|
||||||
virtual void ClearBackBuffer(const glm::vec4& clearColor) = 0;
|
|
||||||
|
|
||||||
virtual void Draw(unsigned int count) = 0;
|
|
||||||
virtual void DrawIndexed(unsigned int count) = 0;
|
|
||||||
|
|
||||||
virtual void DefaultTargetFramebuffer() = 0;
|
|
||||||
|
|
||||||
virtual void SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height) = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
RenderCommand() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
37
Engine/src/Engine/Graphics/RenderCommand.hpp
Normal file
37
Engine/src/Engine/Graphics/RenderCommand.hpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
struct GLFWwindow;
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
class RenderCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Scope<RenderCommand> Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
RenderCommand(const RenderCommand&) = delete;
|
||||||
|
RenderCommand& operator=(const RenderCommand&) = delete;
|
||||||
|
|
||||||
|
virtual ~RenderCommand() = default;
|
||||||
|
|
||||||
|
virtual void SwapBuffers() = 0;
|
||||||
|
virtual void ClearBackBuffer(const glm::vec4& clearColor) = 0;
|
||||||
|
|
||||||
|
virtual void Draw(unsigned int count) = 0;
|
||||||
|
virtual void DrawIndexed(unsigned int count) = 0;
|
||||||
|
|
||||||
|
virtual void DefaultTargetFramebuffer() = 0;
|
||||||
|
|
||||||
|
virtual void SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
RenderCommand() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,12 +1,12 @@
|
||||||
#include "Renderer.h"
|
#include "Renderer.hpp"
|
||||||
|
|
||||||
#include "Blender.h"
|
#include "Blender.hpp"
|
||||||
#include "Buffers.h"
|
#include "Buffers.hpp"
|
||||||
#include "Camera/SceneCamera.h"
|
#include "Camera/SceneCamera.hpp"
|
||||||
#include "Events/WindowEvents.h"
|
#include "Events/WindowEvents.hpp"
|
||||||
#include "Framebuffer.h"
|
#include "Framebuffer.hpp"
|
||||||
#include "RenderCommand.h"
|
#include "RenderCommand.hpp"
|
||||||
#include "Texture.h"
|
#include "Texture.hpp"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
|
@ -1,85 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include "RendererPrograms/QuadRendererProgram.h"
|
|
||||||
#include "RendererPrograms/TextureRendererProgram.h"
|
|
||||||
#include "RendererPrograms/TintedTextureRendererProgram.h"
|
|
||||||
|
|
||||||
#define LT_MAX_QUAD_RENDERER_VERTICES 1028u * 4u
|
|
||||||
#define LT_MAX_TEXTURE_RENDERER_VERTICES 1028u * 4u
|
|
||||||
#define LT_MAX_TINTED_TEXTURE_RENDERER_VERTICES 1028u * 4u
|
|
||||||
|
|
||||||
struct GLFWwindow;
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Blender;
|
|
||||||
class ConstantBuffer;
|
|
||||||
class Framebuffer;
|
|
||||||
class RenderCommand;
|
|
||||||
class Texture;
|
|
||||||
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
class Camera;
|
|
||||||
|
|
||||||
class WindowResizedEvent;
|
|
||||||
|
|
||||||
class Renderer
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
static Renderer* s_Context;
|
|
||||||
|
|
||||||
// renderer programs
|
|
||||||
QuadRendererProgram m_QuadRenderer;
|
|
||||||
TextureRendererProgram m_TextureRenderer;
|
|
||||||
TintedTextureRendererProgram m_TintedTextureRenderer;
|
|
||||||
|
|
||||||
// constant buffers
|
|
||||||
Scope<ConstantBuffer> m_ViewProjectionBuffer;
|
|
||||||
|
|
||||||
Scope<RenderCommand> m_RenderCommand;
|
|
||||||
Scope<Blender> m_Blender;
|
|
||||||
|
|
||||||
Camera* m_DefaultFramebufferCamera;
|
|
||||||
Ref<Framebuffer> m_TargetFramebuffer;
|
|
||||||
|
|
||||||
bool m_ShouldClearBackbuffer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static Scope<Renderer> Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint, Ref<Texture> texture) { s_Context->DrawQuadImpl(position, size, tint, texture); }
|
|
||||||
static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint) { s_Context->DrawQuadImpl(position, size, tint); }
|
|
||||||
static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, Ref<Texture> texture) { s_Context->DrawQuadImpl(position, size, texture); }
|
|
||||||
|
|
||||||
static void DrawQuad(const glm::mat4& transform, const glm::vec4& tint, Ref<Texture> texture) { s_Context->DrawQuadImpl(transform, tint, texture); }
|
|
||||||
static void DrawQuad(const glm::mat4& transform, const glm::vec4& tint) { s_Context->DrawQuadImpl(transform, tint); }
|
|
||||||
static void DrawQuad(const glm::mat4& transform, Ref<Texture> texture) { s_Context->DrawQuadImpl(transform, texture); }
|
|
||||||
|
|
||||||
static inline void BeginScene(Camera* camera, const glm::mat4& cameraTransform, const Ref<Framebuffer>& targetFrameBuffer = nullptr) { s_Context->BeginSceneImpl(camera, cameraTransform, targetFrameBuffer); }
|
|
||||||
static inline void EndScene() { s_Context->EndSceneImpl(); }
|
|
||||||
|
|
||||||
void OnWindowResize(const WindowResizedEvent& event);
|
|
||||||
|
|
||||||
void BeginFrame();
|
|
||||||
void EndFrame();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Renderer(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint, Ref<Texture> texture);
|
|
||||||
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint);
|
|
||||||
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, Ref<Texture> texture);
|
|
||||||
|
|
||||||
void DrawQuadImpl(const glm::mat4& transform, const glm::vec4& tint, Ref<Texture> texture);
|
|
||||||
void DrawQuadImpl(const glm::mat4& transform, const glm::vec4& tint);
|
|
||||||
void DrawQuadImpl(const glm::mat4& transform, Ref<Texture> texture);
|
|
||||||
|
|
||||||
void BeginSceneImpl(Camera* camera, const glm::mat4& cameraTransform, const Ref<Framebuffer>& targetFrameBuffer = nullptr);
|
|
||||||
void FlushScene();
|
|
||||||
void EndSceneImpl();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
84
Engine/src/Engine/Graphics/Renderer.hpp
Normal file
84
Engine/src/Engine/Graphics/Renderer.hpp
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "RendererPrograms/QuadRendererProgram.hpp"
|
||||||
|
#include "RendererPrograms/TextureRendererProgram.hpp"
|
||||||
|
#include "RendererPrograms/TintedTextureRendererProgram.hpp"
|
||||||
|
|
||||||
|
#define LT_MAX_QUAD_RENDERER_VERTICES 1028u * 4u
|
||||||
|
#define LT_MAX_TEXTURE_RENDERER_VERTICES 1028u * 4u
|
||||||
|
#define LT_MAX_TINTED_TEXTURE_RENDERER_VERTICES 1028u * 4u
|
||||||
|
|
||||||
|
struct GLFWwindow;
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Blender;
|
||||||
|
class ConstantBuffer;
|
||||||
|
class Framebuffer;
|
||||||
|
class RenderCommand;
|
||||||
|
class Texture;
|
||||||
|
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
class Camera;
|
||||||
|
|
||||||
|
class WindowResizedEvent;
|
||||||
|
|
||||||
|
class Renderer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static Renderer* s_Context;
|
||||||
|
|
||||||
|
// renderer programs
|
||||||
|
QuadRendererProgram m_QuadRenderer;
|
||||||
|
TextureRendererProgram m_TextureRenderer;
|
||||||
|
TintedTextureRendererProgram m_TintedTextureRenderer;
|
||||||
|
|
||||||
|
// constant buffers
|
||||||
|
Scope<ConstantBuffer> m_ViewProjectionBuffer;
|
||||||
|
|
||||||
|
Scope<RenderCommand> m_RenderCommand;
|
||||||
|
Scope<Blender> m_Blender;
|
||||||
|
|
||||||
|
Camera* m_DefaultFramebufferCamera;
|
||||||
|
Ref<Framebuffer> m_TargetFramebuffer;
|
||||||
|
|
||||||
|
bool m_ShouldClearBackbuffer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Scope<Renderer> Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint, Ref<Texture> texture) { s_Context->DrawQuadImpl(position, size, tint, texture); }
|
||||||
|
static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint) { s_Context->DrawQuadImpl(position, size, tint); }
|
||||||
|
static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, Ref<Texture> texture) { s_Context->DrawQuadImpl(position, size, texture); }
|
||||||
|
|
||||||
|
static void DrawQuad(const glm::mat4& transform, const glm::vec4& tint, Ref<Texture> texture) { s_Context->DrawQuadImpl(transform, tint, texture); }
|
||||||
|
static void DrawQuad(const glm::mat4& transform, const glm::vec4& tint) { s_Context->DrawQuadImpl(transform, tint); }
|
||||||
|
static void DrawQuad(const glm::mat4& transform, Ref<Texture> texture) { s_Context->DrawQuadImpl(transform, texture); }
|
||||||
|
|
||||||
|
static inline void BeginScene(Camera* camera, const glm::mat4& cameraTransform, const Ref<Framebuffer>& targetFrameBuffer = nullptr) { s_Context->BeginSceneImpl(camera, cameraTransform, targetFrameBuffer); }
|
||||||
|
static inline void EndScene() { s_Context->EndSceneImpl(); }
|
||||||
|
|
||||||
|
void OnWindowResize(const WindowResizedEvent& event);
|
||||||
|
|
||||||
|
void BeginFrame();
|
||||||
|
void EndFrame();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Renderer(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint, Ref<Texture> texture);
|
||||||
|
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint);
|
||||||
|
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, Ref<Texture> texture);
|
||||||
|
|
||||||
|
void DrawQuadImpl(const glm::mat4& transform, const glm::vec4& tint, Ref<Texture> texture);
|
||||||
|
void DrawQuadImpl(const glm::mat4& transform, const glm::vec4& tint);
|
||||||
|
void DrawQuadImpl(const glm::mat4& transform, Ref<Texture> texture);
|
||||||
|
|
||||||
|
void BeginSceneImpl(Camera* camera, const glm::mat4& cameraTransform, const Ref<Framebuffer>& targetFrameBuffer = nullptr);
|
||||||
|
void FlushScene();
|
||||||
|
void EndSceneImpl();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,10 +1,10 @@
|
||||||
#include "QuadRendererProgram.h"
|
#include "QuadRendererProgram.hpp"
|
||||||
|
|
||||||
#include "Camera/Camera.h"
|
#include "Camera/Camera.hpp"
|
||||||
#include "Graphics/Buffers.h"
|
#include "Graphics/Buffers.hpp"
|
||||||
#include "Graphics/Shader.h"
|
#include "Graphics/Shader.hpp"
|
||||||
#include "Graphics/VertexLayout.h"
|
#include "Graphics/VertexLayout.hpp"
|
||||||
#include "Utility/ResourceManager.h"
|
#include "Utility/ResourceManager.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "RendererProgram.h"
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Shader;
|
|
||||||
class VertexBuffer;
|
|
||||||
class IndexBuffer;
|
|
||||||
class VertexLayout;
|
|
||||||
|
|
||||||
class OrthographicCamera;
|
|
||||||
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
class QuadRendererProgram : RendererProgram
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct QuadVertexData
|
|
||||||
{
|
|
||||||
glm::vec4 position;
|
|
||||||
glm::vec4 tint;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ref<Shader> m_Shader;
|
|
||||||
Ref<VertexBuffer> m_VertexBuffer;
|
|
||||||
Ref<IndexBuffer> m_IndexBuffer;
|
|
||||||
Ref<VertexLayout> m_VertexLayout;
|
|
||||||
|
|
||||||
QuadVertexData* m_MapCurrent = nullptr;
|
|
||||||
QuadVertexData* m_MapEnd = nullptr;
|
|
||||||
|
|
||||||
unsigned int m_QuadCount = 0u;
|
|
||||||
unsigned int m_MaxVertices = 0u;
|
|
||||||
|
|
||||||
public:
|
|
||||||
QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
bool Advance();
|
|
||||||
|
|
||||||
void Map() override;
|
|
||||||
void UnMap() override;
|
|
||||||
|
|
||||||
void Bind() override;
|
|
||||||
|
|
||||||
inline QuadVertexData* GetMapCurrent() { return m_MapCurrent; }
|
|
||||||
inline unsigned int GetQuadCount() const { return m_QuadCount; }
|
|
||||||
inline constexpr unsigned int GetVertexSize() const { return sizeof(QuadVertexData); }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "RendererProgram.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Shader;
|
||||||
|
class VertexBuffer;
|
||||||
|
class IndexBuffer;
|
||||||
|
class VertexLayout;
|
||||||
|
|
||||||
|
class OrthographicCamera;
|
||||||
|
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
class QuadRendererProgram: RendererProgram
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct QuadVertexData
|
||||||
|
{
|
||||||
|
glm::vec4 position;
|
||||||
|
glm::vec4 tint;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ref<Shader> m_Shader;
|
||||||
|
Ref<VertexBuffer> m_VertexBuffer;
|
||||||
|
Ref<IndexBuffer> m_IndexBuffer;
|
||||||
|
Ref<VertexLayout> m_VertexLayout;
|
||||||
|
|
||||||
|
QuadVertexData* m_MapCurrent = nullptr;
|
||||||
|
QuadVertexData* m_MapEnd = nullptr;
|
||||||
|
|
||||||
|
unsigned int m_QuadCount = 0u;
|
||||||
|
unsigned int m_MaxVertices = 0u;
|
||||||
|
|
||||||
|
public:
|
||||||
|
QuadRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
bool Advance();
|
||||||
|
|
||||||
|
void Map() override;
|
||||||
|
void UnMap() override;
|
||||||
|
|
||||||
|
void Bind() override;
|
||||||
|
|
||||||
|
inline QuadVertexData* GetMapCurrent() { return m_MapCurrent; }
|
||||||
|
inline unsigned int GetQuadCount() const { return m_QuadCount; }
|
||||||
|
inline constexpr unsigned int GetVertexSize() const { return sizeof(QuadVertexData); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,17 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class OrthographicCamera;
|
|
||||||
|
|
||||||
class RendererProgram
|
|
||||||
{
|
|
||||||
virtual void Map() = 0;
|
|
||||||
virtual void UnMap() = 0;
|
|
||||||
|
|
||||||
virtual void Bind() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class OrthographicCamera;
|
||||||
|
|
||||||
|
class RendererProgram
|
||||||
|
{
|
||||||
|
virtual void Map() = 0;
|
||||||
|
virtual void UnMap() = 0;
|
||||||
|
|
||||||
|
virtual void Bind() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,10 +1,10 @@
|
||||||
#include "TextureRendererProgram.h"
|
#include "TextureRendererProgram.hpp"
|
||||||
|
|
||||||
#include "Camera/Camera.h"
|
#include "Camera/Camera.hpp"
|
||||||
#include "Graphics/Buffers.h"
|
#include "Graphics/Buffers.hpp"
|
||||||
#include "Graphics/Shader.h"
|
#include "Graphics/Shader.hpp"
|
||||||
#include "Graphics/VertexLayout.h"
|
#include "Graphics/VertexLayout.hpp"
|
||||||
#include "Utility/ResourceManager.h"
|
#include "Utility/ResourceManager.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "RendererProgram.h"
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Shader;
|
|
||||||
class VertexBuffer;
|
|
||||||
class IndexBuffer;
|
|
||||||
class VertexLayout;
|
|
||||||
|
|
||||||
class OrthographicCamera;
|
|
||||||
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
class TextureRendererProgram : RendererProgram
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct TextureVertexData
|
|
||||||
{
|
|
||||||
glm::vec4 position;
|
|
||||||
glm::vec2 texcoord;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ref<Shader> m_Shader;
|
|
||||||
Ref<VertexBuffer> m_VertexBuffer;
|
|
||||||
Ref<IndexBuffer> m_IndexBuffer;
|
|
||||||
Ref<VertexLayout> m_VertexLayout;
|
|
||||||
|
|
||||||
TextureVertexData* m_MapCurrent = nullptr;
|
|
||||||
TextureVertexData* m_MapEnd = nullptr;
|
|
||||||
|
|
||||||
unsigned int m_QuadCount;
|
|
||||||
unsigned int m_MaxVertices;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
bool Advance();
|
|
||||||
|
|
||||||
void Map() override;
|
|
||||||
void UnMap() override;
|
|
||||||
|
|
||||||
void Bind() override;
|
|
||||||
|
|
||||||
inline TextureVertexData* GetMapCurrent() { return m_MapCurrent; }
|
|
||||||
|
|
||||||
inline unsigned int GetQuadCount() const { return m_QuadCount; }
|
|
||||||
|
|
||||||
inline constexpr unsigned int GetVertexSize() const { return sizeof(TextureVertexData); }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "RendererProgram.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Shader;
|
||||||
|
class VertexBuffer;
|
||||||
|
class IndexBuffer;
|
||||||
|
class VertexLayout;
|
||||||
|
|
||||||
|
class OrthographicCamera;
|
||||||
|
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
class TextureRendererProgram: RendererProgram
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TextureVertexData
|
||||||
|
{
|
||||||
|
glm::vec4 position;
|
||||||
|
glm::vec2 texcoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ref<Shader> m_Shader;
|
||||||
|
Ref<VertexBuffer> m_VertexBuffer;
|
||||||
|
Ref<IndexBuffer> m_IndexBuffer;
|
||||||
|
Ref<VertexLayout> m_VertexLayout;
|
||||||
|
|
||||||
|
TextureVertexData* m_MapCurrent = nullptr;
|
||||||
|
TextureVertexData* m_MapEnd = nullptr;
|
||||||
|
|
||||||
|
unsigned int m_QuadCount;
|
||||||
|
unsigned int m_MaxVertices;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
bool Advance();
|
||||||
|
|
||||||
|
void Map() override;
|
||||||
|
void UnMap() override;
|
||||||
|
|
||||||
|
void Bind() override;
|
||||||
|
|
||||||
|
inline TextureVertexData* GetMapCurrent() { return m_MapCurrent; }
|
||||||
|
|
||||||
|
inline unsigned int GetQuadCount() const { return m_QuadCount; }
|
||||||
|
|
||||||
|
inline constexpr unsigned int GetVertexSize() const { return sizeof(TextureVertexData); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,10 +1,10 @@
|
||||||
#include "TintedTextureRendererProgram.h"
|
#include "TintedTextureRendererProgram.hpp"
|
||||||
|
|
||||||
#include "Camera/Camera.h"
|
#include "Camera/Camera.hpp"
|
||||||
#include "Graphics/Buffers.h"
|
#include "Graphics/Buffers.hpp"
|
||||||
#include "Graphics/Shader.h"
|
#include "Graphics/Shader.hpp"
|
||||||
#include "Graphics/VertexLayout.h"
|
#include "Graphics/VertexLayout.hpp"
|
||||||
#include "Utility/ResourceManager.h"
|
#include "Utility/ResourceManager.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "RendererProgram.h"
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Shader;
|
|
||||||
class VertexBuffer;
|
|
||||||
class IndexBuffer;
|
|
||||||
class VertexLayout;
|
|
||||||
|
|
||||||
class OrthographicCamera;
|
|
||||||
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
class TintedTextureRendererProgram : RendererProgram
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct TintedTextureVertexData
|
|
||||||
{
|
|
||||||
glm::vec4 position;
|
|
||||||
glm::vec4 tint;
|
|
||||||
glm::vec2 texcoord;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ref<Shader> m_Shader;
|
|
||||||
Ref<VertexBuffer> m_VertexBuffer;
|
|
||||||
Ref<IndexBuffer> m_IndexBuffer;
|
|
||||||
Ref<VertexLayout> m_VertexLayout;
|
|
||||||
|
|
||||||
TintedTextureVertexData* m_MapCurrent = nullptr;
|
|
||||||
TintedTextureVertexData* m_MapEnd = nullptr;
|
|
||||||
|
|
||||||
unsigned int m_QuadCount;
|
|
||||||
unsigned int m_MaxVertices;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TintedTextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
bool Advance();
|
|
||||||
|
|
||||||
void Map() override;
|
|
||||||
void UnMap() override;
|
|
||||||
|
|
||||||
void Bind() override;
|
|
||||||
|
|
||||||
inline TintedTextureVertexData* GetMapCurrent() { return m_MapCurrent; }
|
|
||||||
|
|
||||||
inline unsigned int GetQuadCount() const { return m_QuadCount; }
|
|
||||||
|
|
||||||
inline constexpr unsigned int GetVertexSize() const { return sizeof(TintedTextureVertexData); }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "RendererProgram.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Shader;
|
||||||
|
class VertexBuffer;
|
||||||
|
class IndexBuffer;
|
||||||
|
class VertexLayout;
|
||||||
|
|
||||||
|
class OrthographicCamera;
|
||||||
|
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
class TintedTextureRendererProgram: RendererProgram
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TintedTextureVertexData
|
||||||
|
{
|
||||||
|
glm::vec4 position;
|
||||||
|
glm::vec4 tint;
|
||||||
|
glm::vec2 texcoord;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ref<Shader> m_Shader;
|
||||||
|
Ref<VertexBuffer> m_VertexBuffer;
|
||||||
|
Ref<IndexBuffer> m_IndexBuffer;
|
||||||
|
Ref<VertexLayout> m_VertexLayout;
|
||||||
|
|
||||||
|
TintedTextureVertexData* m_MapCurrent = nullptr;
|
||||||
|
TintedTextureVertexData* m_MapEnd = nullptr;
|
||||||
|
|
||||||
|
unsigned int m_QuadCount;
|
||||||
|
unsigned int m_MaxVertices;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TintedTextureRendererProgram(unsigned int maxVertices, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
bool Advance();
|
||||||
|
|
||||||
|
void Map() override;
|
||||||
|
void UnMap() override;
|
||||||
|
|
||||||
|
void Bind() override;
|
||||||
|
|
||||||
|
inline TintedTextureVertexData* GetMapCurrent() { return m_MapCurrent; }
|
||||||
|
|
||||||
|
inline unsigned int GetQuadCount() const { return m_QuadCount; }
|
||||||
|
|
||||||
|
inline constexpr unsigned int GetVertexSize() const { return sizeof(TintedTextureVertexData); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,13 +1,13 @@
|
||||||
#include "Shader.h"
|
#include "Shader.hpp"
|
||||||
|
|
||||||
#include "OpenGL/glShader.h"
|
#include "OpenGL/glShader.hpp"
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||||
#include "DirectX/dxShader.h"
|
#include "DirectX/dxShader.hpp"
|
||||||
#include "DirectX/dxSharedContext.h"
|
#include "DirectX/dxSharedContext.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "GraphicsContext.h"
|
#include "GraphicsContext.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include "Utility/FileManager.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
class Shader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum Stage
|
|
||||||
{
|
|
||||||
NONE = 0,
|
|
||||||
VERTEX = 1,
|
|
||||||
PIXEL = 2,
|
|
||||||
GEOMETRY = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
static Ref<Shader> Create(BasicFileHandle vertexFile, BasicFileHandle pixelFile, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
virtual ~Shader() = default;
|
|
||||||
|
|
||||||
virtual void Bind() = 0;
|
|
||||||
virtual void UnBind() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Shader() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
35
Engine/src/Engine/Graphics/Shader.hpp
Normal file
35
Engine/src/Engine/Graphics/Shader.hpp
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "Utility/FileManager.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
class Shader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum Stage
|
||||||
|
{
|
||||||
|
NONE = 0,
|
||||||
|
VERTEX = 1,
|
||||||
|
PIXEL = 2,
|
||||||
|
GEOMETRY = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Ref<Shader> Create(BasicFileHandle vertexFile, BasicFileHandle pixelFile, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
virtual ~Shader() = default;
|
||||||
|
|
||||||
|
virtual void Bind() = 0;
|
||||||
|
virtual void UnBind() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Shader() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,13 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class SharedContext
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~SharedContext() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
13
Engine/src/Engine/Graphics/SharedContext.hpp
Normal file
13
Engine/src/Engine/Graphics/SharedContext.hpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class SharedContext
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~SharedContext() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,13 +1,13 @@
|
||||||
#include "Texture.h"
|
#include "Texture.hpp"
|
||||||
|
|
||||||
#include "OpenGL/glTexture.h"
|
#include "OpenGL/glTexture.hpp"
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||||
#include "DirectX/dxTexture.h"
|
#include "DirectX/dxTexture.hpp"
|
||||||
#include "DirectX/dxSharedContext.h"
|
#include "DirectX/dxSharedContext.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "GraphicsContext.h"
|
#include "GraphicsContext.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Base/Base.h"
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#include "VertexLayout.h"
|
#include "VertexLayout.hpp"
|
||||||
|
|
||||||
#include "OpenGL/glVertexLayout.h"
|
#include "OpenGL/glVertexLayout.hpp"
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
||||||
#include "DirectX/dxVertexLayout.h"
|
#include "DirectX/dxVertexLayout.hpp"
|
||||||
#include "DirectX/dxSharedContext.h"
|
#include "DirectX/dxSharedContext.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "GraphicsContext.h"
|
#include "GraphicsContext.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class VertexBuffer;
|
|
||||||
class Shader;
|
|
||||||
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
enum class VertexElementType
|
|
||||||
{
|
|
||||||
Byte1 , Byte2 , Byte4 ,
|
|
||||||
UByte1 , UByte2 , UByte4 ,
|
|
||||||
Int1 , Int2 , Int3 , Int4 ,
|
|
||||||
UInt1 , UInt2 , UInt3 , UInt4 ,
|
|
||||||
Float1 , Float2 , Float3 , Float4 ,
|
|
||||||
};
|
|
||||||
|
|
||||||
class VertexLayout
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Ref<VertexLayout> Create(Ref<VertexBuffer> vertexBuffer, Ref<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
virtual ~VertexLayout() = default;;
|
|
||||||
|
|
||||||
virtual void Bind() = 0;
|
|
||||||
virtual void UnBind() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
VertexLayout() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
49
Engine/src/Engine/Graphics/VertexLayout.hpp
Normal file
49
Engine/src/Engine/Graphics/VertexLayout.hpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class VertexBuffer;
|
||||||
|
class Shader;
|
||||||
|
|
||||||
|
class SharedContext;
|
||||||
|
|
||||||
|
enum class VertexElementType
|
||||||
|
{
|
||||||
|
Byte1,
|
||||||
|
Byte2,
|
||||||
|
Byte4,
|
||||||
|
UByte1,
|
||||||
|
UByte2,
|
||||||
|
UByte4,
|
||||||
|
Int1,
|
||||||
|
Int2,
|
||||||
|
Int3,
|
||||||
|
Int4,
|
||||||
|
UInt1,
|
||||||
|
UInt2,
|
||||||
|
UInt3,
|
||||||
|
UInt4,
|
||||||
|
Float1,
|
||||||
|
Float2,
|
||||||
|
Float3,
|
||||||
|
Float4,
|
||||||
|
};
|
||||||
|
|
||||||
|
class VertexLayout
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Ref<VertexLayout> Create(Ref<VertexBuffer> vertexBuffer, Ref<Shader> shader, const std::vector<std::pair<std::string, VertexElementType>>& elements, Ref<SharedContext> sharedContext);
|
||||||
|
|
||||||
|
virtual ~VertexLayout() = default;
|
||||||
|
;
|
||||||
|
|
||||||
|
virtual void Bind() = 0;
|
||||||
|
virtual void UnBind() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
VertexLayout() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,11 +1,11 @@
|
||||||
#include "Input.h"
|
#include "Input.hpp"
|
||||||
|
|
||||||
#include "Events/CharEvent.h"
|
#include "Events/CharEvent.hpp"
|
||||||
#include "Events/Event.h"
|
#include "Events/Event.hpp"
|
||||||
#include "Events/KeyboardEvents.h"
|
#include "Events/KeyboardEvents.hpp"
|
||||||
#include "Events/MouseEvents.h"
|
#include "Events/MouseEvents.hpp"
|
||||||
#include "Input/KeyCodes.h"
|
#include "Input/KeyCodes.hpp"
|
||||||
#include "ltpch.h"
|
#include "ltpch.hpp"
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Event;
|
|
||||||
|
|
||||||
class Input /* singleton */
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
static Input* s_Context;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::array<bool, 348> m_KeyboadKeys;
|
|
||||||
std::array<bool, 8> m_MouseButtons;
|
|
||||||
|
|
||||||
glm::vec2 m_MousePosition;
|
|
||||||
glm::vec2 m_MouseDelta;
|
|
||||||
float m_MouseWheelDelta;
|
|
||||||
|
|
||||||
bool m_UserInterfaceEvents;
|
|
||||||
bool m_GameEvents;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static Scope<Input> Create();
|
|
||||||
|
|
||||||
static inline void ReceiveUserInterfaceEvents(bool receive, bool toggle = false) { s_Context->ReceiveUserInterfaceEventsImpl(receive, toggle); }
|
|
||||||
static inline void ReceiveGameEvents(bool receive, bool toggle = false) { s_Context->ReceieveGameEventsImpl(receive, toggle); }
|
|
||||||
|
|
||||||
static inline bool GetKeyboardKey(int code) { return s_Context->m_KeyboadKeys[code]; }
|
|
||||||
static inline bool GetMouseButton(int code) { return s_Context->m_MouseButtons[code]; }
|
|
||||||
|
|
||||||
static inline const glm::vec2& GetMousePosition(int code) { return s_Context->m_MousePosition; }
|
|
||||||
|
|
||||||
void OnEvent(const Event& inputEvent);
|
|
||||||
|
|
||||||
inline bool IsReceivingInputEvents() const { return m_UserInterfaceEvents; }
|
|
||||||
inline bool IsReceivingGameEvents() const { return m_GameEvents; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Input();
|
|
||||||
|
|
||||||
void ReceiveUserInterfaceEventsImpl(bool receive, bool toggle = false);
|
|
||||||
void ReceieveGameEventsImpl(bool receive, bool toggle = false);
|
|
||||||
|
|
||||||
void RestartInputState();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
53
Engine/src/Engine/Input/Input.hpp
Normal file
53
Engine/src/Engine/Input/Input.hpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Event;
|
||||||
|
|
||||||
|
class Input /* singleton */
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static Input* s_Context;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::array<bool, 348> m_KeyboadKeys;
|
||||||
|
std::array<bool, 8> m_MouseButtons;
|
||||||
|
|
||||||
|
glm::vec2 m_MousePosition;
|
||||||
|
glm::vec2 m_MouseDelta;
|
||||||
|
float m_MouseWheelDelta;
|
||||||
|
|
||||||
|
bool m_UserInterfaceEvents;
|
||||||
|
bool m_GameEvents;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Scope<Input> Create();
|
||||||
|
|
||||||
|
static inline void ReceiveUserInterfaceEvents(bool receive, bool toggle = false) { s_Context->ReceiveUserInterfaceEventsImpl(receive, toggle); }
|
||||||
|
static inline void ReceiveGameEvents(bool receive, bool toggle = false) { s_Context->ReceieveGameEventsImpl(receive, toggle); }
|
||||||
|
|
||||||
|
static inline bool GetKeyboardKey(int code) { return s_Context->m_KeyboadKeys[code]; }
|
||||||
|
static inline bool GetMouseButton(int code) { return s_Context->m_MouseButtons[code]; }
|
||||||
|
|
||||||
|
static inline const glm::vec2& GetMousePosition(int code) { return s_Context->m_MousePosition; }
|
||||||
|
|
||||||
|
void OnEvent(const Event& inputEvent);
|
||||||
|
|
||||||
|
inline bool IsReceivingInputEvents() const { return m_UserInterfaceEvents; }
|
||||||
|
inline bool IsReceivingGameEvents() const { return m_GameEvents; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Input();
|
||||||
|
|
||||||
|
void ReceiveUserInterfaceEventsImpl(bool receive, bool toggle = false);
|
||||||
|
void ReceieveGameEventsImpl(bool receive, bool toggle = false);
|
||||||
|
|
||||||
|
void RestartInputState();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,185 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "ltpch.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
namespace Key
|
|
||||||
{
|
|
||||||
enum : uint16_t
|
|
||||||
{
|
|
||||||
/* digits */
|
|
||||||
D0 = 48,
|
|
||||||
D1 = 49,
|
|
||||||
D2 = 50,
|
|
||||||
D3 = 51,
|
|
||||||
D4 = 52,
|
|
||||||
D5 = 53,
|
|
||||||
D6 = 54,
|
|
||||||
D7 = 55,
|
|
||||||
D8 = 56,
|
|
||||||
D9 = 57,
|
|
||||||
Semicolon = 59, // ;
|
|
||||||
Equal = 61, // =
|
|
||||||
|
|
||||||
/* letters */
|
|
||||||
A = 65,
|
|
||||||
B = 66,
|
|
||||||
C = 67,
|
|
||||||
D = 68,
|
|
||||||
E = 69,
|
|
||||||
F = 70,
|
|
||||||
G = 71,
|
|
||||||
H = 72,
|
|
||||||
I = 73,
|
|
||||||
J = 74,
|
|
||||||
K = 75,
|
|
||||||
L = 76,
|
|
||||||
M = 77,
|
|
||||||
N = 78,
|
|
||||||
O = 79,
|
|
||||||
P = 80,
|
|
||||||
Q = 81,
|
|
||||||
R = 82,
|
|
||||||
S = 83,
|
|
||||||
T = 84,
|
|
||||||
U = 85,
|
|
||||||
V = 86,
|
|
||||||
W = 87,
|
|
||||||
X = 88,
|
|
||||||
Y = 89,
|
|
||||||
Z = 90,
|
|
||||||
|
|
||||||
/* brackets */
|
|
||||||
LeftBracket = 91, // [
|
|
||||||
LBracket = LeftBracket, // [
|
|
||||||
RightBracket = 93, // ]
|
|
||||||
RBracket = RightBracket, // ]
|
|
||||||
|
|
||||||
/* arrow */
|
|
||||||
Right = 262,
|
|
||||||
RightArrow = Right,
|
|
||||||
RArrow = Right,
|
|
||||||
Left = 263,
|
|
||||||
LeftArrow = Left,
|
|
||||||
LArrow = Left,
|
|
||||||
Down = 264,
|
|
||||||
DownArrow = Down,
|
|
||||||
DArrow = Down,
|
|
||||||
Up = 265,
|
|
||||||
UpArrow = Up,
|
|
||||||
UArrow = Up,
|
|
||||||
|
|
||||||
/* page */
|
|
||||||
PageUp = 266,
|
|
||||||
PageDown = 267,
|
|
||||||
|
|
||||||
/* home/end */
|
|
||||||
Home = 268,
|
|
||||||
End = 269,
|
|
||||||
|
|
||||||
/* toggles */
|
|
||||||
CapsLock = 280,
|
|
||||||
ScrollLock = 281,
|
|
||||||
NumLock = 282,
|
|
||||||
NumberLock = NumLock,
|
|
||||||
|
|
||||||
/* function */
|
|
||||||
F1 = 290,
|
|
||||||
F2 = 291,
|
|
||||||
F3 = 292,
|
|
||||||
F4 = 293,
|
|
||||||
F5 = 294,
|
|
||||||
F6 = 295,
|
|
||||||
F7 = 296,
|
|
||||||
F8 = 297,
|
|
||||||
F9 = 298,
|
|
||||||
F10 = 299,
|
|
||||||
F11 = 300,
|
|
||||||
F12 = 301,
|
|
||||||
F13 = 302,
|
|
||||||
F14 = 303,
|
|
||||||
F15 = 304,
|
|
||||||
F16 = 305,
|
|
||||||
F17 = 306,
|
|
||||||
F18 = 307,
|
|
||||||
F19 = 308,
|
|
||||||
F20 = 309,
|
|
||||||
F21 = 310,
|
|
||||||
F22 = 311,
|
|
||||||
F23 = 312,
|
|
||||||
F24 = 313,
|
|
||||||
F25 = 314,
|
|
||||||
|
|
||||||
/* keypad */
|
|
||||||
Kp0 = 320,
|
|
||||||
Kp1 = 321,
|
|
||||||
Kp2 = 322,
|
|
||||||
Kp3 = 323,
|
|
||||||
Kp4 = 324,
|
|
||||||
Kp5 = 325,
|
|
||||||
Kp6 = 326,
|
|
||||||
Kp7 = 327,
|
|
||||||
Kp8 = 328,
|
|
||||||
Kp9 = 329,
|
|
||||||
KpDecimal = 330,
|
|
||||||
KpDivide = 331,
|
|
||||||
KpMultiply = 332,
|
|
||||||
KpSubstract = 333,
|
|
||||||
KpAdd = 334,
|
|
||||||
KpEnter = 335,
|
|
||||||
KpEqual = 336,
|
|
||||||
|
|
||||||
/* modifiers */
|
|
||||||
LeftShift = 340,
|
|
||||||
LShift = LeftShift,
|
|
||||||
LeftControl = 341,
|
|
||||||
LControl = LeftControl,
|
|
||||||
LeftAlt = 342,
|
|
||||||
LAlt = LeftAlt,
|
|
||||||
LeftSuper = 343,
|
|
||||||
LSuper = LeftSuper,
|
|
||||||
RightShift = 344,
|
|
||||||
RShift = 344,
|
|
||||||
RightControl = 345,
|
|
||||||
RControl = 345,
|
|
||||||
RightAlt = 346,
|
|
||||||
RAlt = 346,
|
|
||||||
RightSuper = 347,
|
|
||||||
RSuper = 347,
|
|
||||||
|
|
||||||
/* misc */
|
|
||||||
Space = 32,
|
|
||||||
Apostrophe = 39, // '
|
|
||||||
Quote = Apostrophe,
|
|
||||||
|
|
||||||
Comma = 44, // ,
|
|
||||||
Minus = 45, // -
|
|
||||||
Period = 46, // .
|
|
||||||
Slash = 47, // /
|
|
||||||
ForwardSlash = Slash, // /
|
|
||||||
BackSlash = 92, // \
|
|
||||||
|
|
||||||
GraveAccent = 96, // `
|
|
||||||
Console = GraveAccent,
|
|
||||||
World1 = 161, // non-US #1
|
|
||||||
World2 = 162, // non-US #2
|
|
||||||
Escape = 256,
|
|
||||||
Esc = Escape,
|
|
||||||
Enter = 257,
|
|
||||||
Tab = 258,
|
|
||||||
BackSpace = 259,
|
|
||||||
Insert = 260,
|
|
||||||
Delete = 261,
|
|
||||||
|
|
||||||
PrintScreen = 283,
|
|
||||||
Pause = 284,
|
|
||||||
|
|
||||||
Menu = 348,
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
184
Engine/src/Engine/Input/KeyCodes.hpp
Normal file
184
Engine/src/Engine/Input/KeyCodes.hpp
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ltpch.hpp"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
namespace Key {
|
||||||
|
enum : uint16_t
|
||||||
|
{
|
||||||
|
/* digits */
|
||||||
|
D0 = 48,
|
||||||
|
D1 = 49,
|
||||||
|
D2 = 50,
|
||||||
|
D3 = 51,
|
||||||
|
D4 = 52,
|
||||||
|
D5 = 53,
|
||||||
|
D6 = 54,
|
||||||
|
D7 = 55,
|
||||||
|
D8 = 56,
|
||||||
|
D9 = 57,
|
||||||
|
Semicolon = 59, // ;
|
||||||
|
Equal = 61, // =
|
||||||
|
|
||||||
|
/* letters */
|
||||||
|
A = 65,
|
||||||
|
B = 66,
|
||||||
|
C = 67,
|
||||||
|
D = 68,
|
||||||
|
E = 69,
|
||||||
|
F = 70,
|
||||||
|
G = 71,
|
||||||
|
H = 72,
|
||||||
|
I = 73,
|
||||||
|
J = 74,
|
||||||
|
K = 75,
|
||||||
|
L = 76,
|
||||||
|
M = 77,
|
||||||
|
N = 78,
|
||||||
|
O = 79,
|
||||||
|
P = 80,
|
||||||
|
Q = 81,
|
||||||
|
R = 82,
|
||||||
|
S = 83,
|
||||||
|
T = 84,
|
||||||
|
U = 85,
|
||||||
|
V = 86,
|
||||||
|
W = 87,
|
||||||
|
X = 88,
|
||||||
|
Y = 89,
|
||||||
|
Z = 90,
|
||||||
|
|
||||||
|
/* brackets */
|
||||||
|
LeftBracket = 91, // [
|
||||||
|
LBracket = LeftBracket, // [
|
||||||
|
RightBracket = 93, // ]
|
||||||
|
RBracket = RightBracket, // ]
|
||||||
|
|
||||||
|
/* arrow */
|
||||||
|
Right = 262,
|
||||||
|
RightArrow = Right,
|
||||||
|
RArrow = Right,
|
||||||
|
Left = 263,
|
||||||
|
LeftArrow = Left,
|
||||||
|
LArrow = Left,
|
||||||
|
Down = 264,
|
||||||
|
DownArrow = Down,
|
||||||
|
DArrow = Down,
|
||||||
|
Up = 265,
|
||||||
|
UpArrow = Up,
|
||||||
|
UArrow = Up,
|
||||||
|
|
||||||
|
/* page */
|
||||||
|
PageUp = 266,
|
||||||
|
PageDown = 267,
|
||||||
|
|
||||||
|
/* home/end */
|
||||||
|
Home = 268,
|
||||||
|
End = 269,
|
||||||
|
|
||||||
|
/* toggles */
|
||||||
|
CapsLock = 280,
|
||||||
|
ScrollLock = 281,
|
||||||
|
NumLock = 282,
|
||||||
|
NumberLock = NumLock,
|
||||||
|
|
||||||
|
/* function */
|
||||||
|
F1 = 290,
|
||||||
|
F2 = 291,
|
||||||
|
F3 = 292,
|
||||||
|
F4 = 293,
|
||||||
|
F5 = 294,
|
||||||
|
F6 = 295,
|
||||||
|
F7 = 296,
|
||||||
|
F8 = 297,
|
||||||
|
F9 = 298,
|
||||||
|
F10 = 299,
|
||||||
|
F11 = 300,
|
||||||
|
F12 = 301,
|
||||||
|
F13 = 302,
|
||||||
|
F14 = 303,
|
||||||
|
F15 = 304,
|
||||||
|
F16 = 305,
|
||||||
|
F17 = 306,
|
||||||
|
F18 = 307,
|
||||||
|
F19 = 308,
|
||||||
|
F20 = 309,
|
||||||
|
F21 = 310,
|
||||||
|
F22 = 311,
|
||||||
|
F23 = 312,
|
||||||
|
F24 = 313,
|
||||||
|
F25 = 314,
|
||||||
|
|
||||||
|
/* keypad */
|
||||||
|
Kp0 = 320,
|
||||||
|
Kp1 = 321,
|
||||||
|
Kp2 = 322,
|
||||||
|
Kp3 = 323,
|
||||||
|
Kp4 = 324,
|
||||||
|
Kp5 = 325,
|
||||||
|
Kp6 = 326,
|
||||||
|
Kp7 = 327,
|
||||||
|
Kp8 = 328,
|
||||||
|
Kp9 = 329,
|
||||||
|
KpDecimal = 330,
|
||||||
|
KpDivide = 331,
|
||||||
|
KpMultiply = 332,
|
||||||
|
KpSubstract = 333,
|
||||||
|
KpAdd = 334,
|
||||||
|
KpEnter = 335,
|
||||||
|
KpEqual = 336,
|
||||||
|
|
||||||
|
/* modifiers */
|
||||||
|
LeftShift = 340,
|
||||||
|
LShift = LeftShift,
|
||||||
|
LeftControl = 341,
|
||||||
|
LControl = LeftControl,
|
||||||
|
LeftAlt = 342,
|
||||||
|
LAlt = LeftAlt,
|
||||||
|
LeftSuper = 343,
|
||||||
|
LSuper = LeftSuper,
|
||||||
|
RightShift = 344,
|
||||||
|
RShift = 344,
|
||||||
|
RightControl = 345,
|
||||||
|
RControl = 345,
|
||||||
|
RightAlt = 346,
|
||||||
|
RAlt = 346,
|
||||||
|
RightSuper = 347,
|
||||||
|
RSuper = 347,
|
||||||
|
|
||||||
|
/* misc */
|
||||||
|
Space = 32,
|
||||||
|
Apostrophe = 39, // '
|
||||||
|
Quote = Apostrophe,
|
||||||
|
|
||||||
|
Comma = 44, // ,
|
||||||
|
Minus = 45, // -
|
||||||
|
Period = 46, // .
|
||||||
|
Slash = 47, // /
|
||||||
|
ForwardSlash = Slash, // /
|
||||||
|
BackSlash = 92, // \
|
||||||
|
|
||||||
|
GraveAccent = 96, // `
|
||||||
|
Console = GraveAccent,
|
||||||
|
World1 = 161, // non-US #1
|
||||||
|
World2 = 162, // non-US #2
|
||||||
|
Escape = 256,
|
||||||
|
Esc = Escape,
|
||||||
|
Enter = 257,
|
||||||
|
Tab = 258,
|
||||||
|
BackSpace = 259,
|
||||||
|
Insert = 260,
|
||||||
|
Delete = 261,
|
||||||
|
|
||||||
|
PrintScreen = 283,
|
||||||
|
Pause = 284,
|
||||||
|
|
||||||
|
Menu = 348,
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,28 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "ltpch.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
namespace Mouse
|
|
||||||
{
|
|
||||||
enum : uint8_t
|
|
||||||
{
|
|
||||||
Button1 = 0,
|
|
||||||
Button2 = 1,
|
|
||||||
Button3 = 2,
|
|
||||||
Button4 = 3,
|
|
||||||
Button5 = 4,
|
|
||||||
Button6 = 5,
|
|
||||||
Button7 = 6,
|
|
||||||
Button8 = 7,
|
|
||||||
|
|
||||||
LButton = Button1,
|
|
||||||
RButton = Button2,
|
|
||||||
MButton = Button3,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
27
Engine/src/Engine/Input/MouseCodes.hpp
Normal file
27
Engine/src/Engine/Input/MouseCodes.hpp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ltpch.hpp"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
namespace Mouse {
|
||||||
|
enum : uint8_t
|
||||||
|
{
|
||||||
|
Button1 = 0,
|
||||||
|
Button2 = 1,
|
||||||
|
Button3 = 2,
|
||||||
|
Button4 = 3,
|
||||||
|
Button5 = 4,
|
||||||
|
Button6 = 5,
|
||||||
|
Button7 = 6,
|
||||||
|
Button8 = 7,
|
||||||
|
|
||||||
|
LButton = Button1,
|
||||||
|
RButton = Button2,
|
||||||
|
MButton = Button3,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,62 +1,62 @@
|
||||||
#include "Layer.h"
|
#include "Layer.hpp"
|
||||||
|
|
||||||
#include "Events/Event.h"
|
#include "Events/CharEvent.hpp"
|
||||||
#include "Events/CharEvent.h"
|
#include "Events/Event.hpp"
|
||||||
#include "Events/KeyboardEvents.h"
|
#include "Events/KeyboardEvents.hpp"
|
||||||
#include "Events/MouseEvents.h"
|
#include "Events/MouseEvents.hpp"
|
||||||
#include "Events/WindowEvents.h"
|
#include "Events/WindowEvents.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
Layer::Layer(const std::string& name)
|
Layer::Layer(const std::string& name)
|
||||||
: m_LayerName(name)
|
: m_LayerName(name)
|
||||||
{
|
{
|
||||||
}
|
|
||||||
|
|
||||||
bool Layer::OnEvent(const Event& event)
|
|
||||||
{
|
|
||||||
switch (event.GetEventType())
|
|
||||||
{
|
|
||||||
/* mouse */
|
|
||||||
// cursor
|
|
||||||
case EventType::MouseMoved:
|
|
||||||
return OnMouseMoved((MouseMovedEvent&)event);
|
|
||||||
// button
|
|
||||||
case EventType::ButtonPressed:
|
|
||||||
return OnButtonPressed((ButtonPressedEvent&)event);
|
|
||||||
case EventType::ButtonReleased:
|
|
||||||
return OnButtonReleased((ButtonReleasedEvent&)event);
|
|
||||||
// wheel
|
|
||||||
case EventType::WheelScrolled:
|
|
||||||
return OnWheelScrolled((WheelScrolledEvent&)event);
|
|
||||||
|
|
||||||
/* keyboard */
|
|
||||||
// key
|
|
||||||
case EventType::KeyPressed:
|
|
||||||
return OnKeyPressed((KeyPressedEvent&)event);
|
|
||||||
case EventType::KeyRepeated:
|
|
||||||
return OnKeyRepeat((KeyRepeatEvent&)event);
|
|
||||||
case EventType::KeyReleased:
|
|
||||||
return OnKeyReleased((KeyReleasedEvent&)event);
|
|
||||||
// char
|
|
||||||
case EventType::SetChar:
|
|
||||||
return OnSetChar((SetCharEvent&)event);
|
|
||||||
|
|
||||||
/* window */
|
|
||||||
// termination
|
|
||||||
case EventType::WindowClosed:
|
|
||||||
return OnWindowClosed((WindowClosedEvent&)event);
|
|
||||||
// size/position
|
|
||||||
case EventType::WindowResized:
|
|
||||||
return OnWindowResized((WindowResizedEvent&)event);
|
|
||||||
case EventType::WindowMoved:
|
|
||||||
return OnWindowMoved((WindowMovedEvent&)event);
|
|
||||||
// focus
|
|
||||||
case EventType::WindowLostFocus:
|
|
||||||
return OnWindowLostFocus((WindowLostFocusEvent&)event);
|
|
||||||
case EventType::WindowGainFocus:
|
|
||||||
return OnWindowGainFocus((WindowGainFocusEvent&)event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Layer::OnEvent(const Event& event)
|
||||||
|
{
|
||||||
|
switch (event.GetEventType())
|
||||||
|
{
|
||||||
|
/* mouse */
|
||||||
|
// cursor
|
||||||
|
case EventType::MouseMoved:
|
||||||
|
return OnMouseMoved((MouseMovedEvent&)event);
|
||||||
|
// button
|
||||||
|
case EventType::ButtonPressed:
|
||||||
|
return OnButtonPressed((ButtonPressedEvent&)event);
|
||||||
|
case EventType::ButtonReleased:
|
||||||
|
return OnButtonReleased((ButtonReleasedEvent&)event);
|
||||||
|
// wheel
|
||||||
|
case EventType::WheelScrolled:
|
||||||
|
return OnWheelScrolled((WheelScrolledEvent&)event);
|
||||||
|
|
||||||
|
/* keyboard */
|
||||||
|
// key
|
||||||
|
case EventType::KeyPressed:
|
||||||
|
return OnKeyPressed((KeyPressedEvent&)event);
|
||||||
|
case EventType::KeyRepeated:
|
||||||
|
return OnKeyRepeat((KeyRepeatEvent&)event);
|
||||||
|
case EventType::KeyReleased:
|
||||||
|
return OnKeyReleased((KeyReleasedEvent&)event);
|
||||||
|
// char
|
||||||
|
case EventType::SetChar:
|
||||||
|
return OnSetChar((SetCharEvent&)event);
|
||||||
|
|
||||||
|
/* window */
|
||||||
|
// termination
|
||||||
|
case EventType::WindowClosed:
|
||||||
|
return OnWindowClosed((WindowClosedEvent&)event);
|
||||||
|
// size/position
|
||||||
|
case EventType::WindowResized:
|
||||||
|
return OnWindowResized((WindowResizedEvent&)event);
|
||||||
|
case EventType::WindowMoved:
|
||||||
|
return OnWindowMoved((WindowMovedEvent&)event);
|
||||||
|
// focus
|
||||||
|
case EventType::WindowLostFocus:
|
||||||
|
return OnWindowLostFocus((WindowLostFocusEvent&)event);
|
||||||
|
case EventType::WindowGainFocus:
|
||||||
|
return OnWindowGainFocus((WindowGainFocusEvent&)event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,78 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Event;
|
|
||||||
|
|
||||||
// mouse
|
|
||||||
class MouseMovedEvent;
|
|
||||||
class ButtonPressedEvent;
|
|
||||||
class ButtonReleasedEvent;
|
|
||||||
class WheelScrolledEvent;
|
|
||||||
|
|
||||||
// keyboard
|
|
||||||
// key
|
|
||||||
class KeyPressedEvent;
|
|
||||||
class KeyRepeatEvent;
|
|
||||||
class KeyReleasedEvent;
|
|
||||||
// char
|
|
||||||
class SetCharEvent;
|
|
||||||
|
|
||||||
// window
|
|
||||||
class WindowClosedEvent;
|
|
||||||
class WindowResizedEvent;
|
|
||||||
class WindowMovedEvent;
|
|
||||||
class WindowLostFocusEvent;
|
|
||||||
class WindowGainFocusEvent;
|
|
||||||
|
|
||||||
class Layer
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
std::string m_LayerName;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Layer(const std::string& name);
|
|
||||||
virtual ~Layer() = default;
|
|
||||||
|
|
||||||
inline const std::string& GetName() const { return m_LayerName; }
|
|
||||||
|
|
||||||
/* update */
|
|
||||||
virtual void OnUpdate(float deltaTime) {}
|
|
||||||
virtual void OnUserInterfaceUpdate() {}
|
|
||||||
|
|
||||||
virtual void OnRender() {}
|
|
||||||
|
|
||||||
bool OnEvent(const Event& event);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/* mouse */
|
|
||||||
// cursor
|
|
||||||
virtual bool OnMouseMoved(const MouseMovedEvent& event) { return false; }
|
|
||||||
// button
|
|
||||||
virtual bool OnButtonPressed(const ButtonPressedEvent& event) { return false; }
|
|
||||||
virtual bool OnButtonReleased(const ButtonReleasedEvent& event) { return false; }
|
|
||||||
// wheel
|
|
||||||
virtual bool OnWheelScrolled(const WheelScrolledEvent& event) { return false; }
|
|
||||||
|
|
||||||
/* keyboard */
|
|
||||||
// key
|
|
||||||
virtual bool OnKeyPressed(const KeyPressedEvent& event) { return false; }
|
|
||||||
virtual bool OnKeyRepeat(const KeyRepeatEvent& event) { return false; }
|
|
||||||
virtual bool OnKeyReleased(const KeyReleasedEvent& event) { return false; }
|
|
||||||
// char
|
|
||||||
virtual bool OnSetChar(const SetCharEvent& event) { return false; }
|
|
||||||
|
|
||||||
/* window */
|
|
||||||
// termination
|
|
||||||
virtual bool OnWindowClosed(const WindowClosedEvent& event) { return false; }
|
|
||||||
// size/position
|
|
||||||
virtual bool OnWindowResized(const WindowResizedEvent& event) { return false; }
|
|
||||||
virtual bool OnWindowMoved(const WindowMovedEvent& event) { return false; }
|
|
||||||
// focus
|
|
||||||
virtual bool OnWindowLostFocus(const WindowLostFocusEvent& event) { return false; }
|
|
||||||
virtual bool OnWindowGainFocus(const WindowGainFocusEvent& event) { return false; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
78
Engine/src/Engine/Layer/Layer.hpp
Normal file
78
Engine/src/Engine/Layer/Layer.hpp
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Event;
|
||||||
|
|
||||||
|
// mouse
|
||||||
|
class MouseMovedEvent;
|
||||||
|
class ButtonPressedEvent;
|
||||||
|
class ButtonReleasedEvent;
|
||||||
|
class WheelScrolledEvent;
|
||||||
|
|
||||||
|
// keyboard
|
||||||
|
// key
|
||||||
|
class KeyPressedEvent;
|
||||||
|
class KeyRepeatEvent;
|
||||||
|
class KeyReleasedEvent;
|
||||||
|
// char
|
||||||
|
class SetCharEvent;
|
||||||
|
|
||||||
|
// window
|
||||||
|
class WindowClosedEvent;
|
||||||
|
class WindowResizedEvent;
|
||||||
|
class WindowMovedEvent;
|
||||||
|
class WindowLostFocusEvent;
|
||||||
|
class WindowGainFocusEvent;
|
||||||
|
|
||||||
|
class Layer
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
std::string m_LayerName;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Layer(const std::string& name);
|
||||||
|
virtual ~Layer() = default;
|
||||||
|
|
||||||
|
inline const std::string& GetName() const { return m_LayerName; }
|
||||||
|
|
||||||
|
/* update */
|
||||||
|
virtual void OnUpdate(float deltaTime) {}
|
||||||
|
virtual void OnUserInterfaceUpdate() {}
|
||||||
|
|
||||||
|
virtual void OnRender() {}
|
||||||
|
|
||||||
|
bool OnEvent(const Event& event);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* mouse */
|
||||||
|
// cursor
|
||||||
|
virtual bool OnMouseMoved(const MouseMovedEvent& event) { return false; }
|
||||||
|
// button
|
||||||
|
virtual bool OnButtonPressed(const ButtonPressedEvent& event) { return false; }
|
||||||
|
virtual bool OnButtonReleased(const ButtonReleasedEvent& event) { return false; }
|
||||||
|
// wheel
|
||||||
|
virtual bool OnWheelScrolled(const WheelScrolledEvent& event) { return false; }
|
||||||
|
|
||||||
|
/* keyboard */
|
||||||
|
// key
|
||||||
|
virtual bool OnKeyPressed(const KeyPressedEvent& event) { return false; }
|
||||||
|
virtual bool OnKeyRepeat(const KeyRepeatEvent& event) { return false; }
|
||||||
|
virtual bool OnKeyReleased(const KeyReleasedEvent& event) { return false; }
|
||||||
|
// char
|
||||||
|
virtual bool OnSetChar(const SetCharEvent& event) { return false; }
|
||||||
|
|
||||||
|
/* window */
|
||||||
|
// termination
|
||||||
|
virtual bool OnWindowClosed(const WindowClosedEvent& event) { return false; }
|
||||||
|
// size/position
|
||||||
|
virtual bool OnWindowResized(const WindowResizedEvent& event) { return false; }
|
||||||
|
virtual bool OnWindowMoved(const WindowMovedEvent& event) { return false; }
|
||||||
|
// focus
|
||||||
|
virtual bool OnWindowLostFocus(const WindowLostFocusEvent& event) { return false; }
|
||||||
|
virtual bool OnWindowGainFocus(const WindowGainFocusEvent& event) { return false; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,10 +1,10 @@
|
||||||
#include "LayerStack.h"
|
#include "LayerStack.hpp"
|
||||||
|
|
||||||
#include "Events/Event.h"
|
#include "Events/Event.hpp"
|
||||||
#include "Events/KeyboardEvents.h"
|
#include "Events/KeyboardEvents.hpp"
|
||||||
#include "Events/MouseEvents.h"
|
#include "Events/MouseEvents.hpp"
|
||||||
#include "Events/WindowEvents.h"
|
#include "Events/WindowEvents.hpp"
|
||||||
#include "Layer.h"
|
#include "Layer.hpp"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
class Layer;
|
|
||||||
|
|
||||||
class Event;
|
|
||||||
|
|
||||||
class LayerStack /* singleton */
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
static LayerStack* s_Context;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::vector<Layer*> m_Layers;
|
|
||||||
|
|
||||||
std::vector<Layer*>::iterator m_Begin;
|
|
||||||
std::vector<Layer*>::iterator m_End;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static Scope<LayerStack> Create();
|
|
||||||
|
|
||||||
~LayerStack();
|
|
||||||
|
|
||||||
// #todo: is this needed?
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
static inline void EmplaceLayer(Args&&... args) { s_Context->AttachLayerImpl(new T((args)...)); }
|
|
||||||
|
|
||||||
static inline void AttachLayer(Layer* layer) { s_Context->AttachLayerImpl(layer); }
|
|
||||||
static inline void DetachLayer(Layer* layer) { s_Context->DetachLayerImpl(layer); }
|
|
||||||
|
|
||||||
inline bool IsEmpty() { return m_Layers.empty(); }
|
|
||||||
|
|
||||||
std::vector<Layer*>::iterator begin() { return m_Layers.begin(); }
|
|
||||||
std::vector<Layer*>::iterator end() { return m_Layers.end(); }
|
|
||||||
std::vector<Layer*>::reverse_iterator rbegin() { return m_Layers.rbegin(); }
|
|
||||||
std::vector<Layer*>::reverse_iterator rend() { return m_Layers.rend(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
LayerStack();
|
|
||||||
|
|
||||||
void AttachLayerImpl(Layer* layer);
|
|
||||||
void DetachLayerImpl(Layer* layer);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
51
Engine/src/Engine/Layer/LayerStack.hpp
Normal file
51
Engine/src/Engine/Layer/LayerStack.hpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
class Layer;
|
||||||
|
|
||||||
|
class Event;
|
||||||
|
|
||||||
|
class LayerStack /* singleton */
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static LayerStack* s_Context;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Layer*> m_Layers;
|
||||||
|
|
||||||
|
std::vector<Layer*>::iterator m_Begin;
|
||||||
|
std::vector<Layer*>::iterator m_End;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Scope<LayerStack> Create();
|
||||||
|
|
||||||
|
~LayerStack();
|
||||||
|
|
||||||
|
// #todo: is this needed?
|
||||||
|
template<typename T, typename... Args>
|
||||||
|
static inline void EmplaceLayer(Args&&... args)
|
||||||
|
{
|
||||||
|
s_Context->AttachLayerImpl(new T((args)...));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void AttachLayer(Layer* layer) { s_Context->AttachLayerImpl(layer); }
|
||||||
|
static inline void DetachLayer(Layer* layer) { s_Context->DetachLayerImpl(layer); }
|
||||||
|
|
||||||
|
inline bool IsEmpty() { return m_Layers.empty(); }
|
||||||
|
|
||||||
|
std::vector<Layer*>::iterator begin() { return m_Layers.begin(); }
|
||||||
|
std::vector<Layer*>::iterator end() { return m_Layers.end(); }
|
||||||
|
std::vector<Layer*>::reverse_iterator rbegin() { return m_Layers.rbegin(); }
|
||||||
|
std::vector<Layer*>::reverse_iterator rend() { return m_Layers.rend(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
LayerStack();
|
||||||
|
|
||||||
|
void AttachLayerImpl(Layer* layer);
|
||||||
|
void DetachLayerImpl(Layer* layer);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,60 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// core
|
|
||||||
#include "Core/Application.h"
|
|
||||||
#include "Core/Window.h"
|
|
||||||
|
|
||||||
// camera
|
|
||||||
#include "Camera/Camera.h"
|
|
||||||
|
|
||||||
// debug
|
|
||||||
#include "Debug/Logger.h"
|
|
||||||
|
|
||||||
// events
|
|
||||||
#include "Events/Event.h"
|
|
||||||
#include "Events/KeyboardEvents.h"
|
|
||||||
#include "Events/MouseEvents.h"
|
|
||||||
#include "Events/WindowEvents.h"
|
|
||||||
|
|
||||||
// graphics
|
|
||||||
#include "Graphics/Framebuffer.h"
|
|
||||||
#include "Graphics/GraphicsContext.h"
|
|
||||||
#include "Graphics/Renderer.h"
|
|
||||||
#include "Graphics/Texture.h"
|
|
||||||
|
|
||||||
// input
|
|
||||||
#include "Input/Input.h"
|
|
||||||
#include "Input/KeyCodes.h"
|
|
||||||
#include "Input/MouseCodes.h"
|
|
||||||
|
|
||||||
// layer
|
|
||||||
#include "Layer/Layer.h"
|
|
||||||
#include "Layer/LayerStack.h"
|
|
||||||
|
|
||||||
// user interface
|
|
||||||
#include "UserInterface/UserInterface.h"
|
|
||||||
|
|
||||||
// utility
|
|
||||||
#include "Utility/ResourceManager.h"
|
|
||||||
|
|
||||||
// time
|
|
||||||
#include "Time/Timer.h"
|
|
||||||
|
|
||||||
// base
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
// third party
|
|
||||||
#include <imgui.h>
|
|
||||||
|
|
||||||
// math
|
|
||||||
#include "Math/Random.h"
|
|
||||||
|
|
||||||
// scene
|
|
||||||
#include "Scene/Components.h"
|
|
||||||
#include "Scene/Entity.h"
|
|
||||||
#include "Scene/Scene.h"
|
|
||||||
|
|
||||||
// entry point
|
|
||||||
#ifdef LIGHT_ENTRY_POINT
|
|
||||||
#include "Base/EntryPoint.h"
|
|
||||||
#endif
|
|
60
Engine/src/Engine/LightEngine.hpp
Normal file
60
Engine/src/Engine/LightEngine.hpp
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// core
|
||||||
|
#include "Core/Application.hpp"
|
||||||
|
#include "Core/Window.hpp"
|
||||||
|
|
||||||
|
// camera
|
||||||
|
#include "Camera/Camera.hpp"
|
||||||
|
|
||||||
|
// debug
|
||||||
|
#include "Debug/Logger.hpp"
|
||||||
|
|
||||||
|
// events
|
||||||
|
#include "Events/Event.hpp"
|
||||||
|
#include "Events/KeyboardEvents.hpp"
|
||||||
|
#include "Events/MouseEvents.hpp"
|
||||||
|
#include "Events/WindowEvents.hpp"
|
||||||
|
|
||||||
|
// graphics
|
||||||
|
#include "Graphics/Framebuffer.hpp"
|
||||||
|
#include "Graphics/GraphicsContext.hpp"
|
||||||
|
#include "Graphics/Renderer.hpp"
|
||||||
|
#include "Graphics/Texture.hpp"
|
||||||
|
|
||||||
|
// input
|
||||||
|
#include "Input/Input.hpp"
|
||||||
|
#include "Input/KeyCodes.hpp"
|
||||||
|
#include "Input/MouseCodes.hpp"
|
||||||
|
|
||||||
|
// layer
|
||||||
|
#include "Layer/Layer.hpp"
|
||||||
|
#include "Layer/LayerStack.hpp"
|
||||||
|
|
||||||
|
// user interface
|
||||||
|
#include "UserInterface/UserInterface.hpp"
|
||||||
|
|
||||||
|
// utility
|
||||||
|
#include "Utility/ResourceManager.hpp"
|
||||||
|
|
||||||
|
// time
|
||||||
|
#include "Time/Timer.hpp"
|
||||||
|
|
||||||
|
// base
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
|
||||||
|
// third party
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
|
// math
|
||||||
|
#include "Math/Random.hpp"
|
||||||
|
|
||||||
|
// scene
|
||||||
|
#include "Scene/Components.hpp"
|
||||||
|
#include "Scene/Entity.hpp"
|
||||||
|
#include "Scene/Scene.hpp"
|
||||||
|
|
||||||
|
// entry point
|
||||||
|
#ifdef LIGHT_ENTRY_POINT
|
||||||
|
#include "Base/EntryPoint.hpp"
|
||||||
|
#endif
|
|
@ -1,40 +1,42 @@
|
||||||
#include "Random.h"
|
#include "Random.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace Light { namespace Math {
|
namespace Light {
|
||||||
|
namespace Math {
|
||||||
|
|
||||||
float Rand(int min, int max, int decimals /* = 0 */)
|
float Rand(int min, int max, int decimals /* = 0 */)
|
||||||
{
|
{
|
||||||
const int dec = std::pow(10, decimals);
|
const int dec = 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 RandVec2(int min, int max, int decimals /* = 0 */)
|
glm::vec2 RandVec2(int min, int max, int decimals /* = 0 */)
|
||||||
{
|
{
|
||||||
const int dec = std::pow(10, decimals);
|
const int dec = std::pow(10, decimals);
|
||||||
min *= dec;
|
min *= dec;
|
||||||
max *= dec;
|
max *= dec;
|
||||||
|
|
||||||
float r1 = (min + (rand() % (max)-min)) / (float)dec;
|
float r1 = (min + (rand() % (max)-min)) / (float)dec;
|
||||||
float r2 = (min + (rand() % (max)-min)) / (float)dec;
|
float r2 = (min + (rand() % (max)-min)) / (float)dec;
|
||||||
|
|
||||||
return glm::vec2(r1, r2);
|
return glm::vec2(r1, r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 RandVec3(int min, int max, int decimals /* = 0 */)
|
glm::vec3 RandVec3(int min, int max, int decimals /* = 0 */)
|
||||||
{
|
{
|
||||||
const int dec = std::pow(10, decimals);
|
const int dec = std::pow(10, decimals);
|
||||||
min *= dec;
|
min *= dec;
|
||||||
max *= dec;
|
max *= dec;
|
||||||
|
|
||||||
float r1 = (min + (rand() % (max - min))) / (float)dec;
|
float r1 = (min + (rand() % (max - min))) / (float)dec;
|
||||||
float r2 = (min + (rand() % (max - min))) / (float)dec;
|
float r2 = (min + (rand() % (max - min))) / (float)dec;
|
||||||
float r3 = (min + (rand() % (max - min))) / (float)dec;
|
float r3 = (min + (rand() % (max - min))) / (float)dec;
|
||||||
|
|
||||||
return glm::vec3(r1, r2, r3);
|
return glm::vec3(r1, r2, r3);
|
||||||
}
|
}
|
||||||
}}
|
} // namespace Math
|
||||||
|
} // namespace Light
|
|
@ -1,9 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include "Components/CameraComponent.h"
|
|
||||||
#include "Components/NativeScriptComponent.h"
|
|
||||||
#include "Components/SpriteRendererComponent.h"
|
|
||||||
#include "Components/TransformComponent.h"
|
|
||||||
#include "Components/TagComponent.h"
|
|
8
Engine/src/Engine/Scene/Components.hpp
Normal file
8
Engine/src/Engine/Scene/Components.hpp
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "Components/CameraComponent.hpp"
|
||||||
|
#include "Components/NativeScriptComponent.hpp"
|
||||||
|
#include "Components/SpriteRendererComponent.hpp"
|
||||||
|
#include "Components/TagComponent.hpp"
|
||||||
|
#include "Components/TransformComponent.hpp"
|
|
@ -1,28 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include "Camera/SceneCamera.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
struct CameraComponent
|
|
||||||
{
|
|
||||||
SceneCamera camera;
|
|
||||||
bool isPrimary;
|
|
||||||
|
|
||||||
CameraComponent() = default;
|
|
||||||
CameraComponent(const CameraComponent&) = default;
|
|
||||||
|
|
||||||
CameraComponent(SceneCamera _camera, bool _isPrimary = false)
|
|
||||||
: camera(_camera),
|
|
||||||
isPrimary(_isPrimary)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
operator SceneCamera() { return camera; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
26
Engine/src/Engine/Scene/Components/CameraComponent.hpp
Normal file
26
Engine/src/Engine/Scene/Components/CameraComponent.hpp
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "Camera/SceneCamera.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
struct CameraComponent
|
||||||
|
{
|
||||||
|
SceneCamera camera;
|
||||||
|
bool isPrimary;
|
||||||
|
|
||||||
|
CameraComponent() = default;
|
||||||
|
CameraComponent(const CameraComponent&) = default;
|
||||||
|
|
||||||
|
CameraComponent(SceneCamera _camera, bool _isPrimary = false)
|
||||||
|
: camera(_camera), isPrimary(_isPrimary)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
operator SceneCamera() { return camera; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
|
@ -1,24 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Base/Base.h"
|
|
||||||
|
|
||||||
#include "ScriptableEntity.h"
|
|
||||||
|
|
||||||
namespace Light {
|
|
||||||
|
|
||||||
struct NativeScriptComponent
|
|
||||||
{
|
|
||||||
NativeScript* instance;
|
|
||||||
|
|
||||||
NativeScript* (*CreateInstance)();
|
|
||||||
void (*DestroyInstance)(NativeScriptComponent*);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void Bind()
|
|
||||||
{
|
|
||||||
CreateInstance = []() { return static_cast<NativeScript*>(new T()); };
|
|
||||||
DestroyInstance = [](NativeScriptComponent* nsc) { delete (T*)(nsc->instance); nsc->instance = nullptr; };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
28
Engine/src/Engine/Scene/Components/NativeScriptComponent.hpp
Normal file
28
Engine/src/Engine/Scene/Components/NativeScriptComponent.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/Base.hpp"
|
||||||
|
#include "ScriptableEntity.hpp"
|
||||||
|
|
||||||
|
namespace Light {
|
||||||
|
|
||||||
|
struct NativeScriptComponent
|
||||||
|
{
|
||||||
|
NativeScript* instance;
|
||||||
|
|
||||||
|
NativeScript* (*CreateInstance)();
|
||||||
|
void (*DestroyInstance)(NativeScriptComponent*);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void Bind()
|
||||||
|
{
|
||||||
|
CreateInstance = []() {
|
||||||
|
return static_cast<NativeScript*>(new T());
|
||||||
|
};
|
||||||
|
DestroyInstance = [](NativeScriptComponent* nsc) {
|
||||||
|
delete (T*)(nsc->instance);
|
||||||
|
nsc->instance = nullptr;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Light
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue