Skip to content

Commit

Permalink
Refactor|Map Renderer: RenderSystem has ownership of the primary geom…
Browse files Browse the repository at this point in the history
…etry buffer
  • Loading branch information
danij-deng committed Nov 6, 2013
1 parent d17e0f3 commit ae664d0
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 108 deletions.
35 changes: 0 additions & 35 deletions doomsday/client/include/render/rend_list.h
Expand Up @@ -20,41 +20,6 @@
#ifndef DENG_CLIENT_RENDER_DRAWLIST_RENDERER_H
#define DENG_CLIENT_RENDER_DRAWLIST_RENDERER_H

#include <de/Vector>

/**
* Geometry backing store (arrays).
*/
struct Store
{
/// Texture coordinate array indices.
enum
{
TCA_MAIN, // Main texture.
TCA_BLEND, // Blendtarget texture.
TCA_LIGHT, // Dynlight texture.
NUM_TEXCOORD_ARRAYS
};

de::Vector3f *posCoords;
de::Vector2f *texCoords[NUM_TEXCOORD_ARRAYS];
de::Vector4ub *colorCoords;

Store();
~Store();

void rewind();

void clear();

uint allocateVertices(uint count);

private:
uint vertCount, vertMax;
};

Store &RL_Store();

void RL_RenderAllLists();

#endif // DENG_CLIENT_RENDER_DRAWLIST_RENDERER_H
38 changes: 38 additions & 0 deletions doomsday/client/include/render/rendersystem.h
Expand Up @@ -20,8 +20,41 @@
#define CLIENT_RENDERSYSTEM_H

#include <de/System>
#include <de/Vector>
#include "DrawLists"

/**
* Geometry backing store (arrays).
* @todo Replace with GLBuffer -ds
*/
struct Store
{
/// Texture coordinate array indices.
enum
{
TCA_MAIN, // Main texture.
TCA_BLEND, // Blendtarget texture.
TCA_LIGHT, // Dynlight texture.
NUM_TEXCOORD_ARRAYS
};

de::Vector3f *posCoords;
de::Vector2f *texCoords[NUM_TEXCOORD_ARRAYS];
de::Vector4ub *colorCoords;

Store();
~Store();

void rewind();

void clear();

uint allocateVertices(uint count);

private:
uint vertCount, vertMax;
};

/**
* Renderer subsystems, draw lists, etc... @ingroup render
*/
Expand All @@ -30,6 +63,11 @@ class RenderSystem : public de::System
public:
RenderSystem();

/**
* Provides access to the central map geometry buffer.
*/
Store &buffer();

void clearDrawLists();

void resetDrawLists();
Expand Down
5 changes: 3 additions & 2 deletions doomsday/client/src/render/drawlist.cpp
Expand Up @@ -21,8 +21,8 @@
#include "render/drawlist.h"

#include "DrawLists"
#include "render/rend_list.h" // RL_Store()
#include "render/rend_main.h"
#include "clientapp.h"
#include <de/concurrency.h>
#include <de/memoryzone.h>

Expand Down Expand Up @@ -397,7 +397,8 @@ DrawList &DrawList::write(gl::Primitive primitive, bool isLit, uint vertCount,
modColor = 0;
}

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

// Is the geometry lit?
if(modTexture && !isLit)
Expand Down
64 changes: 0 additions & 64 deletions doomsday/client/src/render/rend_list.cpp
Expand Up @@ -35,70 +35,6 @@

using namespace de;

Store::Store() : posCoords(0), colorCoords(0), vertCount(0), vertMax(0)
{
zap(texCoords);
}

Store::~Store()
{
clear();
}

void Store::rewind()
{
vertCount = 0;
}

void Store::clear()
{
vertCount = vertMax = 0;

M_Free(posCoords); posCoords = 0;
M_Free(colorCoords); colorCoords = 0;

for(int i = 0; i < NUM_TEXCOORD_ARRAYS; ++i)
{
M_Free(texCoords[i]); texCoords[i] = 0;
}
}

uint Store::allocateVertices(uint count)
{
uint const base = vertCount;

// Do we need to allocate more memory?
vertCount += count;
while(vertCount > vertMax)
{
if(vertMax == 0)
{
vertMax = 16;
}
else
{
vertMax *= 2;
}

posCoords = (Vector4f *) M_Realloc(posCoords, sizeof(*posCoords) * vertMax);
colorCoords = (Vector4ub *) M_Realloc(colorCoords, sizeof(*colorCoords) * vertMax);
for(int i = 0; i < NUM_TEXCOORD_ARRAYS; ++i)
{
texCoords[i] = (Vector2f *) M_Realloc(texCoords[i], sizeof(Vector2f) * vertMax);
}
}

return base;
}

/// The central geometry store.
static Store store;

Store &RL_Store()
{
return store;
}

/// Logical drawing modes.
enum DrawMode
{
Expand Down
73 changes: 66 additions & 7 deletions doomsday/client/src/render/rendersystem.cpp
Expand Up @@ -21,18 +21,72 @@
#include "render/rendersystem.h"

#include "render/rend_list.h" // RL_Store()
#include <de/memory.h>

using namespace de;

DENG2_PIMPL(RenderSystem)
Store::Store() : posCoords(0), colorCoords(0), vertCount(0), vertMax(0)
{
DrawLists drawLists;
Instance(Public *i) : Base(i) {}
zap(texCoords);
}

Store::~Store()
{
clear();
}

void Store::rewind()
{
vertCount = 0;
}

void Store::clear()
{
vertCount = vertMax = 0;

~Instance()
M_Free(posCoords); posCoords = 0;
M_Free(colorCoords); colorCoords = 0;

for(int i = 0; i < NUM_TEXCOORD_ARRAYS; ++i)
{
self.clearDrawLists();
M_Free(texCoords[i]); texCoords[i] = 0;
}
}

uint Store::allocateVertices(uint count)
{
uint const base = vertCount;

// Do we need to allocate more memory?
vertCount += count;
while(vertCount > vertMax)
{
if(vertMax == 0)
{
vertMax = 16;
}
else
{
vertMax *= 2;
}

posCoords = (Vector4f *) M_Realloc(posCoords, sizeof(*posCoords) * vertMax);
colorCoords = (Vector4ub *) M_Realloc(colorCoords, sizeof(*colorCoords) * vertMax);
for(int i = 0; i < NUM_TEXCOORD_ARRAYS; ++i)
{
texCoords[i] = (Vector2f *) M_Realloc(texCoords[i], sizeof(Vector2f) * vertMax);
}
}

return base;
}

DENG2_PIMPL(RenderSystem)
{
Store buffer; ///< Primary map geometry buffer.
DrawLists drawLists;

Instance(Public *i) : Base(i) {}
};

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

Store &RenderSystem::buffer()
{
return d->buffer;
}

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

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

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

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

DrawLists &RenderSystem::drawLists()
Expand Down

0 comments on commit ae664d0

Please sign in to comment.