- use GZDoom's texture backend to read hightile textures. (Hightile tinting code moved to the shader but isn't active yet.

- remove all code for faking gamma correction through palette manipulated images.
This commit is contained in:
Christoph Oelckers 2019-10-05 21:59:03 +02:00
parent cd0dabf2ae
commit 93ad83b380
15 changed files with 149 additions and 592 deletions

View file

@ -1672,9 +1672,9 @@ void UpdateVideoColorMenu(CGameMenuItemSliderFloat *pItem)
void PreDrawDisplayColor(CGameMenuItem *pItem) void PreDrawDisplayColor(CGameMenuItem *pItem)
{ {
if (pItem == &itemOptionsDisplayColorContrast) if (pItem == &itemOptionsDisplayColorContrast)
pItem->bEnable = gammabrightness; pItem->bEnable = 1;
else if (pItem == &itemOptionsDisplayColorBrightness) else if (pItem == &itemOptionsDisplayColorBrightness)
pItem->bEnable = gammabrightness; pItem->bEnable = 1;
} }
void ResetVideoColor(CGameMenuItemChain *pItem) void ResetVideoColor(CGameMenuItemChain *pItem)

View file

@ -72,7 +72,7 @@ extern void paletteLoadFromDisk(void);
extern void palettePostLoadTables(void); extern void palettePostLoadTables(void);
extern void setup_blend(int32_t blend, int32_t doreverse); extern void setup_blend(int32_t blend, int32_t doreverse);
extern uint8_t basepalreset; extern uint8_t basepalreset;
extern int32_t curbrightness, gammabrightness; extern int32_t curbrightness;
extern int32_t paletteLoadLookupTable(buildvfs_kfd fp); extern int32_t paletteLoadLookupTable(buildvfs_kfd fp);
extern void paletteSetupDefaultFog(void); extern void paletteSetupDefaultFog(void);
@ -88,18 +88,9 @@ extern palette_t palookupfog[MAXPALOOKUPS];
static inline void bricolor(palette_t *wpptr, int32_t dacol) static inline void bricolor(palette_t *wpptr, int32_t dacol)
{ {
if (gammabrightness)
{
wpptr->r = curpalette[dacol].r; wpptr->r = curpalette[dacol].r;
wpptr->g = curpalette[dacol].g; wpptr->g = curpalette[dacol].g;
wpptr->b = curpalette[dacol].b; wpptr->b = curpalette[dacol].b;
}
else
{
wpptr->r = britable[curbrightness][curpalette[dacol].r];
wpptr->g = britable[curbrightness][curpalette[dacol].g];
wpptr->b = britable[curbrightness][curpalette[dacol].b];
}
} }
enum enum

View file

