Polymost palette-indexed texture rendering

git-svn-id: https://svn.eduke32.com/eduke32@6776 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
pogokeen 2018-03-21 20:41:26 +00:00
parent f19607daa8
commit a364b7bbfd
18 changed files with 784 additions and 155 deletions

View file

@ -1320,6 +1320,7 @@ enum cutsceneflags {
extern int32_t glanisotropy;
extern int32_t glusetexcompr;
extern int32_t gltexfiltermode;
extern int32_t r_useindexedcolortextures;
enum {
TEXFILTER_OFF = 0, // GL_NEAREST
@ -1429,10 +1430,9 @@ int32_t loadoldboard(const char *filename, char fromwhere, vec3_t *dapos, int16_
#ifdef POLYMER
# include "polymer.h"
#else
# ifdef USE_OPENGL
# include "polymost.h"
# endif
#endif
#ifdef USE_OPENGL
# include "polymost.h"
#endif
#ifdef __cplusplus
@ -1444,7 +1444,7 @@ static FORCE_INLINE void push_nofog(void)
#ifdef USE_OPENGL
if (getrendermode() >= REND_POLYMOST)
{
glDisable(GL_FOG);
polymost_setFogEnabled(false);
}
#endif
}
@ -1453,7 +1453,7 @@ static FORCE_INLINE void pop_nofog(void)
{
#ifdef USE_OPENGL
if (getrendermode() >= REND_POLYMOST && !nofog)
glEnable(GL_FOG);
polymost_setFogEnabled(true);
#endif
}

View file

@ -32,6 +32,8 @@ extern void Polymost_prepare_loadboard(void);
//void phex(char v, char *s);
void uploadtexture(int32_t doalloc, vec2_t siz, int32_t texfmt, coltype *pic, vec2_t tsiz, int32_t dameth);
void uploadbasepalette(int32_t basepalnum);
void uploadpalswap(int32_t palookupnum);
void polymost_drawsprite(int32_t snum);
void polymost_drawmaskwall(int32_t damaskwallcnt);
void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum,
@ -40,14 +42,26 @@ void polymost_fillpolygon(int32_t npoints);
void polymost_initosdfuncs(void);
void polymost_drawrooms(void);
void polymost_resetVertexPointers();
void polymost_resetVertexPointers(void);
void polymost_disableProgram(void);
void polymost_resetProgram(void);
void polymost_setFogEnabled(char fogEnabled);
void polymost_useColorOnly(char useColorOnly);
void polymost_usePaletteIndexing(char usePaletteIndexing);
void polymost_useDetailMapping(char useDetailMapping);
void polymost_useGlowMapping(char useGlowMapping);
void useShaderProgram(uint32_t shaderID);
void polymost_glinit(void);
void polymost_glreset(void);
void polymost_init(void);
enum {
INVALIDATE_ALL,
INVALIDATE_ART
INVALIDATE_ART,
INVALIDATE_ALL_NON_INDEXED,
INVALIDATE_ART_NON_INDEXED
};
void gltexinvalidate(int32_t dapicnum, int32_t dapalnum, int32_t dameth);
@ -214,6 +228,8 @@ enum pthtyp_flags {
PTH_INVALIDATED = 128,
PTH_NOTRANSFIX = 256, // fixtransparency() bypassed
PTH_INDEXED = 512,
};
typedef struct pthtyp_t

View file

@ -75,6 +75,7 @@ void plotlines2d(const int32_t *xx, const int32_t *yy, int32_t numpoints, int co
{
palette_t p = getpal(col);
polymost_useColorOnly(true);
glBegin(GL_LINE_STRIP);
glColor4ub(p.r, p.g, p.b, 1);
@ -83,6 +84,7 @@ void plotlines2d(const int32_t *xx, const int32_t *yy, int32_t numpoints, int co
glVertex2i(xx[i], yy[i]);
glEnd();
polymost_useColorOnly(false);
return;
}
#endif
@ -134,20 +136,23 @@ static void drawlinegl(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
}
gloy1 = -1;
glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND); // When using line antialiasing, this is needed
polymost_useColorOnly(true);
glBegin(GL_LINES);
glColor4ub(p.r, p.g, p.b, 255);
glVertex2f((float) x1 * (1.f/4096.f), (float) y1 * (1.f/4096.f));
glVertex2f((float) x2 * (1.f/4096.f), (float) y2 * (1.f/4096.f));
glEnd();
polymost_useColorOnly(false);
}
#endif
@ -1403,12 +1408,13 @@ void setpolymost2dview(void)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
}
gloy1 = -1;
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
#endif
}

