From 2d8f706efe6e0a02b3238c2f22e7cdce620e9807 Mon Sep 17 00:00:00 2001 From: hachem Date: Wed, 13 Aug 2025 18:20:54 +0200 Subject: feat: compute shaders and compute textures --- src/platform/opengl/opengl_shader.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/platform/opengl/opengl_shader.cpp') 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 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); + } }; -- cgit v1.3