From 7e9b2eae0fb1bb7ccc2337937776ec3915a58012 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 24 Jul 2011 15:15:57 +0000 Subject: [PATCH] * Clean up after myself. It seems that Polymost isn't very clean with handling texture IDs sometimes, so switching between the two GL renderers could mess them up with the last revision. This is fixed now by always uninitializing Polymer when changing from it to another renderer. * New shade/visibility calculation code, which is activated with 'r_usenewshading' (on by default), and is closer to the classic look. Also tweak the FOGSCALE macro to have approximately the same fog distance with all renderers. * Mapster32: END modifier to RShift. If it's pressed when RShift is released, sprites which are in grayed out sectors are also selected; Make changing shade affect all highlighted sprites in 3D mode (when aiming at one of them). * some debug code to watch out for suspicious glGenTexture/glDeleteTextures calls, not active. git-svn-id: https://svn.eduke32.com/eduke32@1943 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/compat.h | 5 ++ polymer/eduke32/build/include/glbuild.h | 3 + polymer/eduke32/build/include/polymost.h | 23 ++++-- polymer/eduke32/build/src/build.c | 15 +++- polymer/eduke32/build/src/engine.c | 2 + polymer/eduke32/build/src/glbuild.c | 97 +++++++++++++++++++++++- polymer/eduke32/build/src/mdsprite.c | 4 +- polymer/eduke32/build/src/polymer.c | 50 ++++++++---- polymer/eduke32/build/src/polymost.c | 3 + polymer/eduke32/source/animvpx.c | 4 +- polymer/eduke32/source/astub.c | 17 ++++- 11 files changed, 191 insertions(+), 32 deletions(-) diff --git a/polymer/eduke32/build/include/compat.h b/polymer/eduke32/build/include/compat.h index 2bc7c0a72..c679007db 100644 --- a/polymer/eduke32/build/include/compat.h +++ b/polymer/eduke32/build/include/compat.h @@ -588,5 +588,10 @@ char *Bstrupr(char *); #define EDUKE32_TMRTIC t[ti++]=getticks() #define EDUKE32_TMRPRN do { int ii=0; fprintf(stderr,"%s: ",tmrstr); for (ii=1; ii 239) ? (float)(gvisibility*((vis-240+f)/(klabs(vis-256)))) : - (float)(gvisibility*(vis+16+f)); + if (r_usenewshading) + { + f = 0.9f * shade; + f = (vis > 239) ? (float)(gvisibility*((vis-240+f))) : + (float)(gvisibility*(vis+16+f)); + } + else + { + f = (shade < 0) ? shade * 3.5f : shade * .66f; + f = (vis > 239) ? (float)(gvisibility*((vis-240+f)/(klabs(vis-256)))) : + (float)(gvisibility*(vis+16+f)); + } if (f < 0.001f) f = 0.001f; else if (f > 100.0f) f = 100.0f; + fogresult = f; Bmemcpy(fogcol, &fogtable[pal<<2], sizeof(fogcol)); diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index f1b368b53..516c903f2 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -2883,8 +2883,16 @@ void overheadeditor(void) if (keystatus[0x28]) drawline16base(searchx+16, searchy-16, 0,-4, 0,+4, col); } - else if (keystatus[0x36] && eitherCTRL) - printext16(searchx+6,searchy-6-8,editorcolors[12],-1,"S",0); + + if (keystatus[0x36]) + { + if (eitherCTRL) + printext16(searchx+6,searchy-6-8,editorcolors[12],-1,"S",0); +#ifdef YAX_ENABLE + if (keystatus[0xcf]) + printext16(searchx+6,searchy-6+8,editorcolors[12],-1,"A",0); +#endif + } } drawline16base(searchx,searchy, +0,-8, +0,-1, col); @@ -3734,7 +3742,8 @@ end_yax: ; if (sprite[i].statnum == MAXSTATUS) continue; - if ((unsigned)sprite[i].sectnum < MAXSECTORS) + // v v v: if END pressed, also permit sprites from grayed out sectors + if (!keystatus[0xcf] && (unsigned)sprite[i].sectnum < MAXSECTORS) YAX_SKIPSECTOR(sprite[i].sectnum); if (!m32_sideview) diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 14f7bf6b7..3b081646c 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -15637,6 +15637,8 @@ int32_t setrendermode(int32_t renderer) if (!polymer_init()) renderer = 3; } + else if (rendmode==4) // going from Polymer to another renderer + polymer_uninit(); # else else renderer = 3; # endif diff --git a/polymer/eduke32/build/src/glbuild.c b/polymer/eduke32/build/src/glbuild.c index 438d4697b..62948a583 100644 --- a/polymer/eduke32/build/src/glbuild.c +++ b/polymer/eduke32/build/src/glbuild.c @@ -999,5 +999,100 @@ int32_t unloadglulibrary(void) return 0; } -#endif + +//////// glGenTextures/glDeleteTextures debugging //////// +# if defined DEBUGGINGAIDS && defined DEBUG_TEXTURE_NAMES +static uint8_t *texnameused; // bitmap +static uint32_t *texnamefromwhere; // hash of __FILE__ +static uint32_t texnameallocsize; + +// djb3 algorithm +static inline uint32_t texdbg_getcode(const char *s) +{ + uint32_t h = 5381; + int32_t ch; + + while ((ch = *s++) != '\0') + h = ((h << 5) + h) ^ ch; + + return h; +} + +static void texdbg_realloc(uint32_t maxtexname) +{ + uint32_t newsize = texnameallocsize ? texnameallocsize : 64; + + if (texnameallocsize >= maxtexname) + return; + + while (newsize < maxtexname) + newsize <<= 1; +// initprintf("texdebug: new size %u\n", newsize); + + texnameused = Brealloc(texnameused, newsize>>3); + texnamefromwhere = Brealloc(texnamefromwhere, newsize*sizeof(uint32_t)); + + Bmemset(texnameused + (texnameallocsize>>3), 0, (newsize-texnameallocsize)>>3); + Bmemset(texnamefromwhere + texnameallocsize, 0, (newsize-texnameallocsize)*sizeof(uint32_t)); + + texnameallocsize = newsize; +} + +#undef bglGenTextures +void texdbg_bglGenTextures(GLsizei n, GLuint *textures, const char *srcfn) +{ + int32_t i; + uint32_t hash = srcfn ? texdbg_getcode(srcfn) : 0; + + for (i=0; i>3]&(1<<(textures[i]&7)))) + initprintf("texdebug %x Gen: overwriting used tex name %u from %x\n", hash, textures[i], texnamefromwhere[textures[i]]); + + bglGenTextures(n, textures); + + { + GLuint maxtexname = 0; + + for (i=0; i>3] |= (1<<(textures[i]&7)); + texnamefromwhere[textures[i]] = hash; + } + } +} + +#undef bglDeleteTextures +void texdbg_bglDeleteTextures(GLsizei n, const GLuint *textures, const char *srcfn) +{ + int32_t i; + uint32_t hash = srcfn ? texdbg_getcode(srcfn) : 0; + + for (i=0; i>3]&(1<<(textures[i]&7)))==0) + initprintf("texdebug %x Del: deleting unused tex name %u\n", hash, textures[i]); + else if ((texnameused[textures[i]>>3]&(1<<(textures[i]&7))) && + texnamefromwhere[textures[i]] != hash) + initprintf("texdebug %x Del: deleting foreign tex name %u from %x\n", hash, + textures[i], texnamefromwhere[textures[i]]); + } + + bglDeleteTextures(n, textures); + + if (texnameallocsize) + for (i=0; i>3] &= ~(1<<(textures[i]&7)); + texnamefromwhere[textures[i]] = 0; + } +} +# endif // defined DEBUGGINGAIDS + +#endif diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index 7197eb62e..fea8c58e6 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -2486,8 +2486,8 @@ static void md3free(md3model_t *m) if (s->xyzn) Bfree(s->xyzn); if (s->geometry) Bfree(s->geometry); } - else - if (s->geometry) Bfree(s->geometry); // ? +// else +// if (s->geometry) Bfree(s->geometry); // this is wrong! } Bfree(m->head.surfs); } diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index 1ec67b47a..ec8c804fe 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -648,14 +648,12 @@ int32_t polymer_init(void) return (0); } - polymer_freeboard(); + // clean up existing stuff since it will be initialized again if we're re-entering here + polymer_uninit(); Bmemset(&prsectors[0], 0, sizeof(prsectors[0]) * MAXSECTORS); Bmemset(&prwalls[0], 0, sizeof(prwalls[0]) * MAXWALLS); - if (prtess) - bgluDeleteTess(prtess); - prtess = bgluNewTess(); if (prtess == 0) { @@ -693,7 +691,7 @@ int32_t polymer_init(void) polymersearching = FALSE; polymer_initrendertargets(pr_shadowcount + 1); - + // Prime highpalookup maps i = 0; while (i < MAXBASEPALS) @@ -703,9 +701,6 @@ int32_t polymer_init(void) { if (prhighpalookups[i][j].data) { - if (prhighpalookups[i][j].map) - bglDeleteTextures(1, &prhighpalookups[i][j].map); - bglGenTextures(1, &prhighpalookups[i][j].map); bglBindTexture(GL_TEXTURE_3D, prhighpalookups[i][j].map); bglTexImage3D(GL_TEXTURE_3D, // target @@ -739,8 +734,16 @@ void polymer_uninit(void) { int32_t i, j; + if (prtess) + { + bgluDeleteTess(prtess); + prtess = NULL; + } + polymer_freeboard(); - + + polymer_initrendertargets(0); + i = 0; while (i < MAXBASEPALS) { @@ -5341,19 +5344,34 @@ static void polymer_initrendertargets(int32_t count) int32_t i; static int32_t ocount; - if (prrts) + + if (count == 0) // uninit { - for (i=0; iRGB conversion fragment shader adapted from @@ -409,7 +409,7 @@ void animvpx_restore_glstate(void) bglPopAttrib(); bglDeleteTextures(1, &texname); - texname = -1; + texname = 0; texuploaded = 0; } diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 3856b0688..50feedbf8 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -5621,9 +5621,20 @@ static void Keys3d(void) { if (ASSERT_AIMING) { - clamped = addtobyte(&AIMED_CF_SEL(shade), tsign); - message("%s %d shade %d%s", Typestr[searchstat], i, AIMED_CF_SEL(shade), - clamped ? " (clamped)":""); + if (AIMING_AT_SPRITE && (show2dsprite[searchwall>>3]&(1<<(searchwall&7)))) + { + for (i=0; i