aboutsummaryrefslogtreecommitdiff
path: root/src/Core
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/Application.h42
-rw-r--r--src/Core/Camera.cpp16
-rw-r--r--src/Core/Camera.h22
-rw-r--r--src/Core/Event.h26
-rw-r--r--src/Core/Window.cpp44
-rw-r--r--src/Core/Window.h10
6 files changed, 74 insertions, 86 deletions
diff --git a/src/Core/Application.h b/src/Core/Application.h
index 922af67..e384e71 100644
--- a/src/Core/Application.h
+++ b/src/Core/Application.h
@@ -6,14 +6,11 @@
#include <memory>
#include <functional>
-namespace Donut
-{
- class VertexArray;
- class VertexBuffer;
- class IndexBuffer;
- class Shader;
- class Texture2D;
-};
+#include "Rendering/VertexArray.h"
+#include "Rendering/VertexBuffer.h"
+#include "Rendering/IndexBuffer.h"
+#include "Rendering/Shader.h"
+#include "Rendering/Texture.h"
namespace Donut
{
@@ -41,30 +38,29 @@ namespace Donut
bool m_Running;
bool m_Minimized;
- std::shared_ptr<VertexArray> m_VertexArray;
+ std::shared_ptr<VertexArray> m_VertexArray;
std::shared_ptr<VertexBuffer> m_VertexBuffer;
- std::shared_ptr<IndexBuffer> m_IndexBuffer;
- std::shared_ptr<Shader> m_Shader;
- std::shared_ptr<Texture2D> m_Texture;
+ std::shared_ptr<IndexBuffer> m_IndexBuffer;
+ std::shared_ptr<Shader> m_Shader;
+ std::shared_ptr<Texture2D> m_Texture;
- // Compute shader related members
- std::shared_ptr<Shader> m_ComputeShader;
+ std::shared_ptr<Shader> m_ComputeShader;
std::shared_ptr<Texture2D> m_ProcessedTexture;
float m_ComputeBrightness;
float m_ComputeContrast;
float m_ComputeSaturation;
- bool m_UseComputeShader;
+ bool m_UseComputeShader;
std::unique_ptr<Camera> m_Camera;
- bool m_Keys[1024] = { false };
- bool m_FirstMouse = true;
- float m_LastX = 0.0f;
- float m_LastY = 0.0f;
- float m_DeltaTime = 0.0f;
- float m_LastFrame = 0.0f;
- bool m_MouseDragging = false;
- float m_TextureTime = 0.0f;
+ bool m_Keys[1024] = { false };
+ bool m_FirstMouse = true;
+ float m_LastX = 0.0f;
+ float m_LastY = 0.0f;
+ float m_DeltaTime = 0.0f;
+ float m_LastFrame = 0.0f;
+ bool m_MouseDragging = false;
+ float m_TextureTime = 0.0f;
static Application* s_Instance;
};
diff --git a/src/Core/Camera.cpp b/src/Core/Camera.cpp
index ea363b0..ecfb6df 100644
--- a/src/Core/Camera.cpp
+++ b/src/Core/Camera.cpp
@@ -28,27 +28,27 @@ namespace Donut
void Camera::RecalculateViewMatrix()
{
float pitch = glm::radians(m_Rotation.x);
- float yaw = glm::radians(m_Rotation.y);
- float roll = glm::radians(m_Rotation.z);
+ float yaw = glm::radians(m_Rotation.y);
+ float roll = glm::radians(m_Rotation.z);
glm::vec3 direction;
direction.x = cos(yaw) * cos(pitch);
direction.y = sin(pitch);
direction.z = sin(yaw) * cos(pitch);
- glm::vec3 front = glm::normalize(direction);
glm::vec3 worldUp(0.0f, 1.0f, 0.0f);
+ glm::vec3 front = glm::normalize(direction);
glm::vec3 right = glm::normalize(glm::cross(front, worldUp));
- glm::vec3 up = glm::normalize(glm::cross(right, front));
+ glm::vec3 up = glm::normalize(glm::cross(right, front));
- m_ViewMatrix = glm::lookAt(m_Position, m_Position + front, up);
+ m_ViewMatrix = glm::lookAt(m_Position, m_Position + front, up);
m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix;
}
glm::vec3 Camera::GetForwardDirection() const
{
float pitch = glm::radians(m_Rotation.x);
- float yaw = glm::radians(m_Rotation.y);
+ float yaw = glm::radians(m_Rotation.y);
glm::vec3 direction;
direction.x = cos(yaw) * cos(pitch);
@@ -69,10 +69,6 @@ namespace Donut
return glm::normalize(glm::cross(GetRightDirection(), GetForwardDirection()));
}
- void Camera::OnUpdate(float deltaTime)
- {
- }
-
void Camera::OnMouseMove(float xOffset, float yOffset, bool constrainPitch)
{
xOffset *= m_MouseSensitivity;
diff --git a/src/Core/Camera.h b/src/Core/Camera.h
index b2037b7..e3569b8 100644
--- a/src/Core/Camera.h
+++ b/src/Core/Camera.h
@@ -27,8 +27,6 @@ namespace Donut
const glm::mat4& GetViewProjectionMatrix() const { return m_ViewProjectionMatrix; }
void SetProjection(float fov, float aspectRatio, float nearPlane, float farPlane);
-
- void OnUpdate(float deltaTime);
void OnMouseMove(float xOffset, float yOffset, bool constrainPitch = true);
void MoveForward(float deltaTime);
@@ -39,10 +37,10 @@ namespace Donut
void MoveDown(float deltaTime);
void SetMouseSensitivity(float sensitivity) { m_MouseSensitivity = sensitivity; }
- float GetMouseSensitivity() const { return m_MouseSensitivity; }
+ float GetMouseSensitivity() const { return m_MouseSensitivity; }
- void SetMovementSpeed(float speed) { m_MovementSpeed = speed; }
- float GetMovementSpeed() const { return m_MovementSpeed; }
+ void SetMovementSpeed(float speed) { m_MovementSpeed = speed; }
+ float GetMovementSpeed() const { return m_MovementSpeed; }
private:
void RecalculateViewMatrix();
@@ -55,15 +53,15 @@ namespace Donut
glm::vec3 m_Position = { 0.0f, 0.0f, 3.0f };
glm::vec3 m_Rotation = { 0.0f, 0.0f, 0.0f };
- float m_FOV = 45.0f;
+ float m_FOV = 45.0f;
float m_AspectRatio = 16.0f / 9.0f;
- float m_NearPlane = 0.1f;
- float m_FarPlane = 100.0f;
+ float m_NearPlane = 0.1f;
+ float m_FarPlane = 100.0f;
float m_MouseSensitivity = 0.1f;
- float m_MovementSpeed = 5.0f;
- bool m_FirstMouse = true;
- float m_LastX = 0.0f;
- float m_LastY = 0.0f;
+ float m_MovementSpeed = 5.0f;
+ bool m_FirstMouse = true;
+ float m_LastX = 0.0f;
+ float m_LastY = 0.0f;
};
}
diff --git a/src/Core/Event.h b/src/Core/Event.h
index 60d446d..23d92fd 100644
--- a/src/Core/Event.h
+++ b/src/Core/Event.h
@@ -156,7 +156,8 @@ namespace Donut
EventCategoryInput; }
protected:
- KeyEvent(int keycode) : m_KeyCode(keycode) { }
+ KeyEvent(int keycode)
+ : m_KeyCode(keycode) { }
int m_KeyCode;
};
@@ -185,7 +186,8 @@ namespace Donut
: public KeyEvent
{
public:
- KeyReleasedEvent(int keycode) : KeyEvent(keycode) { }
+ KeyReleasedEvent(int keycode)
+ : KeyEvent(keycode) { }
std::string ToString() const override
{
@@ -199,7 +201,8 @@ namespace Donut
: public KeyEvent
{
public:
- KeyTypedEvent(int keycode) : KeyEvent(keycode) { }
+ KeyTypedEvent(int keycode)
+ : KeyEvent(keycode) { }
std::string ToString() const override
{
@@ -262,7 +265,8 @@ namespace Donut
EventCategoryInput; }
protected:
- MouseButtonEvent(int button) : m_Button(button) { }
+ MouseButtonEvent(int button)
+ : m_Button(button) { }
int m_Button;
};
@@ -270,7 +274,8 @@ namespace Donut
: public MouseButtonEvent
{
public:
- MouseButtonPressedEvent(int button) : MouseButtonEvent(button) { }
+ MouseButtonPressedEvent(int button)
+ : MouseButtonEvent(button) { }
std::string ToString() const override
{
@@ -284,7 +289,8 @@ namespace Donut
: public MouseButtonEvent
{
public:
- MouseButtonReleasedEvent(int button) : MouseButtonEvent(button) { }
+ MouseButtonReleasedEvent(int button)
+ : MouseButtonEvent(button) { }
std::string ToString() const override
{
@@ -297,7 +303,8 @@ namespace Donut
class EventDispatcher
{
public:
- EventDispatcher(Event& event) : m_Event(event) { }
+ EventDispatcher(Event& event)
+ : m_Event(event) { }
template<typename T, typename F>
bool Dispatch(const F& func)
@@ -322,7 +329,10 @@ namespace Donut
EventHandler() = default;
~EventHandler() = default;
- void SetEventCallback(const EventCallbackFn& callback) { m_EventCallback = callback; }
+ void SetEventCallback(const EventCallbackFn& callback)
+ {
+ m_EventCallback = callback;
+ }
void OnEvent(Event& event)
{
diff --git a/src/Core/Window.cpp b/src/Core/Window.cpp
index ff451fd..853abb0 100644
--- a/src/Core/Window.cpp
+++ b/src/Core/Window.cpp
@@ -1,11 +1,10 @@
#include "Window.h"
#include <cstdint>
#include <iostream>
-#include <glad/glad.h>
namespace Donut
{
- static bool s_GLFWInitialized = false;
+ static bool s_GLFWInitialized = false;
static uint32_t s_GLFWWindowCount = 0;
Window::Window(const std::string& title, int width, int height)
@@ -43,26 +42,18 @@ namespace Donut
}
glfwMakeContextCurrent(m_Window);
-
- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
- {
- std::cout << "Failed to initialize GLAD!" << std::endl;
- glfwTerminate();
- return;
- }
-
glfwSetWindowUserPointer(m_Window, this);
glfwSetErrorCallback(GLFWErrorCallback);
glfwSetWindowCloseCallback(m_Window, GLFWWindowCloseCallback);
- glfwSetWindowSizeCallback(m_Window, GLFWWindowSizeCallback);
+ glfwSetWindowSizeCallback(m_Window, GLFWWindowSizeCallback);
glfwSetWindowFocusCallback(m_Window, GLFWWindowFocusCallback);
- glfwSetWindowPosCallback(m_Window, GLFWWindowPosCallback);
- glfwSetKeyCallback(m_Window, GLFWKeyCallback);
- glfwSetCharCallback(m_Window, GLFWCharCallback);
+ glfwSetWindowPosCallback(m_Window, GLFWWindowPosCallback);
+ glfwSetKeyCallback(m_Window, GLFWKeyCallback);
+ glfwSetCharCallback(m_Window, GLFWCharCallback);
glfwSetMouseButtonCallback(m_Window, GLFWMouseButtonCallback);
- glfwSetScrollCallback(m_Window, GLFWMouseScrollCallback);
- glfwSetCursorPosCallback(m_Window, GLFWCursorPosCallback);
+ glfwSetScrollCallback(m_Window, GLFWMouseScrollCallback);
+ glfwSetCursorPosCallback(m_Window, GLFWCursorPosCallback);
s_GLFWWindowCount++;
}
@@ -93,19 +84,15 @@ namespace Donut
void Window::SetCursorLocked(bool locked)
{
m_CursorLocked = locked;
- if (locked)
- glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
- else
- glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
+ glfwSetInputMode(m_Window, GLFW_CURSOR, locked ?
+ GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
}
void Window::SetCursorVisible(bool visible)
{
m_CursorVisible = visible;
- if (visible)
- glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
- else
- glfwSetInputMode(m_Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+ glfwSetInputMode(m_Window, GLFW_CURSOR, visible ?
+ GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
}
void Window::GLFWErrorCallback(int error, const char* description)
@@ -153,7 +140,8 @@ namespace Donut
win->m_EventHandler.OnEvent(event);
}
- void Window::GLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
+ void Window::GLFWKeyCallback(GLFWwindow* window, int key, int scancode,
+ int action, int mods)
{
Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
@@ -184,7 +172,8 @@ namespace Donut
win->m_EventHandler.OnEvent(event);
}
- void Window::GLFWMouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
+ void Window::GLFWMouseButtonCallback(GLFWwindow* window, int button,
+ int action, int mods)
{
Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
@@ -199,8 +188,7 @@ namespace Donut
{
MouseButtonReleasedEvent event(button);
win->m_EventHandler.OnEvent(event);
- break;
- }
+ } break;
}
}
diff --git a/src/Core/Window.h b/src/Core/Window.h
index c1cda2d..64cde32 100644
--- a/src/Core/Window.h
+++ b/src/Core/Window.h
@@ -24,14 +24,14 @@ namespace Donut
EventHandler& GetEventHandler() { return m_EventHandler; }
- unsigned int GetWidth() const { return m_Width; }
+ unsigned int GetWidth() const { return m_Width; }
unsigned int GetHeight() const { return m_Height; }
- void* GetNativeWindow() const { return m_Window; }
+ void* GetNativeWindow() const { return m_Window; }
void SetCursorLocked(bool locked);
void SetCursorVisible(bool visible);
- bool IsCursorLocked() const { return m_CursorLocked; }
+ bool IsCursorLocked() const { return m_CursorLocked; }
bool IsCursorVisible() const { return m_CursorVisible; }
private:
void Init();
@@ -48,10 +48,10 @@ namespace Donut
static void GLFWMouseScrollCallback(GLFWwindow* window, double xOffset, double yOffset);
static void GLFWCursorPosCallback(GLFWwindow* window, double xPos, double yPos);
private:
- GLFWwindow* m_Window;
+ GLFWwindow* m_Window;
EventHandler m_EventHandler;
- std::string m_Title;
+ std::string m_Title;
unsigned int m_Width;
unsigned int m_Height;
bool m_IsClosed;