Skip to content

Commit

Permalink
Renderer|DrawList|Client: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 13, 2015
1 parent 784e2ff commit 02e0c2b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 58 deletions.
37 changes: 22 additions & 15 deletions doomsday/apps/client/include/render/drawlist.h
Expand Up @@ -126,10 +126,14 @@ class DrawList
DrawList(Spec const &spec);

/**
* Write indices for a geometry primitive to the list.
* Write indices for a (buffered) geometry primitive to the list.
*
* @param buffer Geometry buffer containing the primitive to write. It is the caller's
* responsibility to ensure this data remains accessible and valid while
* this DrawList is used (i.e., until a @ref clear(), rewind() or the
* list itself is destroyed).
* @param primitive Type identifier for the GL primitive being written.
* @param indices Indices for the vertex elements in the backing store.
* @param indices Indices for the vertex elements in @a buffer.
* @param blendMode
* @param oneLight
* @param manyLights
Expand All @@ -140,11 +144,16 @@ class DrawList
* @param modTexture GL-name of the modulation texture; otherwise @c 0.
* @param modColor Modulation color.
*/
DrawList &write(de::gl::Primitive primitive, Indices const &indices,
blendmode_t blendMode, bool oneLight, bool manyLights,
de::Vector2f const &texScale, de::Vector2f const &texOffset,
de::Vector2f const &detailTexScale, de::Vector2f const &detailTexOffset,
GLuint modTexture = 0, de::Vector3f const &modColor = de::Vector3f());
DrawList &write(Store const &buffer, de::gl::Primitive primitive, Indices const &indices,
blendmode_t blendMode = BM_NORMAL,
bool oneLight = false,
bool manyLights = false,
de::Vector2f const &texScale = de::Vector2f(1, 1),
de::Vector2f const &texOffset = de::Vector2f(0, 0),
de::Vector2f const &detailTexScale = de::Vector2f(1, 1),
de::Vector2f const &detailTexOffset = de::Vector2f(0, 0),
GLuint modTexture = 0,
de::Vector3f const &modColor = de::Vector3f());

void draw(DrawMode mode, TexUnitMap const &texUnitMap) const;

Expand All @@ -154,23 +163,21 @@ class DrawList
bool isEmpty() const;

/**
* Clear the list of all buffered GL commands, returning it to the default,
* empty state.
* Clear the list of all buffered GL commands, returning it to the default, empty state.
*/
void clear();

/**
* Return the read/write cursor to the beginning of the list, retaining all
* allocated storage for buffered GL commands so that it can be reused.
* Return the read/write cursor to the beginning of the list, retaining all allocated storage for
* buffered GL commands so that it can be reused.
*
* To be called at the beginning of a new render frame before any geometry
* is written to the list.
* To be called at the beginning of a new render frame before any geometry is written to the list.
*/
void rewind();

/**
* Provides mutable access to the list's specification. Note that any changes
* to this configuration will affect @em all geometry in the list.
* Provides mutable access to the list's specification. Note that any changes to this configuration
* will affect @em all geometry in the list.
*/
Spec &spec();

Expand Down
8 changes: 5 additions & 3 deletions doomsday/apps/client/src/render/drawlist.cpp
Expand Up @@ -78,7 +78,7 @@ DENG2_PIMPL(DrawList)
}

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

