Skip to content

Commit

Permalink
Refactor|Client|Map Renderer: Removed the old "RTU map" mechanism
Browse files Browse the repository at this point in the history
Now that we have an object-oriented interface to the draw lists this
sort of a mechanism is no longer useful.
  • Loading branch information
danij-deng committed Nov 7, 2013
1 parent bdd6a90 commit f600169
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 375 deletions.
3 changes: 3 additions & 0 deletions doomsday/client/include/render/drawlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class DrawList
GeomGroup group;
GLTextureUnit texunits[NUM_TEXTURE_UNITS];

Spec(GeomGroup group = UnlitGeom) : group(group)
{}

inline GLTextureUnit &unit(int index) {
DENG2_ASSERT(index >= 0 && index < NUM_TEXTURE_UNITS);
return texunits[index];
Expand Down
53 changes: 0 additions & 53 deletions doomsday/client/include/render/drawlists.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#ifndef DENG_CLIENT_RENDER_DRAWLISTS_H
#define DENG_CLIENT_RENDER_DRAWLISTS_H

#include "de_platform.h"
#include "api_gl.h" // DGLuint

#include "DrawList"
#include <de/Vector>
#include <QVarLengthArray>
Expand Down Expand Up @@ -70,54 +67,4 @@ class DrawLists
DENG2_PRIVATE(d)
};

struct GLTextureUnit;

/**
* Reset the texture unit write state back to the initial default values.
* Any mappings between logical units and preconfigured RTU states are
* cleared at this time.
*/
void RL_LoadDefaultRtus();

DrawListSpec const &RL_ListSpec(GeomGroup group);

/**
* Map the texture unit write state for the identified @a idx unit to
* @a rtu. This creates a reference to @a rtu which MUST continue to
* remain accessible until the mapping is subsequently cleared or
* changed (explicitly by call to RL_MapRtu/RL_LoadDefaultRtus, or,
* implicitly by customizing the unit configuration through one of the
* RL_RTU* family of functions (at which point a copy will be performed).
*/
void RL_MapRtu(uint idx, GLTextureUnit const *rtu);

/**
* Copy the configuration for the identified @a idx texture unit of
* the primitive writer's internal state from @a rtu.
*
* @param idx Logical index of the texture unit being configured.
* @param rtu Configured RTU state to copy the configuration from.
*/
void RL_CopyRtu(uint idx, GLTextureUnit const *rtu);

/// @todo Avoid modifying the RTU write state for the purposes of primitive
/// specific translations by implementing these as arguments to the
/// RL_Add* family of functions.

/// Change the scale property of the identified @a idx texture unit.
void RL_Rtu_SetScale(uint idx, de::Vector2f const &st);

/// Scale the offset and scale properties of the identified @a idx texture unit.
void RL_Rtu_Scale(uint idx, float scalar);
void RL_Rtu_ScaleST(uint idx, de::Vector2f const &st);

/// Change the offset property of the identified @a idx texture unit.
void RL_Rtu_SetOffset(uint idx, de::Vector2f const &st);

/// Translate the offset property of the identified @a idx texture unit.
void RL_Rtu_TranslateOffset(uint idx, de::Vector2f const &st);

/// Change the texture assigned to the identified @a idx texture unit.
void RL_Rtu_SetTextureUnmanaged(uint idx, DGLuint glName, int wrapS, int wrapT);

#endif // DENG_CLIENT_RENDER_DRAWLISTS_H
137 changes: 1 addition & 136 deletions doomsday/client/src/render/drawlists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@

using namespace de;

// Logical texture unit state. Used with RL_LoadDefaultRtus and RL_CopyRtu
static GLTextureUnit const rtuDefault;
static GLTextureUnit rtuState[NUM_TEXMAP_UNITS];
static GLTextureUnit const *rtuMap[NUM_TEXMAP_UNITS];

// GL texture unit state used during write. Global for performance reasons.
static DrawListSpec currentListSpec;

typedef QMultiHash<DGLuint, DrawList *> DrawListHash;

DENG2_PIMPL(DrawLists)
Expand Down Expand Up @@ -70,9 +62,7 @@ DENG2_PIMPL(DrawLists)
};

DrawLists::DrawLists() : d(new Instance(this))
{
RL_LoadDefaultRtus();
}
{}

static void clearAllLists(DrawListHash &hash)
{
Expand Down Expand Up @@ -251,128 +241,3 @@ int DrawLists::findAll(GeomGroup group, FoundLists &found)

return found.count();
}

static bool isWriteStateRTU(GLTextureUnit const *ptr)
{
// Note that the default texture unit is not considered to be part of the
// writeable state.
for(int i = 0; i < NUM_TEXMAP_UNITS; ++i)
{
if(ptr == &rtuState[i])
return true;
}
return false;
}

