replace karts batching with srb2s batching

currently palette renderer does not work
may need to try it with the reworked
This commit is contained in:
Alug committed 2024-01-15 13:35:17 +01:00
1 parent 48320b5f96
commit d5fdd60fed
11 files changed
+677 -675

No files matched your search

+1 -1
View File
@@ -275,7 +275,7 @@ else
OPTS+=-DHWRENDER
OBJS+=$(OBJDIR)/hw_bsp.o $(OBJDIR)/hw_draw.o $(OBJDIR)/hw_light.o \
$(OBJDIR)/hw_main.o $(OBJDIR)/hw_clip.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o $(OBJDIR)/hw_trick.o \
$(OBJDIR)/hw_md2load.o $(OBJDIR)/hw_md3load.o $(OBJDIR)/hw_model.o $(OBJDIR)/u_list.o
$(OBJDIR)/hw_md2load.o $(OBJDIR)/hw_md3load.o $(OBJDIR)/hw_model.o $(OBJDIR)/u_list.o $(OBJDIR)/hw_batching.o
endif
OPTS += -DCOMPVERSION
+488
View File
@@ -0,0 +1,488 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2020-2023 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file hw_batching.c
/// \brief Draw call batching and related things.
#ifdef HWRENDER
#include "hw_glob.h"
#include "hw_batching.h"
#include "hw_main.h"
#include "../i_system.h"
// The texture for the next polygon given to HWR_ProcessPolygon.
// Set with HWR_SetCurrentTexture.
GLMipmap_t *current_texture = NULL;
boolean currently_batching = false;
FOutVector* finalVertexArray = NULL;// contains subset of sorted vertices and texture coordinates to be sent to gpu
UINT32* finalVertexIndexArray = NULL;// contains indexes for glDrawElements, taking into account fan->triangles conversion
// NOTE have this alloced as 3x finalVertexArray size
int finalVertexArrayAllocSize = 65536;
//GLubyte* colorArray = NULL;// contains color data to be sent to gpu, if needed
//int colorArrayAllocSize = 65536;
// not gonna use this for now, just sort by color and change state when it changes
// later maybe when using vertex attributes if it's needed
PolygonArrayEntry* polygonArray = NULL;// contains the polygon data from DrawPolygon, waiting to be processed
int polygonArraySize = 0;
UINT32* polygonIndexArray = NULL;// contains sorting pointers for polygonArray
int polygonArrayAllocSize = 65536;
FOutVector* unsortedVertexArray = NULL;// contains unsorted vertices and texture coordinates from DrawPolygon
int unsortedVertexArraySize = 0;
int unsortedVertexArrayAllocSize = 65536;
// Enables batching mode. HWR_ProcessPolygon will collect polygons instead of passing them directly to the rendering backend.
// Call HWR_RenderBatches to render all the collected geometry.
void HWR_StartBatching(void)
{
if (currently_batching)
I_Error("Repeat call to HWR_StartBatching without HWR_RenderBatches");
// init arrays if that has not been done yet
if (!finalVertexArray)
{
finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector));
finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32));
polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry));
polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32));
unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector));
}
currently_batching = true;
}
// This replaces the direct calls to pfnSetTexture in cases where batching is available.
// The texture selection is saved for the next HWR_ProcessPolygon call.
// Doing this was easier than getting a texture pointer to HWR_ProcessPolygon.
void HWR_SetCurrentTexture(GLMipmap_t *texture)
{
if (currently_batching)
{
current_texture = texture;
}
else
{
HWD.pfnSetTexture(texture);
}
}
// If batching is enabled, this function collects the polygon data and the chosen texture
// for later use in HWR_RenderBatches. Otherwise the rendering backend is used to
// render the polygon immediately.
void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial)
{
if (currently_batching)
{
if (!pSurf)
I_Error("Got a null FSurfaceInfo in batching");// nulls should not come in the stuff that batching currently applies to
if (polygonArraySize == polygonArrayAllocSize)
{
PolygonArrayEntry* new_array;
// ran out of space, make new array double the size
polygonArrayAllocSize *= 2;
new_array = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry));
memcpy(new_array, polygonArray, polygonArraySize * sizeof(PolygonArrayEntry));
free(polygonArray);
polygonArray = new_array;
// also need to redo the index array, dont need to copy it though
free(polygonIndexArray);
polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32));
}
while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize)
{
FOutVector* new_array;
// need more space for vertices in unsortedVertexArray
unsortedVertexArrayAllocSize *= 2;
new_array = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector));
memcpy(new_array, unsortedVertexArray, unsortedVertexArraySize * sizeof(FOutVector));
free(unsortedVertexArray);
unsortedVertexArray = new_array;
}
// add the polygon data to the arrays
polygonArray[polygonArraySize].surf = *pSurf;
polygonArray[polygonArraySize].vertsIndex = unsortedVertexArraySize;
polygonArray[polygonArraySize].numVerts = iNumPts;
polygonArray[polygonArraySize].polyFlags = PolyFlags;
polygonArray[polygonArraySize].texture = current_texture;
polygonArray[polygonArraySize].shader = shader;
polygonArray[polygonArraySize].horizonSpecial = horizonSpecial;
polygonArraySize++;
memcpy(&unsortedVertexArray[unsortedVertexArraySize], pOutVerts, iNumPts * sizeof(FOutVector));
unsortedVertexArraySize += iNumPts;
}
else
{
if (shader)
HWD.pfnSetShader(shader);
HWD.pfnDrawPolygon(pSurf, pOutVerts, iNumPts, PolyFlags);
}
}
static int comparePolygons(const void *p1, const void *p2)
{
unsigned int index1 = *(const unsigned int*)p1;
unsigned int index2 = *(const unsigned int*)p2;
PolygonArrayEntry* poly1 = &polygonArray[index1];
PolygonArrayEntry* poly2 = &polygonArray[index2];
int diff;
INT64 diff64;
UINT32 downloaded1 = 0;
UINT32 downloaded2 = 0;
int shader1 = poly1->shader;
int shader2 = poly2->shader;
// make skywalls and horizon lines first in order
if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial)
shader1 = -1;
if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial)
shader2 = -1;
diff = shader1 - shader2;
if (diff != 0) return diff;
// skywalls and horizon lines must retain their order for horizon lines to work
if (shader1 == -1 && shader2 == -1)
return index1 - index2;
if (poly1->texture)
downloaded1 = poly1->texture->downloaded; // there should be a opengl texture name here, usable for comparisons
if (poly2->texture)
downloaded2 = poly2->texture->downloaded;
diff64 = downloaded1 - downloaded2;
if (diff64 != 0) return diff64;
if (HWR_ShouldUsePaletteRendering())
{
diff = poly1->surf.LightTableId - poly2->surf.LightTableId;
if (diff != 0) return diff;
}
diff = poly1->polyFlags - poly2->polyFlags;
if (diff != 0) return diff;
diff64 = poly1->surf.PolyColor.rgba - poly2->surf.PolyColor.rgba;
if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
diff64 = poly1->surf.TintColor.rgba - poly2->surf.TintColor.rgba;
if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
diff64 = poly1->surf.FadeColor.rgba - poly2->surf.FadeColor.rgba;
if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
diff = poly1->surf.LightInfo.light_level - poly2->surf.LightInfo.light_level;
if (diff != 0) return diff;
diff = poly1->surf.LightInfo.fade_start - poly2->surf.LightInfo.fade_start;
if (diff != 0) return diff;
diff = poly1->surf.LightInfo.fade_end - poly2->surf.LightInfo.fade_end;
return diff;
}
static int comparePolygonsNoShaders(const void *p1, const void *p2)
{
unsigned int index1 = *(const unsigned int*)p1;
unsigned int index2 = *(const unsigned int*)p2;
PolygonArrayEntry* poly1 = &polygonArray[index1];
PolygonArrayEntry* poly2 = &polygonArray[index2];
int diff;
INT64 diff64;
GLMipmap_t *texture1 = poly1->texture;
GLMipmap_t *texture2 = poly2->texture;
UINT32 downloaded1 = 0;
UINT32 downloaded2 = 0;
if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial)
texture1 = NULL;
if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial)
texture2 = NULL;
if (texture1)
downloaded1 = texture1->downloaded; // there should be a opengl texture name here, usable for comparisons
if (texture2)
downloaded2 = texture2->downloaded;
// skywalls and horizon lines must retain their order for horizon lines to work
if (!texture1 && !texture2)
return index1 - index2;
diff64 = downloaded1 - downloaded2;
if (diff64 != 0) return diff64;
diff = poly1->polyFlags - poly2->polyFlags;
if (diff != 0) return diff;
diff64 = poly1->surf.PolyColor.rgba - poly2->surf.PolyColor.rgba;
if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
return 0;
}
// This function organizes the geometry collected by HWR_ProcessPolygon calls into batches and uses
// the rendering backend to draw them.
void HWR_RenderBatches(void)
{
int finalVertexWritePos = 0;// position in finalVertexArray
int finalIndexWritePos = 0;// position in finalVertexIndexArray
int polygonReadPos = 0;// position in polygonIndexArray
int currentShader;
int nextShader = 0;
GLMipmap_t *currentTexture;
GLMipmap_t *nextTexture = NULL;
FBITFIELD currentPolyFlags = 0;
FBITFIELD nextPolyFlags = 0;
FSurfaceInfo currentSurfaceInfo;
FSurfaceInfo nextSurfaceInfo;
int i;
if (!currently_batching)
I_Error("HWR_RenderBatches called without starting batching");
nextSurfaceInfo.LightInfo.fade_end = 0;
nextSurfaceInfo.LightInfo.fade_start = 0;
nextSurfaceInfo.LightInfo.light_level = 0;
currently_batching = false;// no longer collecting batches
if (!polygonArraySize)
{
ps_hw_numpolys.value.i = ps_hw_numcalls.value.i = ps_hw_numshaders.value.i
= ps_hw_numtextures.value.i = ps_hw_numpolyflags.value.i
= ps_hw_numcolors.value.i = 0;
return;// nothing to draw
}
// init stats vars
ps_hw_numpolys.value.i = polygonArraySize;
ps_hw_numcalls.value.i = ps_hw_numverts.value.i = 0;
ps_hw_numshaders.value.i = ps_hw_numtextures.value.i
= ps_hw_numpolyflags.value.i = ps_hw_numcolors.value.i = 1;
// init polygonIndexArray
for (i = 0; i < polygonArraySize; i++)
{
polygonIndexArray[i] = i;
}
// sort polygons
PS_START_TIMING(ps_hw_batchsorttime);
if (cv_grshaders.value && gr_shadersavailable)
qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons);
else
qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders);
PS_STOP_TIMING(ps_hw_batchsorttime);
// sort order
// 1. shader
// 2. texture
// 3. polyflags
// 4. colors + light level
// not sure about what order of the last 2 should be, or if it even matters
PS_START_TIMING(ps_hw_batchdrawtime);
currentShader = polygonArray[polygonIndexArray[0]].shader;
currentTexture = polygonArray[polygonIndexArray[0]].texture;
currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags;
currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf;
// For now, will sort and track the colors. Vertex attributes could be used instead of uniforms
// and a color array could replace the color calls.
// set state for first batch
if (cv_grshaders.value && gr_shadersavailable)
{
HWD.pfnSetShader(currentShader);
}
if (currentPolyFlags & PF_NoTexture)
currentTexture = NULL;
else
HWD.pfnSetTexture(currentTexture);
while (1)// note: remember handling notexture polyflag as having texture number 0 (also in comparePolygons)
{
int firstIndex;
int lastIndex;
boolean stopFlag = false;
boolean changeState = false;
boolean changeShader = false;
boolean changeTexture = false;
boolean changePolyFlags = false;
boolean changeSurfaceInfo = false;
// steps:
// write vertices
// check for changes or end, otherwise go back to writing
// changes will affect the next vars and the change bools
// end could set flag for stopping
// execute draw call
// could check ending flag here
// change states according to next vars and change bools, updating the current vars and reseting the bools
// reset write pos
// repeat loop
int index = polygonIndexArray[polygonReadPos++];
int numVerts = polygonArray[index].numVerts;
// before writing, check if there is enough room
// using 'while' instead of 'if' here makes sure that there will *always* be enough room.
// probably never will this loop run more than once though
while (finalVertexWritePos + numVerts > finalVertexArrayAllocSize)
{
FOutVector* new_array;
unsigned int* new_index_array;
finalVertexArrayAllocSize *= 2;
new_array = malloc(finalVertexArrayAllocSize * sizeof(FOutVector));
memcpy(new_array, finalVertexArray, finalVertexWritePos * sizeof(FOutVector));
free(finalVertexArray);
finalVertexArray = new_array;
// also increase size of index array, 3x of vertex array since
// going from fans to triangles increases vertex count to 3x
new_index_array = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32));
memcpy(new_index_array, finalVertexIndexArray, finalIndexWritePos * sizeof(UINT32));
free(finalVertexIndexArray);
finalVertexIndexArray = new_index_array;
}
// write the vertices of the polygon
memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[polygonArray[index].vertsIndex],
numVerts * sizeof(FOutVector));
// write the indexes, pointing to the fan vertexes but in triangles format
firstIndex = finalVertexWritePos;
lastIndex = finalVertexWritePos + numVerts;
finalVertexWritePos += 2;
while (finalVertexWritePos < lastIndex)
{
finalVertexIndexArray[finalIndexWritePos++] = firstIndex;
finalVertexIndexArray[finalIndexWritePos++] = finalVertexWritePos - 1;
finalVertexIndexArray[finalIndexWritePos++] = finalVertexWritePos++;
}
if (polygonReadPos >= polygonArraySize)
{
stopFlag = true;
}
else
{
// check if a state change is required, set the change bools and next vars
int nextIndex = polygonIndexArray[polygonReadPos];
nextShader = polygonArray[nextIndex].shader;
nextTexture = polygonArray[nextIndex].texture;
nextPolyFlags = polygonArray[nextIndex].polyFlags;
nextSurfaceInfo = polygonArray[nextIndex].surf;
if (nextPolyFlags & PF_NoTexture)
nextTexture = 0;
if (currentShader != nextShader && cv_grshaders.value && gr_shadersavailable)
{
changeState = true;
changeShader = true;
}
if (currentTexture != nextTexture)
{
changeState = true;
changeTexture = true;
}
if (currentPolyFlags != nextPolyFlags)
{
changeState = true;
changePolyFlags = true;
}
if ((cv_grshaders.value && gr_shadersavailable) && (HWR_ShouldUsePaletteRendering()))
{
if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba ||
currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba ||
currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba ||
currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level ||
currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start ||
currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end ||
currentSurfaceInfo.LightTableId != nextSurfaceInfo.LightTableId)
{
changeState = true;
changeSurfaceInfo = true;
}
}
else if (cv_grshaders.value && gr_shadersavailable)
{
if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba ||
currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba ||
currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba ||
currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level ||
currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start ||
currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end)
{
changeState = true;
changeSurfaceInfo = true;
}
}
else
{
if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba)
{
changeState = true;
changeSurfaceInfo = true;
}
}
}
if (changeState || stopFlag)
{
// execute draw call
HWD.pfnDrawIndexedTriangles(&currentSurfaceInfo, finalVertexArray, finalIndexWritePos, currentPolyFlags, finalVertexIndexArray);
// update stats
ps_hw_numcalls.value.i++;
ps_hw_numverts.value.i += finalIndexWritePos;
// reset write positions
finalVertexWritePos = 0;
finalIndexWritePos = 0;
}
else continue;
// if we're here then either its time to stop or time to change state
if (stopFlag) break;
// change state according to change bools and next vars, update current vars and reset bools
if (changeShader)
{
HWD.pfnSetShader(nextShader);
currentShader = nextShader;
changeShader = false;
ps_hw_numshaders.value.i++;
}
if (changeTexture)
{
// texture should be already ready for use from calls to SetTexture during batch collection
HWD.pfnSetTexture(nextTexture);
currentTexture = nextTexture;
changeTexture = false;
ps_hw_numtextures.value.i++;
}
if (changePolyFlags)
{
currentPolyFlags = nextPolyFlags;
changePolyFlags = false;
ps_hw_numpolyflags.value.i++;
}
if (changeSurfaceInfo)
{
currentSurfaceInfo = nextSurfaceInfo;
changeSurfaceInfo = false;
ps_hw_numcolors.value.i++;
}
// and that should be it?
}
// reset the arrays (set sizes to 0)
polygonArraySize = 0;
unsortedVertexArraySize = 0;
PS_STOP_TIMING(ps_hw_batchdrawtime);
}
#endif // HWRENDER
+39
View File
@@ -0,0 +1,39 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2020 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file hw_batching.h
/// \brief Draw call batching and related things.
#ifndef __HWR_BATCHING_H__
#define __HWR_BATCHING_H__
#include "hw_defs.h"
#include "hw_data.h"
#include "hw_drv.h"
typedef struct
{
FSurfaceInfo surf;// surf also has its own polyflags for some reason, but it seems unused
unsigned int vertsIndex;// location of verts in unsortedVertexArray
FUINT numVerts;
FBITFIELD polyFlags;
GLMipmap_t *texture;
int shader;
// this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls
boolean horizonSpecial;
} PolygonArrayEntry;
void HWR_StartBatching(void);
void HWR_SetCurrentTexture(GLMipmap_t *texture);
void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial);
void HWR_RenderBatches(void);
extern boolean currently_batching;
#endif
+21 -5
View File
@@ -17,6 +17,7 @@
#include "hw_main.h"
#include "hw_glob.h"
#include "hw_drv.h"
#include "hw_batching.h"
#include "../doomstat.h" //gamemode
#include "../i_video.h" //rendermode
@@ -591,7 +592,11 @@ GLTexture_t *HWR_GetTexture(INT32 tex)
if (!grtex->mipmap.grInfo.data && !grtex->mipmap.downloaded)
HWR_GenerateTexture(tex, grtex);
HWD.pfnSetTexture(&grtex->mipmap);
// If hardware does not have the texture, then call pfnSetTexture to upload it
if (!grtex->mipmap.downloaded)
HWD.pfnSetTexture(&grtex->mipmap);
HWR_SetCurrentTexture(&grtex->mipmap);
// The system-memory data can be purged now.
Z_ChangeTag(grtex->mipmap.grInfo.data, PU_HWRCACHE_UNLOCKED);
@@ -675,7 +680,11 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap)
if (!grmip->downloaded && !grmip->grInfo.data)
HWR_CacheFlat(grmip, flatlumpnum);
HWD.pfnSetTexture(grmip);
// If hardware does not have the texture, then call pfnSetTexture to upload it
if (!grmip->downloaded)
HWD.pfnSetTexture(grmip);
HWR_SetCurrentTexture(grmip);
// The system-memory data can be purged now.
Z_ChangeTag(grmip->grInfo.data, PU_HWRCACHE_UNLOCKED);
@@ -701,8 +710,11 @@ static void HWR_LoadMappedPatch(GLMipmap_t *grmip, GLPatch_t *gpatch)
Z_Free(patch);
}
HWD.pfnSetTexture(grmip);
// If hardware does not have the texture, then call pfnSetTexture to upload it
if (!grmip->downloaded)
HWD.pfnSetTexture(grmip);
HWR_SetCurrentTexture(grmip);
// The system-memory data can be purged now.
Z_ChangeTag(grmip->grInfo.data, PU_HWRCACHE_UNLOCKED);
@@ -732,7 +744,11 @@ void HWR_GetPatch(GLPatch_t *gpatch)
Z_Free(ptr);
}
HWD.pfnSetTexture(gpatch->mipmap);
// If hardware does not have the texture, then call pfnSetTexture to upload it
if (!gpatch->mipmap->downloaded)
HWD.pfnSetTexture(gpatch->mipmap);
HWR_SetCurrentTexture(gpatch->mipmap);
// The system-memory patch data can be purged now.
Z_ChangeTag(gpatch->mipmap->grInfo.data, PU_HWRCACHE_UNLOCKED);
+11 -11
View File
@@ -122,7 +122,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option)
flags |= PF_ForceWrapY;
// clip it since it is used for bunny scroll in doom I
HWD.pfnDrawPolygon(NULL, v, 4, flags, false);
HWD.pfnDrawPolygon(NULL, v, 4, flags);
}
void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap)
@@ -300,10 +300,10 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t
else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[hudtrans];
else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel];
flags |= PF_Modulated;
HWD.pfnDrawPolygon(&Surf, v, 4, flags, false);
HWD.pfnDrawPolygon(&Surf, v, 4, flags);
}
else
HWD.pfnDrawPolygon(NULL, v, 4, flags, false);
HWD.pfnDrawPolygon(NULL, v, 4, flags);
}
void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h)
@@ -454,10 +454,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal
else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[cv_translucenthud.value];
else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel];
flags |= PF_Modulated;
HWD.pfnDrawPolygon(&Surf, v, 4, flags, false);
HWD.pfnDrawPolygon(&Surf, v, 4, flags);
}
else
HWD.pfnDrawPolygon(NULL, v, 4, flags, false);
HWD.pfnDrawPolygon(NULL, v, 4, flags);
}
// ==========================================================================
@@ -533,7 +533,7 @@ void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum
// BTW, I see we put 0 for PFs, and If I'm right, that
// means we take the previous PFs as default
// how can we be sure they are ok?
HWD.pfnDrawPolygon(NULL, v, 4, PF_NoDepthTest, false); //PF_Translucent);
HWD.pfnDrawPolygon(NULL, v, 4, PF_NoDepthTest); //PF_Translucent);
}
@@ -575,7 +575,7 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength)
Surf.PolyColor.s.alpha = (UINT8)(strength*25.5f);
}
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest);
}
// Draw the console background with translucency support
@@ -602,7 +602,7 @@ void HWR_DrawConsoleBack(UINT32 color, INT32 height)
Surf.PolyColor.rgba = UINT2RGBA(color);
Surf.PolyColor.s.alpha = 0x80;
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest);
}
@@ -851,7 +851,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color)
Surf.PolyColor = V_GetColor(color);
HWD.pfnDrawPolygon(&Surf, v, 4,
PF_Modulated|PF_NoTexture|PF_NoDepthTest, false);
PF_Modulated|PF_NoTexture|PF_NoDepthTest);
}
// -------------------+
@@ -959,7 +959,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32
Surf.PolyColor.rgba = UINT2RGBA(color);
Surf.PolyColor.s.alpha = 0x80;
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest);
}
// -----------------+
@@ -1076,7 +1076,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color)
else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel];
}
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest);
}
#ifdef HAVE_PNG
+3 -7
View File
@@ -36,7 +36,8 @@ EXPORT void HWRAPI(SetPalette) (RGBA_t *ppal, RGBA_t *pgamma);
#endif
EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl);
EXPORT void HWRAPI(Draw2DLine) (F2DCoord *v1, F2DCoord *v2, RGBA_t Color);
EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, boolean horizonSpecial);
EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags);
EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray);
EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags);
EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat *ClearColor);
EXPORT void HWRAPI(SetTexture) (FTextureInfo *TexInfo);
@@ -81,9 +82,6 @@ EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value);
EXPORT void HWRAPI(LoadCustomShader) (int number, char *shader, size_t size, boolean fragment);
EXPORT boolean HWRAPI(InitCustomShaders) (void);
EXPORT void HWRAPI(StartBatching) (void);
EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors);
EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut);
EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable);
EXPORT void HWRAPI(ClearLightTableCache) (void);
@@ -102,6 +100,7 @@ struct hwdriver_s
FinishUpdate pfnFinishUpdate;
Draw2DLine pfnDraw2DLine;
DrawPolygon pfnDrawPolygon;
DrawIndexedTriangles pfnDrawIndexedTriangles;
SetBlend pfnSetBlend;
ClearBuffer pfnClearBuffer;
SetTexture pfnSetTexture;
@@ -136,9 +135,6 @@ struct hwdriver_s
LoadCustomShader pfnLoadCustomShader;
InitCustomShaders pfnInitCustomShaders;
StartBatching pfnStartBatching;
RenderBatches pfnRenderBatches;
InitPalette pfnInitPalette;
AddLightTable pfnAddLightTable;
ClearLightTableCache pfnClearLightTableCache;
+57 -40
View File
@@ -19,6 +19,7 @@
#include "hw_main.h"
#include "hw_glob.h"
#include "hw_drv.h"
#include "hw_batching.h"
#include "hw_md2.h"
#include "hw_clip.h"
#include "hw_light.h"
@@ -682,6 +683,8 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc
static FOutVector *planeVerts = NULL;
static UINT16 numAllocedPlaneVerts = 0;
INT32 shader = 0;
// no convex poly were generated for this subsector
if (!xsub->planepoly)
@@ -859,16 +862,16 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc
if (HWR_UseShader())
{
if (PolyFlags & PF_Fog)
HWD.pfnSetShader(6); // fog shader
shader = 6; // fog shader
else if (PolyFlags & PF_Ripple)
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 11 : 5); // water shader
shader = (HWR_ShouldUsePaletteRendering() ? 11 : 5); // water shader
else
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
shader = (HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
PolyFlags |= PF_ColorMapped;
}
HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, false);
HWR_ProcessPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, shader, false);
if (subsector)
{
@@ -953,7 +956,7 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc
horizonpts[4].y = gr_viewz;
// Draw
HWD.pfnDrawPolygon(&Surf, horizonpts, 6, PolyFlags, true);
HWR_ProcessPolygon(&Surf, horizonpts, 6, PolyFlags, shader, true);
}
}
}
@@ -969,6 +972,8 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf)
fixed_t i;
// seg bbox
fixed_t segbbox[4];
INT32 shader = 0;
M_ClearBox(segbbox);
M_AddToBox(segbbox,
@@ -1022,10 +1027,10 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf)
if (HWR_UseShader())
{
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
shader = (HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
}
HWD.pfnDrawPolygon(&pSurf, wallVerts, 4, i|PF_Modulated|PF_Decal, false);
HWD.HWR_ProcessPolygon(&pSurf, wallVerts, 4, i|PF_Modulated|PF_Decal, shader, false);
}
}
#endif
@@ -1056,11 +1061,13 @@ FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf)
//
void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blendmode, INT32 lightlevel, extracolormap_t *wallcolormap)
{
INT32 shader = 0;
HWR_Lighting(pSurf, lightlevel, wallcolormap);
if (HWR_UseShader())
{
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
shader = (HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
blendmode |= PF_ColorMapped;
}
@@ -1071,7 +1078,7 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend
blendmode &= ~PF_Masked;
}
HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode|PF_Modulated|PF_Occlude, false);
HWR_ProcessPolygon(pSurf, wallVerts, 4, blendmode|PF_Modulated|PF_Occlude, shader, false); // wall shader
#ifdef WALLSPLATS
if (gr_curline->linedef->splats && cv_splats.value)
@@ -1427,11 +1434,11 @@ static void HWR_DrawSkyWallList(void)
surf.PolyColor.rgba = 0xFFFFFFFF;
HWD.pfnSetTexture(NULL);
HWR_SetCurrentTexture(NULL);
HWD.pfnUnSetShader();
for (i = 0; i < skyWallVertexArraySize; i++)
{
HWD.pfnDrawPolygon(&surf, skyWallVertexArray + i * 4, 4, PF_Occlude|PF_Invisible|PF_NoTexture, false);
HWD.pfnDrawPolygon(&surf, skyWallVertexArray + i * 4, 4, PF_Occlude|PF_Invisible|PF_NoTexture);
}
}
@@ -1452,7 +1459,7 @@ void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf)
}
else
{
HWD.pfnSetTexture(NULL);
HWR_SetCurrentTexture(NULL);
HWR_ProjectWall(wallVerts, Surf, PF_Invisible|PF_NoTexture, 255, NULL);
}
// PF_Invisible so it's not drawn into the colour buffer
@@ -3147,6 +3154,8 @@ void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t
static FOutVector *planeVerts = NULL;
static UINT16 numAllocedPlaneVerts = 0;
INT32 shader = 0;
nrPlaneVerts = polysector->numVertices;
@@ -3292,11 +3301,11 @@ void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t
if (HWR_UseShader())
{
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
shader = (HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
blendmode |= PF_ColorMapped;
}
HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, blendmode, false);
HWR_ProcessPolygon(&Surf, planeVerts, nrPlaneVerts, blendmode, shader, false); // floor shader
}
void HWR_AddPolyObjectPlanes(void)
@@ -3952,6 +3961,8 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t
fixed_t slopez;
float offset = 0;
INT32 shader = 0;
R_GetShadowZ(spr->mobj, &floorslope);
mobjfloor = HWR_OpaqueFloorAtPos(
@@ -4101,10 +4112,10 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t
if (HWR_UseShader())
{
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
shader = (HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
}
HWD.pfnDrawPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated, false);
HWR_ProcessPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated, shader, false);
}
}
@@ -4200,6 +4211,8 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
fixed_t v1x, v1y, v2x, v2y;
#endif
INT32 shader = 0;
this_scale = FIXED_TO_FLOAT(spr->mobj->scale);
if (hires)
@@ -4473,11 +4486,11 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
if (HWR_UseShader())
{
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
shader = (HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
blend |= PF_ColorMapped;
}
HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false);
HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false); // sprite shader
top = bot;
#ifdef ESLOPE
@@ -4518,11 +4531,11 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
if (HWR_UseShader())
{
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
shader = (HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
blend |= PF_ColorMapped;
}
HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false);
HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false); // sprite shader
}
// -----------------+
@@ -4536,6 +4549,9 @@ static void HWR_DrawSprite(gr_vissprite_t *spr)
FOutVector wallVerts[4];
GLPatch_t *gpatch; // sprite patch converted to hardware
FSurfaceInfo Surf;
INT32 shader = 0;
const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->flags & SF_HIRES);
if (spr->mobj)
this_scale = FIXED_TO_FLOAT(spr->mobj->scale);
@@ -4676,11 +4692,11 @@ static void HWR_DrawSprite(gr_vissprite_t *spr)
if (HWR_UseShader())
{
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
shader = (HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
blend |= PF_ColorMapped;
}
HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false);
HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false);
}
}
@@ -4691,6 +4707,8 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr)
FOutVector wallVerts[4];
GLPatch_t *gpatch; // sprite patch converted to hardware
FSurfaceInfo Surf;
INT32 shader = 0;
if (!spr->mobj)
return;
@@ -4775,11 +4793,11 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr)
if (HWR_UseShader())
{
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
shader = (HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
blend |= PF_ColorMapped;
}
HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false);
HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false);
}
// --------------------------------------------------------------------------
@@ -5945,8 +5963,8 @@ static void HWR_PortalClipping(gl_portal_t *portal)
line_t *line = &lines[portal->clipline];
angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y);
angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y);
angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y);
angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y);
// clip things that are not inside the portal window from our viewpoint
gld_clipper_SafeAddClipRange(angle2, angle1);
@@ -6076,8 +6094,9 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe
}
//drawcount = 0;
validcount++;
if (cv_grbatching.value)
HWD.pfnStartBatching();
HWR_StartBatching();
ps_numbspcalls.value.i = 0;
ps_numpolyobjects.value.i = 0;
@@ -6098,14 +6117,10 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe
gr_portal = oldgl_portal_state;
PS_STOP_TIMING(ps_bsptime);
if (cv_grbatching.value)
{
HWD.pfnRenderBatches(&ps_hw_batchsorttime.value.p, &ps_hw_batchdrawtime.value.p,
&ps_hw_numpolys.value.i, &ps_hw_numverts.value.i, &ps_hw_numcalls.value.i,
&ps_hw_numshaders.value.i, &ps_hw_numtextures.value.i, &ps_hw_numpolyflags.value.i,
&ps_hw_numcolors.value.i);
}
HWR_RenderBatches();
if (skyWallVertexArraySize)// if there are skywalls to draw using the alternate method
{
HWR_SetStencilState(HWR_STENCIL_SKY, -1);
@@ -6353,7 +6368,7 @@ void HWR_AddCommands(void)
CV_RegisterVar(&cv_granisotropicmode);
CV_RegisterVar(&cv_grcorrecttricks);
CV_RegisterVar(&cv_grsolvetjoin);
CV_RegisterVar(&cv_grbatching);
CV_RegisterVar(&cv_grfofcut);
CV_RegisterVar(&cv_fofzfightfix);
@@ -6444,6 +6459,8 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend,
{
FBITFIELD blendmode = blend;
UINT8 alpha = pSurf->PolyColor.s.alpha; // retain the alpha
INT32 shader = 0;
// Lighting is done here instead so that fog isn't drawn incorrectly on transparent walls after sorting
HWR_Lighting(pSurf, lightlevel, wallcolormap);
@@ -6456,7 +6473,7 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend,
if (fogwall)
{
blendmode |= PF_Fog;
HWD.pfnSetShader(6); // fog shader
shader = 6; // fog shader
}
blendmode |= PF_Modulated; // No PF_Occlude means overlapping (incorrect) transparency
@@ -6465,12 +6482,12 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend,
{
if (HWR_UseShader())
{
HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
shader = (HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
blendmode |= PF_ColorMapped;
}
}
HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode, false);
HWR_ProcessPolygon(pSurf, wallVerts, 4, blendmode, shader, false);
#ifdef WALLSPLATS
if (gr_curline->linedef->splats && cv_splats.value)
@@ -6521,7 +6538,7 @@ void HWR_DoPostProcessor(player_t *player)
Surf.PolyColor.s.alpha = 0xc0; // match software mode
HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest, false);
HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest);
}
if (!cv_grscreentextures.value) // screen textures are needed for the rest of the effects
+2
View File
@@ -64,6 +64,8 @@ extern ps_metric_t ps_hw_numcolors;
extern ps_metric_t ps_hw_batchsorttime;
extern ps_metric_t ps_hw_batchdrawtime;
extern boolean gr_shadersavailable;
// hw_draw.c
void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option);
void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap);
+52 -604
View File
@@ -34,6 +34,7 @@
#include "../../i_system.h" // for I_GetPreciseTime (batching time measurements)
#include "../hw_main.h"
#include "../hw_batching.h"
// Eeeeh not sure is this right way, but it works < sry :c
extern consvar_t cv_grusecustomshaders;
@@ -638,8 +639,6 @@ static boolean gl_shadersenabled = false;
static GLuint gl_currentshaderprogram = 0;
static boolean gl_shaderprogramchanged = true;
static boolean gl_batching = false;// are we currently collecting batches?
static GLint gl_palette[768];
boolean gl_palette_initialized = false;
static boolean gl_palshader = false;
@@ -1464,7 +1463,7 @@ EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut)
static void SetNoTexture(void)
{
// Disable texture.
if (tex_downloaded != NOTEXTURE_NUM && !gl_batching)
if (tex_downloaded != NOTEXTURE_NUM)
{
pglBindTexture(GL_TEXTURE_2D, NOTEXTURE_NUM);
tex_downloaded = NOTEXTURE_NUM;
@@ -1685,7 +1684,7 @@ EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable)
pglTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 256, 32, 0, GL_RED, GL_UNSIGNED_BYTE, lighttable);
// restore previously bound texture
if (!gl_batching)
if (!cv_grbatching.value)
pglBindTexture(GL_TEXTURE_2D, tex_downloaded);
return ltcachetail->id;
@@ -2362,628 +2361,77 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF
#endif
}
// unfinished draw call batching
// Note: could use realloc in the array reallocation code
typedef struct
// code that is common between DrawPolygon and DrawIndexedTriangles
// the corona thing is there too, i have no idea if that stuff works with DrawIndexedTriangles and batching
static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD PolyFlags)
{
FSurfaceInfo surf;// surf also has its own polyflags for some reason, but it seems unused
unsigned int vertsIndex;// location of verts in unsortedVertexArray
FUINT numVerts;
FBITFIELD polyFlags;
GLuint texNum;
GLuint shader;
// this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls
boolean horizonSpecial;
} PolygonArrayEntry;
static GLRGBAFloat poly = {0,0,0,0};
static GLRGBAFloat tint = {0,0,0,0};
static GLRGBAFloat fade = {0,0,0,0};
FOutVector* finalVertexArray = NULL;// contains subset of sorted vertices and texture coordinates to be sent to gpu
UINT32* finalVertexIndexArray = NULL;// contains indexes for glDrawElements, taking into account fan->triangles conversion
// NOTE have this alloced as 3x finalVertexArray size
int finalVertexArrayAllocSize = 65536;
//GLubyte* colorArray = NULL;// contains color data to be sent to gpu, if needed
//int colorArrayAllocSize = 65536;
// not gonna use this for now, just sort by color and change state when it changes
// later maybe when using vertex attributes if it's needed
SetBlend(PolyFlags); //TODO: inline (#pragma..)
PolygonArrayEntry* polygonArray = NULL;// contains the polygon data from DrawPolygon, waiting to be processed
int polygonArraySize = 0;
UINT32* polygonIndexArray = NULL;// contains sorting pointers for polygonArray
int polygonArrayAllocSize = 65536;
FOutVector* unsortedVertexArray = NULL;// contains unsorted vertices and texture coordinates from DrawPolygon
int unsortedVertexArraySize = 0;
int unsortedVertexArrayAllocSize = 65536;
EXPORT void HWRAPI(StartBatching) (void)
{
//CONS_Printf("StartBatching begin\n");
// init arrays if that has not been done yet
if (!finalVertexArray)
// PolyColor
if (pSurf)
{
finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector));
finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32));
polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry));
polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32));
unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector));
}
// drawing functions will now collect the drawing data instead of passing it to opengl
gl_batching = true;
//CONS_Printf("StartBatching end\n");
}
// If Modulated, mix the surface colour to the texture
if (CurrentPolyFlags & PF_Modulated)
{
// Poly color
poly.red = byte2float[pSurf->PolyColor.s.red];
poly.green = byte2float[pSurf->PolyColor.s.green];
poly.blue = byte2float[pSurf->PolyColor.s.blue];
poly.alpha = byte2float[pSurf->PolyColor.s.alpha];
static int comparePolygons(const void *p1, const void *p2)
{
unsigned int index1 = *(const unsigned int*)p1;
unsigned int index2 = *(const unsigned int*)p2;
PolygonArrayEntry* poly1 = &polygonArray[index1];
PolygonArrayEntry* poly2 = &polygonArray[index2];
int diff;
INT64 diff64;
pglColor4ubv((GLubyte*)&pSurf->PolyColor.s);
}
int shader1 = poly1->shader;
int shader2 = poly2->shader;
// make skywalls and horizon lines first in order
if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial)
shader1 = -1;
if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial)
shader2 = -1;
diff = shader1 - shader2;
if (diff != 0) return diff;
// Tint color
tint.red = byte2float[pSurf->TintColor.s.red];
tint.green = byte2float[pSurf->TintColor.s.green];
tint.blue = byte2float[pSurf->TintColor.s.blue];
tint.alpha = byte2float[pSurf->TintColor.s.alpha];
// skywalls and horizon lines must retain their order for horizon lines to work
if (shader1 == -1 && shader2 == -1)
return index1 - index2;
diff = poly1->texNum - poly2->texNum;
if (diff != 0) return diff;
if (gl_palshader)
{
diff = poly1->surf.LightTableId - poly2->surf.LightTableId;
if (diff != 0) return diff;
// Fade color
fade.red = byte2float[pSurf->FadeColor.s.red];
fade.green = byte2float[pSurf->FadeColor.s.green];
fade.blue = byte2float[pSurf->FadeColor.s.blue];
fade.alpha = byte2float[pSurf->FadeColor.s.alpha];
}
diff = poly1->polyFlags - poly2->polyFlags;
if (diff != 0) return diff;
diff64 = poly1->surf.PolyColor.rgba - poly2->surf.PolyColor.rgba;
if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
diff64 = poly1->surf.TintColor.rgba - poly2->surf.TintColor.rgba;
if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
diff64 = poly1->surf.FadeColor.rgba - poly2->surf.FadeColor.rgba;
if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
diff = poly1->surf.LightInfo.light_level - poly2->surf.LightInfo.light_level;
if (diff != 0) return diff;
diff = poly1->surf.LightInfo.fade_start - poly2->surf.LightInfo.fade_start;
if (diff != 0) return diff;
diff = poly1->surf.LightInfo.fade_end - poly2->surf.LightInfo.fade_end;
return diff;
}
static int comparePolygonsNoShaders(const void *p1, const void *p2)
{
unsigned int index1 = *(const unsigned int*)p1;
unsigned int index2 = *(const unsigned int*)p2;
PolygonArrayEntry* poly1 = &polygonArray[index1];
PolygonArrayEntry* poly2 = &polygonArray[index2];
int diff;
INT64 diff64;
GLuint texNum1 = poly1->texNum;
GLuint texNum2 = poly2->texNum;
if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial)
texNum1 = 0;
if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial)
texNum2 = 0;
diff = texNum1 - texNum2;
if (diff != 0) return diff;
// skywalls and horizon lines must retain their order for horizon lines to work
if (texNum1 == 0 && texNum2 == 0)
return index1 - index2;
diff = poly1->polyFlags - poly2->polyFlags;
if (diff != 0) return diff;
diff64 = poly1->surf.PolyColor.rgba - poly2->surf.PolyColor.rgba;
if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
return 0;
}
// the parameters for this functions (numPolys etc.) are used to return rendering stats
EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors)
{
int finalVertexWritePos = 0;// position in finalVertexArray
int finalIndexWritePos = 0;// position in finalVertexIndexArray
int polygonReadPos = 0;// position in polygonIndexArray
GLuint currentShader;
GLuint currentTexture;
FBITFIELD currentPolyFlags;
FSurfaceInfo currentSurfaceInfo;
GLRGBAFloat firstPoly = {0,0,0,0}; // may be misleading but this means first PolyColor
GLRGBAFloat firstTint = {0,0,0,0};
GLRGBAFloat firstFade = {0,0,0,0};
boolean needRebind = false;
int i;
//CONS_Printf("RenderBatches\n");
gl_batching = false;// no longer collecting batches
if (!polygonArraySize)
{
*sSortTime = *sDrawTime = *sNumPolys = *sNumCalls = *sNumShaders = *sNumTextures = *sNumPolyFlags = *sNumColors = 0;
return;// nothing to draw
}
// init stats vars
*sNumPolys = polygonArraySize;
*sNumCalls = *sNumVerts = 0;
*sNumShaders = *sNumTextures = *sNumPolyFlags = *sNumColors = 1;
// init polygonIndexArray
for (i = 0; i < polygonArraySize; i++)
{
polygonIndexArray[i] = i;
}
// sort polygons
//CONS_Printf("qsort polys\n");
*sSortTime = I_GetPreciseTime();
if (gl_allowshaders)
qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons);
else
qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders);
*sSortTime = I_GetPreciseTime() - *sSortTime;
//CONS_Printf("sort done\n");
// sort order
// 1. shader
// 2. texture
// 3. polyflags
// 4. colors + light level
// not sure about order of last 2, or if it even matters
*sDrawTime = I_GetPreciseTime();
currentShader = polygonArray[polygonIndexArray[0]].shader;
currentTexture = polygonArray[polygonIndexArray[0]].texNum;
currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags;
currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf;
// For now, will sort and track the colors. Vertex attributes could be used instead of uniforms
// and a color array could replace the color calls.
// set state for first batch
//CONS_Printf("set first state\n");
gl_currentshaderprogram = currentShader;
gl_shaderprogramchanged = true;
if (currentPolyFlags & PF_Modulated)
{
// Poly color
firstPoly.red = byte2float[currentSurfaceInfo.PolyColor.s.red];
firstPoly.green = byte2float[currentSurfaceInfo.PolyColor.s.green];
firstPoly.blue = byte2float[currentSurfaceInfo.PolyColor.s.blue];
firstPoly.alpha = byte2float[currentSurfaceInfo.PolyColor.s.alpha];
pglColor4ubv((GLubyte*)&currentSurfaceInfo.PolyColor.s);
}
// Tint color
firstTint.red = byte2float[currentSurfaceInfo.TintColor.s.red];
firstTint.green = byte2float[currentSurfaceInfo.TintColor.s.green];
firstTint.blue = byte2float[currentSurfaceInfo.TintColor.s.blue];
firstTint.alpha = byte2float[currentSurfaceInfo.TintColor.s.alpha];
// Fade color
firstFade.red = byte2float[currentSurfaceInfo.FadeColor.s.red];
firstFade.green = byte2float[currentSurfaceInfo.FadeColor.s.green];
firstFade.blue = byte2float[currentSurfaceInfo.FadeColor.s.blue];
firstFade.alpha = byte2float[currentSurfaceInfo.FadeColor.s.alpha];
if (gl_allowshaders)
{
Shader_Load(&currentSurfaceInfo, &firstPoly, &firstTint, &firstFade);
if (gl_palshader)
{
pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now
pglBindTexture(GL_TEXTURE_2D, currentSurfaceInfo.LightTableId);
pglActiveTexture(GL_TEXTURE0);
}
}
if (currentPolyFlags & PF_NoTexture)
currentTexture = 0;
pglBindTexture(GL_TEXTURE_2D, currentTexture);
tex_downloaded = currentTexture;
SetBlend(currentPolyFlags);
//CONS_Printf("first pointers to ogl\n");
pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &finalVertexArray[0].x);
pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &finalVertexArray[0].s);
while (1)// note: remember handling notexture polyflag as having texture number 0 (also in comparePolygons)
{
int firstIndex;
int lastIndex;
boolean stopFlag = false;
boolean changeState = false;
boolean changeShader = false;
GLuint nextShader = 0U;
boolean changeTexture = false;
GLuint nextTexture = 0U;
boolean changePolyFlags = false;
FBITFIELD nextPolyFlags = 0U;
boolean changeSurfaceInfo = false;
FSurfaceInfo nextSurfaceInfo;
//CONS_Printf("loop iter start\n");
// new try:
// write vertices
// check for changes or end, otherwise go back to writing
// changes will affect the next vars and the change bools
// end could set flag for stopping
// execute draw call
// could check ending flag here
// change states according to next vars and change bools, updating the current vars and reseting the bools
// reset write pos
// repeat loop
int index = polygonIndexArray[polygonReadPos++];
int numVerts = polygonArray[index].numVerts;
// before writing, check if there is enough room
// using 'while' instead of 'if' here makes sure that there will *always* be enough room.
// probably never will this loop run more than once though
while (finalVertexWritePos + numVerts > finalVertexArrayAllocSize)
{
FOutVector* new_array;
unsigned int* new_index_array;
//CONS_Printf("final vert realloc\n");
finalVertexArrayAllocSize *= 2;
new_array = malloc(finalVertexArrayAllocSize * sizeof(FOutVector));
memcpy(new_array, finalVertexArray, finalVertexWritePos * sizeof(FOutVector));
free(finalVertexArray);
finalVertexArray = new_array;
// also increase size of index array, 3x of vertex array since
// going from fans to triangles increases vertex count to 3x
new_index_array = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32));
memcpy(new_index_array, finalVertexIndexArray, finalIndexWritePos * sizeof(UINT32));
free(finalVertexIndexArray);
finalVertexIndexArray = new_index_array;
// if vertex buffers are reallocated then opengl needs to know too
needRebind = true;
}
//CONS_Printf("write verts to final\n");
// write the vertices of the polygon
memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[polygonArray[index].vertsIndex],
numVerts * sizeof(FOutVector));
// write the indexes, pointing to the fan vertexes but in triangles format
firstIndex = finalVertexWritePos;
lastIndex = finalVertexWritePos + numVerts;
finalVertexWritePos += 2;
//CONS_Printf("write final vert indices\n");
while (finalVertexWritePos < lastIndex)
{
finalVertexIndexArray[finalIndexWritePos++] = firstIndex;
finalVertexIndexArray[finalIndexWritePos++] = finalVertexWritePos - 1;
finalVertexIndexArray[finalIndexWritePos++] = finalVertexWritePos++;
}
if (polygonReadPos >= polygonArraySize)
{
stopFlag = true;
}
else
{
//CONS_Printf("state change check\n");
// check if a state change is required, set the change bools and next vars
int nextIndex = polygonIndexArray[polygonReadPos];
nextShader = polygonArray[nextIndex].shader;
nextTexture = polygonArray[nextIndex].texNum;
nextPolyFlags = polygonArray[nextIndex].polyFlags;
nextSurfaceInfo = polygonArray[nextIndex].surf;
if (nextPolyFlags & PF_NoTexture)
nextTexture = 0;
if (currentShader != nextShader)
{
changeState = true;
changeShader = true;
}
if (currentTexture != nextTexture)
{
changeState = true;
changeTexture = true;
}
if (currentPolyFlags != nextPolyFlags)
{
changeState = true;
changePolyFlags = true;
}
if (gl_allowshaders && gl_palshader)
{
if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba ||
currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba ||
currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba ||
currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level ||
currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start ||
currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end ||
currentSurfaceInfo.LightTableId != nextSurfaceInfo.LightTableId)
{
changeState = true;
changeSurfaceInfo = true;
}
}
else if ((gl_allowshaders) && (!gl_palshader))
{
if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba ||
currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba ||
currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba ||
currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level ||
currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start ||
currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end)
{
changeState = true;
changeSurfaceInfo = true;
}
}
else
{
if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba)
{
changeState = true;
changeSurfaceInfo = true;
}
}
}
if (changeState || stopFlag)
{
if (needRebind)
{
//CONS_Printf("rebind\n");
pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &finalVertexArray[0].x);
pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &finalVertexArray[0].s);
needRebind = false;
}
//CONS_Printf("exec draw call\n");
// execute draw call
pglDrawElements(GL_TRIANGLES, finalIndexWritePos, GL_UNSIGNED_INT, finalVertexIndexArray);
//CONS_Printf("draw call done\n");
// update stats
(*sNumCalls)++;
*sNumVerts += finalIndexWritePos;
// reset write positions
finalVertexWritePos = 0;
finalIndexWritePos = 0;
}
else continue;
// if we're here then either its time to stop or time to change state
if (stopFlag) break;
//CONS_Printf("state change\n");
// change state according to change bools and next vars, update current vars and reset bools
if (changeShader)
{
GLRGBAFloat poly = {0,0,0,0};
GLRGBAFloat tint = {0,0,0,0};
GLRGBAFloat fade = {0,0,0,0};
gl_currentshaderprogram = nextShader;
gl_shaderprogramchanged = true;
if (nextPolyFlags & PF_Modulated)
{
// Poly color
poly.red = byte2float[nextSurfaceInfo.PolyColor.s.red];
poly.green = byte2float[nextSurfaceInfo.PolyColor.s.green];
poly.blue = byte2float[nextSurfaceInfo.PolyColor.s.blue];
poly.alpha = byte2float[nextSurfaceInfo.PolyColor.s.alpha];
}
// Tint color
tint.red = byte2float[nextSurfaceInfo.TintColor.s.red];
tint.green = byte2float[nextSurfaceInfo.TintColor.s.green];
tint.blue = byte2float[nextSurfaceInfo.TintColor.s.blue];
tint.alpha = byte2float[nextSurfaceInfo.TintColor.s.alpha];
// Fade color
fade.red = byte2float[nextSurfaceInfo.FadeColor.s.red];
fade.green = byte2float[nextSurfaceInfo.FadeColor.s.green];
fade.blue = byte2float[nextSurfaceInfo.FadeColor.s.blue];
fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha];
Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade);
currentShader = nextShader;
changeShader = false;
(*sNumShaders)++;
}
if (changeTexture)
{
// texture should be already ready for use from calls to SetTexture during batch collection
pglBindTexture(GL_TEXTURE_2D, nextTexture);
tex_downloaded = nextTexture;
currentTexture = nextTexture;
changeTexture = false;
(*sNumTextures)++;
}
if (changePolyFlags)
{
SetBlend(nextPolyFlags);
currentPolyFlags = nextPolyFlags;
changePolyFlags = false;
(*sNumPolyFlags)++;
}
if (changeSurfaceInfo)
{
GLRGBAFloat poly = {0,0,0,0};
GLRGBAFloat tint = {0,0,0,0};
GLRGBAFloat fade = {0,0,0,0};
gl_shaderprogramchanged = false;
if (nextPolyFlags & PF_Modulated)
{
// Poly color
poly.red = byte2float[nextSurfaceInfo.PolyColor.s.red];
poly.green = byte2float[nextSurfaceInfo.PolyColor.s.green];
poly.blue = byte2float[nextSurfaceInfo.PolyColor.s.blue];
poly.alpha = byte2float[nextSurfaceInfo.PolyColor.s.alpha];
pglColor4ubv((GLubyte*)&nextSurfaceInfo.PolyColor.s);
}
if (gl_allowshaders)
{
// Tint color
tint.red = byte2float[nextSurfaceInfo.TintColor.s.red];
tint.green = byte2float[nextSurfaceInfo.TintColor.s.green];
tint.blue = byte2float[nextSurfaceInfo.TintColor.s.blue];
tint.alpha = byte2float[nextSurfaceInfo.TintColor.s.alpha];
// Fade color
fade.red = byte2float[nextSurfaceInfo.FadeColor.s.red];
fade.green = byte2float[nextSurfaceInfo.FadeColor.s.green];
fade.blue = byte2float[nextSurfaceInfo.FadeColor.s.blue];
fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha];
Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade);
if (gl_palshader)
{
pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now
pglBindTexture(GL_TEXTURE_2D, nextSurfaceInfo.LightTableId);
pglActiveTexture(GL_TEXTURE0);
}
}
currentSurfaceInfo = nextSurfaceInfo;
changeSurfaceInfo = false;
(*sNumColors)++;
}
// and that should be it?
}
// reset the arrays (set sizes to 0)
polygonArraySize = 0;
unsortedVertexArraySize = 0;
*sDrawTime = I_GetPreciseTime() - *sDrawTime;
Shader_Load(pSurf, &poly, &tint, &fade);
}
// -----------------+
// DrawPolygon : Render a polygon, set the texture, set render mode
// -----------------+
EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, boolean horizonSpecial)
EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags)
{
if (gl_batching)
{
//CONS_Printf("Batched DrawPolygon\n");
if (!pSurf)
I_Error("Got a null FSurfaceInfo in batching");// nulls should only come in sky background pic drawing
if (polygonArraySize == polygonArrayAllocSize)
{
PolygonArrayEntry* new_array;
// ran out of space, make new array double the size
polygonArrayAllocSize *= 2;
new_array = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry));
memcpy(new_array, polygonArray, polygonArraySize * sizeof(PolygonArrayEntry));
free(polygonArray);
polygonArray = new_array;
// also need to redo the index array, dont need to copy it though
free(polygonIndexArray);
polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(unsigned int));
}
PreparePolygon(pSurf, pOutVerts, PolyFlags);
while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize)
{
FOutVector* new_array;
// need more space for vertices in unsortedVertexArray
unsortedVertexArrayAllocSize *= 2;
new_array = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector));
memcpy(new_array, unsortedVertexArray, unsortedVertexArraySize * sizeof(FOutVector));
free(unsortedVertexArray);
unsortedVertexArray = new_array;
}
pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x);
pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s);
pglDrawArrays(GL_TRIANGLE_FAN, 0, iNumPts);
// add the polygon data to the arrays
if (PolyFlags & PF_RemoveYWrap)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
polygonArray[polygonArraySize].surf = *pSurf;
polygonArray[polygonArraySize].vertsIndex = unsortedVertexArraySize;
polygonArray[polygonArraySize].numVerts = iNumPts;
polygonArray[polygonArraySize].polyFlags = PolyFlags;
polygonArray[polygonArraySize].texNum = tex_downloaded;
polygonArray[polygonArraySize].shader = gl_currentshaderprogram;
polygonArray[polygonArraySize].horizonSpecial = horizonSpecial;
polygonArraySize++;
if (PolyFlags & PF_ForceWrapX)
Clamp2D(GL_TEXTURE_WRAP_S);
memcpy(&unsortedVertexArray[unsortedVertexArraySize], pOutVerts, iNumPts * sizeof(FOutVector));
unsortedVertexArraySize += iNumPts;
}
else
{
static GLRGBAFloat poly = {0,0,0,0};
static GLRGBAFloat tint = {0,0,0,0};
static GLRGBAFloat fade = {0,0,0,0};
if (PolyFlags & PF_ForceWrapY)
Clamp2D(GL_TEXTURE_WRAP_T);
}
SetBlend(PolyFlags); //TODO: inline (#pragma..)
EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray)
{
PreparePolygon(pSurf, pOutVerts, PolyFlags);
if (gl_portal_mode == HWD_PORTAL_NORMAL)
{
// PolyColor
if (pSurf)
{
// If modulated, mix the surface colour to the texture
if (CurrentPolyFlags & PF_Modulated)
pglColor4ubv((GLubyte*)&pSurf->PolyColor.s);
pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x);
pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s);
pglDrawElements(GL_TRIANGLES, iNumPts, GL_UNSIGNED_INT, IndexArray);
// If the surface is either modulated or colormapped, or both
if (CurrentPolyFlags & (PF_Modulated | PF_ColorMapped))
{
poly.red = byte2float[pSurf->PolyColor.s.red];
poly.green = byte2float[pSurf->PolyColor.s.green];
poly.blue = byte2float[pSurf->PolyColor.s.blue];
poly.alpha = byte2float[pSurf->PolyColor.s.alpha];
}
// Only if the surface is colormapped
if (CurrentPolyFlags & PF_ColorMapped)
{
tint.red = byte2float[pSurf->TintColor.s.red];
tint.green = byte2float[pSurf->TintColor.s.green];
tint.blue = byte2float[pSurf->TintColor.s.blue];
tint.alpha = byte2float[pSurf->TintColor.s.alpha];
fade.red = byte2float[pSurf->FadeColor.s.red];
fade.green = byte2float[pSurf->FadeColor.s.green];
fade.blue = byte2float[pSurf->FadeColor.s.blue];
fade.alpha = byte2float[pSurf->FadeColor.s.alpha];
}
if (gl_palshader && gl_allowshaders)
{
pglActiveTexture(GL_TEXTURE2);
pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId);
pglActiveTexture(GL_TEXTURE0);
}
}
Shader_Load(pSurf, &poly, &tint, &fade);
}
else
UnSetShader();
pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x);
pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s);
pglDrawArrays(GL_TRIANGLE_FAN, 0, iNumPts);
if (PolyFlags & PF_RemoveYWrap)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (PolyFlags & PF_ForceWrapX)
Clamp2D(GL_TEXTURE_WRAP_S);
if (PolyFlags & PF_ForceWrapY)
Clamp2D(GL_TEXTURE_WRAP_T);
}
// the DrawPolygon variant of this has some code about polyflags and wrapping here but havent noticed any problems from omitting it?
}
// Sky dome code, taken/backported from SRB2
+2 -4
View File
@@ -81,6 +81,7 @@ void *hwSym(const char *funcName,void *handle)
GETFUNC(SetupGLInfo);
GETFUNC(Draw2DLine);
GETFUNC(DrawPolygon);
GETFUNC(DrawIndexedTriangles);
GETFUNC(SetBlend);
GETFUNC(ClearBuffer);
GETFUNC(SetTexture);
@@ -114,10 +115,7 @@ void *hwSym(const char *funcName,void *handle)
GETFUNC(SetShaderInfo);
GETFUNC(LoadCustomShader);
GETFUNC(InitCustomShaders);
GETFUNC(StartBatching);
GETFUNC(RenderBatches);
GETFUNC(InitPalette);
GETFUNC(AddLightTable);
GETFUNC(ClearLightTableCache);
+1 -3
View File
@@ -2113,6 +2113,7 @@ void I_StartupGraphics(void)
HWD.pfnFinishUpdate = NULL;
HWD.pfnDraw2DLine = hwSym("Draw2DLine",NULL);
HWD.pfnDrawPolygon = hwSym("DrawPolygon",NULL);
HWD.pfnDrawIndexedTriangles = hwSym("DrawIndexedTriangles",NULL);
HWD.pfnSetBlend = hwSym("SetBlend",NULL);
HWD.pfnClearBuffer = hwSym("ClearBuffer",NULL);
HWD.pfnSetTexture = hwSym("SetTexture",NULL);
@@ -2148,9 +2149,6 @@ void I_StartupGraphics(void)
HWD.pfnLoadCustomShader = hwSym("LoadCustomShader",NULL);
HWD.pfnInitCustomShaders = hwSym("InitCustomShaders",NULL);
HWD.pfnStartBatching = hwSym("StartBatching",NULL);
HWD.pfnRenderBatches = hwSym("RenderBatches",NULL);
HWD.pfnInitPalette = hwSym("InitPalette",NULL);
HWD.pfnAddLightTable = hwSym("AddLightTable",NULL);
HWD.pfnClearLightTableCache = hwSym("ClearLightTableCache",NULL);