diff options
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/opengl/opengl_shader.cpp | 30 | ||||
| -rw-r--r-- | src/platform/opengl/opengl_shader.h | 6 | ||||
| -rw-r--r-- | src/platform/opengl/opengl_texture.cpp | 7 | ||||
| -rw-r--r-- | src/platform/opengl/opengl_texture.h | 4 |
4 files changed, 46 insertions, 1 deletions
diff --git a/src/platform/opengl/opengl_shader.cpp b/src/platform/opengl/opengl_shader.cpp index 39e582a..10da3de 100644 --- a/src/platform/opengl/opengl_shader.cpp +++ b/src/platform/opengl/opengl_shader.cpp @@ -12,6 +12,8 @@ namespace Donut return GL_VERTEX_SHADER; if (type == "fragment" || type == "pixel") return GL_FRAGMENT_SHADER; + if (type == "compute") + return GL_COMPUTE_SHADER; return 0; } @@ -37,6 +39,14 @@ namespace Donut compile(sources); } + OpenGLShader::OpenGLShader(const std::string& name, const std::string& compute_src) + : m_name(name) + { + std::unordered_map<uint32_t, std::string> sources; + sources[GL_COMPUTE_SHADER] = compute_src; + compile(sources); + } + OpenGLShader::~OpenGLShader() { glDeleteProgram(m_renderer_id); @@ -160,6 +170,11 @@ namespace Donut upload_uniform_float(name, value); } + void OpenGLShader::set_float2(const std::string& name, const glm::vec2& value) + { + upload_uniform_float2(name, value); + } + void OpenGLShader::set_float3(const std::string& name, const glm::vec3& value) { upload_uniform_float3(name, value); @@ -222,4 +237,19 @@ namespace Donut int location = glGetUniformLocation(m_renderer_id, name.c_str()); glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(matrix)); } + + void OpenGLShader::dispatch(uint32_t x, uint32_t y, uint32_t z) + { + glDispatchCompute(x, y, z); + } + + void OpenGLShader::dispatch_indirect(uint32_t offset) + { + glDispatchComputeIndirect(offset); + } + + void OpenGLShader::memory_barrier(uint32_t barriers) + { + glMemoryBarrier(barriers); + } }; diff --git a/src/platform/opengl/opengl_shader.h b/src/platform/opengl/opengl_shader.h index e87c839..1a79461 100644 --- a/src/platform/opengl/opengl_shader.h +++ b/src/platform/opengl/opengl_shader.h @@ -12,6 +12,7 @@ namespace Donut public: OpenGLShader(const std::string& filepath); OpenGLShader(const std::string& name, const std::string& vertex_src, const std::string& fragment_src); + OpenGLShader(const std::string& name, const std::string& compute_src); virtual ~OpenGLShader(); virtual void bind() const override; @@ -20,10 +21,15 @@ namespace Donut 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 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 const std::string& get_name() const override { return m_name; } void upload_uniform_int(const std::string& name, int value); diff --git a/src/platform/opengl/opengl_texture.cpp b/src/platform/opengl/opengl_texture.cpp index 87e9345..100909f 100644 --- a/src/platform/opengl/opengl_texture.cpp +++ b/src/platform/opengl/opengl_texture.cpp @@ -55,6 +55,7 @@ namespace Donut std::cout << "Data must be entire texture!" << std::endl; return; } + glTextureSubImage2D(m_renderer_id, 0, 0, 0, m_width, m_height, m_data_format, GL_UNSIGNED_BYTE, data); } @@ -62,4 +63,10 @@ namespace Donut { glBindTextureUnit(slot, m_renderer_id); } + + void OpenGLTexture2D::bind_as_image(uint32_t slot, bool read_only) const + { + GLenum access = read_only ? GL_READ_ONLY : GL_WRITE_ONLY; + glBindImageTexture(slot, m_renderer_id, 0, GL_FALSE, 0, access, m_internal_format); + } }; diff --git a/src/platform/opengl/opengl_texture.h b/src/platform/opengl/opengl_texture.h index 0782e8b..ddd4f39 100644 --- a/src/platform/opengl/opengl_texture.h +++ b/src/platform/opengl/opengl_texture.h @@ -5,7 +5,8 @@ namespace Donut { - class OpenGLTexture2D : public Texture2D + class OpenGLTexture2D + : public Texture2D { public: OpenGLTexture2D(uint32_t width, uint32_t height); @@ -18,6 +19,7 @@ namespace Donut 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 { |