/**
* If the identified @a idx texture unit of the primitive writer has been mapped
* to an external address, insert a copy of it into our internal write state.
*
* To be called before customizing a texture unit begins to ensure we are
* modifying data we have ownership of!
*/
static void copyMappedRtuToState(uint idx)
{
DENG2_ASSERT(idx < NUM_TEXMAP_UNITS);
if(isWriteStateRTU(rtuMap[idx])) return;
RL_CopyRtu(idx, rtuMap[idx]);
}

DrawListSpec const &RL_ListSpec(GeomGroup group)
{
DrawListSpec &spec = currentListSpec;

spec.group = group;
if(group == ShineGeom)
{
spec.texunits[TU_PRIMARY] = *rtuMap[RTU_REFLECTION];
spec.texunits[TU_PRIMARY_DETAIL] = rtuDefault;
spec.texunits[TU_INTER] = *rtuMap[RTU_REFLECTION_MASK];
spec.texunits[TU_INTER_DETAIL] = rtuDefault;
}
else
{
spec.texunits[TU_PRIMARY] = *rtuMap[RTU_PRIMARY];
spec.texunits[TU_PRIMARY_DETAIL] = *rtuMap[RTU_PRIMARY_DETAIL];
spec.texunits[TU_INTER] = *rtuMap[RTU_INTER];
spec.texunits[TU_INTER_DETAIL] = *rtuMap[RTU_INTER_DETAIL];
}

return spec;
}

void RL_LoadDefaultRtus()
{
for(int i = 0; i < NUM_TEXMAP_UNITS; ++i)
{
rtuMap[i] = &rtuDefault;
}
}

void RL_MapRtu(uint idx, GLTextureUnit const *rtu)
{
DENG2_ASSERT(idx < NUM_TEXMAP_UNITS);
rtuMap[idx] = (rtu? rtu : &rtuDefault);
}

void RL_CopyRtu(uint idx, GLTextureUnit const *rtu)
{
DENG2_ASSERT(idx < NUM_TEXMAP_UNITS);
if(!rtu)
{
// Restore defaults.
rtuMap[idx] = &rtuDefault;
return;
}

rtuState[idx] = *rtu;
// Map this unit to that owned by the write state.
rtuMap[idx] = rtuState + idx;
}

void RL_Rtu_SetScale(uint idx, Vector2f const &st)
{
DENG2_ASSERT(idx < NUM_TEXMAP_UNITS);
copyMappedRtuToState(idx);
rtuState[idx].scale = st;
}

void RL_Rtu_Scale(uint idx, float scalar)
{
DENG2_ASSERT(idx < NUM_TEXMAP_UNITS);
copyMappedRtuToState(idx);
rtuState[idx].scale *= scalar;
rtuState[idx].offset *= scalar;
}

void RL_Rtu_ScaleST(uint idx, Vector2f const &st)
{
DENG2_ASSERT(idx < NUM_TEXMAP_UNITS);
copyMappedRtuToState(idx);
rtuState[idx].scale *= st;
rtuState[idx].offset *= st;
}

void RL_Rtu_SetOffset(uint idx, Vector2f const &xy)
{
DENG2_ASSERT(idx < NUM_TEXMAP_UNITS);
copyMappedRtuToState(idx);
rtuState[idx].offset = xy;
}

void RL_Rtu_TranslateOffset(uint idx, Vector2f const &xy)
{
DENG2_ASSERT(idx < NUM_TEXMAP_UNITS);
copyMappedRtuToState(idx);
rtuState[idx].offset += xy;
}

void RL_Rtu_SetTextureUnmanaged(uint idx, DGLuint glName, int wrapS, int wrapT)
{
DENG2_ASSERT(idx < NUM_TEXMAP_UNITS);
copyMappedRtuToState(idx);
rtuState[idx].textureGLName = glName;
rtuState[idx].textureGLWrapS = wrapS;
rtuState[idx].textureGLWrapT = wrapT;
rtuState[idx].textureVariant = 0;
}
48 changes: 24 additions & 24 deletions doomsday/client/src/render/rend_dynlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,39 +94,39 @@ static void drawDynlight(TexProjection const &tp, renderlightprojectionparams_t
std::memcpy(rvertices, parm.rvertices, sizeof(Vector3f) * parm.numVertices);
}

