From 4847d2d8448ae5e5d588bb4bb3e817ba9afc1513 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 17:51:58 +0100 Subject: [PATCH 1/7] Handle OpenGL textures with a linked list --- src/hardware/hw_cache.c | 1 + src/hardware/hw_defs.h | 12 +++- src/hardware/hw_drv.h | 6 +- src/hardware/hw_main.c | 1 - src/hardware/r_opengl/r_opengl.c | 106 +++++++++++++++++++++++-------- src/sdl/hwsym_sdl.c | 1 + src/sdl/i_video.c | 1 + 7 files changed, 97 insertions(+), 31 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 888a8414e..db15bf5d2 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -492,6 +492,7 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) if (next->data) Z_Free(next->data); next->data = NULL; + HWD.pfnDeleteTexture(next); // Free the old colormap mipmap from memory. free(next); diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index b7c46b2e1..b49c0f316 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -253,7 +253,17 @@ enum ETextureFlags TF_TRANSPARENT = 0x00000040, // texture with some alpha == 0 }; -typedef struct GLMipmap_s FTextureInfo; +struct FTextureInfo +{ + UINT32 width, height; + UINT32 downloaded; + UINT32 format; + + struct GLMipmap_s *texture; + struct FTextureInfo *prev, *next; +}; +typedef struct FTextureInfo FTextureInfo; + struct FLightInfo { diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 7d58dc495..8376ab405 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -36,8 +36,9 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI 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); -EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *TexInfo); +EXPORT void HWRAPI(SetTexture) (GLMipmap_t *TexInfo); +EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *TexInfo); +EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *TexInfo); EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT16 *dst_data); EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip, float farclip); EXPORT void HWRAPI(ClearMipMapCache) (void); @@ -99,6 +100,7 @@ struct hwdriver_s ClearBuffer pfnClearBuffer; SetTexture pfnSetTexture; UpdateTexture pfnUpdateTexture; + DeleteTexture pfnDeleteTexture; ReadScreenTexture pfnReadScreenTexture; GClipRect pfnGClipRect; ClearMipMapCache pfnClearMipMapCache; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 131775c53..2f0d72cd7 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4947,7 +4947,6 @@ void HWR_ProjectSprite(mobj_t *thing) spritexscale = FIXED_TO_FLOAT(interp.spritexscale); spriteyscale = FIXED_TO_FLOAT(interp.spriteyscale); - // transform the origin point tr_x = FIXED_TO_FLOAT(interp.x) - gr_viewx; tr_y = FIXED_TO_FLOAT(interp.y) - gr_viewy; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 9fcf90a62..e8a1cc003 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -79,8 +79,9 @@ static GLuint lt_downloaded = 0; // currently bound lighttable texture static GLfloat fov = 90.0f; static FBITFIELD CurrentPolyFlags; -static FTextureInfo *gr_cachetail = NULL; -static FTextureInfo *gr_cachehead = NULL; +// Linked list of all textures. +static FTextureInfo *TexCacheTail = NULL; +static FTextureInfo *TexCacheHead = NULL; static RGBA_t *textureBuffer = NULL; static size_t textureBufferSize = 0; @@ -935,7 +936,7 @@ void SetStates(void) pglEnable(GL_STENCIL_TEST); pglEnable(GL_DEPTH_TEST); // check the depth buffer - pglDepthMask(GL_TRUE); // enable writing to depth buffer + pglDepthMask(GL_TRUE); // enable writing to depth buffer pglClearDepth(1.0f); pglDepthRange(0.0f, 1.0f); pglDepthFunc(GL_LEQUAL); @@ -954,6 +955,40 @@ void SetStates(void) pglScalef(1.0f, 1.0f, -1.0f); pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer) } +// -----------------+ +// DeleteTexture : Deletes a texture from the GPU and frees its data +// -----------------+ +EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *pTexInfo) +{ + FTextureInfo *head = TexCacheHead; + + if (!pTexInfo) + return; + else if (pTexInfo->downloaded) + pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded); + + while (head) + { + if (head->downloaded == pTexInfo->downloaded) + { + if (head->next) + head->next->prev = head->prev; + else // no next -> tail is being deleted -> update TexCacheTail + TexCacheTail = head->prev; + if (head->prev) + head->prev->next = head->next; + else // no prev -> head is being deleted -> update TexCacheHead + TexCacheHead = head->next; + free(head); + break; + } + + head = head->next; + } + + pTexInfo->downloaded = 0; +} + // -----------------+ // Flush : flush OpenGL textures @@ -961,21 +996,29 @@ void SetStates(void) // -----------------+ void Flush(void) { - //GL_DBG_Printf("HWR_Flush()\n"); + //GL_DBG_Printf ("HWR_Flush()\n"); - while (gr_cachehead) + while (TexCacheHead) { - // this is not necessary at all, because you have loaded them normally, - // and so they already are in your list! - 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 + FTextureInfo *pTexInfo = TexCacheHead; + GLMipmap_t *texture = pTexInfo->texture; + if (pTexInfo->downloaded) + { + pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded); + pTexInfo->downloaded = 0; + } + + if (texture) + texture->downloaded = 0; + + TexCacheHead = pTexInfo->next; + free(pTexInfo); + } + + TexCacheTail = TexCacheHead = NULL; //Hurdler: well, TexCacheHead is already NULL tex_downloaded = 0; - + free(textureBuffer); textureBuffer = NULL; textureBufferSize = 0; @@ -1334,7 +1377,7 @@ static void AllocTextureBuffer(GLMipmap_t *pTexInfo) // -----------------+ // UpdateTexture : Updates texture data. // -----------------+ -EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) +EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo) { // Upload a texture GLuint num = pTexInfo->downloaded; @@ -1391,7 +1434,6 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) tex[w*j+i].s.alpha = *pImgData; pImgData++; } - } } } @@ -1474,7 +1516,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); } else @@ -1506,7 +1548,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); } else @@ -1567,7 +1609,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) // -----------------+ // SetTexture : The mipmap becomes the current texture source // -----------------+ -EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) +EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo) { if (!pTexInfo) { @@ -1584,15 +1626,25 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) } else { + FTextureInfo *newTex = calloc(1, sizeof (*newTex)); + UpdateTexture(pTexInfo); - pTexInfo->nextmipmap = NULL; - if (gr_cachetail) - { // insertion at the tail - gr_cachetail->nextmipmap = pTexInfo; - gr_cachetail = pTexInfo; + + newTex->texture = pTexInfo; + newTex->downloaded = (UINT32)pTexInfo->downloaded; + newTex->width = (UINT32)pTexInfo->width; + newTex->height = (UINT32)pTexInfo->height; + newTex->format = (UINT32)pTexInfo->format; + + // insertion at the tail + if (TexCacheTail) + { + newTex->prev = TexCacheTail; + TexCacheTail->next = newTex; + TexCacheTail = newTex; } else // initialization of the linked list - gr_cachetail = gr_cachehead = pTexInfo; + TexCacheTail = TexCacheHead = newTex; } } @@ -2794,7 +2846,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) EXPORT INT32 HWRAPI(GetTextureUsed) (void) { - FTextureInfo *tmp = gr_cachehead; + FTextureInfo *tmp = TexCacheHead; INT32 res = 0; while (tmp) @@ -2811,7 +2863,7 @@ EXPORT INT32 HWRAPI(GetTextureUsed) (void) // Add it up! res += tmp->height*tmp->width*bpp; - tmp = tmp->nextmipmap; + tmp = tmp->next; } return res; diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 64f9b7da9..23526a98f 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -86,6 +86,7 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(ClearBuffer); GETFUNC(SetTexture); GETFUNC(UpdateTexture); + GETFUNC(DeleteTexture); GETFUNC(ReadScreenTexture); GETFUNC(GClipRect); GETFUNC(ClearMipMapCache); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a1dd8bef6..1738145e6 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2268,6 +2268,7 @@ void I_StartupGraphics(void) HWD.pfnClearBuffer = hwSym("ClearBuffer",NULL); HWD.pfnSetTexture = hwSym("SetTexture",NULL); HWD.pfnUpdateTexture = hwSym("UpdateTexture",NULL); + HWD.pfnDeleteTexture = hwSym("DeleteTexture",NULL); HWD.pfnReadScreenTexture= hwSym("ReadScreenTexture",NULL); HWD.pfnGClipRect = hwSym("GClipRect",NULL); HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL); -- 2.54.0 From 2fc6a26e7773cc23459ceec1fbf92d131d0f5de8 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 20:36:07 +0100 Subject: [PATCH 2/7] GL_GENERATE_MIPMAP is enough also made MajorGL and MinorGL extern, so can be used in other parts if needed to check for it --- src/hardware/r_opengl/r_opengl.c | 83 ++++++++------------------------ src/hardware/r_opengl/r_opengl.h | 3 ++ src/sdl/ogl_sdl.c | 5 ++ 3 files changed, 27 insertions(+), 64 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 9fcf90a62..a5a519ec2 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -103,12 +103,16 @@ static GLboolean MipMap = GL_FALSE; static GLint min_filter = GL_LINEAR; static GLint mag_filter = GL_LINEAR; static GLint anisotropic_filter = 0; +boolean supportMipMap = false; static FTransform md2_transform; const GLubyte *gl_version = NULL; const GLubyte *gl_renderer = NULL; const GLubyte *gl_extensions = NULL; +// Loaded OpenGL version +int majorGL = 0, minorGL = 0; + //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) static GLfloat modelMatrix[16]; GLfloat projMatrix[16]; @@ -157,9 +161,6 @@ static const GLfloat byte2float[256] = { 0.972549f, 0.976471f, 0.980392f, 0.984314f, 0.988235f, 0.992157f, 0.996078f, 1.000000f }; -// Loaded OpenGL version -static int majorGL = 0, minorGL = 0; - // -----------------+ // GL_DBG_Printf : Output debug messages to debug log if DEBUG_TO_FILE is defined, // : else do nothing @@ -427,11 +428,6 @@ static PFNglCopyTexImage2D pglCopyTexImage2D; typedef void (APIENTRY * PFNglCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; #endif - -/* 3.0 functions */ -#ifdef GL_VERSION_3_0 -typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target); -static PFNglGenerateMipmap pglGenerateMipmap; #endif /* 1.2 functions for 3D textures */ @@ -716,10 +712,6 @@ void SetupGLFunc4(void) pglUniform2fv = GetGLFunc("glUniform2fv"); pglUniform3fv = GetGLFunc("glUniform3fv"); pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); - -#ifdef GL_VERSION_3_0 - pglGenerateMipmap = GetGLFunc("glGenerateMipmap"); -#endif } EXPORT boolean HWRAPI(InitShaders) (void) @@ -935,7 +927,7 @@ void SetStates(void) pglEnable(GL_STENCIL_TEST); pglEnable(GL_DEPTH_TEST); // check the depth buffer - pglDepthMask(GL_TRUE); // enable writing to depth buffer + pglDepthMask(GL_TRUE); // enable writing to depth buffer pglClearDepth(1.0f); pglDepthRange(0.0f, 1.0f); pglDepthFunc(GL_LEQUAL); @@ -1458,23 +1450,14 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); if (MipMap) { - if ((majorGL == 1 && minorGL >= 4) || (majorGL == 2)) - { - pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - } -#ifdef GL_VERSION_3_0 - else if (majorGL >= 3) - { - pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - pglGenerateMipmap(GL_TEXTURE_2D); - } -#endif + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); } else @@ -1490,23 +1473,14 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); if (MipMap) { - if ((majorGL == 1 && minorGL >= 4) || (majorGL == 2)) - { - pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - } -#ifdef GL_VERSION_3_0 - else if (majorGL >= 3) - { - pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - pglGenerateMipmap(GL_TEXTURE_2D); - } -#endif + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); } else @@ -1521,24 +1495,15 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) { if (MipMap) { - if ((majorGL == 1 && minorGL >= 4) || (majorGL == 2)) - { - pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - } -#ifdef GL_VERSION_3_0 - else if (majorGL >= 3) - { - pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); - pglGenerateMipmap(GL_TEXTURE_2D); - } -#endif + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + // Control the mipmap level of detail pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); // the lower the number, the higer the detail if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); } else { @@ -2176,22 +2141,12 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) mag_filter = GL_LINEAR; min_filter = GL_NEAREST; } - if (majorGL == 1 && minorGL <= 3) + if (!supportMipMap) { MipMap = GL_FALSE; min_filter = GL_LINEAR; } -#ifdef GL_VERSION_3_0 - else - { - if (!pglGenerateMipmap) - { - MipMap = GL_FALSE; - min_filter = GL_LINEAR; - } - } -#endif - + Flush(); //??? if we want to change filter mode by texture, remove this break; diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 34b2d3cf7..c67c69303 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -112,11 +112,14 @@ extern const GLubyte *gl_version; extern const GLubyte *gl_renderer; extern const GLubyte *gl_extensions; +extern int majorGL, minorGL; + extern RGBA_t myPaletteData[]; extern GLint screen_width; extern GLint screen_height; extern GLbyte screen_depth; extern GLint maximumAnisotropy; +extern boolean supportMipMap; /** \brief OpenGL flags for video driver */ diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 00e3896ed..1098ce7a5 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -161,6 +161,11 @@ boolean OglSdlSurface(INT32 w, INT32 h) SetupGLFunc4(); + if (majorGL == 1 && minorGL <= 3) // GL_GENERATE_MIPMAP is unavailible for OGL 1.3 and below + supportMipMap = false; + else + supportMipMap = true; + granisotropicmode_cons_t[1].value = maximumAnisotropy; SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); -- 2.54.0 From 847a8cfd8139500f7bc992a8332fa17848c0d176 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 20:38:29 +0100 Subject: [PATCH 3/7] Zzz... --- src/hardware/r_opengl/r_opengl.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index a5a519ec2..a1e642d22 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -428,7 +428,6 @@ static PFNglCopyTexImage2D pglCopyTexImage2D; typedef void (APIENTRY * PFNglCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; #endif -#endif /* 1.2 functions for 3D textures */ typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -- 2.54.0 From 8486bddaf2c9442dd39ffd62b7a6a3c3e5037297 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 28 Mar 2024 00:15:44 +0100 Subject: [PATCH 4/7] fix highresscale issue on startup in the worst way ever cause CV_NOINIT doesent work for whatever reason --- src/d_main.c | 2 ++ src/screen.c | 5 ++++- src/screen.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/d_main.c b/src/d_main.c index 34b940494..ad4c3745f 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1772,6 +1772,8 @@ void D_SRB2Main(void) COM_ImmedExecute(va("exec \"%s"PATHSEP"kartserv.cfg\"\n", srb2home)); else COM_ImmedExecute(va("exec \"%s"PATHSEP"kartexec.cfg\" -noerror\n", srb2home)); + + hrscale_shit = 1; if (!autostart) M_PushSpecialParameters(); // push all "+" parameters at the command buffer diff --git a/src/screen.c b/src/screen.c index 738c70c35..29f0ba9a5 100644 --- a/src/screen.c +++ b/src/screen.c @@ -50,6 +50,8 @@ void (*transtransfunc)(void); // translucent translated column drawer void (*twosmultipatchfunc)(void); // for cols with transparent pixels void (*twosmultipatchtransfunc)(void); // for cols with transparent pixels AND translucency +int hrscale_shit = 0; + // ------------------ // global video state // ------------------ @@ -74,7 +76,8 @@ consvar_t cv_highreshudscale = {"highreshudscale", "1", CV_SAVE|CV_FLOAT|CV_CALL static void Highreshudscale_OnChange(void) { - SCR_Recalc(); + if (hrscale_shit) + SCR_Recalc(); } static void SCR_ChangeFullscreen (void); diff --git a/src/screen.h b/src/screen.h index a6a0eb477..a9e090fc1 100644 --- a/src/screen.h +++ b/src/screen.h @@ -166,6 +166,8 @@ void SCR_Startup (void); void SCR_CalculateFPS(void); +extern int hrscale_shit; + FUNCMATH boolean SCR_IsAspectCorrect(INT32 width, INT32 height); // move out to main code for consistency -- 2.54.0 From ca1302475ed8d9e9421f0c7cb2afb3a0dd75e80f Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 28 Mar 2024 08:13:16 +0100 Subject: [PATCH 5/7] use this instead --- src/d_main.c | 2 -- src/screen.c | 4 +--- src/screen.h | 2 -- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index ad4c3745f..34b940494 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1772,8 +1772,6 @@ void D_SRB2Main(void) COM_ImmedExecute(va("exec \"%s"PATHSEP"kartserv.cfg\"\n", srb2home)); else COM_ImmedExecute(va("exec \"%s"PATHSEP"kartexec.cfg\" -noerror\n", srb2home)); - - hrscale_shit = 1; if (!autostart) M_PushSpecialParameters(); // push all "+" parameters at the command buffer diff --git a/src/screen.c b/src/screen.c index 29f0ba9a5..e5c1ebff4 100644 --- a/src/screen.c +++ b/src/screen.c @@ -50,8 +50,6 @@ void (*transtransfunc)(void); // translucent translated column drawer void (*twosmultipatchfunc)(void); // for cols with transparent pixels void (*twosmultipatchtransfunc)(void); // for cols with transparent pixels AND translucency -int hrscale_shit = 0; - // ------------------ // global video state // ------------------ @@ -76,7 +74,7 @@ consvar_t cv_highreshudscale = {"highreshudscale", "1", CV_SAVE|CV_FLOAT|CV_CALL static void Highreshudscale_OnChange(void) { - if (hrscale_shit) + if (!con_startup) SCR_Recalc(); } diff --git a/src/screen.h b/src/screen.h index a9e090fc1..a6a0eb477 100644 --- a/src/screen.h +++ b/src/screen.h @@ -166,8 +166,6 @@ void SCR_Startup (void); void SCR_CalculateFPS(void); -extern int hrscale_shit; - FUNCMATH boolean SCR_IsAspectCorrect(INT32 width, INT32 height); // move out to main code for consistency -- 2.54.0 From 1e524a8240210bc385106d61e34b2c29e58ca656 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 28 Mar 2024 13:21:58 +0100 Subject: [PATCH 6/7] when the GLENCORE --- src/hardware/hw_cache.c | 14 +++++++++----- src/hardware/hw_main.h | 2 -- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 888a8414e..c506b64e8 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -535,7 +535,11 @@ void HWR_LoadTextures(size_t pnumtextures) HWR_FreeTextureCache(); gr_numtextures = pnumtextures; +#ifdef GLENCORE gr_textures = calloc(pnumtextures, sizeof (*gr_textures)*2); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore) +#else + gr_textures = calloc(pnumtextures, sizeof (*gr_textures)); +#endif if (gr_textures == NULL) I_Error("HWR_LoadTextures: ran out of memory for OpenGL textures. Sad!"); } @@ -555,9 +559,11 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) tex = 0; #endif } - +#ifdef GLENCORE grtex = &gr_textures[tex*2 + (encoremap && !noencore ? 0 : 1)]; - +#else + grtex = &gr_textures[tex]; +#endif if (!grtex->mipmap.data && !grtex->mipmap.downloaded) HWR_GenerateTexture(tex, grtex, noencore); @@ -665,7 +671,7 @@ static void HWR_LoadMappedPatch(GLMipmap_t *grmip, GLPatch_t *gpatch) { patch_t *patch = gpatch->rawpatch; if (!patch) - patch = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC); + patch = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC); HWR_MakePatch(patch, gpatch, grmip, true); // You can't free rawpatch for some reason? @@ -678,7 +684,6 @@ static void HWR_LoadMappedPatch(GLMipmap_t *grmip, GLPatch_t *gpatch) // 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. @@ -709,7 +714,6 @@ void HWR_GetPatch(GLPatch_t *gpatch) // 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. diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 3530c2915..ec5420f2c 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -17,8 +17,6 @@ /// \file /// \brief 3D render mode functions -#define GLENCORE - #ifndef __HWR_MAIN_H__ #define __HWR_MAIN_H__ -- 2.54.0 From de6a54bc8cb9ee03ce56ccba1d4122cb71fc620f Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 28 Mar 2024 14:25:07 +0100 Subject: [PATCH 7/7] why tf is that here --- src/r_defs.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/r_defs.h b/src/r_defs.h index f5a4195bc..5a78a362b 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -639,6 +639,10 @@ typedef struct // textures from the TEXTURE1 list of patches. // // WARNING: this structure is cloned in GLPatch_t +#if defined(_MSC_VER) +#pragma pack(1) +#endif + typedef struct { INT16 width; // bounding box size @@ -656,20 +660,6 @@ typedef struct #endif } patch_t; -#if defined(_MSC_VER) -#pragma pack(1) -#endif - -typedef struct -{ - INT16 width; // bounding box size - INT16 height; - INT16 leftoffset; // pixels to the left of origin - INT16 topoffset; // pixels below the origin - INT32 columnofs[8]; // only [width] used - // the [0] is &columnofs[width] -} ATTRPACK softwarepatch_t; - #ifdef _MSC_VER #pragma warning(disable : 4200) #endif -- 2.54.0