Skip to content

Commit

Permalink
Refactor|Client|Map Renderer|DrawLists: Clear/reset draw lists and ve…
Browse files Browse the repository at this point in the history
…rtex buffer from RenderSystem

Also store a pointer to the vertex buffer internally within DrawList.
  • Loading branch information
danij-deng committed Nov 6, 2013
1 parent fe63c03 commit d17e0f3
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 27 deletions.
4 changes: 4 additions & 0 deletions doomsday/client/include/render/rendersystem.h
Expand Up @@ -30,6 +30,10 @@ class RenderSystem : public de::System
public:
RenderSystem();

void clearDrawLists();

void resetDrawLists();

DrawLists &drawLists();

// System.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/gl/gl_texmanager.cpp
Expand Up @@ -1120,7 +1120,7 @@ void GL_ReleaseSystemTextures()

// The rendering lists contain persistent references to texture names.
// Which, obviously, can't persist any longer...
ClientApp::renderSystem().drawLists().clear();
ClientApp::renderSystem().clearDrawLists();

glDeleteTextures(NUM_LIGHTING_TEXTURES, (GLuint const *) lightingTextures);
std::memset(lightingTextures, 0, sizeof(lightingTextures));
Expand All @@ -1143,7 +1143,7 @@ void GL_ReleaseRuntimeTextures()

// The rendering lists contain persistent references to texture names.
// Which, obviously, can't persist any longer...
ClientApp::renderSystem().drawLists().clear();
ClientApp::renderSystem().clearDrawLists();

// texture-wrapped GL textures; textures, flats, sprites...
GL_ReleaseTexturesByScheme("Flats");
Expand Down
30 changes: 16 additions & 14 deletions doomsday/client/src/render/drawlist.cpp
Expand Up @@ -38,6 +38,7 @@ DENG2_PIMPL(DrawList)
uint size; ///< Size of this element (zero = n/a).

struct Data {
Store *buffer;
gl::Primitive type;

// Element indices into the global backing store for the geometry.
Expand Down Expand Up @@ -151,18 +152,18 @@ DENG2_PIMPL(DrawList)
{
if(texUnitMap[j])
{
Vector2f const &tc = RL_Store().texCoords[texUnitMap[j] - 1][index];
Vector2f const &tc = buffer->texCoords[texUnitMap[j] - 1][index];
glMultiTexCoord2f(GL_TEXTURE0 + j, tc.x, tc.y);
}
}

if(!(conditions & NoColor))
{
Vector4ub const &color = RL_Store().colorCoords[index];
Vector4ub const &color = buffer->colorCoords[index];
glColor4ub(color.x, color.y, color.z, color.w);
}

Vector3f const &pos = RL_Store().posCoords[index];
Vector3f const &pos = buffer->posCoords[index];
glVertex3f(pos.x, pos.z, pos.y);
}
glEnd();
Expand Down Expand Up @@ -204,9 +205,9 @@ DENG2_PIMPL(DrawList)

Element *next() {
if(!size) return 0;
Element *nextGeom = (Element *) ((byte *) (this) + size);
if(!nextGeom->size) return 0;
return nextGeom;
Element *elem = (Element *) ((byte *) (this) + size);
if(!elem->size) return 0;
return elem;
}
};

Expand Down Expand Up @@ -326,12 +327,13 @@ DENG2_PIMPL(DrawList)
}
}

