Add batching support to OGL brightmaps

This commit is contained in:
Sally Coolatta 2023-09-18 01:05:36 -04:00 committed by James R
parent e4a2461faf
commit d03eb9e9cd
2 changed files with 72 additions and 30 deletions

View file

@ -17,6 +17,7 @@
// The texture for the next polygon given to HWR_ProcessPolygon. // The texture for the next polygon given to HWR_ProcessPolygon.
// Set with HWR_SetCurrentTexture. // Set with HWR_SetCurrentTexture.
GLMipmap_t *current_texture = NULL; GLMipmap_t *current_texture = NULL;
GLMipmap_t *current_brightmap = NULL;
boolean currently_batching = false; boolean currently_batching = false;
@ -64,8 +65,23 @@ void HWR_StartBatching(void)
void HWR_SetCurrentTexture(GLMipmap_t *texture) void HWR_SetCurrentTexture(GLMipmap_t *texture)
{ {
if (currently_batching) if (currently_batching)
{
if (texture != NULL)
{
if (texture->flags & TF_BRIGHTMAP)
{
current_brightmap = texture;
}
else
{ {
current_texture = texture; current_texture = texture;
current_brightmap = NULL;
}
}
else
{
current_texture = current_brightmap = NULL;
}
} }
else else
{ {
@ -114,6 +130,7 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt
polygonArray[polygonArraySize].numVerts = iNumPts; polygonArray[polygonArraySize].numVerts = iNumPts;
polygonArray[polygonArraySize].polyFlags = PolyFlags; polygonArray[polygonArraySize].polyFlags = PolyFlags;
polygonArray[polygonArraySize].texture = current_texture; polygonArray[polygonArraySize].texture = current_texture;
polygonArray[polygonArraySize].brightmap = current_brightmap;
polygonArray[polygonArraySize].shader = shader; polygonArray[polygonArraySize].shader = shader;
polygonArray[polygonArraySize].horizonSpecial = horizonSpecial; polygonArray[polygonArraySize].horizonSpecial = horizonSpecial;
polygonArraySize++; polygonArraySize++;
@ -161,6 +178,15 @@ static int comparePolygons(const void *p1, const void *p2)
diff64 = downloaded1 - downloaded2; diff64 = downloaded1 - downloaded2;
if (diff64 != 0) return diff64; if (diff64 != 0) return diff64;
downloaded1 = 0;
downloaded2 = 0;
if (poly1->brightmap)
downloaded1 = poly1->brightmap->downloaded; // there should be a opengl texture name here, usable for comparisons
if (poly2->brightmap)
downloaded2 = poly2->brightmap->downloaded;
diff64 = downloaded1 - downloaded2;
if (diff64 != 0) return diff64;
diff = poly1->polyFlags - poly2->polyFlags; diff = poly1->polyFlags - poly2->polyFlags;
if (diff != 0) return diff; if (diff != 0) return diff;
@ -226,8 +252,10 @@ void HWR_RenderBatches(void)
int currentShader; int currentShader;
int nextShader = 0; int nextShader = 0;
GLMipmap_t *currentTexture; GLMipmap_t *currentTexture = NULL;
GLMipmap_t *nextTexture = NULL; GLMipmap_t *nextTexture = NULL;
GLMipmap_t *currentBrightmap = NULL;
GLMipmap_t *nextBrightmap = NULL;
FBITFIELD currentPolyFlags = 0; FBITFIELD currentPolyFlags = 0;
FBITFIELD nextPolyFlags = 0; FBITFIELD nextPolyFlags = 0;
FSurfaceInfo currentSurfaceInfo; FSurfaceInfo currentSurfaceInfo;
@ -268,14 +296,16 @@ void HWR_RenderBatches(void)
// sort order // sort order
// 1. shader // 1. shader
// 2. texture // 2. texture
// 3. polyflags // 3. brightmap
// 4. colors + light level // 4. polyflags
// 5. colors + light level
// not sure about what order of the last 2 should be, or if it even matters // not sure about what order of the last 2 should be, or if it even matters
ps_hw_batchdrawtime = I_GetPreciseTime(); ps_hw_batchdrawtime = I_GetPreciseTime();
currentShader = polygonArray[polygonIndexArray[0]].shader; currentShader = polygonArray[polygonIndexArray[0]].shader;
currentTexture = polygonArray[polygonIndexArray[0]].texture; currentTexture = polygonArray[polygonIndexArray[0]].texture;
currentBrightmap = polygonArray[polygonIndexArray[0]].brightmap;
currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags; currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags;
currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf; currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf;
// For now, will sort and track the colors. Vertex attributes could be used instead of uniforms // For now, will sort and track the colors. Vertex attributes could be used instead of uniforms
@ -289,9 +319,15 @@ void HWR_RenderBatches(void)
} }
if (currentPolyFlags & PF_NoTexture) if (currentPolyFlags & PF_NoTexture)
currentTexture = NULL; {
currentTexture = currentBrightmap = NULL;
}
else else
{
HWD.pfnSetTexture(currentTexture); HWD.pfnSetTexture(currentTexture);
if (currentBrightmap)
HWD.pfnSetTexture(currentBrightmap);
}
while (1)// note: remember handling notexture polyflag as having texture number 0 (also in comparePolygons) while (1)// note: remember handling notexture polyflag as having texture number 0 (also in comparePolygons)
{ {
@ -361,16 +397,17 @@ void HWR_RenderBatches(void)
int nextIndex = polygonIndexArray[polygonReadPos]; int nextIndex = polygonIndexArray[polygonReadPos];
nextShader = polygonArray[nextIndex].shader; nextShader = polygonArray[nextIndex].shader;
nextTexture = polygonArray[nextIndex].texture; nextTexture = polygonArray[nextIndex].texture;
nextBrightmap = polygonArray[nextIndex].brightmap;
nextPolyFlags = polygonArray[nextIndex].polyFlags; nextPolyFlags = polygonArray[nextIndex].polyFlags;
nextSurfaceInfo = polygonArray[nextIndex].surf; nextSurfaceInfo = polygonArray[nextIndex].surf;
if (nextPolyFlags & PF_NoTexture) if (nextPolyFlags & PF_NoTexture)
nextTexture = 0; nextTexture = nextBrightmap = 0;
if (currentShader != nextShader && cv_glshaders.value && gl_shadersavailable) if (currentShader != nextShader && cv_glshaders.value && gl_shadersavailable)
{ {
changeState = true; changeState = true;
changeShader = true; changeShader = true;
} }
if (currentTexture != nextTexture) if (currentTexture != nextTexture || currentBrightmap != nextBrightmap)
{ {
changeState = true; changeState = true;
changeTexture = true; changeTexture = true;
@ -433,8 +470,12 @@ void HWR_RenderBatches(void)
// texture should be already ready for use from calls to SetTexture during batch collection // texture should be already ready for use from calls to SetTexture during batch collection
HWD.pfnSetTexture(nextTexture); HWD.pfnSetTexture(nextTexture);
currentTexture = nextTexture; currentTexture = nextTexture;
changeTexture = false;
if (nextBrightmap)
HWD.pfnSetTexture(nextBrightmap);
currentBrightmap = nextBrightmap;
changeTexture = false;
ps_hw_numtextures++; ps_hw_numtextures++;
} }
if (changePolyFlags) if (changePolyFlags)

View file

@ -27,6 +27,7 @@ typedef struct
FUINT numVerts; FUINT numVerts;
FBITFIELD polyFlags; FBITFIELD polyFlags;
GLMipmap_t *texture; GLMipmap_t *texture;
GLMipmap_t *brightmap;
int shader; int shader;
// this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls // this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls
boolean horizonSpecial; boolean horizonSpecial;