Skip to content

Commit

Permalink
libgui|GL: Drawables can share GLBuffers
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent d2d8ff3 commit b9d7acb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 9 additions & 0 deletions doomsday/libs/gui/include/de/graphics/drawable.h
Expand Up @@ -159,6 +159,15 @@ class LIBGUI_PUBLIC Drawable : public AssetGroup
*/
void addBuffer(Id id, GLBuffer *buffer);

/**
* Adds a new buffer or replaces an existing one. The buffer will use the
* default program.
*
* @param id Identifier of the buffer.
* @param buffer GL buffer.
*/
void addBuffer(Id id, std::shared_ptr<GLBuffer> buffer);

Id addBuffer(Name const &bufferName, GLBuffer *buffer);

/**
Expand Down
10 changes: 7 additions & 3 deletions doomsday/libs/gui/src/graphics/drawable.cpp
Expand Up @@ -24,7 +24,7 @@ namespace de {

DENG2_PIMPL(Drawable)
{
typedef QMap<Id, GLBuffer *> Buffers;
typedef QMap<Id, std::shared_ptr<GLBuffer>> Buffers;
typedef QMap<Id, GLProgram *> Programs;
typedef QMap<Id, GLState *> States;
typedef QMap<String, Id> Names;
Expand Down Expand Up @@ -59,7 +59,6 @@ DENG2_PIMPL(Drawable)

void clear()
{
qDeleteAll(buffers.values());
qDeleteAll(programs.values());
qDeleteAll(states.values());

Expand Down Expand Up @@ -242,6 +241,11 @@ Drawable::Id Drawable::stateId(Name const &stateName) const
}

void Drawable::addBuffer(Id id, GLBuffer *buffer)
{
addBuffer(id, std::shared_ptr<GLBuffer>(buffer));
}

void Drawable::addBuffer(Id id, std::shared_ptr<GLBuffer> buffer)
{
removeBuffer(id);

Expand Down Expand Up @@ -337,7 +341,7 @@ void Drawable::removeBuffer(Id id)
if (d->buffers.contains(id))
{
remove(*d->buffers[id]);
delete d->buffers.take(id);
d->buffers.remove(id);
}
d->configs.remove(id);
}
Expand Down

0 comments on commit b9d7acb

Please sign in to comment.