hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/opengl/opengl_index_buffer.h4
-rw-r--r--src/platform/opengl/opengl_renderer_api.cpp14
-rw-r--r--src/platform/opengl/opengl_renderer_api.h16
-rw-r--r--src/platform/opengl/opengl_shader.cpp11
-rw-r--r--src/platform/opengl/opengl_shader.h33
-rw-r--r--src/platform/opengl/opengl_texture.cpp12
-rw-r--r--src/platform/opengl/opengl_texture.h14
-rw-r--r--src/platform/opengl/opengl_vertex_array.h8
-rw-r--r--src/platform/opengl/opengl_vertex_buffer.cpp1
-rw-r--r--src/platform/opengl/opengl_vertex_buffer.h8
-rw-r--r--src/platform/vulkan/.gitkeep1
11 files changed, 72 insertions, 50 deletions
diff --git a/src/platform/opengl/opengl_index_buffer.h b/src/platform/opengl/opengl_index_buffer.h
index b0498b4..43a9d86 100644
--- a/src/platform/opengl/opengl_index_buffer.h
+++ b/src/platform/opengl/opengl_index_buffer.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 get_count() const override { return m_count; }
private:
diff --git a/src/platform/opengl/opengl_renderer_api.cpp b/src/platform/opengl/opengl_renderer_api.cpp
index 3a147b9..1d41735 100644
--- a/src/platform/opengl/opengl_renderer_api.cpp
+++ b/src/platform/opengl/opengl_renderer_api.cpp
@@ -1,10 +1,24 @@
#include "opengl_renderer_api.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/opengl_renderer_api.h b/src/platform/opengl/opengl_renderer_api.h
index f28567c..15984d5 100644
--- a/src/platform/opengl/opengl_renderer_api.h
+++ b/src/platform/opengl/opengl_renderer_api.h
@@ -9,13 +9,15 @@ namespace Donut
: public RendererAPI
{
public:
- virtual void init() override;
- virtual void set_viewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override;
- virtual void set_clear_color(const glm::vec4& color) override;
- virtual void clear() override;
- virtual void enable_depth_test() override;
- virtual void set_face_culling(bool enabled) override;
+ virtual void init() override;
+ virtual void set_viewport(uint32_t x, uint32_t y,
+ uint32_t width, uint32_t height) override;
+ virtual void set_clear_color(const glm::vec4& color) override;
+ virtual void clear() override;
+ virtual void enable_depth_test() override;
+ virtual void set_face_culling(bool enabled) override;
- virtual void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, uint32_t index_count = 0) override;
+ virtual void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array,
+ uint32_t index_count = 0) override;
};
};
diff --git a/src/platform/opengl/opengl_shader.cpp b/src/platform/opengl/opengl_shader.cpp
index 10da3de..f4b99bc 100644
--- a/src/platform/opengl/opengl_shader.cpp
+++ b/src/platform/opengl/opengl_shader.cpp
@@ -55,11 +55,15 @@ namespace Donut
std::string OpenGLShader::read_file(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* type_token = "#type";
size_t type_token_length = strlen(type_token);
size_t pos = source.find(type_token, 0);
+
while (pos != std::string::npos)
{
size_t eol = source.find_first_of("\r\n", pos);
diff --git a/src/platform/opengl/opengl_shader.h b/src/platform/opengl/opengl_shader.h
index 1a79461..5870bda 100644
--- a/src/platform/opengl/opengl_shader.h
+++ b/src/platform/opengl/opengl_shader.h
@@ -18,36 +18,35 @@ namespace Donut
virtual void bind() const override;
virtual void unbind() const override;
- virtual void set_int(const std::string& name, int value) override;
+ virtual void set_int( const std::string& name, int value) override;
virtual void set_int_array(const std::string& name, int* values, uint32_t count) override;
- virtual void set_float(const std::string& name, float value) override;
- virtual void set_float2(const std::string& name, const glm::vec2& value) override;
- virtual void set_float3(const std::string& name, const glm::vec3& value) override;
- virtual void set_float4(const std::string& name, const glm::vec4& value) override;
- virtual void set_mat4(const std::string& name, const glm::mat4& value) override;
+ virtual void set_float( const std::string& name, float value) override;
+ virtual void set_float2( const std::string& name, const glm::vec2& value) override;
+ virtual void set_float3( const std::string& name, const glm::vec3& value) override;
+ virtual void set_float4( const std::string& name, const glm::vec4& value) override;
+ virtual void set_mat4( 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 dispatch_indirect(uint32_t offset = 0) override;
- virtual void memory_barrier(uint32_t barriers) override;
+ virtual void dispatch_indirect(uint32_t offset = 0) override;
+ virtual void memory_barrier(uint32_t barriers) override;
virtual const std::string& get_name() const override { return m_name; }
- void upload_uniform_int(const std::string& name, int value);
+ void upload_uniform_int( const std::string& name, int value);
void upload_uniform_int_array(const std::string& name, int* values, uint32_t count);
- void upload_uniform_float(const std::string& name, float value);
- void upload_uniform_float2(const std::string& name, const glm::vec2& value);
- void upload_uniform_float3(const std::string& name, const glm::vec3& value);
- void upload_uniform_float4(const std::string& name, const glm::vec4& value);
- void upload_uniform_mat3(const std::string& name, const glm::mat3& matrix);
- void upload_uniform_mat4(const std::string& name, const glm::mat4& matrix);
+ void upload_uniform_float( const std::string& name, float value);
+ void upload_uniform_float2( const std::string& name, const glm::vec2& value);
+ void upload_uniform_float3( const std::string& name, const glm::vec3& value);
+ void upload_uniform_float4( const std::string& name, const glm::vec4& value);
+ void upload_uniform_mat3( const std::string& name, const glm::mat3& matrix);
+ void upload_uniform_mat4( const std::string& name, const glm::mat4& matrix);
private:
std::string read_file(const std::string& filepath);
std::unordered_map<uint32_t, std::string> pre_process(const std::string& source);
void compile(const std::unordered_map<uint32_t, std::string>& shader_sources);
-
private:
- uint32_t m_renderer_id;
+ uint32_t m_renderer_id;
std::string m_name;
};
};
diff --git a/src/platform/opengl/opengl_texture.cpp b/src/platform/opengl/opengl_texture.cpp
index 100909f..53ed06c 100644
--- a/src/platform/opengl/opengl_texture.cpp
+++ b/src/platform/opengl/opengl_texture.cpp
@@ -7,9 +7,9 @@ namespace Donut
: m_width(width), m_height(height)
{
m_internal_format = GL_RGBA8;
- m_data_format = GL_RGBA;
+ m_data_format = GL_RGBA;
- glCreateTextures(GL_TEXTURE_2D, 1, &m_renderer_id);
+ glCreateTextures(GL_TEXTURE_2D, 1, &m_renderer_id);
glTextureStorage2D(m_renderer_id, 1, m_internal_format, m_width, m_height);
glTextureParameteri(m_renderer_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -22,12 +22,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_internal_format = GL_RGBA8;
- m_data_format = GL_RGBA;
+ m_data_format = GL_RGBA;
- glCreateTextures(GL_TEXTURE_2D, 1, &m_renderer_id);
+ glCreateTextures(GL_TEXTURE_2D, 1, &m_renderer_id);
glTextureStorage2D(m_renderer_id, 1, m_internal_format, m_width, m_height);
glTextureParameteri(m_renderer_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
diff --git a/src/platform/opengl/opengl_texture.h b/src/platform/opengl/opengl_texture.h
index ddd4f39..41b352a 100644
--- a/src/platform/opengl/opengl_texture.h
+++ b/src/platform/opengl/opengl_texture.h
@@ -13,12 +13,12 @@ namespace Donut
OpenGLTexture2D(const std::string& path);
virtual ~OpenGLTexture2D();
- virtual uint32_t get_width() const override { return m_width; }
- virtual uint32_t get_height() const override { return m_height; }
+ virtual uint32_t get_width() const override { return m_width; }
+ virtual uint32_t get_height() const override { return m_height; }
virtual uint32_t get_renderer_id() const override { return m_renderer_id; }
- virtual void set_data(void* data, uint32_t size) override;
- virtual void bind(uint32_t slot = 0) const override;
+ virtual void set_data(void* data, uint32_t size) override;
+ virtual void bind(uint32_t slot = 0) const override;
virtual void bind_as_image(uint32_t slot = 0, bool read_only = 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_renderer_id;
- GLenum m_internal_format, m_data_format;
+ uint32_t m_width, m_height;
+ uint32_t m_renderer_id;
+ GLenum m_internal_format, m_data_format;
};
}
diff --git a/src/platform/opengl/opengl_vertex_array.h b/src/platform/opengl/opengl_vertex_array.h
index e1a02f6..d6986db 100644
--- a/src/platform/opengl/opengl_vertex_array.h
+++ b/src/platform/opengl/opengl_vertex_array.h
@@ -1,14 +1,14 @@
#pragma once
#include "rendering/vertex_array.h"
+#include "rendering/vertex_buffer.h"
+#include "rendering/index_buffer.h"
+
#include <vector>
#include <memory>
namespace Donut
{
- class VertexBuffer;
- class IndexBuffer;
-
class OpenGLVertexArray
: public VertexArray
{
@@ -35,6 +35,6 @@ namespace Donut
uint32_t m_renderer_id;
uint32_t m_vertex_buffer_index = 0;
std::vector<std::shared_ptr<VertexBuffer>> m_vertex_buffers;
- std::shared_ptr<IndexBuffer> m_index_buffer;
+ std::shared_ptr<IndexBuffer> m_index_buffer;
};
};
diff --git a/src/platform/opengl/opengl_vertex_buffer.cpp b/src/platform/opengl/opengl_vertex_buffer.cpp
index 76b620a..543a7d6 100644
--- a/src/platform/opengl/opengl_vertex_buffer.cpp
+++ b/src/platform/opengl/opengl_vertex_buffer.cpp
@@ -1,5 +1,6 @@
#include "opengl_vertex_buffer.h"
#include "rendering/vertex_buffer.h"
+
#include <glad/glad.h>
namespace Donut
diff --git a/src/platform/opengl/opengl_vertex_buffer.h b/src/platform/opengl/opengl_vertex_buffer.h
index bdc0645..678f0e0 100644
--- a/src/platform/opengl/opengl_vertex_buffer.h
+++ b/src/platform/opengl/opengl_vertex_buffer.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 set_data(const void* data, uint32_t size) override;
- virtual const VertexBufferLayout& get_layout() const override { return m_layout; }
+ virtual const VertexBufferLayout& get_layout() const override { return m_layout; }
virtual void set_layout(const VertexBufferLayout& layout) override { m_layout = layout; }
private:
- uint32_t m_renderer_id;
+ uint32_t m_renderer_id;
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