aboutsummaryrefslogtreecommitdiff
path: root/src/Platform/OpenGL
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 /src/Platform/OpenGL
parentf1517709556827fb8b7bab00bdee4a9794d88dd1 (diff)
[fix]: More consistent formatting
Diffstat (limited to 'src/Platform/OpenGL')
-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
10 files changed, 71 insertions, 50 deletions
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;
};
};