@ -15,6 +15,8 @@
#include "kplib.h" #include "kplib.h"
#include "common.h" #include "common.h"
#include "palette.h" #include "palette.h"
#include "textures.h"
#include "bitmap.h"
#include "../../glbackend/glbackend.h" #include "../../glbackend/glbackend.h"
#include "vfs.h" #include "vfs.h"
@ -647,235 +649,26 @@ FHardwareTexture *mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t
*texidx = 0; *texidx = 0;
buildvfs_kfd filh; auto texture = FTexture::GetTexture(fn);
if ((filh = kopen4load(fn, 0)) == buildvfs_kfd_invalid)
if (texture == nullptr)
{
return mdloadskin_notfound(skinfile, fn); return mdloadskin_notfound(skinfile, fn);
int32_t picfillen = kfilelength(filh);
kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c
int32_t startticks = timerGetTicks(), willprint = 0;
char hasalpha;
vec2_t siz = { 0, 0 }, tsiz = { 0, 0 };
{
polytintflags_t const effect = hicfxmask(pal);
// CODEDUP: gloadtile_hi
int32_t isart = 0;
int32_t const length = kpzbufload(fn);
if (length == 0)
return mdloadskin_notfound(skinfile, fn);
// tsizx/y = replacement texture's natural size
// xsiz/y = 2^x size of replacement
#ifdef WITHKPLIB
kpgetdim(kpzbuf,picfillen,&tsiz.x,&tsiz.y);
#endif
if (tsiz.x == 0 || tsiz.y == 0)
{
if (artCheckUnitFileHeader((uint8_t *)kpzbuf, picfillen))
return mdloadskin_failed(skinfile, fn);
tsiz.x = B_LITTLE16(B_UNBUF16(&kpzbuf[16]));
tsiz.y = B_LITTLE16(B_UNBUF16(&kpzbuf[18]));
if (tsiz.x == 0 || tsiz.y == 0)
return mdloadskin_failed(skinfile, fn);
isart = 1;
} }
siz = tsiz;
if (isart)
{
if (tsiz.x * tsiz.y + ARTv1_UNITOFFSET > picfillen)
return mdloadskin_failed(skinfile, fn);
}
int32_t const bytesperline = siz.x * sizeof(coltype);
coltype *pic = (coltype *)Xcalloc(siz.y, bytesperline);
static coltype *lastpic = NULL;
static char *lastfn = NULL;
static int32_t lastsize = 0;
if (lastpic && lastfn && !Bstrcmp(lastfn,fn))
{
willprint=1;
Bmemcpy(pic, lastpic, siz.x*siz.y*sizeof(coltype));
}
else
{
if (isart)
{
artConvertRGB((palette_t *)pic, (uint8_t *)&kpzbuf[ARTv1_UNITOFFSET], siz.x, tsiz.x, tsiz.y);
}
#ifdef WITHKPLIB
else
{
if (kprender(kpzbuf,picfillen,(intptr_t)pic,bytesperline,siz.x,siz.y))
{
Xfree(pic);
return mdloadskin_failed(skinfile, fn);
}
}
#endif
willprint=2;
if (hicprecaching)
{
lastfn = fn; // careful...
if (!lastpic)
{
lastpic = (coltype *)Xmalloc(siz.x*siz.y*sizeof(coltype));
lastsize = siz.x*siz.y;
}
else if (lastsize < siz.x*siz.y)
{
Xfree(lastpic);
lastpic = (coltype *)Xmalloc(siz.x*siz.y*sizeof(coltype));
}
if (lastpic)
Bmemcpy(lastpic, pic, siz.x*siz.y*sizeof(coltype));
}
else if (lastpic)
{
DO_FREE_AND_NULL(lastpic);
lastfn = NULL;
lastsize = 0;
}
}
char *cptr = britable[gammabrightness ? 0 : curbrightness];
polytint_t const & tint = hictinting[pal];
int32_t r = tint.r;
int32_t g = tint.g;
int32_t b = tint.b;
char al = 255;
char onebitalpha = 1;
for (bssize_t y = 0, j = 0; y < tsiz.y; ++y, j += siz.x)
{
coltype tcol, *rpptr = &pic[j];
for (bssize_t x = 0; x < tsiz.x; ++x)
{
tcol.b = cptr[rpptr[x].b];
tcol.g = cptr[rpptr[x].g];
tcol.r = cptr[rpptr[x].r];
al &= tcol.a = rpptr[x].a;
onebitalpha &= tcol.a == 0 || tcol.a == 255;
if (effect & HICTINT_GRAYSCALE)
{
tcol.g = tcol.r = tcol.b = (uint8_t) ((tcol.b * GRAYSCALE_COEFF_RED) +
(tcol.g * GRAYSCALE_COEFF_GREEN) +
(tcol.r * GRAYSCALE_COEFF_BLUE));
}
if (effect & HICTINT_INVERT)
{
tcol.b = 255 - tcol.b;
tcol.g = 255 - tcol.g;
tcol.r = 255 - tcol.r;
}
if (effect & HICTINT_COLORIZE)
{
tcol.b = min((int32_t)((tcol.b) * r) >> 6, 255);
tcol.g = min((int32_t)((tcol.g) * g) >> 6, 255);
tcol.r = min((int32_t)((tcol.r) * b) >> 6, 255);
}
switch (effect & HICTINT_BLENDMASK)
{
case HICTINT_BLEND_SCREEN:
tcol.b = 255 - (((255 - tcol.b) * (255 - r)) >> 8);
tcol.g = 255 - (((255 - tcol.g) * (255 - g)) >> 8);
tcol.r = 255 - (((255 - tcol.r) * (255 - b)) >> 8);
break;
case HICTINT_BLEND_OVERLAY:
tcol.b = tcol.b < 128 ? (tcol.b * r) >> 7 : 255 - (((255 - tcol.b) * (255 - r)) >> 7);
tcol.g = tcol.g < 128 ? (tcol.g * g) >> 7 : 255 - (((255 - tcol.g) * (255 - g)) >> 7);
tcol.r = tcol.r < 128 ? (tcol.r * b) >> 7 : 255 - (((255 - tcol.r) * (255 - b)) >> 7);
break;
case HICTINT_BLEND_HARDLIGHT:
tcol.b = r < 128 ? (tcol.b * r) >> 7 : 255 - (((255 - tcol.b) * (255 - r)) >> 7);
tcol.g = g < 128 ? (tcol.g * g) >> 7 : 255 - (((255 - tcol.g) * (255 - g)) >> 7);
tcol.r = b < 128 ? (tcol.r * b) >> 7 : 255 - (((255 - tcol.r) * (255 - b)) >> 7);
break;
}
rpptr[x] = tcol;
}
}
hasalpha = (al != 255);
// mdloadskin doesn't duplicate npow2 texture pixels
if (pal < (MAXPALOOKUPS - RESERVEDPALS))
m->usesalpha = hasalpha;
if ((doalloc & 3) == 1) if ((doalloc & 3) == 1)
{ {
*texidx = GLInterface.NewTexture(); *texidx = GLInterface.NewTexture();
} }
uploadtexture(*texidx, (doalloc&1), siz, 1, pic, tsiz, auto glpic = *texidx;
DAMETH_HI | DAMETH_MASK | glpic->CreateTexture(texture->GetWidth(), texture->GetHeight(), false, true);
TO_DAMETH_NODOWNSIZE(sk->flags) | auto image = texture->GetBgraBitmap(nullptr, nullptr);
TO_DAMETH_NOTEXCOMPRESS(sk->flags) | bool hasalpha = texture->GetTranslucency();
TO_DAMETH_ARTIMMUNITY(sk->flags) | bool onebitalpha = texture->isMasked();
(onebitalpha ? DAMETH_ONEBITALPHA : 0) | glpic->LoadTexture(image);
(hasalpha ? DAMETH_HASALPHA : 0));
Xfree(pic);
}
if (!m->skinloaded) if (!m->skinloaded)
{ {
if (siz.x != tsiz.x || siz.y != tsiz.y)
{
float fx, fy;
fx = ((float)tsiz.x)/((float)siz.x);
fy = ((float)tsiz.y)/((float)siz.y);
if (m->mdnum == 2)
{
int32_t *lptr;
for (lptr=m->glcmds; (i=*lptr++);)
for (i=labs(i); i>0; i--,lptr+=3)
{
((float *)lptr)[0] *= fx;
((float *)lptr)[1] *= fy;
}
}
else if (m->mdnum == 3)
{
md3model_t *m3 = (md3model_t *)m;
md3surf_t *s;
int32_t surfi;
for (surfi=0; surfi<m3->head.numsurfs; surfi++)
{
s = &m3->head.surfs[surfi];
for (i=s->numverts-1; i>=0; i--)
{
s->uv[i].u *= fx;
s->uv[i].v *= fy;
}
}
}
}
m->skinloaded = 1+number; m->skinloaded = 1+number;
} }
@ -883,13 +676,6 @@ FHardwareTexture *mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t
{ {
(*texidx)->SetSampler(SamplerRepeat); (*texidx)->SetSampler(SamplerRepeat);
} }
if (willprint)
{
int32_t etime = timerGetTicks()-startticks;
if (etime>=MIN_CACHETIME_PRINT)
OSD_Printf("Load skin: p%d-e%d \"%s\"... %d ms\n", pal, hicfxmask(pal), fn, etime);
}
return (*texidx); return (*texidx);
} }

