aboutsummaryrefslogtreecommitdiff
path: root/src/Platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/Platform')
-rw-r--r--src/Platform/OpenGL/OpenGLShader.cpp30
-rw-r--r--src/Platform/OpenGL/OpenGLShader.h6
-rw-r--r--src/Platform/OpenGL/OpenGLTexture.cpp9
-rw-r--r--src/Platform/OpenGL/OpenGLTexture.h4
4 files changed, 47 insertions, 2 deletions
diff --git a/src/Platform/OpenGL/OpenGLShader.cpp b/src/Platform/OpenGL/OpenGLShader.cpp
index 39e95b7..6fcaa74 100644
--- a/src/Platform/OpenGL/OpenGLShader.cpp
+++ b/src/Platform/OpenGL/OpenGLShader.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& computeSrc)
+ : m_Name(name)
+ {
+ std::unordered_map<uint32_t, std::string> sources;
+ sources[GL_COMPUTE_SHADER] = computeSrc;
+ Compile(sources);
+ }
+
OpenGLShader::~OpenGLShader()
{
glDeleteProgram(m_RendererID);
@@ -160,6 +170,11 @@ namespace Donut
UploadUniformFloat(name, value);
}
+ void OpenGLShader::SetFloat2(const std::string& name, const glm::vec2& value)
+ {
+ UploadUniformFloat2(name, value);
+ }
+
void OpenGLShader::SetFloat3(const std::string& name, const glm::vec3& value)
{
UploadUniformFloat3(name, value);
@@ -222,4 +237,19 @@ namespace Donut
int location = glGetUniformLocation(m_RendererID, 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::DispatchIndirect(uint32_t offset)
+ {
+ glDispatchComputeIndirect(offset);
+ }
+
+ void OpenGLShader::MemoryBarrier(uint32_t barriers)
+ {
+ glMemoryBarrier(barriers);
+ }
};
diff --git a/src/Platform/OpenGL/OpenGLShader.h b/src/Platform/OpenGL/OpenGLShader.h
index 2ebde12..bd58834 100644
--- a/src/Platform/OpenGL/OpenGLShader.h
+++ b/src/Platform/OpenGL/OpenGLShader.h
@@ -12,6 +12,7 @@ namespace Donut
public:
OpenGLShader(const std::string& filepath);
OpenGLShader(const std::string& name, const std::string& vertexSrc, const std::string& fragmentSrc);
+ OpenGLShader(const std::string& name, const std::string& computeSrc);
virtual ~OpenGLShader();
virtual void Bind() const override;
@@ -20,10 +21,15 @@ namespace Donut
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 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 const std::string& GetName() const override { return m_Name; }
void UploadUniformInt(const std::string& name, int value);
diff --git a/src/Platform/OpenGL/OpenGLTexture.cpp b/src/Platform/OpenGL/OpenGLTexture.cpp
index 02252d1..7e2dea0 100644
--- a/src/Platform/OpenGL/OpenGLTexture.cpp
+++ b/src/Platform/OpenGL/OpenGLTexture.cpp
@@ -19,7 +19,7 @@ namespace Donut
glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
- // TODO: Texture Loading
+ // TODO(Hachem): Texture Loading
OpenGLTexture2D::OpenGLTexture2D(const std::string& path)
: m_Path(path)
{
@@ -56,6 +56,7 @@ namespace Donut
std::cout << "Data must be entire texture!" << std::endl;
return;
}
+
glTextureSubImage2D(m_RendererID, 0, 0, 0, m_Width, m_Height, m_DataFormat, GL_UNSIGNED_BYTE, data);
}
@@ -63,4 +64,10 @@ namespace Donut
{
glBindTextureUnit(slot, m_RendererID);
}
+
+ void OpenGLTexture2D::BindAsImage(uint32_t slot, bool readOnly) const
+ {
+ GLenum access = readOnly ? GL_READ_ONLY : GL_WRITE_ONLY;
+ glBindImageTexture(slot, m_RendererID, 0, GL_FALSE, 0, access, m_InternalFormat);
+ }
}; \ No newline at end of file
diff --git a/src/Platform/OpenGL/OpenGLTexture.h b/src/Platform/OpenGL/OpenGLTexture.h
index 4a95ab4..b27bb16 100644
--- a/src/Platform/OpenGL/OpenGLTexture.h
+++ b/src/Platform/OpenGL/OpenGLTexture.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 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
{