Skip to content

Commit

Permalink
Continued renderer clean up:
Browse files Browse the repository at this point in the history
* Revised dynlight projection interface, DL_ProjectOnSurface is now used for all lumobj-lit world surfaces.
* Removed redundant paramaters from RL_AddPoly.
* Further cleaned up of section section drawing.
* Only call Rend_RadioUpdateLinedef once per frame per drawn seg (was called for each seg section).
  • Loading branch information
danij committed Jan 20, 2009
1 parent df56f67 commit c80bb63
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 238 deletions.
14 changes: 9 additions & 5 deletions doomsday/engine/portable/include/rend_dyn.h
Expand Up @@ -36,6 +36,12 @@

#define MAX_GLOWHEIGHT (1024.0f) // Absolute max glow height.

// Flags for DL_ProjectOnSurface
#define DLF_SORT_LUMADSC 0x1 // Sort dynlights by luma, brightest to dullest.
#define DLF_NO_PLANAR 0x2 // Surface is not lit by planar lights.
#define DLF_TEX_FLOOR 0x4 // Prefer the "floor" slot when picking textures.
#define DLF_TEX_CEILING 0x8 // Prefer the "ceiling" slot when picking textures.

/**
* The data of a projected dynamic light is stored in this structure.
* A list of these is associated with each surface lit by texture mapped lights
Expand All @@ -60,11 +66,9 @@ void DL_InitForMap(void);
void DL_InitForNewFrame(void);

// Action.
uint DL_ProcessSegSection(seg_t* seg, subsector_t* ssec,
float bottom, float top,
boolean sortBrightestFirst);
uint DL_ProcessSubSectorPlane(subsector_t* ssec, uint plane);

uint DL_ProjectOnSurface(subsector_t* ssec, const pvec3_t topLeft,
const pvec3_t bottomRight,
const float* normal, byte flags);
// Helpers.
boolean DL_ListIterator(uint listIdx, void* data,
boolean (*func) (const dynlight_t*, void*));
Expand Down
5 changes: 2 additions & 3 deletions doomsday/engine/portable/include/rend_list.h
Expand Up @@ -56,7 +56,7 @@ typedef struct rtexmapuint_s {
int magMode;
float blend;
float scale[2], offset[2]; // For use with the texture matrix.
blendmode_t blendMode; // Currently used only with reflection.
blendmode_t blendMode;
} rtexmapunit_t;

extern int renderTextures;
Expand All @@ -83,8 +83,7 @@ void RL_AddPoly(primtype_t type, rendpolytype_t polyType,
const rcolor_t* rcolors,
uint numVertices, uint numLights,
DGLuint modTex, float modColor[3],
const rtexmapunit_t rTU[NUM_TEXMAP_UNITS],
blendmode_t blendMode /*temp*/);
const rtexmapunit_t rTU[NUM_TEXMAP_UNITS]);
void RL_RenderAllLists(void);