View file

@ -434,7 +434,7 @@ void animvpx_setup_glstate(int32_t animvpx_flags)
OSD_Printf("animvpx link log: %s\n", logbuf);
/* Finally, use the program. */
glUseProgram(PHandle);
useShaderProgram(PHandle);
}
#endif
@ -490,7 +490,10 @@ void animvpx_restore_glstate(void)
{
#ifdef USE_GLEXT
if (glinfo.glsl)
glUseProgram(0);
{
useShaderProgram(0);
polymost_resetProgram();
}
#endif
// glPopAttrib();

View file

@ -266,17 +266,19 @@ void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f)
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
glDisable(GL_FOG);
polymost_setFogEnabled(false);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glColor4ub(r, g, b, f);
polymost_useColorOnly(true);
glBegin(GL_TRIANGLES);
glVertex2f(-2.5f, 1.f);
glVertex2f(2.5f, 1.f);
glVertex2f(.0f, -2.5f);
glEnd();
polymost_useColorOnly(false);
glPopMatrix();
glMatrixMode(GL_PROJECTION);

View file

@ -247,7 +247,7 @@ void COMMON_clearbackground(int32_t numcols, int32_t numrows)
if (getrendermode() >= REND_POLYMOST && qsetmode==200)
{
// glPushAttrib(GL_FOG_BIT);
glDisable(GL_FOG);
polymost_setFogEnabled(false);
setpolymost2dview();
glColor4f(0.f, 0.f, 0.f, 0.67f);
@ -257,7 +257,7 @@ void COMMON_clearbackground(int32_t numcols, int32_t numrows)
glRecti(0, 8*numrows+4, xdim, 8*numrows+8);
// glPopAttrib();
glEnable(GL_FOG);
polymost_setFogEnabled(true);
return;
}

View file

@ -13126,6 +13126,11 @@ int32_t setrendermode(int32_t renderer)
rendmode = renderer;
if (getrendermode() >= REND_POLYMOST)
glrendmode = rendmode;
if (renderer == REND_POLYMOST)
{
polymost_init();
}
#endif
return 0;

View file

@ -2396,13 +2396,17 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr)
if (!(tspr->extra&TSPR_EXTRA_MDHACK))
{
#ifdef USE_GLEXT
//POGOTODO: if we add support for palette indexing on model skins, the texture for the palswap could be setup here
texunits += 4;
i = r_detailmapping ? mdloadskin((md2model_t *) m, tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum, DETAILPAL, surfi) : 0;
if (i)
{
mdskinmap_t *sk;
polymost_setupdetailtexture(++texunits, i);
polymost_useDetailMapping(true);
polymost_setupdetailtexture(GL_TEXTURE3, i);
for (sk = m->skinmap; sk; sk = sk->next)
if ((int32_t) sk->palette == DETAILPAL && sk->skinnum == tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum && sk->surfnum == surfi)
@ -2419,7 +2423,8 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr)
if (i)
{
polymost_setupglowtexture(++texunits, i);
polymost_useGlowMapping(true);
polymost_setupglowtexture(GL_TEXTURE4, i);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
@ -2571,6 +2576,9 @@ static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr)
glActiveTexture(--texunits);
}
} // r_vertexarrays
polymost_useDetailMapping(false);
polymost_useGlowMapping(false);
#endif
}
//------------
@ -2747,8 +2755,20 @@ int32_t polymost_mddraw(const uspritetype *tspr)
mdmodel_t *const vm = models[tile2model[Ptile2tile(tspr->picnum,
(tspr->owner >= MAXSPRITES) ? tspr->pal : sprite[tspr->owner].pal)].modelid];
if (vm->mdnum == 1) { return polymost_voxdraw((voxmodel_t *)vm,tspr); }
if (vm->mdnum == 3) { return polymost_md3draw((md3model_t *)vm,tspr); }
if (vm->mdnum == 1)
{
polymost_usePaletteIndexing(false);
int ret = polymost_voxdraw((voxmodel_t *)vm,tspr);
polymost_usePaletteIndexing(true);
return ret;
}
if (vm->mdnum == 3)
{
polymost_usePaletteIndexing(false);
int ret = polymost_md3draw((md3model_t *)vm,tspr);
polymost_usePaletteIndexing(true);
return ret;
}
return 0;
}