View file

@ -43,7 +43,7 @@ palette_t palookupfog[MAXPALOOKUPS];
// NOTE: g_noFloorPal[0] is irrelevant as it's never checked. // NOTE: g_noFloorPal[0] is irrelevant as it's never checked.
int8_t g_noFloorPal[MAXPALOOKUPS]; int8_t g_noFloorPal[MAXPALOOKUPS];
int32_t curbrightness = 0, gammabrightness = 0; int32_t curbrightness = 0;
static void paletteSetFade(uint8_t offset); static void paletteSetFade(uint8_t offset);
@ -771,7 +771,7 @@ void videoSetPalette(char dabrightness, uint8_t dapalid, uint8_t flags)
} }
videoSetGamma(); videoSetGamma();
j = !gammabrightness ? curbrightness : 0; j = !0;
for (i=0; i<256; i++) for (i=0; i<256; i++)
{ {
@ -811,7 +811,6 @@ void videoSetPalette(char dabrightness, uint8_t dapalid, uint8_t flags)
g_lastpalettesum = lastpalettesum = newpalettesum; g_lastpalettesum = lastpalettesum = newpalettesum;
#ifdef USE_OPENGL
if (videoGetRenderMode() >= REND_POLYMOST) if (videoGetRenderMode() >= REND_POLYMOST)
{ {
// Only reset the textures if the corresponding preserve flags are clear and // Only reset the textures if the corresponding preserve flags are clear and
@ -820,18 +819,13 @@ void videoSetPalette(char dabrightness, uint8_t dapalid, uint8_t flags)
// XXX: no-HW-gamma OpenGL platforms will exhibit bad performance with // XXX: no-HW-gamma OpenGL platforms will exhibit bad performance with
// simultaneous basepal and tint changes? // simultaneous basepal and tint changes?
const int32_t doinvalidate = (paldidchange || (palsumdidchange && !gammabrightness)); const int32_t doinvalidate = (paldidchange);
if (!(flags&2) && doinvalidate) if (!(flags&2) && doinvalidate)
gltexinvalidatetype(INVALIDATE_ALL_NON_INDEXED); gltexinvalidatetype(INVALIDATE_ALL_NON_INDEXED);
if (!(flags&8) && doinvalidate) if (!(flags&8) && doinvalidate)
gltexinvalidatetype(INVALIDATE_ART_NON_INDEXED); gltexinvalidatetype(INVALIDATE_ART_NON_INDEXED);
#ifdef POLYMER
if ((videoGetRenderMode() == REND_POLYMER) && doinvalidate)
polymer_texinvalidate();
#endif
} }
#endif
if ((flags&16)==0) if ((flags&16)==0)
{ {
@ -842,13 +836,6 @@ void videoSetPalette(char dabrightness, uint8_t dapalid, uint8_t flags)
palette_t paletteGetColor(int32_t col) palette_t paletteGetColor(int32_t col)
{ {
if (!gammabrightness)
{
palette_t const p = { (uint8_t)britable[curbrightness][curpalette[col].r], (uint8_t)britable[curbrightness][curpalette[col].g],
(uint8_t)britable[curbrightness][curpalette[col].b], 0 };
return p;
}
return curpalette[col]; return curpalette[col];
} }

View file

@ -13,6 +13,8 @@ Ken Silverman's official web site: http://www.advsys.net/ken
#include "mdsprite.h" #include "mdsprite.h"
#include "polymost.h" #include "polymost.h"
#include "files.h" #include "files.h"
#include "textures.h"
#include "bitmap.h"
#include "../../glbackend/glbackend.h" #include "../../glbackend/glbackend.h"
extern char textfont[2048], smalltextfont[2048]; extern char textfont[2048], smalltextfont[2048];
@ -691,21 +693,7 @@ static void fixtransparency(coltype *dapic, vec2_t dasiz, vec2_t dasiz2, int32_t
void uploadtexture(FHardwareTexture *tex, int32_t doalloc, vec2_t siz, int32_t texfmt, void uploadtexture(FHardwareTexture *tex, int32_t doalloc, vec2_t siz, int32_t texfmt,
coltype* pic, vec2_t tsiz, int32_t dameth) coltype* pic, vec2_t tsiz, int32_t dameth)
{ {
#ifdef TIMING
cycle_t clock;
clock.Reset();
clock.Clock();
#endif
tex->LoadTexture((uint8_t *)pic); tex->LoadTexture((uint8_t *)pic);
#ifdef TIMING
clock.Unclock();
static int ttt;
OSD_Printf("%d: texture upload %d x %d took %2.3f ms\n", ttt++, siz.x, siz.y, clock.TimeMS());
#endif
} }
void uploadbasepalette(int32_t basepalnum) void uploadbasepalette(int32_t basepalnum)
@ -1060,240 +1048,27 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
fn = hicr->filename; fn = hicr->filename;
} }
buildvfs_kfd filh; auto texture = FTexture::GetTexture(fn);
if (EDUKE32_PREDICT_FALSE((filh = kopen4load(fn, 0)) == buildvfs_kfd_invalid))
if (texture == nullptr)
{ {
OSD_Printf("hightile: %s (pic %d) not found\n", fn, dapic); OSD_Printf("hightile: %s (pic %d) not found\n", fn, dapic);
return -2; return -2;
} }
int32_t picfillen = kfilelength(filh);
kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c
int32_t startticks = timerGetTicks(), willprint = 0;
char onebitalpha = 1;
char hasalpha;
vec2_t siz = { 0, 0 }, tsiz = { 0, 0 };
{
// CODEDUP: mdloadskin
int32_t isart = 0;
int32_t const length = kpzbufload(fn);
if (length == 0)
return -1;
// tsizx/y = replacement texture's natural size
// xsiz/y = 2^x size of replacement
#ifdef WITHKPLIB
kpgetdim(kpzbuf,picfillen,&tsiz.x,&tsiz.y);
#endif
if (tsiz.x == 0 || tsiz.y == 0)
{
if (artCheckUnitFileHeader((uint8_t *)kpzbuf, picfillen))
return -1;
tsiz = { B_LITTLE16(B_UNBUF16(&kpzbuf[16])), B_LITTLE16(B_UNBUF16(&kpzbuf[18])) };
if (tsiz.x == 0 || tsiz.y == 0)
return -1;
isart = 1;
}
siz = tsiz;
if (isart)
{
if (tsiz.x * tsiz.y + ARTv1_UNITOFFSET > picfillen)
return -2;
}
int32_t const bytesperline = siz.x * sizeof(coltype);
coltype *pic = (coltype *)Xcalloc(siz.y, bytesperline);
static coltype *lastpic = NULL;
static char *lastfn = NULL;
static int32_t lastsize = 0;
if (lastpic && lastfn && !Bstrcmp(lastfn,fn))
{
willprint=1;
Bmemcpy(pic, lastpic, siz.x*siz.y*sizeof(coltype));
}
else
{
if (isart)
{
artConvertRGB((palette_t *)pic, (uint8_t *)&kpzbuf[ARTv1_UNITOFFSET], siz.x, tsiz.x, tsiz.y);
}
#ifdef WITHKPLIB
else
{
if (kprender(kpzbuf,picfillen,(intptr_t)pic,bytesperline,siz.x,siz.y))
{
Xfree(pic);
return -2;
}
}
#endif
willprint=2;
if (hicprecaching)
{
lastfn = fn; // careful...
if (!lastpic)
{
lastpic = (coltype *)Xmalloc(siz.x*siz.y*sizeof(coltype));
lastsize = siz.x*siz.y;
}
else if (lastsize < siz.x*siz.y)
{
Xfree(lastpic);
lastpic = (coltype *)Xmalloc(siz.x*siz.y*sizeof(coltype));
}
if (lastpic)
Bmemcpy(lastpic, pic, siz.x*siz.y*sizeof(coltype));
}
else if (lastpic)
{
DO_FREE_AND_NULL(lastpic);
lastfn = NULL;
lastsize = 0;
}
}
char *cptr = britable[gammabrightness ? 0 : curbrightness];
polytint_t const & tint = hictinting[dapalnum];
int32_t r = tint.r;
int32_t g = tint.g;
int32_t b = tint.b;
char al = 255;
for (bssize_t y = 0, j = 0; y < tsiz.y; ++y, j += siz.x)
{
coltype tcol, *rpptr = &pic[j];
for (bssize_t x = 0; x < tsiz.x; ++x)
{
tcol.b = cptr[rpptr[x].b];
tcol.g = cptr[rpptr[x].g];
tcol.r = cptr[rpptr[x].r];
al &= tcol.a = rpptr[x].a;
onebitalpha &= tcol.a == 0 || tcol.a == 255;
if (effect & HICTINT_GRAYSCALE)
{
tcol.g = tcol.r = tcol.b = (uint8_t) ((tcol.b * GRAYSCALE_COEFF_RED) +
(tcol.g * GRAYSCALE_COEFF_GREEN) +
(tcol.r * GRAYSCALE_COEFF_BLUE));
}
if (effect & HICTINT_INVERT)
{
tcol.b = 255 - tcol.b;
tcol.g = 255 - tcol.g;
tcol.r = 255 - tcol.r;
}
if (effect & HICTINT_COLORIZE)
{
tcol.b = min((int32_t)((tcol.b) * r) >> 6, 255);
tcol.g = min((int32_t)((tcol.g) * g) >> 6, 255);
tcol.r = min((int32_t)((tcol.r) * b) >> 6, 255);
}
switch (effect & HICTINT_BLENDMASK)
{
case HICTINT_BLEND_SCREEN:
tcol.b = 255 - (((255 - tcol.b) * (255 - r)) >> 8);
tcol.g = 255 - (((255 - tcol.g) * (255 - g)) >> 8);
tcol.r = 255 - (((255 - tcol.r) * (255 - b)) >> 8);
break;
case HICTINT_BLEND_OVERLAY:
tcol.b = tcol.b < 128 ? (tcol.b * r) >> 7 : 255 - (((255 - tcol.b) * (255 - r)) >> 7);
tcol.g = tcol.g < 128 ? (tcol.g * g) >> 7 : 255 - (((255 - tcol.g) * (255 - g)) >> 7);
tcol.r = tcol.r < 128 ? (tcol.r * b) >> 7 : 255 - (((255 - tcol.r) * (255 - b)) >> 7);
break;
case HICTINT_BLEND_HARDLIGHT:
tcol.b = r < 128 ? (tcol.b * r) >> 7 : 255 - (((255 - tcol.b) * (255 - r)) >> 7);
tcol.g = g < 128 ? (tcol.g * g) >> 7 : 255 - (((255 - tcol.g) * (255 - g)) >> 7);
tcol.r = b < 128 ? (tcol.r * b) >> 7 : 255 - (((255 - tcol.r) * (255 - b)) >> 7);
break;
}
rpptr[x] = tcol;
}
}
hasalpha = (al != 255);
onebitalpha &= hasalpha;
if ((!(dameth & DAMETH_CLAMPED)) || facen) //Duplicate texture pixels (wrapping tricks for non power of 2 texture sizes)
{
if (siz.x > tsiz.x) // Copy left to right
{
for (int32_t y = 0, *lptr = (int32_t *)pic; y < tsiz.y; y++, lptr += siz.x)
Bmemcpy(&lptr[tsiz.x], lptr, (siz.x - tsiz.x) << 2);
}
if (siz.y > tsiz.y) // Copy top to bottom
Bmemcpy(&pic[siz.x * tsiz.y], pic, (siz.y - tsiz.y) * siz.x << 2);
}
// end CODEDUP
if (tsiz.x>>r_downsize <= tilesiz[dapic].x || tsiz.y>>r_downsize <= tilesiz[dapic].y)
hicr->flags |= HICR_ARTIMMUNITY;
if ((doalloc & 3) == 1) if ((doalloc & 3) == 1)
{ {
pth->glpic = GLInterface.NewTexture(); pth->glpic = GLInterface.NewTexture();
pth->glpic->CreateTexture(siz.x, siz.y, false, true); pth->glpic->CreateTexture(texture->GetWidth(), texture->GetHeight(), false, true);
} }
auto image = texture->GetBgraBitmap(nullptr, nullptr);
bool hasalpha = texture->GetTranslucency();
bool onebitalpha = texture->isMasked();
fixtransparency(pic,tsiz,siz,dameth); pth->glpic->LoadTexture(image);
if (!doalloc)
{
vec2_t pthSiz2 = pth->siz;
pthSiz2 = tsiz;
if (siz.x > pthSiz2.x ||
siz.y > pthSiz2.y)
{
//POGO: grow our texture to hold the tile data
doalloc = true;
}
}
uploadtexture(pth->glpic, doalloc,siz,0,pic,tsiz,
dameth | DAMETH_HI | DAMETH_NOFIX |
TO_DAMETH_NODOWNSIZE(hicr->flags) |
TO_DAMETH_NOTEXCOMPRESS(hicr->flags) |
TO_DAMETH_ARTIMMUNITY(hicr->flags) |
(onebitalpha ? DAMETH_ONEBITALPHA : 0) |
(hasalpha ? DAMETH_HASALPHA : 0));
Xfree(pic);
}
// precalculate scaling parameters for replacement
if (facen > 0)
pth->scale = { (float)tsiz.x * (1.0f/64.f), (float)tsiz.y * (1.0f/64.f) };
else
pth->scale = { (float)tsiz.x / (float)tilesiz[dapic].x, (float)tsiz.y / (float)tilesiz[dapic].y };
polymost_setuptexture(pth->glpic, dameth, (hicr->flags & HICR_FORCEFILTER) ? TEXFILTER_ON : -1); polymost_setuptexture(pth->glpic, dameth, (hicr->flags & HICR_FORCEFILTER) ? TEXFILTER_ON : -1);
if (tsiz.x>>r_downsize <= tilesiz[dapic].x || tsiz.y>>r_downsize <= tilesiz[dapic].y)
hicr->flags |= HICR_ARTIMMUNITY;
pth->picnum = dapic; pth->picnum = dapic;
pth->effects = effect; pth->effects = effect;
pth->flags = TO_PTH_CLAMPED(dameth) | TO_PTH_NOTRANSFIX(dameth) | pth->flags = TO_PTH_CLAMPED(dameth) | TO_PTH_NOTRANSFIX(dameth) |
@ -1303,17 +1078,10 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
((hicr->flags & HICR_FORCEFILTER) ? PTH_FORCEFILTER : 0); ((hicr->flags & HICR_FORCEFILTER) ? PTH_FORCEFILTER : 0);
pth->skyface = facen; pth->skyface = facen;
pth->hicr = hicr; pth->hicr = hicr;
pth->siz = tsiz;
if (willprint)
{
int32_t etime = timerGetTicks()-startticks;
if (etime>=MIN_CACHETIME_PRINT)
OSD_Printf("Load tile %4d: p%d-m%d-e%d %s... %d ms\n", dapic, dapalnum, dameth, effect,
willprint==2 ? fn : "", etime);
}
// pretend to the higher level code that this texture is not scaled.
pth->scale = { 1.f, 1.f };
if (facen > 0) pth->siz = { 64, 64 }; else pth->siz = { tilesiz[dapic].x, tilesiz[dapic].y };
return 0; return 0;
} }

View file

@ -108,7 +108,6 @@ static int32_t vsync_renderlayer;
int32_t maxrefreshfreq=0; int32_t maxrefreshfreq=0;
// last gamma, contrast, brightness // last gamma, contrast, brightness
static float lastvidgcb[3];
//#define KEY_PRINT_DEBUG //#define KEY_PRINT_DEBUG
@ -1369,9 +1368,6 @@ int32_t setvideomode_sdlcommon(int32_t *x, int32_t *y, int32_t c, int32_t fs, in
softsurface_destroy(); softsurface_destroy();
} }
// clear last gamma/contrast/brightness so that it will be set anew
lastvidgcb[0] = lastvidgcb[1] = lastvidgcb[2] = 0.0f;
return 1; return 1;
} }
@ -1395,18 +1391,6 @@ void setvideomode_sdlcommonpost(int32_t x, int32_t y, int32_t c, int32_t fs, int
modechange = 1; modechange = 1;
videomodereset = 0; videomodereset = 0;
// save the current system gamma to determine if gamma is available
if (!gammabrightness)
{
// float f = 1.0 + ((float)curbrightness / 10.0);
if (SDL_GetWindowGammaRamp(sdl_window, sysgamma[0], sysgamma[1], sysgamma[2]) == 0)
gammabrightness = 1;
// see if gamma really is working by trying to set the brightness
if (gammabrightness && videoSetGamma() < 0)
gammabrightness = 0; // nope
}
videoFadePalette(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta); videoFadePalette(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta);
if (regrab) if (regrab)
@ -1759,55 +1743,7 @@ int32_t videoSetGamma(void)
if (novideo) if (novideo)
return 0; return 0;
int32_t i; return 1;
uint16_t gammaTable[768];
float gamma = max(0.1f, min(4.f, g_videoGamma));
float contrast = max(0.1f, min(3.f, g_videoContrast));
float bright = max(-0.8f, min(0.8f, g_videoBrightness));
float invgamma = 1.f / gamma;
float norm = powf(255.f, invgamma - 1.f);
if (lastvidgcb[0] == gamma && lastvidgcb[1] == contrast && lastvidgcb[2] == bright)
return 0;
// This formula is taken from Doomsday
for (i = 0; i < 256; i++)
{
float val = i * contrast - (contrast - 1.f) * 127.f;
if (gamma != 1.f)
val = powf(val, invgamma) / norm;
val += bright * 128.f;
gammaTable[i] = gammaTable[i + 256] = gammaTable[i + 512] = (uint16_t)max(0.f, min(65535.f, val * 256.f));
}
i = INT32_MIN;
if (sdl_window)
i = SDL_SetWindowGammaRamp(sdl_window, &gammaTable[0], &gammaTable[256], &gammaTable[512]);
if (i < 0)
{
OSD_Printf("videoSetGamma(): %s\n", SDL_GetError());
if (sdl_window)
SDL_SetWindowGammaRamp(sdl_window, &sysgamma[0][0], &sysgamma[1][0], &sysgamma[2][0]);
gammabrightness = 0;
}
else
{
lastvidgcb[0] = gamma;
lastvidgcb[1] = contrast;
lastvidgcb[2] = bright;
gammabrightness = 1;
}
return i;
} }
#if !defined __APPLE__ && !defined EDUKE32_TOUCH_DEVICES #if !defined __APPLE__ && !defined EDUKE32_TOUCH_DEVICES