#endif
104 changes: 34 additions & 70 deletions doomsday/engine/portable/src/rend_dyn.c
Expand Up @@ -425,12 +425,9 @@ static boolean genTexCoords(const pvec3_t point, float scale,
typedef struct surfacelumobjiterparams_s {
vec3_t v1, v2;
vec3_t normal;
boolean sortBrightestFirst;
boolean haveList;
uint listIdx;
boolean isPlane;
byte useTex; /* For omni lights:
@c 0 = side tex, @c 1 = floortex, @c 2 = ceiltex. */
byte flags; // DLF_* flags.
} surfacelumobjiterparams_t;

boolean DLIT_SurfaceLumobjContacts(void* ptr, void* data)
Expand All @@ -454,13 +451,12 @@ boolean DLIT_SurfaceLumobjContacts(void* ptr, void* data)
if(LO_IsHidden(lumIdx, viewPlayer - ddPlayers))
return true;

switch(params->useTex)
{
case 0:
default: tex = LUM_OMNI(lum)->tex; break;
case 1: tex = LUM_OMNI(lum)->floorTex; break;
case 2: tex = LUM_OMNI(lum)->ceilTex; break;
}
if(params->flags & DLF_TEX_CEILING)
tex = LUM_OMNI(lum)->ceilTex;
else if(params->flags & DLF_TEX_FLOOR)
tex = LUM_OMNI(lum)->floorTex;
else
tex = LUM_OMNI(lum)->tex;

lightRGB = LUM_OMNI(lum)->color;

Expand Down Expand Up @@ -519,7 +515,7 @@ boolean DLIT_SurfaceLumobjContacts(void* ptr, void* data)
break;

case LT_PLANE:
if(!params->isPlane) // Plannar glows don't currently affect planes.
if(!(params->flags & DLF_NO_PLANAR))
tex = LUM_PLANE(lum)->tex;

if(tex)
Expand All @@ -546,8 +542,10 @@ boolean DLIT_SurfaceLumobjContacts(void* ptr, void* data)
// Got a list for this surface yet?
if(!params->haveList)
{
params->listIdx =
newDynlightList(params->sortBrightestFirst);
boolean sortBrightestFirst =
(params->flags & DLF_SORT_LUMADSC)? true : false;

params->listIdx = newDynlightList(sortBrightestFirst);
params->haveList = true;
}

Expand All @@ -571,39 +569,26 @@ static uint processSubSector(subsector_t* ssec, surfacelumobjiterparams_t* param
}

/**
* Process dynamic lights for the specified seg.
* Project all lumobjs affecting the given quad (world space), calculate
* coordinates (in texture space) then store into a new list of dynlights.
*
* \assume The coordinates of the given quad must be contained wholly within
* the subsector specified. This is due to an optimization within the lumobj
* management which seperates them according to their position in the BSP.
*
* @param ssec Subsector within which the quad wholly resides.
* @param topLeft Coordinates of the top left corner of the quad.
* @param bottomRight Coordinates of the bottom right corner of the quad.
* @param normal Normalized normal of the quad.
* @param flags DLF_* flags.
*
* @return Dynlight list name if the quad is lit by one or more
* light sources, else @c 0.
*/
uint DL_ProcessSegSection(seg_t* seg, subsector_t* ssec, float bottom,
float top, boolean sortBrightestFirst)
uint DL_ProjectOnSurface(subsector_t* ssec, const pvec3_t topLeft,
const pvec3_t bottomRight, const float* normal,
byte flags)
{
sidedef_t* side;
surfacelumobjiterparams_t params;

if(!useDynLights && !useWallGlow)
return 0; // Disabled.

if(!seg || !ssec)
return 0;

side = SEG_SIDEDEF(seg);

V3_Set(params.v1, seg->SG_v1pos[VX], seg->SG_v1pos[VY], top);
V3_Set(params.v2, seg->SG_v2pos[VX], seg->SG_v2pos[VY], bottom);
params.normal[VX] = side->SW_middlenormal[VX];
params.normal[VY] = side->SW_middlenormal[VY];
params.normal[VZ] = side->SW_middlenormal[VZ];
params.sortBrightestFirst = sortBrightestFirst;
params.haveList = false;
params.listIdx = 0;
params.useTex = 0;
params.isPlane = false;

return processSubSector(ssec, &params);
}

uint DL_ProcessSubSectorPlane(subsector_t* ssec, uint plane)
{
plane_t* pln;
surfacelumobjiterparams_t params;

if(!useDynLights && !useWallGlow)
Expand All @@ -612,33 +597,12 @@ uint DL_ProcessSubSectorPlane(subsector_t* ssec, uint plane)
if(!ssec)
return 0;

assert(plane < ssec->sector->planeCount); // Sanity check.

pln = ssec->sector->SP_plane(plane);

if(pln->type == PLN_FLOOR)
{
V3_Set(params.v1, ssec->bBox[0].pos[VX], ssec->bBox[1].pos[VY],
pln->visHeight);
V3_Set(params.v2, ssec->bBox[1].pos[VX], ssec->bBox[0].pos[VY],
pln->visHeight);
}
else
{
V3_Set(params.v1, ssec->bBox[0].pos[VX], ssec->bBox[0].pos[VY],
pln->visHeight);
V3_Set(params.v2, ssec->bBox[1].pos[VX], ssec->bBox[1].pos[VY],
pln->visHeight);
}

params.normal[VX] = pln->PS_normal[VX];
params.normal[VY] = pln->PS_normal[VY];
params.normal[VZ] = pln->PS_normal[VZ];
params.sortBrightestFirst = false;
V3_Copy(params.v1, topLeft);
V3_Copy(params.v2, bottomRight);
V3_Set(params.normal, normal[VX], normal[VY], normal[VZ]);
params.flags = flags;
params.haveList = false;
params.listIdx = 0;
params.useTex = (pln->type == PLN_CEILING? 2 : 1);
params.isPlane = true;

return processSubSector(ssec, &params);
}
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/src/rend_fakeradio.c
Expand Up @@ -1115,17 +1115,17 @@ static void renderShadowSeg(const rvertex_t* origVertices,
RL_AddPoly(PT_FAN, RPT_SHADOW, rvertices + 3 + divs[0].num,
rtexcoords + 3 + divs[0].num, NULL, NULL,
rcolors + 3 + divs[0].num, 3 + divs[1].num,
0, 0, NULL, rTU, rTU[TU_PRIMARY].blendMode);
0, 0, NULL, rTU);
RL_AddPoly(PT_FAN, RPT_SHADOW, rvertices, rtexcoords, NULL, NULL,
rcolors, 3 + divs[0].num, 0, 0, NULL, rTU, rTU[TU_PRIMARY].blendMode);
rcolors, 3 + divs[0].num, 0, 0, NULL, rTU);