View file

@ -622,6 +622,8 @@ void setbasepal(int32_t id, uint8_t const * const table)
basepaltable[id] = (uint8_t *) Xmalloc(768);
Bmemcpy(basepaltable[id], table, 768);
uploadbasepalette(id);
}
void removebasepal(int32_t const id)
{
@ -718,9 +720,9 @@ void setbrightness(char dabrightness, uint8_t dapalid, uint8_t flags)
const int32_t doinvalidate = (paldidchange || (palsumdidchange && !gammabrightness));
if (!(flags&2) && doinvalidate)
gltexinvalidatetype(INVALIDATE_ALL);
gltexinvalidatetype(INVALIDATE_ALL_NON_INDEXED);
if (!(flags&8) && doinvalidate)
gltexinvalidatetype(INVALIDATE_ART);
gltexinvalidatetype(INVALIDATE_ART_NON_INDEXED);
#ifdef POLYMER
if ((getrendermode() == REND_POLYMER) && doinvalidate)
polymer_texinvalidate();

View file

@ -5158,7 +5158,7 @@ static int32_t polymer_bindmaterial(const _prmaterial *material, int16_t* l
if (!prprograms[programbits].handle)
polymer_compileprogram(programbits);
glUseProgram(prprograms[programbits].handle);
useShaderProgram(prprograms[programbits].handle);
// --------- bit setup
@ -5535,7 +5535,7 @@ static void polymer_unbindmaterial(int32_t programbits)
glDisableVertexAttribArray(prprograms[programbits].attrib_N);
}
glUseProgram(0);
useShaderProgram(0);
}
static void polymer_compileprogram(int32_t programbits)

File diff suppressed because it is too large Load diff

View file

@ -44,11 +44,14 @@ static pthtyp *texcache_tryart(int32_t const dapicnum, int32_t const dapalnum, i
// load from art
for (pth=texcache.list[j]; pth; pth=pth->next)
if (pth->picnum == dapicnum && pth->palnum == dapalnum && pth->shade == dashade &&
(pth->flags & (PTH_CLAMPED | PTH_HIGHTILE | PTH_NOTRANSFIX)) ==
(TO_PTH_CLAMPED(dameth) | TO_PTH_NOTRANSFIX(dameth)) &&
polymost_want_npotytex(dameth, tilesiz[dapicnum].y) == !!(pth->flags&PTH_NPOTWALL)
)
if (pth->picnum == dapicnum &&
(dameth & PTH_INDEXED ? (pth->flags & PTH_INDEXED) &&
(pth->flags & PTH_CLAMPED) == TO_PTH_CLAMPED(dameth) :
(pth->palnum == dapalnum && pth->shade == dashade &&
!(pth->flags & PTH_INDEXED) &&
(pth->flags & (PTH_CLAMPED | PTH_HIGHTILE | PTH_NOTRANSFIX)) ==
(TO_PTH_CLAMPED(dameth) | TO_PTH_NOTRANSFIX(dameth)) &&
polymost_want_npotytex(dameth, tilesiz[dapicnum].y) == !!(pth->flags&PTH_NPOTWALL))))
{
if (pth->flags & PTH_INVALIDATED)
{

View file

@ -113,6 +113,7 @@ void E_MapArt_Clear(void)
E_RecalcPicSiz();
#ifdef USE_OPENGL
//POGOTODO: review this to ensure we're not invalidating more than we have to
gltexinvalidatetype(INVALIDATE_ART);
# ifdef POLYMER
if (getrendermode() == REND_POLYMER)
@ -169,6 +170,7 @@ void E_MapArt_Setup(const char *filename)
E_RecalcPicSiz();
#ifdef USE_OPENGL
//POGOTODO: review this to ensure we're not invalidating more than we have to
gltexinvalidatetype(INVALIDATE_ART);
# ifdef POLYMER
if (getrendermode() == REND_POLYMER)
@ -603,6 +605,18 @@ void loadtile(int16_t tilenume)
E_LoadTileIntoBuffer(tilenume, dasiz, (char *) waloff[tilenume]);
#ifdef USE_OPENGL
if (getrendermode() >= REND_POLYMOST)
{
//POGOTODO: this type stuff won't be necessary down the line -- review this
int type;
for (type = 0; type <= 1; ++type)
{
texcache_fetch(tilenume, 0, 0, (type ? DAMETH_CLAMPED : DAMETH_MASK) | PTH_INDEXED);
}
}
#endif
postloadtile(tilenume);
}

View file

@ -1016,6 +1016,8 @@ int32_t polymost_voxdraw(voxmodel_t *m, const uspritetype *tspr)
else
glBindTexture(GL_TEXTURE_2D, m->texid[globalpal]);
polymost_usePaletteIndexing(false);
glBegin(GL_QUADS); // {{{
for (bssize_t i=0, fi=0; i<m->qcnt; i++)
@ -1051,6 +1053,8 @@ int32_t polymost_voxdraw(voxmodel_t *m, const uspritetype *tspr)
glEnd(); // }}}
polymost_usePaletteIndexing(true);
//------------
glDisable(GL_CULL_FACE);
// glPopAttrib();

View file

@ -2363,6 +2363,7 @@ static void m32_showmouse(void)
{
push_nofog();
glDisable(GL_TEXTURE_2D);
polymost_useColorOnly(true);
}
#endif
@ -2404,7 +2405,10 @@ static void m32_showmouse(void)
#ifdef USE_OPENGL
if (getrendermode() >= REND_POLYMOST)
{
pop_nofog();
polymost_useColorOnly(false);
}
#endif
}
@ -2512,7 +2516,7 @@ static inline void pushDisableFog(void)
if (getrendermode() >= REND_POLYMOST)
{
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_FOG);
polymost_setFogEnabled(false);
}
#endif
}

