From 02e0c2b32e7b6da9b4111a36985e40dae0edd596 Mon Sep 17 00:00:00 2001 From: danij Date: Sat, 13 Jun 2015 20:12:47 +0100 Subject: [PATCH] Renderer|DrawList|Client: Cleanup --- .../apps/client/include/render/drawlist.h | 37 +++++++----- doomsday/apps/client/src/render/drawlist.cpp | 8 ++- .../apps/client/src/render/rend_fakeradio.cpp | 12 ++-- doomsday/apps/client/src/render/rend_main.cpp | 57 ++++++++----------- 4 files changed, 56 insertions(+), 58 deletions(-) diff --git a/doomsday/apps/client/include/render/drawlist.h b/doomsday/apps/client/include/render/drawlist.h index 242caa1be9..e1b7ff3fa5 100644 --- a/doomsday/apps/client/include/render/drawlist.h +++ b/doomsday/apps/client/include/render/drawlist.h @@ -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 @@ -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; @@ -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(); diff --git a/doomsday/apps/client/src/render/drawlist.cpp b/doomsday/apps/client/src/render/drawlist.cpp index a806b2684f..51ddf2e3e9 100644 --- a/doomsday/apps/client/src/render/drawlist.cpp +++ b/doomsday/apps/client/src/render/drawlist.cpp @@ -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. @@ -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. @@ -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, @@ -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); diff --git a/doomsday/apps/client/src/render/rend_fakeradio.cpp b/doomsday/apps/client/src/render/rend_fakeradio.cpp index 713ee67eac..f799ec8b5c 100644 --- a/doomsday/apps/client/src/render/rend_fakeradio.cpp +++ b/doomsday/apps/client/src/render/rend_fakeradio.cpp @@ -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); @@ -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); @@ -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); } } @@ -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) diff --git a/doomsday/apps/client/src/render/rend_main.cpp b/doomsday/apps/client/src/render/rend_main.cpp index 28677c36fe..99a92fba2b 100644 --- a/doomsday/apps/client/src/render/rend_main.cpp +++ b/doomsday/apps/client/src/render/rend_main.cpp @@ -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); @@ -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 @@ -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. @@ -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); @@ -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 @@ -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. @@ -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); @@ -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 @@ -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, @@ -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, @@ -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 { @@ -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, @@ -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)); } @@ -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)); } @@ -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)); } @@ -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 { @@ -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, @@ -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); } @@ -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()))) {