R_FreeRendVertices(rvertices);
}
else
{
RL_AddPoly(PT_TRIANGLE_STRIP, RPT_SHADOW, origVertices,
rtexcoords, NULL, NULL,
rcolors, 4, 0, 0, NULL, rTU, rTU[TU_PRIMARY].blendMode);
rcolors, 4, 0, 0, NULL, rTU);
}
}

Expand Down Expand Up @@ -1428,7 +1428,7 @@ static void radioAddShadowEdge(const linedef_t* line, byte side,
if(rendFakeRadio != 2)
RL_AddPoly(PT_FAN, (renderWireframe? RPT_NORMAL : RPT_SHADOW),
rvertices, NULL, NULL, NULL,
rcolors, 4, 0, 0, NULL, rTU, rTU[TU_PRIMARY].blendMode);
rcolors, 4, 0, 0, NULL, rTU);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions doomsday/engine/portable/src/rend_list.c
Expand Up @@ -887,8 +887,7 @@ void RL_AddPoly(primtype_t type, rendpolytype_t polyType,
const rcolor_t* rcolors,
uint numVertices, uint numLights,
DGLuint modTex, float modColor[3],
const rtexmapunit_t rTU[NUM_TEXMAP_UNITS],
blendmode_t blendMode /* temp */)
const rtexmapunit_t rTU[NUM_TEXMAP_UNITS])
{
if(numVertices < 3)
return; // huh?
Expand All @@ -897,7 +896,7 @@ void RL_AddPoly(primtype_t type, rendpolytype_t polyType,
Con_Error("RL_AddPoly: Unknown primtype %i.", type);

addPoly(type, polyType, rvertices, rtexcoords, rtexcoords1, rtexcoords2,
rcolors, numVertices, blendMode, numLights, modTex, modColor, rTU);
rcolors, numVertices, rTU[TU_PRIMARY].blendMode, numLights, modTex, modColor, rTU);
}

/**
Expand Down

0 comments on commit c80bb63

Please sign in to comment.