// Element indices into the global backing store for the geometry.
Expand All @@ -104,6 +104,8 @@ DENG2_PIMPL(DrawList)
*/
void draw(DrawConditions const &conditions, TexUnitMap const &texUnitMap)
{
DENG2_ASSERT(buffer);

if(conditions & SetLightEnv)
{
// Use the correct texture and color for the light.
Expand Down Expand Up @@ -731,7 +733,7 @@ bool DrawList::isEmpty() const
return d->last == nullptr;
}

DrawList &DrawList::write(gl::Primitive primitive, DrawList::Indices const &indices,
DrawList &DrawList::write(Store const &buffer, gl::Primitive primitive, DrawList::Indices const &indices,
blendmode_t blendMode, bool oneLight, bool manyLights,
Vector2f const &texScale, Vector2f const &texOffset,
Vector2f const &detailTexScale, Vector2f const &detailTexOffset,
Expand All @@ -750,7 +752,7 @@ DrawList &DrawList::write(gl::Primitive primitive, DrawList::Indices const &indi

// Vertex buffer element indices for the primitive are stored in the list.
/// @note That 'last' may be reallocated during allocateData() - use a temporary variable.
d->last->data.buffer = &ClientApp::renderSystem().buffer();
d->last->data.buffer = &buffer;
d->last->data.type = primitive;
d->last->data.numIndices = indices.count();
auto *lti = (duint *) d->allocateData(sizeof(duint) * d->last->data.numIndices);
Expand Down
12 changes: 4 additions & 8 deletions doomsday/apps/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1032,8 +1032,7 @@ static void drawWallSectionShadow(Vector3f const *posCoords, WallEdge const &lef
buffer.colorCoords [indices[i]] = (colors [numLeftVerts + i] * 255).toVector4ub();
buffer.texCoords[0][indices[i]] = texCoords[numLeftVerts + i];
}
shadowList.write(gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
shadowList.write(buffer, gl::TriangleFan, indices);
}
{
duint base = buffer.allocateVertices(numLeftVerts);
Expand All @@ -1046,8 +1045,7 @@ static void drawWallSectionShadow(Vector3f const *posCoords, WallEdge const &lef
buffer.colorCoords [indices[i]] = (colors [i] * 255).toVector4ub();
buffer.texCoords[0][indices[i]] = texCoords[i];
}
shadowList.write(gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
shadowList.write(buffer, gl::TriangleFan, indices);
}

R_FreeRendVertices(rvertices);
Expand All @@ -1065,8 +1063,7 @@ static void drawWallSectionShadow(Vector3f const *posCoords, WallEdge const &lef
buffer.colorCoords [indices[i]] = (colors [i] * 255).toVector4ub();
buffer.texCoords[0][indices[i]] = texCoords[i];
}
shadowList.write(gl::TriangleStrip, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
shadowList.write(buffer, gl::TriangleStrip, indices);
}
}

Expand Down Expand Up @@ -1234,8 +1231,7 @@ static void writeShadowSection2(ShadowEdge const &leftEdge, ShadowEdge const &ri
buffer.colorCoords[indices[i]] = (rcolors[i] * 255).toVector4ub();
}
rendSys().drawLists().find(DrawListSpec(renderWireframe? UnlitGeom : ShadowGeom))
.write(gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
.write(buffer, gl::TriangleFan, indices);
}

static void writeShadowSection(dint planeIndex, LineSide const &side, dfloat shadowDark)
Expand Down
57 changes: 25 additions & 32 deletions doomsday/apps/client/src/render/rend_main.cpp
Expand Up @@ -1424,8 +1424,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.colorCoords [indices[i]] = (verts.color[numLeftVerts + i] * 255).toVector4ub();
buffer.texCoords[0][indices[i]] = verts.tex[numLeftVerts + i];
}
lightList.write(gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
lightList.write(buffer, gl::TriangleFan, indices);
}
{
duint base = buffer.allocateVertices(numLeftVerts);
Expand All @@ -1438,8 +1437,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.colorCoords [indices[i]] = (verts.color[i] * 255).toVector4ub();
buffer.texCoords[0][indices[i]] = verts.tex[i];
}
lightList.write(gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
lightList.write(buffer, gl::TriangleFan, indices);
}
}
else
Expand All @@ -1455,8 +1453,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.colorCoords [indices[i]] = (verts.color[i] * 255).toVector4ub();
buffer.texCoords[0][indices[i]] = verts.tex[i];
}
lightList.write(p.isWall ? gl::TriangleStrip : gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
lightList.write(buffer, p.isWall ? gl::TriangleStrip : gl::TriangleFan, indices);
}

// We're done with the geometry.
Expand Down Expand Up @@ -1524,8 +1521,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.colorCoords [indices[i]] = (verts.color[numLeftVerts + i] * 255).toVector4ub();
buffer.texCoords[0][indices[i]] = verts.tex[numLeftVerts + i];
}
shadowList.write(gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
shadowList.write(buffer, gl::TriangleFan, indices);
}
{
duint base = buffer.allocateVertices(numLeftVerts);
Expand All @@ -1538,8 +1534,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.colorCoords [indices[i]] = (verts.color[i] * 255).toVector4ub();
buffer.texCoords[0][indices[i]] = verts.tex[i];
}
shadowList.write(gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
shadowList.write(buffer, gl::TriangleFan, indices);
}
}
else
Expand All @@ -1555,8 +1550,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.colorCoords [indices[i]] = (verts.color[i] * 255).toVector4ub();
buffer.texCoords[0][indices[i]] = verts.tex[i];
}
shadowList.write(p.isWall ? gl::TriangleStrip : gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
shadowList.write(buffer, p.isWall ? gl::TriangleStrip : gl::TriangleFan, indices);
}

