hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/platform/opengl/opengl_shader.cpp
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-08-13 18:20:54 +0200
committerhachem <im@hachem.wtf>2025-08-13 18:20:54 +0200
commit2d8f706efe6e0a02b3238c2f22e7cdce620e9807 (patch)
tree06734503f8422c1509da09b5dd6a3ce50bad875c /src/platform/opengl/opengl_shader.cpp
parent3b02022fd79ad0e130b8c49e7707d221bfc97bb5 (diff)
feat: compute shaders and compute textures
Diffstat (limited to 'src/platform/opengl/opengl_shader.cpp')
-rw-r--r--src/platform/opengl/opengl_shader.cpp30
1 files changed, 30 insertions, 0 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);
+ }
};