diff --git a/source/build/include/mdsprite.h b/source/build/include/mdsprite.h index 803917608..cd20f6a26 100644 --- a/source/build/include/mdsprite.h +++ b/source/build/include/mdsprite.h @@ -194,7 +194,7 @@ struct voxmodel_t : public mdmodel_t vec3_t siz; vec3f_t piv; int32_t is8bit; - TMap *texIds; + TMap *texIds; }; EXTERN mdmodel_t **models; diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index 3ae9e02e5..8f6b138ad 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -1726,7 +1726,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) } #endif int palid = TRANSLATION(Translation_Remap + curbasepal, globalpal); - GLInterface.SetModelTexture(tex, palid, det, detscale, glow); + GLInterface.SetTexture(-1, tex, palid, 0, CLAMP_XY); if (tspr->clipdist & TSPR_FLAGS_MDHACK) { diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index b6c9167ec..d96eb5c97 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -420,11 +420,13 @@ 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); // 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 = SamplerClampXY; + int sampleroverride = CLAMP_NONE; + if (method & DAMETH_CLAMPED) + { + if (drawpoly_srepeat) sampleroverride |= CLAMP_Y; + if (drawpoly_trepeat) sampleroverride |= CLAMP_X; + } + int palid = TRANSLATION(Translation_Remap + curbasepal, globalpal); bool success = GLInterface.SetTexture(globalpicnum, tileGetTexture(globalpicnum), palid, method, sampleroverride); diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index bebcb5b77..28cddd466 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -11,6 +11,7 @@ #include "mdsprite.h" #include "v_video.h" #include "flatvertices.h" +#include "texturemanager.h" #include "palette.h" #include "../../glbackend/glbackend.h" @@ -32,42 +33,59 @@ static int32_t *shcntmal, *shcnt = 0, shcntp; static int32_t mytexo5, *zbit, gmaxx, gmaxy, garea, pow2m1[33]; static voxmodel_t *gvox; +class FStaticImage : public FImageSource +{ + TArray buffer; + +public: + FStaticImage(int w, int h, TArray& srcbuffer) + { + Width = w; + Height = h; + buffer = std::move(srcbuffer); + bUseGamePalette = false; + } + + int CopyPixels(FBitmap* bmp, int conversion) override + { + *bmp = FBitmap(buffer.Data(), 4*Width, Width, Height); + return 0; + } +}; //pitch must equal xsiz*4 -static OpenGLRenderer::FHardwareTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, const PalEntry *paldata) +static FGameTexture *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; - coltype *pic2 = (coltype *)Xmalloc(xsiz*ysiz*sizeof(coltype)); + TArray buffer(xsiz * ysiz * sizeof(PalEntry)); + PalEntry* pic2 = (PalEntry*)buffer.Data(); if (!is8bit) { - for (bssize_t i=xsiz*ysiz-1; i>=0; i--) + for (int i=xsiz*ysiz-1; i>=0; i--) { - pic2[i].r = pic[i].b; + pic2[i].r = pic[i].r; pic2[i].g = pic[i].g; - pic2[i].b = pic[i].r; + pic2[i].b = pic[i].b; pic2[i].a = 255; } } else { - for (bssize_t i=xsiz*ysiz-1; i>=0; i--) + for (int i=xsiz*ysiz-1; i>=0; i--) { const int32_t ii = pic[i].a; - pic2[i].r = paldata[ii].b; + pic2[i].r = paldata[ii].r; pic2[i].g = paldata[ii].g; - pic2[i].b = paldata[ii].r; + pic2[i].b = paldata[ii].b; pic2[i].a = 255; } } - - auto tex = GLInterface.NewTexture(4); - tex->CreateTexture((uint8_t*)pic2, xsiz, ysiz, 15, true, "Voxel"); // Mipmap should be false for this but currently this causes render errors because the proper sampler cannot be selected. - Xfree(pic2); - - return tex; + auto tt = MakeGameTexture(new FImageTexture(new FStaticImage(xsiz, ysiz, buffer)), "", ETextureType::Special); + TexMan.AddGameTexture(tt, false); + return tt; } static int32_t getvox(int32_t x, int32_t y, int32_t z) @@ -838,18 +856,6 @@ void voxfree(voxmodel_t *m) DO_FREE_AND_NULL(m->mytex); DO_FREE_AND_NULL(m->quad); - - if (m->texIds) - { - TMap::Iterator it(*m->texIds); - TMap::Pair* pair; - while (it.NextPair(pair)) - { - if (pair->Value) delete pair->Value; - } - delete m->texIds; - } - Xfree(m); } @@ -1084,11 +1090,6 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) pc[0] = pc[1] = pc[2] = 1.f; - auto& h = lookups.tables[globalpal]; - if (h.tintFlags & (TINTF_USEONART|TINTF_ALWAYSUSEART)) - GLInterface.SetTinting(h.tintFlags, h.tintColor, h.tintColor); - else - GLInterface.SetTinting(-1, 0xffffff, 0xffffff); if (!shadowHack) { @@ -1135,9 +1136,9 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) #if 1 int palId = TRANSLATION(Translation_Remap + curbasepal, globalpal); auto palette = GPalette.TranslationToTable(palId); - if (!m->texIds) m->texIds = new TMap; + if (!m->texIds) m->texIds = new TMap; auto pTex = m->texIds->CheckKey(palId); - OpenGLRenderer::FHardwareTexture* htex; + FGameTexture* htex; if (!pTex) { htex = gloadtex(m->mytex, m->mytexx, m->mytexy, m->is8bit, palette->Palette); @@ -1149,7 +1150,15 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) } GLInterface.SetPalswap(globalpal); - GLInterface.BindTexture(0, htex, -1); + GLInterface.SetTexture(-1, htex, 0/*TRANSLATION(Translation_Remap + curbasepal, globalpal)*/, 0, CLAMP_XY); + + // This must be done after setting up the texture. + auto& h = lookups.tables[globalpal]; + if (h.tintFlags & (TINTF_USEONART|TINTF_ALWAYSUSEART)) + GLInterface.SetTinting(h.tintFlags, h.tintColor, h.tintColor); + else + GLInterface.SetTinting(-1, 0xffffff, 0xffffff); + GLInterface.UseBrightmaps(false); GLInterface.UseGlowMapping(false); GLInterface.UseDetailMapping(false); diff --git a/source/glbackend/gl_texture.cpp b/source/glbackend/gl_texture.cpp index eeab2349c..5da58aae4 100644 --- a/source/glbackend/gl_texture.cpp +++ b/source/glbackend/gl_texture.cpp @@ -61,7 +61,7 @@ OpenGLRenderer::FHardwareTexture* GLInstance::LoadTexture(FTexture *tex, int tex return hwtex; } -bool GLInstance::SetTextureInternal(int picnum, FGameTexture* tex, int paletteid, int method, int sampleroverride, FGameTexture *det, float detscale, FGameTexture *glow) +bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int method, int sampleroverride) { TexturePick pick; if (!PickTexture(picnum, tex, paletteid, pick)) return false; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 65c7064eb..d96a0d507 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -289,7 +289,7 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState) bool reset = false; for (int i = 0; i < MAX_TEXTURES; i++) { - if (texIds[i] != oldState.TexId[i] || samplerIds[i] != oldState.SamplerId[i]) + if ( texIds[i] != oldState.TexId[i] || samplerIds[i] != oldState.SamplerId[i]) { if (i != 0) { diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 95d513309..e7bc82aa9 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -480,17 +480,8 @@ public: } OpenGLRenderer::FHardwareTexture *LoadTexture(FTexture* tex, int texturetype, int palid); - bool SetTextureInternal(int globalpicnum, FGameTexture* tex, int palette, int method, int sampleroverride, FGameTexture *det, float detscale, FGameTexture *glow); - bool SetTexture(int globalpicnum, FGameTexture* tex, int palette, int method, int sampleroverride) - { - return SetTextureInternal(globalpicnum, tex, palette, method, sampleroverride, nullptr, 1, nullptr); - } - - bool SetModelTexture(FGameTexture *tex, int palette, FGameTexture *det, float detscale, FGameTexture *glow) - { - return SetTextureInternal(-1, tex, palette, 8/*DAMETH_MODEL*/, -1, det, detscale, glow); - } + bool SetTexture(int globalpicnum, FGameTexture* tex, int palette, int method, int sampleroverride); }; extern GLInstance GLInterface;