aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-08-13 18:39:13 +0200
committerhachem <im@hachem.wtf>2025-08-13 18:39:13 +0200
commit8a0b2a59c9809d5fc8e6a30c2abc4d5af21aa39e (patch)
tree41adf621418b790100d207c1534236945b431d1e
parentf1517709556827fb8b7bab00bdee4a9794d88dd1 (diff)
[fix]: More consistent formatting
-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
-rw-r--r--src/Platform/OpenGL/OpenGLIndexBuffer.h4
-rw-r--r--src/Platform/OpenGL/OpenGLRendererAPI.cpp14
-rw-r--r--src/Platform/OpenGL/OpenGLRendererAPI.h16
-rw-r--r--src/Platform/OpenGL/OpenGLShader.cpp11
-rw-r--r--src/Platform/OpenGL/OpenGLShader.h33
-rw-r--r--src/Platform/OpenGL/OpenGLTexture.cpp12
-rw-r--r--src/Platform/OpenGL/OpenGLTexture.h14
-rw-r--r--src/Platform/OpenGL/OpenGLVertexArray.h8
-rw-r--r--src/Platform/OpenGL/OpenGLVertexBuffer.cpp1
-rw-r--r--src/Platform/OpenGL/OpenGLVertexBuffer.h8
-rw-r--r--src/Platform/Vulkan/.gitkeep1
-rw-r--r--src/Rendering/IndexBuffer.cpp1
-rw-r--r--src/Rendering/IndexBuffer.h4
-rw-r--r--src/Rendering/Renderer.cpp6
-rw-r--r--src/Rendering/Renderer.h20
-rw-r--r--src/Rendering/Shader.h17
-rw-r--r--src/Rendering/Texture.h13
-rw-r--r--src/Rendering/VertexArray.h6
-rw-r--r--src/Rendering/VertexBuffer.h6
-rw-r--r--src/main.cpp3
26 files changed, 184 insertions, 174 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;
diff --git a/src/Platform/OpenGL/OpenGLIndexBuffer.h b/src/Platform/OpenGL/OpenGLIndexBuffer.h
index 0de8fb2..b3048a3 100644
--- a/src/Platform/OpenGL/OpenGLIndexBuffer.h
+++ b/src/Platform/OpenGL/OpenGLIndexBuffer.h
@@ -11,8 +11,8 @@ namespace Donut
OpenGLIndexBuffer(const uint32_t* indices, uint32_t count);
virtual ~OpenGLIndexBuffer();
- virtual void Bind() const override;
- virtual void Unbind() const override;
+ virtual void Bind() const override;
+ virtual void Unbind() const override;
virtual uint32_t GetCount() const override { return m_Count; }
private:
diff --git a/src/Platform/OpenGL/OpenGLRendererAPI.cpp b/src/Platform/OpenGL/OpenGLRendererAPI.cpp
index 5ee7d8d..7957fa0 100644
--- a/src/Platform/OpenGL/OpenGLRendererAPI.cpp
+++ b/src/Platform/OpenGL/OpenGLRendererAPI.cpp
@@ -1,10 +1,24 @@
#include "OpenGLRendererAPI.h"
#include <glad/glad.h>
+#include <GLFW/glfw3.h>
+#include <iostream>
namespace Donut
{
void OpenGLRendererAPI::Init()
{
+ if (!glfwGetCurrentContext())
+ {
+ std::cout << "No OpenGL context is current! Cannot initialize GLAD." << std::endl;
+ return;
+ }
+
+ if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
+ {
+ std::cout << "Failed to initialize GLAD!" << std::endl;
+ return;
+ }
+
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
diff --git a/src/Platform/OpenGL/OpenGLRendererAPI.h b/src/Platform/OpenGL/OpenGLRendererAPI.h
index 35bd9c3..8211504 100644
--- a/src/Platform/OpenGL/OpenGLRendererAPI.h
+++ b/src/Platform/OpenGL/OpenGLRendererAPI.h
@@ -9,13 +9,15 @@ namespace Donut
: public RendererAPI
{
public:
- virtual void Init() override;
- virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override;
- virtual void SetClearColor(const glm::vec4& color) override;
- virtual void Clear() override;
- virtual void EnableDepthTest() override;
- virtual void SetFaceCulling(bool enabled) override;
+ virtual void Init() override;
+ virtual void SetViewport(uint32_t x, uint32_t y,
+ uint32_t width, uint32_t height) override;
+ virtual void SetClearColor(const glm::vec4& color) override;
+ virtual void Clear() override;
+ virtual void EnableDepthTest() override;
+ virtual void SetFaceCulling(bool enabled) override;
- virtual void DrawIndexed(const std::shared_ptr<VertexArray>& vertexArray, uint32_t indexCount = 0) override;
+ virtual void DrawIndexed(const std::shared_ptr<VertexArray>& vertexArray,
+ uint32_t indexCount = 0) override;
};
};
diff --git a/src/Platform/OpenGL/OpenGLShader.cpp b/src/Platform/OpenGL/OpenGLShader.cpp
index 6fcaa74..b24e158 100644
--- a/src/Platform/OpenGL/OpenGLShader.cpp
+++ b/src/Platform/OpenGL/OpenGLShader.cpp
@@ -55,11 +55,15 @@ namespace Donut
std::string OpenGLShader::ReadFile(const std::string& filepath)
{
std::string result;
- std::ifstream in(filepath, std::ios::in | std::ios::binary);
- if (in) {
+ std::ifstream in(filepath, std::ios::in |
+ std::ios::binary);
+
+ if (in)
+ {
in.seekg(0, std::ios::end);
size_t size = in.tellg();
- if (size != -1) {
+ if (size != -1)
+ {
result.resize(size);
in.seekg(0, std::ios::beg);
in.read(&result[0], size);
@@ -75,6 +79,7 @@ namespace Donut
const char* typeToken = "#type";
size_t typeTokenLength = strlen(typeToken);
size_t pos = source.find(typeToken, 0);
+
while (pos != std::string::npos)
{
size_t eol = source.find_first_of("\r\n", pos);
diff --git a/src/Platform/OpenGL/OpenGLShader.h b/src/Platform/OpenGL/OpenGLShader.h
index bd58834..cb7fec1 100644
--- a/src/Platform/OpenGL/OpenGLShader.h
+++ b/src/Platform/OpenGL/OpenGLShader.h
@@ -18,36 +18,35 @@ namespace Donut
virtual void Bind() const override;
virtual void Unbind() const override;
- virtual void SetInt(const std::string& name, int value) override;
+ virtual void SetInt( const std::string& name, int value) override;
virtual void SetIntArray(const std::string& name, int* values, uint32_t count) override;
- virtual void SetFloat(const std::string& name, float value) override;
- virtual void SetFloat2(const std::string& name, const glm::vec2& value) override;
- virtual void SetFloat3(const std::string& name, const glm::vec3& value) override;
- virtual void SetFloat4(const std::string& name, const glm::vec4& value) override;
- virtual void SetMat4(const std::string& name, const glm::mat4& value) override;
+ virtual void SetFloat( const std::string& name, float value) override;
+ virtual void SetFloat2( const std::string& name, const glm::vec2& value) override;
+ virtual void SetFloat3( const std::string& name, const glm::vec3& value) override;
+ virtual void SetFloat4( const std::string& name, const glm::vec4& value) override;
+ virtual void SetMat4( const std::string& name, const glm::mat4& value) override;
virtual void Dispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1) override;
- virtual void DispatchIndirect(uint32_t offset = 0) override;
- virtual void MemoryBarrier(uint32_t barriers) override;
+ virtual void DispatchIndirect(uint32_t offset = 0) override;
+ virtual void MemoryBarrier(uint32_t barriers) override;
virtual const std::string& GetName() const override { return m_Name; }
- void UploadUniformInt(const std::string& name, int value);
+ void UploadUniformInt( const std::string& name, int value);
void UploadUniformIntArray(const std::string& name, int* values, uint32_t count);
- void UploadUniformFloat(const std::string& name, float value);
- void UploadUniformFloat2(const std::string& name, const glm::vec2& value);
- void UploadUniformFloat3(const std::string& name, const glm::vec3& value);
- void UploadUniformFloat4(const std::string& name, const glm::vec4& value);
- void UploadUniformMat3(const std::string& name, const glm::mat3& matrix);
- void UploadUniformMat4(const std::string& name, const glm::mat4& matrix);
+ void UploadUniformFloat( const std::string& name, float value);
+ void UploadUniformFloat2( const std::string& name, const glm::vec2& value);
+ void UploadUniformFloat3( const std::string& name, const glm::vec3& value);
+ void UploadUniformFloat4( const std::string& name, const glm::vec4& value);
+ void UploadUniformMat3( const std::string& name, const glm::mat3& matrix);
+ void UploadUniformMat4( const std::string& name, const glm::mat4& matrix);
private:
std::string ReadFile(const std::string& filepath);
std::unordered_map<uint32_t, std::string> PreProcess(const std::string& source);
void Compile(const std::unordered_map<uint32_t, std::string>& shaderSources);
-
private:
- uint32_t m_RendererID;
+ uint32_t m_RendererID;
std::string m_Name;
};
};
diff --git a/src/Platform/OpenGL/OpenGLTexture.cpp b/src/Platform/OpenGL/OpenGLTexture.cpp
index 7e2dea0..72e40ee 100644
--- a/src/Platform/OpenGL/OpenGLTexture.cpp
+++ b/src/Platform/OpenGL/OpenGLTexture.cpp
@@ -7,9 +7,9 @@ namespace Donut
: m_Width(width), m_Height(height)
{
m_InternalFormat = GL_RGBA8;
- m_DataFormat = GL_RGBA;
+ m_DataFormat = GL_RGBA;
- glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID);
+ glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID);
glTextureStorage2D(m_RendererID, 1, m_InternalFormat, m_Width, m_Height);
glTextureParameteri(m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -23,12 +23,12 @@ namespace Donut
OpenGLTexture2D::OpenGLTexture2D(const std::string& path)
: m_Path(path)
{
- m_Width = 1;
- m_Height = 1;
+ m_Width = 1;
+ m_Height = 1;
m_InternalFormat = GL_RGBA8;
- m_DataFormat = GL_RGBA;
+ m_DataFormat = GL_RGBA;
- glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID);
+ glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID);
glTextureStorage2D(m_RendererID, 1, m_InternalFormat, m_Width, m_Height);
glTextureParameteri(m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
diff --git a/src/Platform/OpenGL/OpenGLTexture.h b/src/Platform/OpenGL/OpenGLTexture.h
index b27bb16..3c6c08a 100644
--- a/src/Platform/OpenGL/OpenGLTexture.h
+++ b/src/Platform/OpenGL/OpenGLTexture.h
@@ -13,12 +13,12 @@ namespace Donut
OpenGLTexture2D(const std::string& path);
virtual ~OpenGLTexture2D();
- virtual uint32_t GetWidth() const override { return m_Width; }
- virtual uint32_t GetHeight() const override { return m_Height; }
+ virtual uint32_t GetWidth() const override { return m_Width; }
+ virtual uint32_t GetHeight() const override { return m_Height; }
virtual uint32_t GetRendererID() const override { return m_RendererID; }
- virtual void SetData(void* data, uint32_t size) override;
- virtual void Bind(uint32_t slot = 0) const override;
+ virtual void SetData(void* data, uint32_t size) override;
+ virtual void Bind(uint32_t slot = 0) const override;
virtual void BindAsImage(uint32_t slot = 0, bool readOnly = false) const override;
virtual bool operator==(const Texture& other) const override
@@ -28,8 +28,8 @@ namespace Donut
private:
std::string m_Path;
- uint32_t m_Width, m_Height;
- uint32_t m_RendererID;
- GLenum m_InternalFormat, m_DataFormat;
+ uint32_t m_Width, m_Height;
+ uint32_t m_RendererID;
+ GLenum m_InternalFormat, m_DataFormat;
};
}
diff --git a/src/Platform/OpenGL/OpenGLVertexArray.h b/src/Platform/OpenGL/OpenGLVertexArray.h
index 6783140..545f02c 100644
--- a/src/Platform/OpenGL/OpenGLVertexArray.h
+++ b/src/Platform/OpenGL/OpenGLVertexArray.h
@@ -1,14 +1,14 @@
#pragma once
#include "Rendering/VertexArray.h"
+#include "Rendering/VertexBuffer.h"
+#include "Rendering/IndexBuffer.h"
+
#include <vector>
#include <memory>
namespace Donut
{
- class VertexBuffer;
- class IndexBuffer;
-
class OpenGLVertexArray
: public VertexArray
{
@@ -35,6 +35,6 @@ namespace Donut
uint32_t m_RendererID;
uint32_t m_VertexBufferIndex = 0;
std::vector<std::shared_ptr<VertexBuffer>> m_VertexBuffers;
- std::shared_ptr<IndexBuffer> m_IndexBuffer;
+ std::shared_ptr<IndexBuffer> m_IndexBuffer;
};
};
diff --git a/src/Platform/OpenGL/OpenGLVertexBuffer.cpp b/src/Platform/OpenGL/OpenGLVertexBuffer.cpp
index 56080c7..21f152c 100644
--- a/src/Platform/OpenGL/OpenGLVertexBuffer.cpp
+++ b/src/Platform/OpenGL/OpenGLVertexBuffer.cpp
@@ -1,5 +1,6 @@
#include "OpenGLVertexBuffer.h"
#include "Rendering/VertexBuffer.h"
+
#include <glad/glad.h>
namespace Donut
diff --git a/src/Platform/OpenGL/OpenGLVertexBuffer.h b/src/Platform/OpenGL/OpenGLVertexBuffer.h
index 491af6f..6244f7d 100644
--- a/src/Platform/OpenGL/OpenGLVertexBuffer.h
+++ b/src/Platform/OpenGL/OpenGLVertexBuffer.h
@@ -11,15 +11,15 @@ namespace Donut
OpenGLVertexBuffer(const void* data, uint32_t size);
virtual ~OpenGLVertexBuffer();
- virtual void Bind() const override;
- virtual void Unbind() const override;
+ virtual void Bind() const override;
+ virtual void Unbind() const override;
virtual void SetData(const void* data, uint32_t size) override;
- virtual const VertexBufferLayout& GetLayout() const override { return m_Layout; }
+ virtual const VertexBufferLayout& GetLayout() const override { return m_Layout; }
virtual void SetLayout(const VertexBufferLayout& layout) override { m_Layout = layout; }
private:
- uint32_t m_RendererID;
+ uint32_t m_RendererID;
VertexBufferLayout m_Layout;
};
};
diff --git a/src/Platform/Vulkan/.gitkeep b/src/Platform/Vulkan/.gitkeep
new file mode 100644
index 0000000..cb7e3af
--- /dev/null
+++ b/src/Platform/Vulkan/.gitkeep
@@ -0,0 +1 @@
+Kill me \ No newline at end of file
diff --git a/src/Rendering/IndexBuffer.cpp b/src/Rendering/IndexBuffer.cpp
index d8854d3..de9cb87 100644
--- a/src/Rendering/IndexBuffer.cpp
+++ b/src/Rendering/IndexBuffer.cpp
@@ -1,5 +1,6 @@
#include "IndexBuffer.h"
#include "Renderer.h"
+
#include "Platform/OpenGL/OpenGLIndexBuffer.h"
namespace Donut
diff --git a/src/Rendering/IndexBuffer.h b/src/Rendering/IndexBuffer.h
index 0729d95..a58cc6c 100644
--- a/src/Rendering/IndexBuffer.h
+++ b/src/Rendering/IndexBuffer.h
@@ -9,8 +9,8 @@ namespace Donut
public:
virtual ~IndexBuffer() = default;
- virtual void Bind() const = 0;
- virtual void Unbind() const = 0;
+ virtual void Bind() const = 0;
+ virtual void Unbind() const = 0;
virtual uint32_t GetCount() const = 0;
static IndexBuffer* Create(const uint32_t* indices, uint32_t count);
diff --git a/src/Rendering/Renderer.cpp b/src/Rendering/Renderer.cpp
index 3f50a7c..9aa3dd3 100644
--- a/src/Rendering/Renderer.cpp
+++ b/src/Rendering/Renderer.cpp
@@ -34,9 +34,9 @@ namespace Donut
}
void Renderer::Submit(const std::shared_ptr<Shader>& shader,
- const std::shared_ptr<VertexArray>& vertexArray,
- const glm::mat4& transform,
- const glm::mat4& viewProjection)
+ const std::shared_ptr<VertexArray>& vertexArray,
+ const glm::mat4& transform,
+ const glm::mat4& viewProjection)
{
shader->Bind();
shader->SetMat4("u_ViewProjection", viewProjection);
diff --git a/src/Rendering/Renderer.h b/src/Rendering/Renderer.h
index 82c156e..3083c4c 100644
--- a/src/Rendering/Renderer.h
+++ b/src/Rendering/Renderer.h
@@ -21,26 +21,26 @@ namespace Donut
public:
enum class API
{
- None = 0,
+ None = 0,
OpenGL = 1,
Vulkan = 2,
};
-
public:
virtual ~RendererAPI() = default;
- virtual void Init() = 0;
- virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0;
- virtual void SetClearColor(const glm::vec4& color) = 0;
- virtual void Clear() = 0;
- virtual void EnableDepthTest() = 0;
- virtual void SetFaceCulling(bool enabled) = 0;
+ virtual void Init() = 0;
+ virtual void SetViewport(uint32_t x, uint32_t y,
+ uint32_t width, uint32_t height) = 0;
+ virtual void SetClearColor(const glm::vec4& color) = 0;
+ virtual void Clear() = 0;
+ virtual void EnableDepthTest() = 0;
+ virtual void SetFaceCulling(bool enabled) = 0;
- virtual void DrawIndexed(const std::shared_ptr<VertexArray>& vertexArray, uint32_t indexCount = 0) = 0;
+ virtual void DrawIndexed(const std::shared_ptr<VertexArray>& vertexArray,
+ uint32_t indexCount = 0) = 0;
inline static API GetAPI() { return s_API; }
static Scope<RendererAPI> Create();
-
private:
static API s_API;
};
diff --git a/src/Rendering/Shader.h b/src/Rendering/Shader.h
index aa46f07..ef0bdb1 100644
--- a/src/Rendering/Shader.h
+++ b/src/Rendering/Shader.h
@@ -20,17 +20,17 @@ namespace Donut
virtual void Bind() const = 0;
virtual void Unbind() const = 0;
- virtual void SetInt(const std::string& name, int value) = 0;
+ virtual void SetInt( const std::string& name, int value) = 0;
virtual void SetIntArray(const std::string& name, int* values, uint32_t count) = 0;
- virtual void SetFloat(const std::string& name, float value) = 0;
- virtual void SetFloat2(const std::string& name, const glm::vec2& value) = 0;
- virtual void SetFloat3(const std::string& name, const glm::vec3& value) = 0;
- virtual void SetFloat4(const std::string& name, const glm::vec4& value) = 0;
- virtual void SetMat4(const std::string& name, const glm::mat4& value) = 0;
+ virtual void SetFloat( const std::string& name, float value) = 0;
+ virtual void SetFloat2( const std::string& name, const glm::vec2& value) = 0;
+ virtual void SetFloat3( const std::string& name, const glm::vec3& value) = 0;
+ virtual void SetFloat4( const std::string& name, const glm::vec4& value) = 0;
+ virtual void SetMat4( const std::string& name, const glm::mat4& value) = 0;
virtual void Dispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1) = 0;
- virtual void DispatchIndirect(uint32_t offset = 0) = 0;
- virtual void MemoryBarrier(uint32_t barriers) = 0;
+ virtual void DispatchIndirect(uint32_t offset = 0) = 0;
+ virtual void MemoryBarrier(uint32_t barriers) = 0;
virtual const std::string& GetName() const = 0;
@@ -50,7 +50,6 @@ namespace Donut
std::shared_ptr<Shader> Get(const std::string& name);
bool Exists(const std::string& name) const;
-
private:
std::unordered_map<std::string, std::shared_ptr<Shader>> m_Shaders;
};
diff --git a/src/Rendering/Texture.h b/src/Rendering/Texture.h
index f17bb1d..4d150c0 100644
--- a/src/Rendering/Texture.h
+++ b/src/Rendering/Texture.h
@@ -11,15 +11,16 @@ namespace Donut
public:
virtual ~Texture() = default;
- virtual uint32_t GetWidth() const = 0;
- virtual uint32_t GetHeight() const = 0;
+ virtual uint32_t GetWidth() const = 0;
+ virtual uint32_t GetHeight() const = 0;
virtual uint32_t GetRendererID() const = 0;
- virtual void SetData(void* data, uint32_t size) = 0;
- virtual void Bind(uint32_t slot = 0) const = 0;
- virtual void BindAsImage(uint32_t slot = 0, bool readOnly = false) const = 0;
+ virtual void SetData(void* data, uint32_t size) = 0;
+ virtual void Bind(uint32_t slot = 0) const = 0;
+ virtual void BindAsImage(uint32_t slot = 0,
+ bool readOnly = false) const = 0;
- virtual bool operator==(const Texture& other) const = 0;
+ virtual bool operator==(const Texture& other) const = 0;
};
class Texture2D
diff --git a/src/Rendering/VertexArray.h b/src/Rendering/VertexArray.h
index 3c8254e..8ae61a7 100644
--- a/src/Rendering/VertexArray.h
+++ b/src/Rendering/VertexArray.h
@@ -12,14 +12,14 @@ namespace Donut
public:
virtual ~VertexArray() = default;
- virtual void Bind() const = 0;
+ virtual void Bind() const = 0;
virtual void Unbind() const = 0;
virtual void AddVertexBuffer(const std::shared_ptr<VertexBuffer>& vertexBuffer) = 0;
- virtual void SetIndexBuffer(const std::shared_ptr<IndexBuffer>& indexBuffer) = 0;
+ virtual void SetIndexBuffer(const std::shared_ptr<IndexBuffer>& indexBuffer) = 0;
virtual const std::vector<std::shared_ptr<VertexBuffer>>& GetVertexBuffers() const = 0;
- virtual const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const = 0;
+ virtual const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const = 0;
static VertexArray* Create();
};
diff --git a/src/Rendering/VertexBuffer.h b/src/Rendering/VertexBuffer.h
index 807e1be..35b9a84 100644
--- a/src/Rendering/VertexBuffer.h
+++ b/src/Rendering/VertexBuffer.h
@@ -61,11 +61,11 @@ namespace Donut
public:
virtual ~VertexBuffer() = default;
- virtual void Bind() const = 0;
- virtual void Unbind() const = 0;
+ virtual void Bind() const = 0;
+ virtual void Unbind() const = 0;
virtual void SetData(const void* data, uint32_t size) = 0;
- virtual const VertexBufferLayout& GetLayout() const = 0;
+ virtual const VertexBufferLayout& GetLayout() const = 0;
virtual void SetLayout(const VertexBufferLayout& layout) = 0;
static VertexBuffer* Create(const void* data, uint32_t size);
diff --git a/src/main.cpp b/src/main.cpp
index 1290268..77fe4b6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2,8 +2,7 @@
int main()
{
- Donut::Application* app = new Donut::Application() ;
+ Donut::Application* app = new Donut::Application("Donut", 1280, 720);
app->Run();
delete app;
- return 0;
} \ No newline at end of file