summaryrefslogtreecommitdiffstats
path: root/src/render/io
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire350@gmail.com>2015-09-19 18:23:22 +0200
committerPaul Lemire <paul.lemire@kdab.com>2015-10-14 13:27:13 +0000
commit05902cb5bd821e9aaa851af1619ecef91f61cd6f (patch)
tree383646573a664ac75ddf803dc077be6cff385d18 /src/render/io
parentbd10ed192e7496186281cef137e474eccae46e67 (diff)
Uniform Buffers: try to minimize bind / unbind
Change-Id: I52c7d3fd3ff50211f2869df7e81e70ca1475d245 Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'src/render/io')
-rw-r--r--src/render/io/uniformbuffer.cpp17
-rw-r--r--src/render/io/uniformbuffer_p.h3
2 files changed, 16 insertions, 4 deletions
diff --git a/src/render/io/uniformbuffer.cpp b/src/render/io/uniformbuffer.cpp
index 458a7ac4d..881d557df 100644
--- a/src/render/io/uniformbuffer.cpp
+++ b/src/render/io/uniformbuffer.cpp
@@ -53,9 +53,22 @@ namespace Render {
UniformBuffer::UniformBuffer()
: m_bufferId(~0)
, m_isCreated(false)
+ , m_bound(false)
{
}
+void UniformBuffer::bind(GraphicsContext *ctx)
+{
+ ctx->openGLContext()->functions()->glBindBuffer(GL_UNIFORM_BUFFER, m_bufferId);
+ m_bound = true;
+}
+
+void UniformBuffer::release(GraphicsContext *ctx)
+{
+ m_bound = false;
+ ctx->openGLContext()->functions()->glBindBuffer(GL_UNIFORM_BUFFER, 0);
+}
+
void UniformBuffer::create(GraphicsContext *ctx)
{
ctx->openGLContext()->functions()->glGenBuffers(1, &m_bufferId);
@@ -70,18 +83,14 @@ void UniformBuffer::destroy(GraphicsContext *ctx)
void UniformBuffer::allocate(GraphicsContext *ctx, uint size, bool dynamic)
{
- ctx->openGLContext()->functions()->glBindBuffer(GL_UNIFORM_BUFFER, m_bufferId);
// Either GL_STATIC_DRAW OR GL_DYNAMIC_DRAW depending on the use case
// TO DO: find a way to know how a buffer/QShaderData will be used to use the right usage
ctx->openGLContext()->functions()->glBufferData(GL_UNIFORM_BUFFER, size, NULL, dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
- ctx->openGLContext()->functions()->glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
void UniformBuffer::update(GraphicsContext *ctx, const void *data, uint size, int offset)
{
- ctx->openGLContext()->functions()->glBindBuffer(GL_UNIFORM_BUFFER, m_bufferId);
ctx->openGLContext()->functions()->glBufferSubData(GL_UNIFORM_BUFFER, offset, size, data);
- ctx->openGLContext()->functions()->glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
void UniformBuffer::bindToUniformBlock(GraphicsContext *ctx, int bindingPoint)
diff --git a/src/render/io/uniformbuffer_p.h b/src/render/io/uniformbuffer_p.h
index 49db79f51..e60d30054 100644
--- a/src/render/io/uniformbuffer_p.h
+++ b/src/render/io/uniformbuffer_p.h
@@ -67,6 +67,7 @@ public:
UniformBuffer();
void bind(GraphicsContext *ctx);
+ void release(GraphicsContext *ctx);
void create(GraphicsContext *ctx);
void destroy(GraphicsContext *ctx);
void allocate(GraphicsContext *ctx, uint size, bool dynamic = true);
@@ -75,10 +76,12 @@ public:
inline GLuint bufferId() const { return m_bufferId; }
inline bool isCreated() const { return m_isCreated; }
+ inline bool isBound() const { return m_bound; }
private:
GLuint m_bufferId;
bool m_isCreated;
+ bool m_bound;
};
} // namespace Render