// We're done with the geometry.
Expand Down Expand Up @@ -1617,8 +1611,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
indices[i] = base + i;
buffer.posCoords[indices[i]] = verts.pos[numLeftVerts + i];
}
skyMaskList.write(gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
skyMaskList.write(buffer, gl::TriangleFan, indices);
}
{
duint base = buffer.allocateVertices(numLeftVerts);
Expand All @@ -1629,8 +1622,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
indices[i] = base + i;
buffer.posCoords[indices[i]] = verts.pos[i];
}
skyMaskList.write(gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
skyMaskList.write(buffer, gl::TriangleFan, indices);
}
}
else
Expand Down Expand Up @@ -1723,7 +1715,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.modCoords[indices[i]] = modTexCoords[numLeftVerts + i];
}
}
drawList.write(gl::TriangleFan, indices, BM_NORMAL, oneLight, manyLights,
drawList.write(buffer, gl::TriangleFan, indices, BM_NORMAL, oneLight, manyLights,
listSpec.unit(TU_PRIMARY ).scale,
listSpec.unit(TU_PRIMARY ).offset,
listSpec.unit(TU_PRIMARY_DETAIL).scale,
Expand Down Expand Up @@ -1761,7 +1753,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.modCoords[indices[i]] = modTexCoords[i];
}
}
drawList.write(gl::TriangleFan, indices, BM_NORMAL, oneLight, manyLights,
drawList.write(buffer, gl::TriangleFan, indices, BM_NORMAL, oneLight, manyLights,
listSpec.unit(TU_PRIMARY ).scale,
listSpec.unit(TU_PRIMARY ).offset,
listSpec.unit(TU_PRIMARY_DETAIL).scale,
Expand All @@ -1784,8 +1776,7 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.posCoords[indices[i]] = verts.pos[i];
}
rendSys().drawLists().find(DrawListSpec(SkyMaskGeom))
.write(p.isWall? gl::TriangleStrip : gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
.write(buffer, p.isWall? gl::TriangleStrip : gl::TriangleFan, indices);
}
else
{
Expand Down Expand Up @@ -1877,7 +1868,8 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
}
}
rendSys().drawLists().find(listSpec)
.write(p.isWall? gl::TriangleStrip : gl::TriangleFan, indices, BM_NORMAL, oneLight, manyLights,
.write(buffer, p.isWall? gl::TriangleStrip : gl::TriangleFan, indices,
BM_NORMAL, oneLight, manyLights,
listSpec.unit(TU_PRIMARY ).scale,
listSpec.unit(TU_PRIMARY ).offset,
listSpec.unit(TU_PRIMARY_DETAIL).scale,
Expand Down Expand Up @@ -1963,7 +1955,8 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.texCoords[1][indices[i]] = verts.tex[numLeftVerts + i];
}
}
shineList.write(gl::TriangleFan, indices, matAnimator.shineBlendMode(), false /*not lit*/, false /*not lit*/,
shineList.write(buffer, gl::TriangleFan, indices,
matAnimator.shineBlendMode(), false /*not lit*/, false /*not lit*/,
listSpec.unit(TU_INTER).scale, listSpec.unit(TU_INTER).offset,
Vector2f(1, 1), Vector2f(0, 0));
}
Expand All @@ -1982,7 +1975,8 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.texCoords[1][indices[i]] = verts.tex[i];
}
}
shineList.write(gl::TriangleFan, indices, matAnimator.shineBlendMode(), false /*not lit*/, false /*not lit*/,
shineList.write(buffer, gl::TriangleFan, indices,
matAnimator.shineBlendMode(), false /*not lit*/, false /*not lit*/,
listSpec.unit(TU_INTER).scale, listSpec.unit(TU_INTER).offset,
Vector2f(1, 1), Vector2f(0, 0));
}
Expand All @@ -2004,7 +1998,8 @@ static bool renderWorldPoly(Vector3f const *rvertices, duint numVertices,
buffer.texCoords[1][indices[i]] = verts.tex[i];
}
}
shineList.write(p.isWall? gl::TriangleStrip : gl::TriangleFan, indices, matAnimator.shineBlendMode(), false /*not lit*/, false /*not lit*/,
shineList.write(buffer, p.isWall? gl::TriangleStrip : gl::TriangleFan, indices,
matAnimator.shineBlendMode(), false /*not lit*/, false /*not lit*/,
listSpec.unit(TU_INTER).scale, listSpec.unit(TU_INTER).offset,
Vector2f(1, 1), Vector2f(0, 0));
}
Expand Down Expand Up @@ -2920,8 +2915,7 @@ static void writeSkyMaskStrip(dint vertCount, Vector3f const *posCoords, Vector2
buffer.posCoords[indices[i]] = posCoords[i];
}
rendSys().drawLists().find(DrawListSpec(SkyMaskGeom))
.write(gl::TriangleStrip, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
.write(buffer, gl::TriangleStrip, indices);
}
else
{
Expand Down Expand Up @@ -2957,7 +2951,8 @@ static void writeSkyMaskStrip(dint vertCount, Vector3f const *posCoords, Vector2
}

rendSys().drawLists().find(listSpec)
.write(gl::TriangleStrip, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
.write(buffer, gl::TriangleStrip, indices,
BM_NORMAL, false /*not lit*/, false /*not lit*/,
listSpec.unit(TU_PRIMARY ).scale,
listSpec.unit(TU_PRIMARY ).offset,
listSpec.unit(TU_PRIMARY_DETAIL).scale,
Expand Down Expand Up @@ -3137,8 +3132,7 @@ static void writeSubspaceSkyMaskCap(dint skyCap)
}

rendSys().drawLists().find(DrawListSpec(SkyMaskGeom))
.write(gl::TriangleFan, indices, BM_NORMAL, false /*not lit*/, false /*not lit*/,
Vector2f(1, 1), Vector2f(0, 0), Vector2f(1, 1), Vector2f(0, 0));
.write(buffer, gl::TriangleFan, indices);

R_FreeRendVertices(posCoords);
}
Expand Down Expand Up @@ -3214,15 +3208,14 @@ static bool coveredOpenRange(HEdge &hedge, coord_t middleBottomZ, coord_t middle
xbottom += middle.materialOriginSmoothed().y;
xtop += middle.materialOriginSmoothed().y;

middleCoversOpening = (middleTopZ >= xtop &&
middleBottomZ <= xbottom);
middleCoversOpening = (middleTopZ >= xtop && middleBottomZ <= xbottom);
}

if(wroteOpaqueMiddle && middleCoversOpening)
return true;

if( (bceil <= ffloor &&
(front.top().hasMaterial() || front.middle().hasMaterial()))
(front.top ().hasMaterial() || front.middle().hasMaterial()))
|| (bfloor >= fceil &&
(front.bottom().hasMaterial() || front.middle().hasMaterial())))
{
Expand Down

0 comments on commit 02e0c2b

Please sign in to comment.