View file

@ -39,8 +39,6 @@ static voxmodel_t *gvox;
//pitch must equal xsiz*4 //pitch must equal xsiz*4
FHardwareTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, int32_t dapal) FHardwareTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, int32_t dapal)
{ {
const char *const cptr = &britable[gammabrightness ? 0 : curbrightness][0];
// Correct for GL's RGB order; also apply gamma here: // Correct for GL's RGB order; also apply gamma here:
const coltype *const pic = (const coltype *)picbuf; const coltype *const pic = (const coltype *)picbuf;
coltype *pic2 = (coltype *)Xmalloc(xsiz*ysiz*sizeof(coltype)); coltype *pic2 = (coltype *)Xmalloc(xsiz*ysiz*sizeof(coltype));
@ -49,9 +47,9 @@ FHardwareTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t ysiz, in
{ {
for (bssize_t i=xsiz*ysiz-1; i>=0; i--) for (bssize_t i=xsiz*ysiz-1; i>=0; i--)
{ {
pic2[i].b = cptr[pic[i].r]; pic2[i].b = pic[i].r;
pic2[i].g = cptr[pic[i].g]; pic2[i].g = pic[i].g;
pic2[i].r = cptr[pic[i].b]; pic2[i].r = pic[i].b;
pic2[i].a = 255; pic2[i].a = 255;
} }
} }
@ -64,9 +62,9 @@ FHardwareTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t ysiz, in
{ {
const int32_t ii = palookup[dapal][pic[i].a]; const int32_t ii = palookup[dapal][pic[i].a];
pic2[i].b = cptr[curpalette[ii].b]; pic2[i].b = curpalette[ii].b;
pic2[i].g = cptr[curpalette[ii].g]; pic2[i].g = curpalette[ii].g;
pic2[i].r = cptr[curpalette[ii].r]; pic2[i].r = curpalette[ii].r;
pic2[i].a = 255; pic2[i].a = 255;
} }
} }

