mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
- safety commit: all relevant code for the texturing system has been moved to texcache.cpp.
This commit is contained in:
parent
bef8c9ae76
commit
3da49ad20a
9 changed files with 118 additions and 190 deletions
|
@ -175,6 +175,4 @@ extern char ptempbuf[MAXWALLSB<<1];
|
|||
|
||||
extern hitdata_t polymost_hitdata;
|
||||
|
||||
#include "texcache.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
#ifndef texcache_h_
|
||||
# define texcache_h_
|
||||
|
||||
#include "vfs.h"
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
|
||||
#define GLTEXCACHEADSIZ 8192
|
||||
|
||||
typedef struct {
|
||||
pthtyp *list[GLTEXCACHEADSIZ];
|
||||
|
||||
} globaltexcache;
|
||||
|
||||
extern globaltexcache texcache;
|
||||
|
||||
extern pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int32_t dameth);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -9,7 +9,6 @@
|
|||
#include "engine_priv.h"
|
||||
#include "hightile.h"
|
||||
#include "polymost.h"
|
||||
#include "texcache.h"
|
||||
#include "mdsprite.h"
|
||||
#include "cache1d.h"
|
||||
#include "kplib.h"
|
||||
|
|
|
@ -280,7 +280,6 @@ void polymost_glreset()
|
|||
delete polymosttext;
|
||||
polymosttext=nullptr;
|
||||
|
||||
Bmemset(texcache.list,0,sizeof(texcache.list));
|
||||
glox1 = -1;
|
||||
|
||||
#ifdef DEBUGGINGAIDS
|
||||
|
@ -288,14 +287,6 @@ void polymost_glreset()
|
|||
#endif
|
||||
}
|
||||
|
||||
static void polymost_bindPth(pthtyp const* const pPth, int sampler)
|
||||
{
|
||||
Bassert(pPth);
|
||||
|
||||
GLInterface.BindTexture(0, pPth->glpic, sampler);
|
||||
}
|
||||
|
||||
|
||||
FileReader GetBaseResource(const char* fn);
|
||||
|
||||
// one-time initialization of OpenGL for polymost
|
||||
|
@ -489,11 +480,6 @@ static int32_t pow2xsplit = 0, skyclamphack = 0, skyzbufferhack = 0, flatskyrend
|
|||
static float drawpoly_alpha = 0.f;
|
||||
static uint8_t drawpoly_blend = 0;
|
||||
|
||||
static inline pthtyp *our_texcache_fetch(int32_t dameth)
|
||||
{
|
||||
return texcache_fetch(globalpicnum, globalpal, getpalookup(1, globalshade), dameth);
|
||||
}
|
||||
|
||||
int32_t polymost_maskWallHasTranslucency(uwalltype const * const wall)
|
||||
{
|
||||
if (wall->cstat & CSTAT_WALL_TRANSLUCENT)
|
||||
|
@ -520,19 +506,6 @@ int32_t polymost_spriteHasTranslucency(uspritetype const * const tspr)
|
|||
}
|
||||
|
||||
|
||||
static void polymost_updatePalette()
|
||||
{
|
||||
if (videoGetRenderMode() != REND_POLYMOST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GLInterface.SetPalswap(fixpalswap >= 1? fixpalswap-1 : globalpal);
|
||||
GLInterface.SetShade(globalshade, numshades);
|
||||
GLInterface.SetPalette(fixpalette >= 1? fixpalette-1 : curbasepal);
|
||||
}
|
||||
|
||||
|
||||
static void polymost_updaterotmat(void)
|
||||
{
|
||||
if (1)
|
||||
|
@ -671,44 +644,22 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
|
|||
|
||||
polymost_outputGLDebugMessage(3, "polymost_drawpoly(dpxy:%p, n:%d, method_:%X), method: %X", dpxy, n, method_, method);
|
||||
|
||||
pthtyp *pth = our_texcache_fetch(method | (videoGetRenderMode() == REND_POLYMOST && r_useindexedcolortextures ? PTH_INDEXED : 0));
|
||||
// This only takes effect for textures with their default set to SamplerClampXY.
|
||||
int sampleroverride;
|
||||
if (drawpoly_srepeat && drawpoly_trepeat) sampleroverride = SamplerRepeat;
|
||||
else if (drawpoly_srepeat) sampleroverride = SamplerClampY;
|
||||
else if (drawpoly_trepeat) sampleroverride = SamplerClampX;
|
||||
else sampleroverride = -1;
|
||||
|
||||
if (!pth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tilePtr(globalpicnum))
|
||||
{
|
||||
tsiz.x = tsiz.y = 1;
|
||||
bool success = GLInterface.SetTexture(TileFiles.tiles[globalpicnum], globalpal, method, sampleroverride);
|
||||
if (!success)
|
||||
{
|
||||
tsiz.x = tsiz.y = 1;
|
||||
GLInterface.SetColorMask(false); //Hack to update Z-buffer for invalid mirror textures
|
||||
}
|
||||
}
|
||||
|
||||
Bassert(pth);
|
||||
|
||||
// If we aren't rendmode 3, we're in Polymer, which means this code is
|
||||
// used for rotatesprite only. Polymer handles all the material stuff,
|
||||
// just submit the geometry and don't mess with textures.
|
||||
if (videoGetRenderMode() == REND_POLYMOST)
|
||||
{
|
||||
|
||||
// The entire logic here is just one lousy hack.
|
||||
int mSampler = NoSampler;
|
||||
if (pth->glpic->GetSampler() != SamplerRepeat)
|
||||
{
|
||||
if (drawpoly_srepeat && drawpoly_trepeat) mSampler = SamplerRepeat;
|
||||
else if (drawpoly_srepeat) mSampler = SamplerClampY;
|
||||
else if (drawpoly_trepeat) mSampler = SamplerClampX;
|
||||
else mSampler = SamplerClampXY;
|
||||
}
|
||||
|
||||
polymost_bindPth(pth, mSampler);
|
||||
|
||||
}
|
||||
if (videoGetRenderMode() == REND_POLYMOST)
|
||||
{
|
||||
polymost_updatePalette();
|
||||
}
|
||||
GLInterface.SetShade(globalshade, numshades);
|
||||
|
||||
if ((method & DAMETH_WALL) != 0)
|
||||
{
|
||||
|
@ -730,27 +681,19 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32
|
|||
|
||||
vec2f_t hacksc = { 1.f, 1.f };
|
||||
|
||||
#if 0
|
||||
if (pth->flags & PTH_HIGHTILE)
|
||||
{
|
||||
hacksc = pth->scale;
|
||||
tsiz = pth->siz;
|
||||
}
|
||||
#endif
|
||||
|
||||
vec2_t tsiz2 = tsiz;
|
||||
|
||||
|
||||
if (method & DAMETH_MASKPROPS)
|
||||
{
|
||||
// Fixme: Alpha test on shaders must be done differently.
|
||||
// Also: Consider a texture's alpha threshold.
|
||||
#ifdef HICR
|
||||
float const al = alphahackarray[globalpicnum] != 0 ? alphahackarray[globalpicnum] * (1.f/255.f) :
|
||||
(pth->hicr && pth->hicr->alphacut >= 0.f ? pth->hicr->alphacut : 0.f);
|
||||
#else
|
||||
float al = 0;
|
||||
#endif
|
||||
|
||||
GLInterface.SetAlphaThreshold(al);
|
||||
handle_blend((method & DAMETH_MASKPROPS) > DAMETH_MASK, drawpoly_blend, (method & DAMETH_MASKPROPS) == DAMETH_TRANS2);
|
||||
}
|
||||
|
||||
|
@ -5324,14 +5267,7 @@ void polymost_fillpolygon(int32_t npoints)
|
|||
|
||||
if (gloy1 != -1) polymostSet2dView(); //disables blending, texturing, and depth testing
|
||||
GLInterface.EnableAlphaTest(true);
|
||||
pthtyp const * const pth = our_texcache_fetch(DAMETH_NOMASK | (videoGetRenderMode() == REND_POLYMOST && r_useindexedcolortextures ? PTH_INDEXED : 0));
|
||||
|
||||
if (pth)
|
||||
{
|
||||
polymost_bindPth(pth, -1);
|
||||
}
|
||||
|
||||
polymost_updatePalette();
|
||||
GLInterface.SetTexture(TileFiles.tiles[globalpicnum], globalpal, DAMETH_NOMASK);
|
||||
|
||||
uint8_t const maskprops = (globalorientation>>7)&DAMETH_MASKPROPS;
|
||||
handle_blend(maskprops > DAMETH_MASK, 0, maskprops == DAMETH_TRANS2);
|
||||
|
@ -5663,7 +5599,7 @@ void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype)
|
|||
|
||||
//OSD_Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype);
|
||||
hicprecaching = 1;
|
||||
texcache_fetch(dapicnum, dapalnum, 0, (datype & 1)*(DAMETH_MASK));
|
||||
GLInterface.SetTexture(TileFiles.tiles[dapicnum], dapalnum, 0);
|
||||
hicprecaching = 0;
|
||||
|
||||
if (datype == 0 || !usemodels) return;
|
||||
|
@ -5682,15 +5618,5 @@ void PrecacheHardwareTextures(int nTile)
|
|||
{
|
||||
// PRECACHE
|
||||
// This really *really* needs improvement on the game side - the entire precaching logic has no clue about the different needs of a hardware renderer.
|
||||
|
||||
polymost_precache(nTile, 0, 1);
|
||||
|
||||
if (r_detailmapping)
|
||||
polymost_precache(nTile, DETAILPAL, 1);
|
||||
|
||||
if (r_glowmapping)
|
||||
polymost_precache(nTile, GLOWPAL, 1);
|
||||
|
||||
polymost_precache(nTile, BRIGHTPAL, 1);
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "bitmap.h"
|
||||
#include "../../glbackend/glbackend.h"
|
||||
|
||||
#if 0
|
||||
|
||||
void gltexinvalidate(int32_t dapicnum, int32_t dapalnum, int32_t dameth)
|
||||
{
|
||||
const int32_t pic = (dapicnum & (GLTEXCACHEADSIZ - 1));
|
||||
|
@ -82,7 +84,7 @@ void cleartexturecache()
|
|||
}
|
||||
}
|
||||
|
||||
static void polymost_setuptexture(FHardwareTexture* tex, const int32_t dameth, int filter)
|
||||
static void polymost_setupsampler(FHardwareTexture* tex, const int32_t dameth, int filter)
|
||||
{
|
||||
|
||||
if (!(dameth & DAMETH_CLAMPED))
|
||||
|
@ -135,7 +137,7 @@ void gloadtile_art(int32_t dapic, int32_t dameth, pthtyp* pth, int32_t doalloc)
|
|||
pth->glpic->CreateTexture(siz.x, siz.y, true, false);
|
||||
pth->glpic->SetSampler((dameth & DAMETH_CLAMPED) ? SamplerClampXY : SamplerRepeat);
|
||||
|
||||
polymost_setuptexture(pth->glpic, dameth, 0);
|
||||
polymost_setupsampler(pth->glpic, dameth, 0);
|
||||
}
|
||||
TArray<uint8_t> flipped(siz.x * siz.y, true);
|
||||
FlipNonSquareBlock(flipped.Data(), p, siz.y, siz.x, siz.y);
|
||||
|
@ -207,7 +209,7 @@ int32_t gloadtile_hi(int32_t dapic, int32_t dapalnum, int32_t facen, hicreplctyp
|
|||
pth->scale = { 1.f,1.f };
|
||||
#endif
|
||||
|
||||
polymost_setuptexture(pth->glpic, dameth, (hicr->flags & HICR_FORCEFILTER) ? TEXFILTER_ON : -1);
|
||||
polymost_setupsampler(pth->glpic, dameth, (hicr->flags & HICR_FORCEFILTER) ? TEXFILTER_ON : -1);
|
||||
|
||||
pth->picnum = dapic;
|
||||
pth->effects = effect;
|
||||
|
@ -377,7 +379,94 @@ pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int3
|
|||
|
||||
}
|
||||
|
||||
extern int r_detailmapping, r_glowmapping, usehightile;
|
||||
|
||||
bool GLInstance::ApplyTextureProps()
|
||||
{
|
||||
int pal = palmanager.ActivePalswap();
|
||||
if (currentTexture == nullptr) return false;
|
||||
auto rep = currentTexture->FindReplacement(pal);
|
||||
VSMatrix texmat;
|
||||
bool changed = false;
|
||||
|
||||
// texture scale
|
||||
if (rep && ((rep->scale.x != 1.0f) || (rep->scale.y != 1.0f)))
|
||||
{
|
||||
texmat.loadIdentity();
|
||||
texmat.scale(rep->scale.x, rep->scale.y, 1.0f);
|
||||
GLInterface.SetMatrix(Matrix_Texture, &texmat);
|
||||
}
|
||||
|
||||
if (r_detailmapping)
|
||||
{
|
||||
auto detailrep = currentTexture->FindReplacement(DETAILPAL);
|
||||
if (detailrep)
|
||||
{
|
||||
UseDetailMapping(true);
|
||||
//BindTexture(3, detailrep->faces[0], SamplerRepeat);
|
||||
|
||||
texmat.loadIdentity();
|
||||
bool scaled = false;
|
||||
|
||||
if (rep && ((rep->scale.x != 1.0f) || (rep->scale.y != 1.0f)))
|
||||
{
|
||||
texmat.scale(rep->scale.x, rep->scale.y, 1.0f);
|
||||
scaled = true;
|
||||
}
|
||||
|
||||
if ((detailrep->scale.x != 1.0f) || (detailrep->scale.y != 1.0f))
|
||||
{
|
||||
texmat.scale(detailrep->scale.x, detailrep->scale.y, 1.0f);
|
||||
scaled = true;
|
||||
}
|
||||
|
||||
if (scaled) GLInterface.SetMatrix(Matrix_Detail, &texmat);
|
||||
changed |= scaled;
|
||||
}
|
||||
}
|
||||
|
||||
// glow texture
|
||||
if (r_glowmapping)
|
||||
{
|
||||
auto glowrep = currentTexture->FindReplacement(GLOWPAL);
|
||||
if (glowrep)
|
||||
{
|
||||
UseGlowMapping(true);
|
||||
//BindTexture(4, glowrep->faces[0], SamplerRepeat);
|
||||
}
|
||||
}
|
||||
|
||||
auto brightrep = currentTexture->FindReplacement(BRIGHTPAL);
|
||||
if (brightrep)
|
||||
{
|
||||
//UseGlowMapping(true);
|
||||
//BindTexture(5, glowrep->faces[0], SamplerRepeat);
|
||||
}
|
||||
|
||||
return false; // true if the matrices were changed, false otherwise
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GLInstance::SetTexture(FTexture* tex, int palette, int method)
|
||||
{
|
||||
|
||||
GLInterface.SetPalswap(fixpalswap >= 1 ? fixpalswap - 1 : globalpal);
|
||||
GLInterface.SetPalette(fixpalette >= 1 ? fixpalette - 1 : curbasepal);
|
||||
|
||||
|
||||
pthtyp* pth = texcache_fetch(globalpicnum, globalpal, getpalookup(1, globalshade), method | PTH_INDEXED);
|
||||
GLInterface.BindTexture(0, pth->glpic, mSampler);
|
||||
|
||||
// Fixme: Alpha test on shaders must be done differently.
|
||||
// Also: Consider a texture's alpha threshold.
|
||||
float const al = alphahackarray[globalpicnum] != 0 ? alphahackarray[globalpicnum] * (1.f / 255.f) :
|
||||
(pth->hicr && pth->hicr->alphacut >= 0.f ? pth->hicr->alphacut : 0.f);
|
||||
|
||||
GLInterface.SetAlphaThreshold(al);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -9,7 +9,6 @@
|
|||
#include "engine_priv.h"
|
||||
#include "hightile.h"
|
||||
#include "polymost.h"
|
||||
#include "texcache.h"
|
||||
#include "mdsprite.h"
|
||||
#include "cache1d.h"
|
||||
#include "kplib.h"
|
||||
|
|
|
@ -435,10 +435,15 @@ void FTexture::DeleteReplacement(int palnum)
|
|||
|
||||
HightileReplacement *FTexture::FindReplacement(int palnum, bool skybox)
|
||||
{
|
||||
for (auto &rep : Hightiles)
|
||||
{
|
||||
if (rep.palnum == palnum && (rep.faces[1] != nullptr) == skybox) return &rep;
|
||||
}
|
||||
for(;;)
|
||||
{
|
||||
for (auto &rep : Hightiles)
|
||||
{
|
||||
if (rep.palnum == palnum && (rep.faces[1] != nullptr) == skybox) return &rep;
|
||||
}
|
||||
if (!palnum) break;
|
||||
palnum = 0;
|
||||
}
|
||||
return nullptr; // no replacement found
|
||||
}
|
||||
|
||||
|
|
|
@ -203,73 +203,6 @@ std::pair<size_t, BaseVertex *> GLInstance::AllocVertices(size_t num)
|
|||
return std::make_pair((size_t)0, Buffer.data());
|
||||
}
|
||||
|
||||
extern int r_detailmapping, r_glowmapping, usehightile;
|
||||
|
||||
bool GLInstance::ApplyTextureProps()
|
||||
{
|
||||
int pal = palmanager.ActivePalswap();
|
||||
if (currentTexture == nullptr) return false;
|
||||
auto rep = currentTexture->FindReplacement(pal);
|
||||
VSMatrix texmat;
|
||||
bool changed = false;
|
||||
|
||||
// texture scale
|
||||
if (rep && ((rep->scale.x != 1.0f) || (rep->scale.y != 1.0f)))
|
||||
{
|
||||
texmat.loadIdentity();
|
||||
texmat.scale(rep->scale.x, rep->scale.y, 1.0f);
|
||||
GLInterface.SetMatrix(Matrix_Texture, &texmat);
|
||||
}
|
||||
|
||||
if (r_detailmapping)
|
||||
{
|
||||
auto detailrep = currentTexture->FindReplacement(DETAILPAL);
|
||||
if (detailrep)
|
||||
{
|
||||
UseDetailMapping(true);
|
||||
//BindTexture(3, detailrep->faces[0], SamplerRepeat);
|
||||
|
||||
texmat.loadIdentity();
|
||||
bool scaled = false;
|
||||
|
||||
if (rep && ((rep->scale.x != 1.0f) || (rep->scale.y != 1.0f)))
|
||||
{
|
||||
texmat.scale(rep->scale.x, rep->scale.y, 1.0f);
|
||||
scaled = true;
|
||||
}
|
||||
|
||||
if ((detailrep->scale.x != 1.0f) || (detailrep->scale.y != 1.0f))
|
||||
{
|
||||
texmat.scale(detailrep->scale.x, detailrep->scale.y, 1.0f);
|
||||
scaled = true;
|
||||
}
|
||||
|
||||
if (scaled) GLInterface.SetMatrix(Matrix_Detail, &texmat);
|
||||
changed |= scaled;
|
||||
}
|
||||
}
|
||||
|
||||
// glow texture
|
||||
if (r_glowmapping)
|
||||
{
|
||||
auto glowrep = currentTexture->FindReplacement(GLOWPAL);
|
||||
if (glowrep)
|
||||
{
|
||||
UseGlowMapping(true);
|
||||
//BindTexture(4, glowrep->faces[0], SamplerRepeat);
|
||||
}
|
||||
}
|
||||
|
||||
auto brightrep = currentTexture->FindReplacement(BRIGHTPAL);
|
||||
if (brightrep)
|
||||
{
|
||||
//UseGlowMapping(true);
|
||||
//BindTexture(5, glowrep->faces[0], SamplerRepeat);
|
||||
}
|
||||
|
||||
return false; // true if the matrices were changed, false otherwise
|
||||
}
|
||||
|
||||
void GLInstance::RestoreTextureProps()
|
||||
{
|
||||
// todo: reset everything that's needed to ensure proper functionality
|
||||
|
|
|
@ -365,7 +365,7 @@ public:
|
|||
// not yet implemented - only relevant for hires replacements.
|
||||
}
|
||||
|
||||
FTexture *GetTexture(const char *filename);
|
||||
bool SetTexture(FTexture* tex, int palette, int method, int sampleroverride = -1);
|
||||
};
|
||||
|
||||
extern GLInstance GLInterface;
|
||||
|
|
Loading…
Reference in a new issue