Skip to content

Commit

Permalink
libgui|GLBuffer: Using GLBuffer for managing raw buffer data
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 23, 2017
1 parent e91ba8f commit 30df3c5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doomsday/sdk/libgui/include/de/graphics/glbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ class LIBGUI_PUBLIC GLBuffer : public Asset

void setIndices(gl::Primitive primitive, Indices const &indices, gl::Usage usage);

void setData(void const *data, dsize dataSize, gl::Usage usage);

void setData(dsize startOffset, void const *data, dsize dataSize);

void setUninitializedData(dsize dataSize, gl::Usage usage);
Expand Down Expand Up @@ -321,6 +323,8 @@ class LIBGUI_PUBLIC GLBuffer : public Asset

void setFormat(internal::AttribSpecs const &format);

GLuint glName() const;

static duint drawCount();
static void resetDrawCount();

Expand Down
25 changes: 24 additions & 1 deletion doomsday/sdk/libgui/src/graphics/glbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ void GLBuffer::setIndices(Primitive primitive, dsize count, Index const *indices

auto &GL = LIBGUI_GL;
GL.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, d->idxName);
GL.glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(Index), indices, Impl::glUsage(usage));
GL.glBufferData(GL_ELEMENT_ARRAY_BUFFER, GLsizeiptr(count * sizeof(Index)),
indices, Impl::glUsage(usage));
GL.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
else
Expand All @@ -378,6 +379,23 @@ void GLBuffer::setIndices(Primitive primitive, Indices const &indices, Usage usa
setIndices(primitive, indices.size(), indices.constData(), usage);
}

void GLBuffer::setData(void const *data, dsize dataSize, gl::Usage usage)
{
if (data && dataSize)
{
d->alloc();

auto &GL = LIBGUI_GL;
GL.glBindBuffer(GL_ARRAY_BUFFER, d->name);
GL.glBufferData(GL_ARRAY_BUFFER, GLsizeiptr(dataSize), data, Impl::glUsage(usage));
GL.glBindBuffer(GL_ARRAY_BUFFER, 0);
}
else
{
d->release();
}
}

void GLBuffer::setData(dsize startOffset, void const *data, dsize dataSize)
{
DENG2_ASSERT(isReady());
Expand Down Expand Up @@ -523,6 +541,11 @@ void GLBuffer::setFormat(AttribSpecs const &format)
d->specs = format;
}

GLuint GLBuffer::glName() const
{
return d->name;
}

duint GLBuffer::drawCount() // static
{
return drawCounter;
Expand Down

0 comments on commit 30df3c5

Please sign in to comment.