diff --git a/source/build/include/mdsprite.h b/source/build/include/mdsprite.h index 454f953cc..45b162936 100644 --- a/source/build/include/mdsprite.h +++ b/source/build/include/mdsprite.h @@ -193,8 +193,7 @@ struct voxmodel_t : public mdmodel_t vec3_t siz; vec3f_t piv; int32_t is8bit; - FHardwareTexture* texid[256] = { 0 }; - + TMap *texIds; }; EXTERN mdmodel_t **models; diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index 827a14673..c6001cebe 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -35,7 +35,7 @@ static voxmodel_t *gvox; //pitch must equal xsiz*4 -static FHardwareTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, int32_t dapal) +static FHardwareTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, const PalEntry *paldata) { // Correct for GL's RGB order; also apply gamma here: const coltype *const pic = (const coltype *)picbuf; @@ -53,16 +53,13 @@ static FHardwareTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t y } else { - if (palookup[dapal] == NULL) - dapal = 0; - for (bssize_t i=xsiz*ysiz-1; i>=0; i--) { - const int32_t ii = palookup[dapal][pic[i].a]; + const int32_t ii = pic[i].a; - pic2[i].r = curpalette[ii].b; - pic2[i].g = curpalette[ii].g; - pic2[i].b = curpalette[ii].r; + pic2[i].r = paldata[ii].b; + pic2[i].g = paldata[ii].g; + pic2[i].b = paldata[ii].r; pic2[i].a = 255; } } @@ -844,10 +841,16 @@ void voxfree(voxmodel_t *m) DO_FREE_AND_NULL(m->mytex); DO_FREE_AND_NULL(m->quad); - for (auto& tex : m->texid) + + if (m->texIds) { - if (tex) delete tex; - tex = nullptr; + TMap::Iterator it(*m->texIds); + TMap::Pair* pair; + while (it.NextPair(pair)) + { + if (pair->Value) delete pair->Value; + } + delete m->texIds; } Xfree(m); @@ -1133,10 +1136,22 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) int prevClamp = GLInterface.GetClamp(); GLInterface.SetClamp(0); #if 1 - if (!m->texid[globalpal]) - m->texid[globalpal] = gloadtex(m->mytex, m->mytexx, m->mytexy, m->is8bit, globalpal); + int palId = GLInterface.LookupPalette(curbasepal, globalpal, false); + auto palette = GLInterface.GetPaletteData(palId); + if (!m->texIds) m->texIds = new TMap; + auto pTex = m->texIds->CheckKey(palId); + FHardwareTexture* htex; + if (!pTex) + { + htex = gloadtex(m->mytex, m->mytexx, m->mytexy, m->is8bit, palette); + m->texIds->Insert(palId, htex); + } + else + { + htex = *pTex; + } - GLInterface.BindTexture(0, m->texid[globalpal], -1); + GLInterface.BindTexture(0, htex, -1); GLInterface.UseBrightmaps(false); GLInterface.UseGlowMapping(false); GLInterface.UseDetailMapping(false); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 400314181..e51b3e12f 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -513,6 +513,12 @@ public: renderState.AlphaThreshold = al; } + int LookupPalette(int palette, int palswap, bool brightmap, bool nontransparent255 = false) + { + return palmanager.LookupPalette(palette, palswap, brightmap, nontransparent255); + } + const PalEntry* GetPaletteData(int palid) const { return palmanager.GetPaletteData(palid); } + FHardwareTexture* CreateIndexedTexture(FTexture* tex); FHardwareTexture* CreateTrueColorTexture(FTexture* tex, int palid, bool checkfulltransparency = false, bool rgb8bit = false);