* 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
This commit is contained in:
helixhorned 2011-07-24 15:15:57 +00:00
parent 793aadebc5
commit 7e9b2eae0f
11 changed files with 191 additions and 32 deletions

View file

@ -588,5 +588,10 @@ char *Bstrupr(char *);
#define EDUKE32_TMRTIC t[ti++]=getticks() #define EDUKE32_TMRTIC t[ti++]=getticks()
#define EDUKE32_TMRPRN do { int ii=0; fprintf(stderr,"%s: ",tmrstr); for (ii=1; ii<ti; ii++) fprintf(stderr,"%d ", t[ii]-t[ii-1]); fprintf(stderr,"\n"); } while (0) #define EDUKE32_TMRPRN do { int ii=0; fprintf(stderr,"%s: ",tmrstr); for (ii=1; ii<ti; ii++) fprintf(stderr,"%d ", t[ii]-t[ii-1]); fprintf(stderr,"\n"); } while (0)
#if defined USE_OPENGL && defined DEBUGGINGAIDS && defined DEBUG_TEXTURE_NAMES
# define bglGenTextures(numtexs, texnamear) texdbg_bglGenTextures(numtexs, texnamear, __FILE__)
# define bglDeleteTextures(numtexs, texnamear) texdbg_bglDeleteTextures(numtexs, texnamear, __FILE__)
#endif
#endif // __compat_h__ #endif // __compat_h__

View file