RL_LoadDefaultRtus();
RL_Rtu_SetTextureUnmanaged(RTU_PRIMARY, tp.texture,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
DrawListSpec listSpec;
listSpec.group = LightGeom;
listSpec.texunits[TU_PRIMARY].textureGLName = tp.texture;
listSpec.texunits[TU_PRIMARY].textureGLWrapS = GL_CLAMP_TO_EDGE;
listSpec.texunits[TU_PRIMARY].textureGLWrapT = GL_CLAMP_TO_EDGE;

DrawList &lightList = ClientApp::renderSystem().drawLists().find(listSpec);

if(mustSubdivide)
{
WallEdge const &leftEdge = *parm.wall.leftEdge;
WallEdge const &rightEdge = *parm.wall.rightEdge;

ClientApp::renderSystem().drawLists()
.find(RL_ListSpec(LightGeom))
.write(gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, 3 + rightEdge.divisionCount(),
rvertices + 3 + leftEdge.divisionCount(),
rcolors + 3 + leftEdge.divisionCount(),
rtexcoords + 3 + leftEdge.divisionCount())
.write(gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, 3 + leftEdge.divisionCount(),
rvertices, rcolors, rtexcoords);
lightList.write(gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, 3 + rightEdge.divisionCount(),
rvertices + 3 + leftEdge.divisionCount(),
rcolors + 3 + leftEdge.divisionCount(),
rtexcoords + 3 + leftEdge.divisionCount())
.write(gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, 3 + leftEdge.divisionCount(),
rvertices, rcolors, rtexcoords);
}
else
{
ClientApp::renderSystem().drawLists()
.find(RL_ListSpec(LightGeom))
.write(parm.isWall? gl::TriangleStrip : gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, parm.numVertices,
rvertices, rcolors, rtexcoords);
lightList.write(parm.isWall? gl::TriangleStrip : gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, parm.numVertices,
rvertices, rcolors, rtexcoords);
}

R_FreeRendVertices(rvertices);
Expand Down
52 changes: 25 additions & 27 deletions doomsday/client/src/render/rend_fakeradio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,13 @@ static void drawWallSectionShadow(Vector3f const *origVertices,
if(rendFakeRadio != 2)
{
// Write multiple polys depending on rend params.
RL_LoadDefaultRtus();
RL_Rtu_SetTextureUnmanaged(RTU_PRIMARY, GL_PrepareLSTexture(wsParms.texture),
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
DrawListSpec listSpec;
listSpec.group = ShadowGeom;
listSpec.texunits[TU_PRIMARY].textureGLName = GL_PrepareLSTexture(wsParms.texture);
listSpec.texunits[TU_PRIMARY].textureGLWrapS = GL_CLAMP_TO_EDGE;
listSpec.texunits[TU_PRIMARY].textureGLWrapT = GL_CLAMP_TO_EDGE;

DrawList &shadowList = ClientApp::renderSystem().drawLists().find(listSpec);

if(mustSubdivide)
{
Expand All @@ -1057,32 +1061,28 @@ static void drawWallSectionShadow(Vector3f const *origVertices,
R_DivTexCoords(rtexcoords, origTexCoords, leftEdge, rightEdge);
R_DivVertColors(rcolors, origColors, leftEdge, rightEdge);

ClientApp::renderSystem().drawLists()
.find(RL_ListSpec(ShadowGeom))
.write(gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, 3 + rightEdge.divisionCount(),
rvertices + 3 + leftEdge.divisionCount(),
rcolors + 3 + leftEdge.divisionCount(),
rtexcoords + 3 + leftEdge.divisionCount())
.write(gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, 3 + leftEdge.divisionCount(),
rvertices, rcolors, rtexcoords);
shadowList.write(gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, 3 + rightEdge.divisionCount(),
rvertices + 3 + leftEdge.divisionCount(),
rcolors + 3 + leftEdge.divisionCount(),
rtexcoords + 3 + leftEdge.divisionCount())
.write(gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, 3 + leftEdge.divisionCount(),
rvertices, rcolors, rtexcoords);

R_FreeRendVertices(rvertices);
}
else
{
ClientApp::renderSystem().drawLists()
.find(RL_ListSpec(ShadowGeom))
.write(gl::TriangleStrip,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, 4,
origVertices, rcolors, rtexcoords);
shadowList.write(gl::TriangleStrip,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
0, 4,
origVertices, rcolors, rtexcoords);
}
}

Expand Down Expand Up @@ -1252,10 +1252,8 @@ static void writeShadowSection2(ShadowEdge const &leftEdge, ShadowEdge const &ri

if(rendFakeRadio == 2) return;

RL_LoadDefaultRtus();

ClientApp::renderSystem().drawLists()
.find(RL_ListSpec(renderWireframe? UnlitGeom : ShadowGeom))
.find(DrawListSpec(renderWireframe? UnlitGeom : ShadowGeom))
.write(gl::TriangleFan,
BM_NORMAL, Vector2f(1, 1), Vector2f(0, 0),
Vector2f(1, 1), Vector2f(0, 0),
Expand Down
Loading

0 comments on commit f600169

Please sign in to comment.