View file

@ -417,3 +417,14 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits)
} }
#endif #endif
TMap<FString, FTexture *> textures;
FTexture *FTexture::GetTexture(const char *path)
{
auto res = textures.CheckKey(path);
if (res) return *res;
auto tex = FTexture::CreateTexture(path);
if (tex) textures.Insert(path, tex);
return tex;
}

View file

@ -36,6 +36,7 @@
#define __TEXTURES_H #define __TEXTURES_H
#include "textureid.h" #include "textureid.h"
#include "zstring.h"
#include "palentry.h" #include "palentry.h"
/* /*
#include "v_palette.h" #include "v_palette.h"
@ -145,6 +146,8 @@ class FTexture
public: public:
static FTexture *CreateTexture(const char *name); static FTexture *CreateTexture(const char *name);
static FTexture* GetTexture(const char* path);
virtual ~FTexture (); virtual ~FTexture ();
virtual FImageSource *GetImage() const { return nullptr; } virtual FImageSource *GetImage() const { return nullptr; }
@ -189,9 +192,8 @@ protected:
PalEntry CeilingSkyColor; PalEntry CeilingSkyColor;
FTexture (const char *name = NULL); FTexture (const char *name = NULL);
};
extern TMap<FString, FTexture *> textures; };
#endif #endif

View file

@ -2172,8 +2172,6 @@ static void Menu_Pre(MenuID_t cm)
case MENU_COLCORR: case MENU_COLCORR:
case MENU_COLCORR_INGAME: case MENU_COLCORR_INGAME:
MenuEntry_DisableOnCondition(&ME_COLCORR_CONTRAST, !gammabrightness);
MenuEntry_DisableOnCondition(&ME_COLCORR_BRIGHTNESS, !gammabrightness);
break; break;
case MENU_CHEATS: case MENU_CHEATS:

View file

@ -22,6 +22,7 @@
#include "glad/glad.h" #include "glad/glad.h"
#include "glbackend.h" #include "glbackend.h"
#include "bitmap.h"
//#include "compat.h" //#include "compat.h"
// Workaround to avoid including the dirty 'compat.h' header. This will hopefully not be needed anymore once the texture format uses something better. // Workaround to avoid including the dirty 'compat.h' header. This will hopefully not be needed anymore once the texture format uses something better.
@ -84,6 +85,10 @@ unsigned int FHardwareTexture::LoadTexture(unsigned char * buffer)
return glTexID; return glTexID;
} }
unsigned int FHardwareTexture::LoadTexture(FBitmap& bmp)
{
return LoadTexture(bmp.GetPixels());
}
//=========================================================================== //===========================================================================
// //

View file

@ -2,6 +2,7 @@
#ifndef __GLTEXTURE_H #ifndef __GLTEXTURE_H
#define __GLTEXTURE_H #define __GLTEXTURE_H
class FBitmap;
class FHardwareTexture //: public IHardwareTexture class FHardwareTexture //: public IHardwareTexture
{ {
@ -23,6 +24,7 @@ public:
unsigned int CreateTexture(int w, int h, bool eightbit, bool mipmapped); unsigned int CreateTexture(int w, int h, bool eightbit, bool mipmapped);
unsigned int LoadTexture(unsigned char * buffer); unsigned int LoadTexture(unsigned char * buffer);
unsigned int LoadTexture(FBitmap &bmp);
unsigned int GetTextureHandle(); unsigned int GetTextureHandle();
int GetSampler() { return mSampler; } int GetSampler() { return mSampler; }
void SetSampler(int sampler) { mSampler = sampler; } void SetSampler(int sampler) { mSampler = sampler; }

View file

@ -12,6 +12,7 @@ class FSamplerManager;
class FShader; class FShader;
class PolymostShader; class PolymostShader;
class SurfaceShader; class SurfaceShader;
class FTexture;
struct glinfo_t { struct glinfo_t {
const char* vendor; const char* vendor;
@ -271,6 +272,8 @@ public:
{ {
renderState.Brightness = 8.f / (brightness + 8.f); renderState.Brightness = 8.f / (brightness + 8.f);
} }
FTexture *GetTexture(const char *filename);
}; };
extern GLInstance GLInterface; extern GLInstance GLInterface;

View file

@ -2102,8 +2102,6 @@ static void Menu_Pre(MenuID_t cm)
case MENU_COLCORR: case MENU_COLCORR:
case MENU_COLCORR_INGAME: case MENU_COLCORR_INGAME:
MenuEntry_DisableOnCondition(&ME_COLCORR_CONTRAST, !gammabrightness);
MenuEntry_DisableOnCondition(&ME_COLCORR_BRIGHTNESS, !gammabrightness);
break; break;
case MENU_CHEATS: case MENU_CHEATS:

View file

@ -46,6 +46,79 @@ const float c_two = 2.0;
const vec4 c_vec4_one = vec4(c_one); const vec4 c_vec4_one = vec4(c_one);
const float c_wrapThreshold = 0.9; const float c_wrapThreshold = 0.9;
//===========================================================================
//
// Color to grayscale
//
//===========================================================================
float grayscale(vec4 color)
{
return dot(color.rgb, vec3(0.3, 0.56, 0.14));
}
//===========================================================================
//
// Hightile tinting code. (hictinting[dapalnum]) This can be done inside the shader
// to avoid costly texture duplication (but needs a more modern GLSL than 1.10.)
//
//===========================================================================
vec4 convertColor(vec4 color, int effect, vec3 tint)
{
#if 0
if (effect & HICTINT_GRAYSCALE)
{
float g = grayscale(color);
color = vec4(g, g, g, color.a);
}
if (effect & HICTINT_INVERT)
{
color = vec4(1.0 - color.r, 1.0 - color.g, 1.0 - color.b);
}
vec3 tcol = color.rgb * 255.0; // * 255.0 to make it easier to reuse the integer math.
tint *= 255.0;
if (effect & HICTINT_COLORIZE)
{
tcol.b = min(((tcol.b) * tint.r) / 64.0, 255.0);
tcol.g = min(((tcol.g) * tint.g) / 64.0, 255.0);
tcol.r = min(((tcol.r) * tint.b) / 64.0, 255.0);
}
switch (effect & HICTINT_BLENDMASK)
{
case HICTINT_BLEND_SCREEN:
tcol.b = 255.0 - (((255.0 - tcol.b) * (255.0 - tint.r)) / 256.0);
tcol.g = 255.0 - (((255.0 - tcol.g) * (255.0 - tint.g)) / 256.0);
tcol.r = 255.0 - (((255.0 - tcol.r) * (255.0 - tint.b)) / 256.0);
break;
case HICTINT_BLEND_OVERLAY:
tcol.b = tcol.b < 128.0? (tcol.b * tint.r) / 128.0 : 255.0 - (((255.0 - tcol.b) * (255.0 - tint.r)) / 128.0);
tcol.g = tcol.g < 128.0? (tcol.g * tint.g) / 128.0 : 255.0 - (((255.0 - tcol.g) * (255.0 - tint.g)) / 128.0);
tcol.r = tcol.r < 128.0? (tcol.r * tint.b) / 128.0 : 255.0 - (((255.0 - tcol.r) * (255.0 - tint.b)) / 128.0);
break;
case HICTINT_BLEND_HARDLIGHT:
tcol.b = tint.r < 128.0 ? (tcol.b * tint.r) / 128.0 : 255.0 - (((255.0 - tcol.b) * (255.0 - r)) / 128.0);
tcol.g = tint.g < 128.0 ? (tcol.g * tint.g) / 128.0 : 255.0 - (((255.0 - tcol.g) * (255.0 - g)) / 128.0);
tcol.r = tint.b < 128.0 ? (tcol.r * tint.b) / 128.0 : 255.0 - (((255.0 - tcol.r) * (255.0 - b)) / 128.0);
break;
}
color.rgb = tcol / 255.0;
#endif
return color;
}
//===========================================================================
//
// Talk about all the wrong way of being 'efficient'... :(
//
//===========================================================================
void main() void main()
{ {
float coordY = mix(gl_TexCoord[0].y,gl_TexCoord[0].x,u_usePalette); float coordY = mix(gl_TexCoord[0].y,gl_TexCoord[0].x,u_usePalette);
@ -100,4 +173,3 @@ void main()
gl_FragData[0] = color; gl_FragData[0] = color;
} }