From c61a2c3486ac522501bbe53112ffde00d3f2a641 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 13 Sep 2020 23:14:44 +0200 Subject: [PATCH] - enable palette emulation for HUD weapon drawing. Not correct yet but the basics are in. --- source/common/2d/v_2ddrawer.cpp | 6 ++++++ source/common/2d/v_2ddrawer.h | 1 + source/common/2d/v_draw.cpp | 5 +++++ source/common/2d/v_draw.h | 2 ++ source/common/rendering/hwrenderer/hw_draw2d.cpp | 6 +++++- source/glbackend/gl_texture.cpp | 2 +- source/glbackend/glbackend.cpp | 10 +++++++--- 7 files changed, 27 insertions(+), 5 deletions(-) diff --git a/source/common/2d/v_2ddrawer.cpp b/source/common/2d/v_2ddrawer.cpp index 9f7ece257..acdef7bff 100644 --- a/source/common/2d/v_2ddrawer.cpp +++ b/source/common/2d/v_2ddrawer.cpp @@ -410,9 +410,15 @@ void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms) dg.mVertCount = 4; dg.mTexture = img; if (img->isWarped()) dg.mFlags |= DTF_Wrap; + if (parms.indexed) dg.mFlags |= DTF_Indexed; dg.mTranslationId = 0; SetStyle(img, parms, vertexcolor, dg); + if (parms.indexed) + { + dg.mLightLevel = vertexcolor.Luminance(); + vertexcolor = 0xffffffff; + } if (!img->isHardwareCanvas() && parms.TranslationId != -1) { diff --git a/source/common/2d/v_2ddrawer.h b/source/common/2d/v_2ddrawer.h index b496234d6..ff23f7919 100644 --- a/source/common/2d/v_2ddrawer.h +++ b/source/common/2d/v_2ddrawer.h @@ -84,6 +84,7 @@ public: DTF_Wrap = 1, DTF_Scissor = 2, DTF_Burn = 4, + DTF_Indexed = 8, }; diff --git a/source/common/2d/v_draw.cpp b/source/common/2d/v_draw.cpp index 1b24449f1..dabd72c3d 100644 --- a/source/common/2d/v_draw.cpp +++ b/source/common/2d/v_draw.cpp @@ -674,6 +674,7 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double parms->viewport = { 0,0,drawer->GetWidth(), drawer->GetHeight() }; parms->rotateangle = 0; parms->flipoffsets = false; + parms->indexed = false; // Parse the tag list for attributes. (For floating point attributes, // consider that the C ABI dictates that all floats be promoted to @@ -1126,6 +1127,10 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double if (fortext) return false; parms->rotateangle = ListGetDouble(tags); break; + + case DTA_Indexed: + parms->indexed = !!ListGetInt(tags); + break; } tag = ListGetInt(tags); } diff --git a/source/common/2d/v_draw.h b/source/common/2d/v_draw.h index 9f797a735..c18566936 100644 --- a/source/common/2d/v_draw.h +++ b/source/common/2d/v_draw.h @@ -129,6 +129,7 @@ enum DTA_Pin, // Pin a non-widescreen image to the left/right edge of the screen. DTA_Rotate, DTA_FlipOffsets, // Flips offsets when using DTA_FlipX and DTA_FlipY, this cannot be automatic due to unexpected behavior with unoffsetted graphics. + DTA_Indexed, // Use an indexed texture combined with the given translation. }; @@ -195,6 +196,7 @@ struct DrawParms bool virtBottom; bool burn; bool flipoffsets; + bool indexed; int8_t fsscalemode; double srcx, srcy; double srcwidth, srcheight; diff --git a/source/common/rendering/hwrenderer/hw_draw2d.cpp b/source/common/rendering/hwrenderer/hw_draw2d.cpp index d659c4ce7..5652777c2 100644 --- a/source/common/rendering/hwrenderer/hw_draw2d.cpp +++ b/source/common/rendering/hwrenderer/hw_draw2d.cpp @@ -169,13 +169,17 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state) } state.SetFog(cmd.mColor1, 0); state.SetColor(1, 1, 1, 1, cmd.mDesaturate); + state.SetSoftLightLevel(cmd.mLightLevel); + state.SetLightParms(0, 0); state.AlphaFunc(Alpha_GEqual, 0.f); if (cmd.mTexture != nullptr && cmd.mTexture->isValid()) { auto flags = cmd.mTexture->GetUseType() >= ETextureType::Special? UF_None : cmd.mTexture->GetUseType() == ETextureType::FontChar? UF_Font : UF_Texture; - state.SetMaterial(cmd.mTexture, flags, 0, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, cmd.mTranslationId, -1); + + auto scaleflags = cmd.mFlags & F2DDrawer::DTF_Indexed ? CTF_Indexed : 0; + state.SetMaterial(cmd.mTexture, flags, scaleflags, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, cmd.mTranslationId, -1); state.EnableTexture(true); // Canvas textures are stored upside down diff --git a/source/glbackend/gl_texture.cpp b/source/glbackend/gl_texture.cpp index 8420284d7..399b2d3b4 100644 --- a/source/glbackend/gl_texture.cpp +++ b/source/glbackend/gl_texture.cpp @@ -83,7 +83,7 @@ bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int sa SetBasepalTint(texpick.basepalTint); auto &mat = renderState.mMaterial; - int flags = (!notindexed && hw_useindexedcolortextures) ? CTF_Indexed : 0; + int flags = (TextureType == TT_INDEXED) ? CTF_Indexed : 0; mat.mMaterial = FMaterial::ValidateTexture(texpick.texture, flags); // todo allow scaling mat.mClampMode = sampler; mat.mTranslation = texpick.translation; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index e9d2068aa..ea21a7086 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -166,7 +166,6 @@ void PolymostRenderState::Apply(FRenderState& state, GLState& oldState) state.EnableTexture(gl_texture); state.SetMaterial(mMaterial.mMaterial, mMaterial.mClampMode, mMaterial.mTranslation, mMaterial.mOverrideShader); } - /* todo: bind indexed textures */ state.SetColor(Color[0], Color[1], Color[2], Color[3]); if (StateFlags != oldState.Flags) @@ -548,11 +547,14 @@ void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dasha { double dz = z / 65536.; alpha *= (dastat & RS_TRANS1)? glblend[0].def[!!(dastat & RS_TRANS2)].alpha : 1.; + TexturePick pick; + int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); + if (!PickTexture(picnum, nullptr, palid, pick)) return; - DrawTexture(&twodpsp, tileGetTexture(picnum, true), sx, sy, + DrawTexture(&twodpsp, pick.texture, sx, sy, DTA_ScaleX, dz, DTA_ScaleY, dz, DTA_Color, shadeToLight(dashade), - DTA_TranslationIndex, TRANSLATION(Translation_Remap + curbasepal, dapalnum), + DTA_TranslationIndex, pick.translation, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, DTA_ViewportWidth, windowxy2.x - windowxy1.x + 1, DTA_ViewportHeight, windowxy2.y - windowxy1.y + 1, DTA_FullscreenScale, (dastat & RS_STRETCH)? FSMode_ScaleToScreen: FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, @@ -565,6 +567,8 @@ void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dasha DTA_Rotate, a * (-360./2048), DTA_FlipOffsets, !(dastat & (/*RS_TOPLEFT |*/ RS_CENTER)), DTA_Alpha, alpha, + DTA_Indexed, !!(pick.translation & 0x80000000), + // todo: pass pick.tintFlags and pick.tintColor TAG_DONE); }