From 56f3249679035cb8efa828b3015f0d152a32e8c6 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 26 Mar 2024 21:03:18 +0100 Subject: [PATCH 1/6] Expose debug library to Lua https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2404 --- src/CMakeLists.txt | 1 + src/blua/Makefile.cfg | 1 + src/blua/ldblib.c | 310 ++++++++++++++++++++++++++++++++++++++++++ src/blua/linit.c | 1 + src/blua/lualib.h | 3 + 5 files changed, 316 insertions(+) create mode 100644 src/blua/ldblib.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7811f9032..2fda45979 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -260,6 +260,7 @@ if(${SRB2_CONFIG_HAVE_BLUA}) blua/lapi.c blua/lauxlib.c blua/lbaselib.c + blua/ldblib.c blua/lcode.c blua/ldebug.c blua/ldo.c diff --git a/src/blua/Makefile.cfg b/src/blua/Makefile.cfg index 19b34383c..f3d38fb70 100644 --- a/src/blua/Makefile.cfg +++ b/src/blua/Makefile.cfg @@ -14,6 +14,7 @@ OBJS:=$(OBJS) \ $(OBJDIR)/lapi.o \ $(OBJDIR)/lbaselib.o \ $(OBJDIR)/ldo.o \ + $(OBJDIR)/ldblib.o \ $(OBJDIR)/lfunc.o \ $(OBJDIR)/linit.o \ $(OBJDIR)/liolib.o \ diff --git a/src/blua/ldblib.c b/src/blua/ldblib.c new file mode 100644 index 000000000..2eacef929 --- /dev/null +++ b/src/blua/ldblib.c @@ -0,0 +1,310 @@ +/* +** $Id: ldblib.c,v 1.104.1.4 2009/08/04 18:50:18 roberto Exp $ +** Interface from Lua to its debug API +** See Copyright Notice in lua.h +*/ + + +#include +#include +#include + +#define ldblib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + +static void settabss (lua_State *L, const char *i, const char *v) { + lua_pushstring(L, v); + lua_setfield(L, -2, i); +} + + +static void settabsi (lua_State *L, const char *i, int v) { + lua_pushinteger(L, v); + lua_setfield(L, -2, i); +} + + +static lua_State *getthread (lua_State *L, int *arg) { + if (lua_isthread(L, 1)) { + *arg = 1; + return lua_tothread(L, 1); + } + else { + *arg = 0; + return L; + } +} + + +static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { + if (L == L1) { + lua_pushvalue(L, -2); + lua_remove(L, -3); + } + else + lua_xmove(L1, L, 1); + lua_setfield(L, -2, fname); +} + + +static int db_getinfo (lua_State *L) { + lua_Debug ar; + int arg; + lua_State *L1 = getthread(L, &arg); + const char *options = luaL_optstring(L, arg+2, "flnSu"); + if (lua_isnumber(L, arg+1)) { + if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) { + lua_pushnil(L); /* level out of range */ + return 1; + } + } + else if (lua_isfunction(L, arg+1)) { + lua_pushfstring(L, ">%s", options); + options = lua_tostring(L, -1); + lua_pushvalue(L, arg+1); + lua_xmove(L, L1, 1); + } + else + return luaL_argerror(L, arg+1, "function or level expected"); + if (!lua_getinfo(L1, options, &ar)) + return luaL_argerror(L, arg+2, "invalid option"); + lua_createtable(L, 0, 2); + if (strchr(options, 'S')) { + settabss(L, "source", ar.source); + settabss(L, "short_src", ar.short_src); + settabsi(L, "linedefined", ar.linedefined); + settabsi(L, "lastlinedefined", ar.lastlinedefined); + settabss(L, "what", ar.what); + } + if (strchr(options, 'l')) + settabsi(L, "currentline", ar.currentline); + if (strchr(options, 'u')) + settabsi(L, "nups", ar.nups); + if (strchr(options, 'n')) { + settabss(L, "name", ar.name); + settabss(L, "namewhat", ar.namewhat); + } + if (strchr(options, 'L')) + treatstackoption(L, L1, "activelines"); + if (strchr(options, 'f')) + treatstackoption(L, L1, "func"); + return 1; /* return table */ +} + + +static int db_getlocal (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + const char *name; + if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + return luaL_argerror(L, arg+1, "level out of range"); + name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2)); + if (name) { + lua_xmove(L1, L, 1); + lua_pushstring(L, name); + lua_pushvalue(L, -2); + return 2; + } + else { + lua_pushnil(L); + return 1; + } +} + + +static int auxupvalue (lua_State *L, int get) { + const char *name; + int n = luaL_checkint(L, 2); + luaL_checktype(L, 1, LUA_TFUNCTION); + if (lua_iscfunction(L, 1)) return 0; /* cannot touch C upvalues from Lua */ + name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n); + if (name == NULL) return 0; + lua_pushstring(L, name); + lua_insert(L, -(get+1)); + return get + 1; +} + + +static int db_getupvalue (lua_State *L) { + return auxupvalue(L, 1); +} + + + +static char KEY_HOOK = 'h'; + + +static void hookf (lua_State *L, lua_Debug *ar) { + static const char *const hooknames[] = + {"call", "return", "line", "count", "tail return"}; + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushlightuserdata(L, L); + lua_rawget(L, -2); + if (lua_isfunction(L, -1)) { + lua_pushstring(L, hooknames[(int)ar->event]); + if (ar->currentline >= 0) + lua_pushinteger(L, ar->currentline); + else lua_pushnil(L); + lua_assert(lua_getinfo(L, "lS", ar)); + lua_call(L, 2, 0); + } +} + + +static int makemask (const char *smask, int count) { + int mask = 0; + if (strchr(smask, 'c')) mask |= LUA_MASKCALL; + if (strchr(smask, 'r')) mask |= LUA_MASKRET; + if (strchr(smask, 'l')) mask |= LUA_MASKLINE; + if (count > 0) mask |= LUA_MASKCOUNT; + return mask; +} + + +static char *unmakemask (int mask, char *smask) { + int i = 0; + if (mask & LUA_MASKCALL) smask[i++] = 'c'; + if (mask & LUA_MASKRET) smask[i++] = 'r'; + if (mask & LUA_MASKLINE) smask[i++] = 'l'; + smask[i] = '\0'; + return smask; +} + + +static void gethooktable (lua_State *L) { + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_rawget(L, LUA_REGISTRYINDEX); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + lua_createtable(L, 0, 1); + lua_pushlightuserdata(L, (void *)&KEY_HOOK); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); + } +} + + +static int db_sethook (lua_State *L) { + int arg, mask, count; + lua_Hook func; + lua_State *L1 = getthread(L, &arg); + if (lua_isnoneornil(L, arg+1)) { + lua_settop(L, arg+1); + func = NULL; mask = 0; count = 0; /* turn off hooks */ + } + else { + const char *smask = luaL_checkstring(L, arg+2); + luaL_checktype(L, arg+1, LUA_TFUNCTION); + count = luaL_optint(L, arg+3, 0); + func = hookf; mask = makemask(smask, count); + } + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_pushvalue(L, arg+1); + lua_rawset(L, -3); /* set new hook */ + lua_pop(L, 1); /* remove hook table */ + lua_sethook(L1, func, mask, count); /* set hooks */ + return 0; +} + + +static int db_gethook (lua_State *L) { + int arg; + lua_State *L1 = getthread(L, &arg); + char buff[5]; + int mask = lua_gethookmask(L1); + lua_Hook hook = lua_gethook(L1); + if (hook != NULL && hook != hookf) /* external hook? */ + lua_pushliteral(L, "external hook"); + else { + gethooktable(L); + lua_pushlightuserdata(L, L1); + lua_rawget(L, -2); /* get hook */ + lua_remove(L, -2); /* remove hook table */ + } + lua_pushstring(L, unmakemask(mask, buff)); + lua_pushinteger(L, lua_gethookcount(L1)); + return 3; +} + + +#define LEVELS1 12 /* size of the first part of the stack */ +#define LEVELS2 10 /* size of the second part of the stack */ + +static int db_errorfb (lua_State *L) { + int level; + int firstpart = 1; /* still before eventual `...' */ + int arg; + lua_State *L1 = getthread(L, &arg); + lua_Debug ar; + if (lua_isnumber(L, arg+2)) { + level = (int)lua_tointeger(L, arg+2); + lua_pop(L, 1); + } + else + level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ + if (lua_gettop(L) == arg) + lua_pushliteral(L, ""); + else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ + else lua_pushliteral(L, "\n"); + lua_pushliteral(L, "stack traceback:"); + while (lua_getstack(L1, level++, &ar)) { + if (level > LEVELS1 && firstpart) { + /* no more than `LEVELS2' more levels? */ + if (!lua_getstack(L1, level+LEVELS2, &ar)) + level--; /* keep going */ + else { + lua_pushliteral(L, "\n\t..."); /* too many levels */ + while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */ + level++; + } + firstpart = 0; + continue; + } + lua_pushliteral(L, "\n\t"); + lua_getinfo(L1, "Snl", &ar); + lua_pushfstring(L, "%s:", ar.short_src); + if (ar.currentline > 0) + lua_pushfstring(L, "%d:", ar.currentline); + if (*ar.namewhat != '\0') /* is there a name? */ + lua_pushfstring(L, " in function " LUA_QS, ar.name); + else { + if (*ar.what == 'm') /* main? */ + lua_pushfstring(L, " in main chunk"); + else if (*ar.what == 'C' || *ar.what == 't') + lua_pushliteral(L, " ?"); /* C function or tail call */ + else + lua_pushfstring(L, " in function <%s:%d>", + ar.short_src, ar.linedefined); + } + lua_concat(L, lua_gettop(L) - arg); + } + lua_concat(L, lua_gettop(L) - arg); + return 1; +} + + +static const luaL_Reg dblib[] = { + {"gethook", db_gethook}, + {"getinfo", db_getinfo}, + {"getlocal", db_getlocal}, + {"getupvalue", db_getupvalue}, + {"sethook", db_sethook}, + {"traceback", db_errorfb}, + {NULL, NULL} +}; + + +LUALIB_API int luaopen_debug (lua_State *L) { + luaL_register(L, LUA_DBLIBNAME, dblib); + return 1; +} diff --git a/src/blua/linit.c b/src/blua/linit.c index d17390b20..7c4de9b26 100644 --- a/src/blua/linit.c +++ b/src/blua/linit.c @@ -19,6 +19,7 @@ static const luaL_Reg lualibs[] = { {LUA_TABLIBNAME, luaopen_table}, {LUA_IOLIBNAME, luaopen_io}, {LUA_STRLIBNAME, luaopen_string}, + {LUA_DBLIBNAME, luaopen_debug}, {NULL, NULL} }; diff --git a/src/blua/lualib.h b/src/blua/lualib.h index 4ea97edf3..478d1d6e8 100644 --- a/src/blua/lualib.h +++ b/src/blua/lualib.h @@ -27,6 +27,9 @@ LUALIB_API int (luaopen_io) (lua_State *L); #define LUA_STRLIBNAME "string" LUALIB_API int (luaopen_string) (lua_State *L); +#define LUA_DBLIBNAME "debug" +LUALIB_API int (luaopen_debug) (lua_State *L); + /* open all previous libraries */ LUALIB_API void (luaL_openlibs) (lua_State *L); From 2fc6a26e7773cc23459ceec1fbf92d131d0f5de8 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 20:36:07 +0100 Subject: [PATCH 2/6] 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); From 847a8cfd8139500f7bc992a8332fa17848c0d176 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Mar 2024 20:38:29 +0100 Subject: [PATCH 3/6] 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); From 8486bddaf2c9442dd39ffd62b7a6a3c3e5037297 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 28 Mar 2024 00:15:44 +0100 Subject: [PATCH 4/6] 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 From ca1302475ed8d9e9421f0c7cb2afb3a0dd75e80f Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 28 Mar 2024 08:13:16 +0100 Subject: [PATCH 5/6] 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 From 1e524a8240210bc385106d61e34b2c29e58ca656 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 28 Mar 2024 13:21:58 +0100 Subject: [PATCH 6/6] 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__