Element *newElement(gl::Primitive primitive)
Element *newElement(Store &buffer, gl::Primitive primitive)
{
// This becomes the new last element.
last = (Element *) allocateData(sizeof(Element));
last->size = 0;

last->data.buffer = &buffer;
last->data.type = primitive;
last->data.indices = 0;
last->data.numIndices = 0;
Expand Down Expand Up @@ -395,7 +397,7 @@ DrawList &DrawList::write(gl::Primitive primitive, bool isLit, uint vertCount,
modColor = 0;
}

Instance::Element *elem = d->newElement(primitive);
Instance::Element *elem = d->newElement(RL_Store(), primitive);

// Is the geometry lit?
if(modTexture && !isLit)
Expand Down Expand Up @@ -435,14 +437,14 @@ DrawList &DrawList::write(gl::Primitive primitive, bool isLit, uint vertCount,
}

// Allocate geometry from the backing store.
uint base = RL_Store().allocateVertices(vertCount);
uint base = elem->data.buffer->allocateVertices(vertCount);

// Setup the indices.
d->allocateIndices(vertCount, base);

for(uint i = 0; i < vertCount; ++i)
{
RL_Store().posCoords[base + i] = posCoords[i];
elem->data.buffer->posCoords[base + i] = posCoords[i];

// Sky masked polys need nothing more.
if(d->group == SkyMaskGeom) continue;
Expand All @@ -451,25 +453,25 @@ DrawList &DrawList::write(gl::Primitive primitive, bool isLit, uint vertCount,
if(unit(TU_PRIMARY).hasTexture())
{
DENG2_ASSERT(texCoords != 0);
RL_Store().texCoords[Store::TCA_MAIN][base + i] = texCoords[i];
elem->data.buffer->texCoords[Store::TCA_MAIN][base + i] = texCoords[i];
}

// Secondary texture coordinates.
if(unit(TU_INTER).hasTexture())
{
DENG2_ASSERT(interTexCoords != 0);
RL_Store().texCoords[Store::TCA_BLEND][base + i] = interTexCoords[i];
elem->data.buffer->texCoords[Store::TCA_BLEND][base + i] = interTexCoords[i];
}

// First light texture coordinates.
if((elem->data.oneLight || elem->data.manyLights) && IS_MTEX_LIGHTS)
{
DENG2_ASSERT(modTexCoords != 0);
RL_Store().texCoords[Store::TCA_LIGHT][base + i] = modTexCoords[i];
elem->data.buffer->texCoords[Store::TCA_LIGHT][base + i] = modTexCoords[i];
}

// Color.
Vector4ub &color = RL_Store().colorCoords[base + i];
Vector4ub &color = elem->data.buffer->colorCoords[base + i];
if(colorCoords)
{
Vector4f const &srcColor = colorCoords[i];
Expand Down
7 changes: 0 additions & 7 deletions doomsday/client/src/render/drawlists.cpp
Expand Up @@ -20,7 +20,6 @@

#include "render/drawlists.h"

#include "render/rend_list.h" // RL_Store()
#include <de/Log>
#include <de/memoryzone.h>
#include <QMultiHash>
Expand Down Expand Up @@ -92,9 +91,6 @@ void DrawLists::clear()
clearLists(d->shadowHash);
clearLists(d->shinyHash);
d->skyMaskList.clear();

// Clear the global vertex buffer, also.
RL_Store().clear();
}

static void rewindLists(DrawListHash &hash)
Expand All @@ -113,9 +109,6 @@ void DrawLists::reset()
rewindLists(d->shadowHash);
rewindLists(d->shinyHash);
d->skyMaskList.rewind();

// Start reallocating storage from the global vertex buffer, also.
RL_Store().rewind();
}

// Prepare the final texture unit map for writing "normal" polygons, filling
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/r_main.cpp
Expand Up @@ -558,7 +558,7 @@ void R_Update()

// The rendering lists have persistent data that has changed during the
// re-initialization.
ClientApp::renderSystem().drawLists().clear();
ClientApp::renderSystem().clearDrawLists();

/// @todo fixme: Update the game title and the status.
#endif
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -356,7 +356,7 @@ void Rend_Init()

void Rend_Shutdown()
{
ClientApp::renderSystem().drawLists().clear();
ClientApp::renderSystem().clearDrawLists();
}

/// World/map renderer reset.
Expand Down Expand Up @@ -2711,7 +2711,7 @@ void Rend_RenderMap(Map &map)
if(!freezeRLs)
{
// Prepare for rendering.
ClientApp::renderSystem().drawLists().reset(); // Clear the lists for new geometry.
ClientApp::renderSystem().resetDrawLists(); // Clear the lists for new geometry.
C_ClearRanges(); // Clear the clipper.

// Recycle the vlight lists. Currently done here as the lists are
Expand Down
23 changes: 23 additions & 0 deletions doomsday/client/src/render/rendersystem.cpp
Expand Up @@ -20,12 +20,19 @@
#include "clientapp.h"
#include "render/rendersystem.h"

#include "render/rend_list.h" // RL_Store()

using namespace de;

DENG2_PIMPL(RenderSystem)
{
DrawLists drawLists;
Instance(Public *i) : Base(i) {}

~Instance()
{
self.clearDrawLists();
}
};

RenderSystem::RenderSystem() : d(new Instance(this))
Expand All @@ -36,6 +43,22 @@ void RenderSystem::timeChanged(Clock const &)
// Nothing to do.
}

void RenderSystem::clearDrawLists()
{
d->drawLists.clear();

// Clear the global vertex buffer, also.
RL_Store().clear();
}

void RenderSystem::resetDrawLists()
{
d->drawLists.reset();

// Start reallocating storage from the global vertex buffer, also.
RL_Store().rewind();
}

DrawLists &RenderSystem::drawLists()
{
return d->drawLists;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/world.cpp
Expand Up @@ -635,7 +635,7 @@ DENG2_PIMPL(World)
App_Materials().processCacheQueue();
LOG_INFO(String("Precaching completed in %1 seconds.").arg(begunPrecacheAt.since(), 0, 'g', 2));

ClientApp::renderSystem().drawLists().clear();
ClientApp::renderSystem().clearDrawLists();
R_InitRendPolyPools();
Rend_UpdateLightModMatrix();

Expand Down

0 comments on commit d17e0f3

Please sign in to comment.