View file

@ -6510,12 +6510,6 @@ int app_main(int argc, char const * const * argv)
g_clipMapFiles.clear();
#endif
// check if the minifont will support lowercase letters (3136-3161)
// there is room for them in tiles012.art between "[\]^_." and "{|}~"
minitext_lowercase = 1;
for (bssize_t i = MINIFONT + ('a'-'!'); minitext_lowercase && i < MINIFONT + ('z'-'!') + 1; ++i)
minitext_lowercase &= tile_exists(i);
char *const setupFileName = Xstrdup(g_setupFileName);
char *const p = strtok(setupFileName, ".");
@ -6573,6 +6567,16 @@ int app_main(int argc, char const * const * argv)
S_MusicStartup();
S_SoundStartup();
}
// check if the minifont will support lowercase letters (3136-3161)
// there is room for them in tiles012.art between "[\]^_." and "{|}~"
minitext_lowercase = 1;
for (bssize_t i = MINIFONT + ('a'-'!'); minitext_lowercase && i < MINIFONT + ('z'-'!') + 1; ++i)
minitext_lowercase &= tile_exists(i);
if (g_networkMode != NET_DEDICATED_SERVER)
{
Menu_Init();
}

View file

@ -1944,6 +1944,10 @@ static void Menu_Pre(MenuID_t cm)
if (getrendermode() != REND_CLASSIC)
{
//POGOTODO: allow setting anisotropy again while r_useindexedcolortextures is set when support is added down the line
// don't allow setting anisotropy while r_useindexedcolortextures is enabled
MenuEntry_DisableOnCondition(&ME_DISPLAYSETUP_ANISOTROPY, r_useindexedcolortextures);
for (i = (int32_t) ARRAY_SIZE(MEOSV_DISPLAYSETUP_ANISOTROPY) - 1; i >= 0; --i)
{
if (MEOSV_DISPLAYSETUP_ANISOTROPY[i] <= glinfo.maxanisotropy)

View file

@ -146,7 +146,7 @@ void GAME_clearbackground(int32_t numcols, int32_t numrows)
{
const int32_t i8n8 = OSD_SCALE(OSDCHAR_HEIGHT*numrows);
// glPushAttrib(GL_FOG_BIT);
glDisable(GL_FOG);
polymost_setFogEnabled(false);
setpolymost2dview();
glColor4f(0.f, 0.f, 0.f, 0.67f);
@ -155,7 +155,7 @@ void GAME_clearbackground(int32_t numcols, int32_t numrows)
glColor4f(0.f, 0.f, 0.f, 1.f);
glRecti(0, i8n8+4, xdim, i8n8+OSDCHAR_HEIGHT);
if (!nofog)
glEnable(GL_FOG);
polymost_setFogEnabled(true);
// glPopAttrib();
return;