From f3bdcb4ec3414d2ce2558a4289cde47cf0772634 Mon Sep 17 00:00:00 2001 From: Hannu Hanhi Date: Sun, 12 Apr 2020 14:17:40 +0300 Subject: [PATCH] Backport from SRB2: Replace NextTexAvail with glGenTextures --- src/hardware/r_opengl/r_opengl.c | 33 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 659388d2..edb0430e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -44,7 +44,6 @@ static const GLubyte white[4] = { 255, 255, 255, 255 }; // With OpenGL 1.1+, the first texture should be 1 #define NOTEXTURE_NUM 0 -#define FIRST_TEX_AVAIL (NOTEXTURE_NUM + 1) #define N_PI_DEMI (M_PIl/2.0f) //(1.5707963268f) @@ -57,7 +56,6 @@ static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE; // ************************************************************************** -static GLuint NextTexAvail = FIRST_TEX_AVAIL; static GLuint tex_downloaded = 0; static GLfloat fov = 90.0f; static FBITFIELD CurrentPolyFlags; @@ -91,16 +89,10 @@ static GLint viewport[4]; GLubyte palette_tex[256*3]; #endif -// Yay for arbitrary numbers! NextTexAvail is buggy for some reason. // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing // flush all of the stored textures, leaving them unavailable at times such as between levels // These need to start at 0 and be set to their number, and be reset to 0 when deleted so that Intel GPUs // can know when the textures aren't there, as textures are always considered resident in their virtual memory -// TODO: Store them in a more normal way -#define SCRTEX_SCREENTEXTURE 4294967295U -#define SCRTEX_STARTSCREENWIPE 4294967294U -#define SCRTEX_ENDSCREENWIPE 4294967293U -#define SCRTEX_FINALSCREENTEXTURE 4294967292U static GLuint screentexture = 0; static GLuint startScreenWipe = 0; static GLuint endScreenWipe = 0; @@ -1014,7 +1006,7 @@ void SetStates(void) CurrentPolyFlags = 0xffffffff; SetBlend(0); - tex_downloaded = (GLuint)-1; + //tex_downloaded = (GLuint)-1; SetNoTexture(); pglPolygonOffset(-1.0f, -1.0f); @@ -1037,12 +1029,12 @@ void Flush(void) { // ceci n'est pas du tout necessaire vu que tu les a charger normalement et // donc il sont dans ta liste ! - pglDeleteTextures(1, (GLuint *)&gr_cachehead->downloaded); + if (gr_cachehead->downloaded) + pglDeleteTextures(1, (GLuint *)&gr_cachehead->downloaded); gr_cachehead->downloaded = 0; gr_cachehead = gr_cachehead->nextmipmap; } gr_cachetail = gr_cachehead = NULL; //Hurdler: well, gr_cachehead is already NULL - NextTexAvail = FIRST_TEX_AVAIL; tex_downloaded = 0; } @@ -1415,8 +1407,10 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) static RGBA_t tex[2048*2048]; const GLvoid *ptex = tex; INT32 w, h; + GLuint texnum = 0; - //GL_DBG_Printf("DownloadMipmap %d\n", NextTexAvail, pTexInfo->grInfo.data); + pglGenTextures(1, &texnum); + //GL_DBG_Printf("DownloadMipmap %d\n", (INT32)texnum, pTexInfo->grInfo.data); w = pTexInfo->width; h = pTexInfo->height; @@ -1515,9 +1509,10 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) else GL_DBG_Printf("SetTexture(bad format) %ld\n", pTexInfo->grInfo.format); - pTexInfo->downloaded = NextTexAvail++; - tex_downloaded = pTexInfo->downloaded; - pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded); + // the texture number was already generated by pglGenTextures + pglBindTexture(GL_TEXTURE_2D, texnum); + pTexInfo->downloaded = texnum; + tex_downloaded = texnum; // disable texture filtering on any texture that has holes so there's no dumb borders or blending issues if (pTexInfo->flags & TF_TRANSPARENT) @@ -2914,7 +2909,7 @@ EXPORT void HWRAPI(StartScreenWipe) (void) // Create screen texture if (firstTime) - startScreenWipe = SCRTEX_STARTSCREENWIPE; + pglGenTextures(1, &startScreenWipe); pglBindTexture(GL_TEXTURE_2D, startScreenWipe); if (firstTime) @@ -2945,7 +2940,7 @@ EXPORT void HWRAPI(EndScreenWipe)(void) // Create screen texture if (firstTime) - endScreenWipe = SCRTEX_ENDSCREENWIPE; + pglGenTextures(1, &endScreenWipe); pglBindTexture(GL_TEXTURE_2D, endScreenWipe); if (firstTime) @@ -3105,7 +3100,7 @@ EXPORT void HWRAPI(MakeScreenTexture) (void) // Create screen texture if (firstTime) - screentexture = SCRTEX_SCREENTEXTURE; + pglGenTextures(1, &screentexture); pglBindTexture(GL_TEXTURE_2D, screentexture); if (firstTime) @@ -3135,7 +3130,7 @@ EXPORT void HWRAPI(MakeScreenFinalTexture) (void) // Create screen texture if (firstTime) - finalScreenTexture = SCRTEX_FINALSCREENTEXTURE; + pglGenTextures(1, &finalScreenTexture); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); if (firstTime)