Skip to content

Commit

Permalink
libgui|Drawable: Adding buffers with automatically generated identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 30, 2013
1 parent 24054c1 commit b7c8722
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doomsday/libgui/include/de/gui/drawable.h
Expand Up @@ -129,6 +129,17 @@ class LIBGUI_PUBLIC Drawable : public AssetGroup
*/
void addBuffer(Id id, GLBuffer *buffer);

/**
* Adds a new buffer, reserving an unused identifier for it. The chosen
* identifier is larger than any of the buffer identifiers currently in
* use.
*
* @param buffer GL buffer. Drawable gets ownership.
*
* @return Identifier chosen for the buffer.
*/
Id addBuffer(GLBuffer *buffer);

/**
* Creates a program or replaces an existing one with a blank program.
* @param id Identifier of the program. Cannot be zero.
Expand Down
17 changes: 17 additions & 0 deletions doomsday/libgui/src/drawable.cpp
Expand Up @@ -65,6 +65,16 @@ DENG2_PIMPL(Drawable)
configs.clear();
}

Id nextBufferId() const
{
Id next = 1;
foreach(Id id, buffers.keys())
{
next = de::max(id + 1, next);
}
return next;
}

void replaceProgram(GLProgram const *src, GLProgram const *dest)
{
DENG2_FOR_EACH(BufferConfigs, i, configs)
Expand Down Expand Up @@ -154,6 +164,13 @@ void Drawable::addBuffer(Id id, GLBuffer *buffer)
insert(*buffer, Required);
}

Drawable::Id Drawable::addBuffer(GLBuffer *buffer)
{
Id id = d->nextBufferId();
addBuffer(id, buffer);
return id;
}

GLProgram &Drawable::addProgram(Id id)
{
// Program 0 is the default program.
Expand Down

0 comments on commit b7c8722

Please sign in to comment.