@ -317,6 +317,9 @@ extern BOOL (WINAPI * bwglSetPixelFormat)(HDC,int32_t,const PIXELFORMATDESCRIPTO
extern BOOL (WINAPI * bwglSwapIntervalEXT)(int32_t); extern BOOL (WINAPI * bwglSwapIntervalEXT)(int32_t);
#endif #endif
//////// glGenTextures/glDeleteTextures debugging ////////
void texdbg_bglGenTextures(GLsizei n, GLuint *textures, const char *srcfn);
void texdbg_bglDeleteTextures(GLsizei n, const GLuint *textures, const char *srcfn);
#endif //USE_OPENGL #endif //USE_OPENGL
extern char *gldriver; extern char *gldriver;

View file

@ -87,6 +87,8 @@ extern float shadescale;
extern int32_t shadescale_unbounded; extern int32_t shadescale_unbounded;
extern float alphahackarray[MAXTILES]; extern float alphahackarray[MAXTILES];
extern int32_t r_usenewshading;
typedef struct pthtyp_t typedef struct pthtyp_t
{ {
struct pthtyp_t *next; struct pthtyp_t *next;
@ -119,22 +121,33 @@ extern double gyxscale, gxyaspect, gviewxrange, ghalfx, grhalfxdown10, grhalfxdo
extern double gcosang, gsinang, gcosang2, gsinang2; extern double gcosang, gsinang, gcosang2, gsinang2;
extern double gchang, gshang, gctang, gstang, gvisibility; extern double gchang, gshang, gctang, gstang, gvisibility;
#define FOGSCALE 0.0000768 //#define FOGSCALE 0.0000768
#define FOGSCALE ((0.0000768+0.0000128)/(1 + 0.5f*(getrendermode()==4)))
extern float fogresult, fogcol[4], fogtable[4*MAXPALOOKUPS]; extern float fogresult, fogcol[4], fogtable[4*MAXPALOOKUPS];
static inline void fogcalc(const int32_t shade, const int32_t vis, const int32_t pal) static inline void fogcalc(const int32_t shade, const int32_t vis, const int32_t pal)
{ {
float f = (shade < 0) ? shade * 3.5f : float f;
shade * .66f;
f = (vis > 239) ? (float)(gvisibility*((vis-240+f)/(klabs(vis-256)))) : if (r_usenewshading)
(float)(gvisibility*(vis+16+f)); {
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) if (f < 0.001f)
f = 0.001f; f = 0.001f;
else if (f > 100.0f) else if (f > 100.0f)
f = 100.0f; f = 100.0f;
fogresult = f; fogresult = f;
Bmemcpy(fogcol, &fogtable[pal<<2], sizeof(fogcol)); Bmemcpy(fogcol, &fogtable[pal<<2], sizeof(fogcol));

View file

@ -2883,8 +2883,16 @@ void overheadeditor(void)
if (keystatus[0x28]) if (keystatus[0x28])
drawline16base(searchx+16, searchy-16, 0,-4, 0,+4, col); 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); drawline16base(searchx,searchy, +0,-8, +0,-1, col);
@ -3734,7 +3742,8 @@ end_yax: ;
if (sprite[i].statnum == MAXSTATUS) if (sprite[i].statnum == MAXSTATUS)
continue; 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); YAX_SKIPSECTOR(sprite[i].sectnum);
if (!m32_sideview) if (!m32_sideview)

View file

@ -15637,6 +15637,8 @@ int32_t setrendermode(int32_t renderer)
if (!polymer_init()) if (!polymer_init())
renderer = 3; renderer = 3;
} }
else if (rendmode==4) // going from Polymer to another renderer
polymer_uninit();
# else # else
else renderer = 3; else renderer = 3;
# endif # endif

View file

@ -999,5 +999,100 @@ int32_t unloadglulibrary(void)
return 0; 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<n; i++)
if (textures[i] < texnameallocsize && (texnameused[textures[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<n; i++)
maxtexname = max(maxtexname, textures[i]);
texdbg_realloc(maxtexname);
for (i=0; i<n; i++)
{
texnameused[textures[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<n; i++)
if (textures[i] < texnameallocsize)
{
if ((texnameused[textures[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<n; i++)
{
texnameused[textures[i]>>3] &= ~(1<<(textures[i]&7));
texnamefromwhere[textures[i]] = 0;
}
}
# endif // defined DEBUGGINGAIDS
#endif

View file

@ -2486,8 +2486,8 @@ static void md3free(md3model_t *m)
if (s->xyzn) Bfree(s->xyzn); if (s->xyzn) Bfree(s->xyzn);
if (s->geometry) Bfree(s->geometry); if (s->geometry) Bfree(s->geometry);
} }
else // else
if (s->geometry) Bfree(s->geometry); // ? // if (s->geometry) Bfree(s->geometry); // this is wrong!
} }
Bfree(m->head.surfs); Bfree(m->head.surfs);
} }

View file

@ -648,14 +648,12 @@ int32_t polymer_init(void)
return (0); 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(&prsectors[0], 0, sizeof(prsectors[0]) * MAXSECTORS);
Bmemset(&prwalls[0], 0, sizeof(prwalls[0]) * MAXWALLS); Bmemset(&prwalls[0], 0, sizeof(prwalls[0]) * MAXWALLS);
if (prtess)
bgluDeleteTess(prtess);
prtess = bgluNewTess(); prtess = bgluNewTess();
if (prtess == 0) if (prtess == 0)
{ {
@ -693,7 +691,7 @@ int32_t polymer_init(void)
polymersearching = FALSE; polymersearching = FALSE;
polymer_initrendertargets(pr_shadowcount + 1); polymer_initrendertargets(pr_shadowcount + 1);
// Prime highpalookup maps // Prime highpalookup maps
i = 0; i = 0;
while (i < MAXBASEPALS) while (i < MAXBASEPALS)
@ -703,9 +701,6 @@ int32_t polymer_init(void)
{ {
if (prhighpalookups[i][j].data) if (prhighpalookups[i][j].data)
{ {
if (prhighpalookups[i][j].map)
bglDeleteTextures(1, &prhighpalookups[i][j].map);
bglGenTextures(1, &prhighpalookups[i][j].map); bglGenTextures(1, &prhighpalookups[i][j].map);
bglBindTexture(GL_TEXTURE_3D, prhighpalookups[i][j].map); bglBindTexture(GL_TEXTURE_3D, prhighpalookups[i][j].map);
bglTexImage3D(GL_TEXTURE_3D, // target bglTexImage3D(GL_TEXTURE_3D, // target
@ -739,8 +734,16 @@ void polymer_uninit(void)
{ {
int32_t i, j; int32_t i, j;
if (prtess)
{
bgluDeleteTess(prtess);
prtess = NULL;
}
polymer_freeboard(); polymer_freeboard();
polymer_initrendertargets(0);
i = 0; i = 0;
while (i < MAXBASEPALS) while (i < MAXBASEPALS)
{ {
@ -5341,19 +5344,34 @@ static void polymer_initrendertargets(int32_t count)
int32_t i; int32_t i;
static int32_t ocount; static int32_t ocount;
if (prrts)
if (count == 0) // uninit
{ {
for (i=0; i<ocount; i++) if (prrts)
{ {
if (!i) for (i=0; i<ocount; i++)
bglDeleteTextures(1, &prrts[i].color); {
bglDeleteTextures(1, &prrts[i].z); if (prrts[i].color)
bglDeleteFramebuffersEXT(1, &prrts[i].fbo); {
bglDeleteTextures(1, &prrts[i].color);
prrts[i].color = 0;
}
bglDeleteTextures(1, &prrts[i].z);
prrts[i].z = 0;
bglDeleteFramebuffersEXT(1, &prrts[i].fbo);
prrts[i].fbo = 0;
}
Bfree(prrts);
prrts = NULL;
} }
Bfree(prrts); ocount = 0;
return;
} }
ocount = count; ocount = count;
//////////
prrts = Bcalloc(count, sizeof(_prrt)); prrts = Bcalloc(count, sizeof(_prrt));

View file

@ -112,6 +112,8 @@ static double dxb1[MAXWALLSB], dxb2[MAXWALLSB];
float shadescale = 1.3f; float shadescale = 1.3f;
int32_t shadescale_unbounded = 0; int32_t shadescale_unbounded = 0;
int32_t r_usenewshading = 1;
double gyxscale, gxyaspect, gviewxrange, ghalfx, grhalfxdown10, grhalfxdown10x, ghoriz; double gyxscale, gxyaspect, gviewxrange, ghalfx, grhalfxdown10, grhalfxdown10x, ghoriz;
double gcosang, gsinang, gcosang2, gsinang2; double gcosang, gsinang, gcosang2, gsinang2;
double gchang, gshang, gctang, gstang, gvisibility; double gchang, gshang, gctang, gstang, gvisibility;
@ -6303,6 +6305,7 @@ void polymost_initosdfuncs(void)
{ "r_texturemaxsize","r_texturemaxsize: changes the maximum OpenGL texture size limit",(void *) &gltexmaxsize, CVAR_INT | CVAR_NOSAVE, 0, 4096 }, { "r_texturemaxsize","r_texturemaxsize: changes the maximum OpenGL texture size limit",(void *) &gltexmaxsize, CVAR_INT | CVAR_NOSAVE, 0, 4096 },
{ "r_texturemiplevel","r_texturemiplevel: changes the highest OpenGL mipmap level used",(void *) &gltexmiplevel, CVAR_INT, 0, 6 }, { "r_texturemiplevel","r_texturemiplevel: changes the highest OpenGL mipmap level used",(void *) &gltexmiplevel, CVAR_INT, 0, 6 },
{ "r_texturemode", "r_texturemode: changes the texture filtering settings", (void *) &gltexfiltermode, CVAR_INT|CVAR_FUNCPTR, 0, 5 }, { "r_texturemode", "r_texturemode: changes the texture filtering settings", (void *) &gltexfiltermode, CVAR_INT|CVAR_FUNCPTR, 0, 5 },
{ "r_usenewshading", "r_usenewshading: enable/disable new shading/visibility code", (void *) &r_usenewshading, CVAR_BOOL, 0, 1 },
{ "r_vbocount","r_vbocount: sets the number of Vertex Buffer Objects to use when drawing models",(void *) &r_vbocount, CVAR_INT, 1, 256 }, { "r_vbocount","r_vbocount: sets the number of Vertex Buffer Objects to use when drawing models",(void *) &r_vbocount, CVAR_INT, 1, 256 },
{ "r_vbos","r_vbos: enable/disable using Vertex Buffer Objects when drawing models",(void *) &r_vbos, CVAR_BOOL, 0, 1 }, { "r_vbos","r_vbos: enable/disable using Vertex Buffer Objects when drawing models",(void *) &r_vbos, CVAR_BOOL, 0, 1 },
{ "r_vertexarrays","r_vertexarrays: enable/disable using vertex arrays when drawing models",(void *) &r_vertexarrays, CVAR_BOOL, 0, 1 }, { "r_vertexarrays","r_vertexarrays: enable/disable using vertex arrays when drawing models",(void *) &r_vertexarrays, CVAR_BOOL, 0, 1 },

View file

@ -292,7 +292,7 @@ read_ivf_frame:
/////////////// DRAWING! /////////////// /////////////// DRAWING! ///////////////
static GLuint texname = -1; static GLuint texname = 0;
static int32_t texuploaded; static int32_t texuploaded;
// YUV->RGB conversion fragment shader adapted from // YUV->RGB conversion fragment shader adapted from
@ -409,7 +409,7 @@ void animvpx_restore_glstate(void)
bglPopAttrib(); bglPopAttrib();
bglDeleteTextures(1, &texname); bglDeleteTextures(1, &texname);
texname = -1; texname = 0;
texuploaded = 0; texuploaded = 0;
} }

View file

@ -5621,9 +5621,20 @@ static void Keys3d(void)
{ {
if (ASSERT_AIMING) if (ASSERT_AIMING)
{ {
clamped = addtobyte(&AIMED_CF_SEL(shade), tsign); if (AIMING_AT_SPRITE && (show2dsprite[searchwall>>3]&(1<<(searchwall&7))))
message("%s %d shade %d%s", Typestr[searchstat], i, AIMED_CF_SEL(shade), {
clamped ? " (clamped)":""); for (i=0; i<highlightcnt; i++)
if (highlight[i]&16384)
clamped = addtobyte(&sprite[highlight[i]&16383].shade, tsign);
message("Highlighted sprite shade changed by %d%s", tsign,
clamped?" (some sprites' shade clamped)":"");
}
else
{
clamped = addtobyte(&AIMED_CF_SEL(shade), tsign);
message("%s %d shade %d%s", Typestr[searchstat], i, AIMED_CF_SEL(shade),
clamped ? " (clamped)":"");
}
} }
} }
else else