diff --git a/source/build/src/animvpx.cpp b/source/build/src/animvpx.cpp index 7915948b2..40fda518d 100644 --- a/source/build/src/animvpx.cpp +++ b/source/build/src/animvpx.cpp @@ -46,8 +46,8 @@ VPXTexture::VPXTexture() {} void VPXTexture::SetFrame(const void *data_, int width, int height) { - Size.x = width; - Size.y = height; + Width = width; + Height = height; data = data_; DeleteHardwareTextures(); } @@ -62,11 +62,11 @@ FBitmap VPXTexture::GetBgraBitmap(const PalEntry* remap, int* trans) { FBitmap bmp; - bmp.Create(Size.x, Size.y); + bmp.Create(Width, Height); auto spix = (uint8_t*)data; auto dpix = bmp.GetPixels(); - for (int i = 0; i < Size.x * Size.y; i++) + for (int i = 0; i < Width * Height; i++) { int p = i * 4; float y = spix[p] * (1/255.f); diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 6df7a50e8..184511537 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -327,8 +327,8 @@ int32_t polymost_spriteHasTranslucency(tspritetype const * const tspr) auto tex = TileFiles.tiles[tspr->picnum]; auto si = tex->FindReplacement(tspr->shade, 0); if (si && hw_hightile) tex = si->faces[0]; - if (tex->Get8BitPixels()) return false; - return tex && tex->GetTranslucency(); + if (tex->GetTexelWidth() == 0 || tex->GetTexelHeight() == 0) return false; + return tex && tex->GetTranslucency(); } int32_t polymost_spriteIsModelOrVoxel(tspritetype const * const tspr) diff --git a/source/common/textures/formats/buildtexture.cpp b/source/common/textures/formats/buildtexture.cpp index 83ddf5cd7..44648a51c 100644 --- a/source/common/textures/formats/buildtexture.cpp +++ b/source/common/textures/formats/buildtexture.cpp @@ -39,7 +39,7 @@ #include "image.h" #include "palettecontainer.h" -#if 0 + //========================================================================== // // @@ -75,4 +75,3 @@ int FBuildTexture::CopyPixels(FBitmap *bmp, int conversion) } -#endif \ No newline at end of file diff --git a/source/common/textures/formats/ddstexture.cpp b/source/common/textures/formats/ddstexture.cpp index 5f9b81fe1..3a88fcdd1 100644 --- a/source/common/textures/formats/ddstexture.cpp +++ b/source/common/textures/formats/ddstexture.cpp @@ -49,13 +49,11 @@ ** the pixel data, it is fairly inefficient to process. */ -#include #include "files.h" +#include "filesystem.h" #include "bitmap.h" #include "imagehelpers.h" #include "image.h" -#include "m_png.h" -#include "filesystem.h" // Since we want this to compile under Linux too, we need to define this // stuff ourselves instead of including a DirectX header. diff --git a/source/common/textures/image.h b/source/common/textures/image.h index 19db61ffa..b8fc4af59 100644 --- a/source/common/textures/image.h +++ b/source/common/textures/image.h @@ -148,6 +148,27 @@ public: static void RegisterForPrecache(FImageSource *img, bool requiretruecolor); }; + +//========================================================================== +// +// A texture defined in a Build TILESxxx.ART file +// +//========================================================================== +struct FRemapTable; + +class FBuildTexture : public FImageSource +{ +public: + FBuildTexture(const FString& pathprefix, int tilenum, const uint8_t* pixels, FRemapTable* translation, int width, int height, int left, int top); + TArray CreatePalettedPixels(int conversion) override; + int CopyPixels(FBitmap* bmp, int conversion) override; + +protected: + const uint8_t* RawPixels; + FRemapTable* Translation; +}; + + //========================================================================== // // a TGA texture diff --git a/source/core/2d/v_2ddrawer.cpp b/source/core/2d/v_2ddrawer.cpp index 28df4497f..8b6d33097 100644 --- a/source/core/2d/v_2ddrawer.cpp +++ b/source/core/2d/v_2ddrawer.cpp @@ -335,17 +335,17 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FTexture * // scaling is not used here. if (!local_origin) { - fU1 = float(left) / src->GetWidth(); - fV1 = float(top) / src->GetHeight(); - fU2 = float(right) / src->GetWidth(); - fV2 = float(bottom) / src->GetHeight(); + fU1 = float(left) / src->GetDisplayWidth(); + fV1 = float(top) / src->GetDisplayHeight(); + fU2 = float(right) / src->GetDisplayWidth(); + fV2 = float(bottom) / src->GetDisplayHeight(); } else { fU1 = 0; fV1 = 0; - fU2 = float(right - left) / src->GetWidth(); - fV2 = float(bottom - top) / src->GetHeight(); + fU2 = float(right - left) / src->GetDisplayWidth(); + fV2 = float(bottom - top) / src->GetDisplayHeight(); } dg.mVertIndex = (int)mVertices.Reserve(4); auto ptr = &mVertices[dg.mVertIndex]; @@ -667,7 +667,7 @@ void F2DDrawer::rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 float alpha = GetAlphaFromBlend(method, dablend) * (1.f - drawpoly_alpha); // Hmmm... p.a = (uint8_t)(alpha * 255); - vec2_16_t const siz = dg.mTexture->GetSize(); + vec2_t const siz = { dg.mTexture->GetDisplayWidth(), dg.mTexture->GetDisplayHeight() }; vec2_16_t ofs = { 0, 0 }; if (!(dastat & RS_TOPLEFT)) diff --git a/source/core/2d/v_draw.cpp b/source/core/2d/v_draw.cpp index a46003805..619048d93 100644 --- a/source/core/2d/v_draw.cpp +++ b/source/core/2d/v_draw.cpp @@ -116,8 +116,8 @@ bool SetTextureParms(DrawParms *parms, FTexture *img, double xx, double yy) { parms->x = xx; parms->y = yy; - parms->texwidth = img->GetWidth(); - parms->texheight = img->GetHeight(); + parms->texwidth = img->GetDisplayWidth(); + parms->texheight = img->GetDisplayHeight(); if (parms->top == INT_MAX || parms->fortext) { parms->top = img->GetTopOffset(); @@ -128,11 +128,11 @@ bool SetTextureParms(DrawParms *parms, FTexture *img, double xx, double yy) } if (parms->destwidth == INT_MAX || parms->fortext) { - parms->destwidth = img->GetWidth(); + parms->destwidth = img->GetDisplayWidth(); } if (parms->destheight == INT_MAX || parms->fortext) { - parms->destheight = img->GetHeight(); + parms->destheight = img->GetDisplayHeight(); } switch (parms->cleanmode) @@ -390,8 +390,8 @@ bool ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t tag, Va_Li assert(fortext == false); if (img == NULL) return false; parms->cleanmode = DTA_Fullscreen; - parms->virtWidth = img->GetWidth(); - parms->virtHeight = img->GetHeight(); + parms->virtWidth = img->GetDisplayWidth(); + parms->virtHeight = img->GetDisplayHeight(); } break; @@ -432,19 +432,19 @@ bool ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t tag, Va_Li break; case DTA_SrcX: - parms->srcx = ListGetDouble(tags) / img->GetWidth(); + parms->srcx = ListGetDouble(tags) / img->GetDisplayWidth(); break; case DTA_SrcY: - parms->srcy = ListGetDouble(tags) / img->GetHeight(); + parms->srcy = ListGetDouble(tags) / img->GetDisplayHeight(); break; case DTA_SrcWidth: - parms->srcwidth = ListGetDouble(tags) / img->GetWidth(); + parms->srcwidth = ListGetDouble(tags) / img->GetDisplayWidth(); break; case DTA_SrcHeight: - parms->srcheight = ListGetDouble(tags) / img->GetHeight(); + parms->srcheight = ListGetDouble(tags) / img->GetDisplayHeight(); break; case DTA_TopOffset: @@ -476,8 +476,8 @@ bool ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t tag, Va_Li if (fortext) return false; if (ListGetInt(tags)) { - parms->left = img->GetWidth() * 0.5; - parms->top = img->GetHeight() * 0.5; + parms->left = img->GetDisplayWidth() * 0.5; + parms->top = img->GetDisplayHeight() * 0.5; } break; @@ -486,8 +486,8 @@ bool ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t tag, Va_Li if (fortext) return false; if (ListGetInt(tags)) { - parms->left = img->GetWidth() * 0.5; - parms->top = img->GetHeight(); + parms->left = img->GetDisplayWidth() * 0.5; + parms->top = img->GetDisplayHeight(); } break; diff --git a/source/core/menu/listmenu.cpp b/source/core/menu/listmenu.cpp index f66133fb1..8528b02f2 100644 --- a/source/core/menu/listmenu.cpp +++ b/source/core/menu/listmenu.cpp @@ -416,13 +416,13 @@ void FListMenuItemStaticPatch::Drawer(DListMenu* menu, const DVector2& origin, b FTexture *tex = mTexture; if (mYpos >= 0) { - if (mCentered) x -= tex->GetWidth()/2; + if (mCentered) x -= tex->GetDisplayWidth()/2; DrawTexture (twod, tex, x, mYpos, DTA_Clean, true, TAG_DONE); } else { int x = (mXpos - 160) * CleanXfac + (screen->GetWidth()>>1); - if (mCentered) x -= (tex->GetWidth()*CleanXfac)/2; + if (mCentered) x -= (tex->GetDisplayWidth()*CleanXfac)/2; DrawTexture (twod, tex, x, -mYpos*CleanYfac, DTA_CleanNoMove, true, TAG_DONE); } } @@ -645,7 +645,7 @@ void FListMenuItemPatch::Drawer(DListMenu* menu, const DVector2& origin, bool se int FListMenuItemPatch::GetWidth() { return mTexture - ? mTexture->GetWidth() + ? mTexture->GetDisplayWidth() : 0; } diff --git a/source/core/menu/menu.cpp b/source/core/menu/menu.cpp index 011c1fcd5..ce9ad7f62 100644 --- a/source/core/menu/menu.cpp +++ b/source/core/menu/menu.cpp @@ -268,10 +268,10 @@ bool DMenu::MouseEventBack(int type, int x, int y) FTexture* tex = TileFiles.GetTexture("engine/graphics/m_back.png"); if (tex != NULL) { - if (m_show_backbutton&1) x -= screen->GetWidth() - tex->GetWidth() * CleanXfac; - if (m_show_backbutton&2) y -= screen->GetHeight() - tex->GetHeight() * CleanYfac; - mBackbuttonSelected = ( x >= 0 && x < tex->GetWidth() * CleanXfac && - y >= 0 && y < tex->GetHeight() * CleanYfac); + if (m_show_backbutton&1) x -= screen->GetWidth() - tex->GetDisplayWidth() * CleanXfac; + if (m_show_backbutton&2) y -= screen->GetHeight() - tex->GetDisplayHeight() * CleanYfac; + mBackbuttonSelected = ( x >= 0 && x < tex->GetDisplayWidth() * CleanXfac && + y >= 0 && y < tex->GetDisplayHeight() * CleanYfac); if (mBackbuttonSelected && type == MOUSE_Release) { if (m_use_mouse == 2) mBackbuttonSelected = false; @@ -322,17 +322,19 @@ void DMenu::Drawer () if (this == DMenu::CurrentMenu && BackbuttonAlpha > 0 && m_show_backbutton >= 0 && m_use_mouse) { FTexture* tex = TileFiles.GetTexture("engine/graphics/m_back.png"); - int w = tex->GetWidth() * CleanXfac; - int h = tex->GetHeight() * CleanYfac; - int x = (!(m_show_backbutton&1))? 0:screen->GetWidth() - w; - int y = (!(m_show_backbutton&2))? 0:screen->GetHeight() - h; - if (mBackbuttonSelected && (mMouseCapture || m_use_mouse == 1)) { - DrawTexture(twod, tex, x, y, DTA_CleanNoMove, true, DTA_ColorOverlay, MAKEARGB(40, 255,255,255), TAG_DONE); - } - else - { - DrawTexture(twod, tex, x, y, DTA_CleanNoMove, true, DTA_Alpha, BackbuttonAlpha, TAG_DONE); + int w = tex->GetDisplayWidth() * CleanXfac; + int h = tex->GetDisplayHeight() * CleanYfac; + int x = (!(m_show_backbutton & 1)) ? 0 : screen->GetWidth() - w; + int y = (!(m_show_backbutton & 2)) ? 0 : screen->GetHeight() - h; + if (mBackbuttonSelected && (mMouseCapture || m_use_mouse == 1)) + { + DrawTexture(twod, tex, x, y, DTA_CleanNoMove, true, DTA_ColorOverlay, MAKEARGB(40, 255, 255, 255), TAG_DONE); + } + else + { + DrawTexture(twod, tex, x, y, DTA_CleanNoMove, true, DTA_Alpha, BackbuttonAlpha, TAG_DONE); + } } } } diff --git a/source/core/menu/savegamemanager.cpp b/source/core/menu/savegamemanager.cpp index 3489b8ac4..87a071004 100644 --- a/source/core/menu/savegamemanager.cpp +++ b/source/core/menu/savegamemanager.cpp @@ -416,7 +416,7 @@ unsigned FSavegameManager::ExtractSaveData(int index) { SavePic = PNGTexture_CreateFromFile(png, node->Filename); delete png; - if (SavePic && SavePic->GetWidth() == 1 && SavePic->GetHeight() == 1) + if (SavePic && SavePic->GetDisplayWidth() == 1 && SavePic->GetDisplayHeight() == 1) { delete SavePic; SavePic = nullptr; diff --git a/source/core/rendering/gl/renderer/gl_renderer.cpp b/source/core/rendering/gl/renderer/gl_renderer.cpp index c966e333e..f28eda2b7 100644 --- a/source/core/rendering/gl/renderer/gl_renderer.cpp +++ b/source/core/rendering/gl/renderer/gl_renderer.cpp @@ -178,10 +178,10 @@ void FGLRenderer::BindToFrameBuffer(FTexture *mat) { // must create the hardware texture first BaseLayer = new FHardwareTexture(); - BaseLayer->CreateTexture(mat->GetWidth()*4, mat->GetHeight()*4, FHardwareTexture::TrueColor, false); + BaseLayer->CreateTexture(mat->GetTexelWidth()*4, mat->GetTexelHeight()*4, ::FHardwareTexture::TrueColor, false); mat->SetHardwareTexture(0, BaseLayer); } - BaseLayer->BindToFrameBuffer(mat->GetWidth()*4, mat->GetHeight()*4); + BaseLayer->BindToFrameBuffer(mat->GetTexelWidth()*4, mat->GetTexelHeight()*4); } //=========================================================================== diff --git a/source/core/textures/textures.h b/source/core/textures/textures.h index 83da80c0a..28bcd49e9 100644 --- a/source/core/textures/textures.h +++ b/source/core/textures/textures.h @@ -226,6 +226,10 @@ public: int GetWidth() const { return Size.x; } int GetHeight() const { return Size.y; } + int GetTexelWidth() const { return Size.x; } + int GetTexelHeight() const { return Size.y; } + int GetDisplayWidth() const { return Size.x; } + int GetDisplayHeight() const { return Size.y; } const vec2_16_t &GetSize() const { return Size; } const uint8_t& GetPicSize() const { return PicSize; } int GetLeftOffset() const { return PicAnim.xofs; } @@ -294,7 +298,11 @@ protected: FString Name; - vec2_16_t Size = { 0,0 }; // Keep this in the native format so that we can use it without copying it around. + union + { + vec2_16_t Size = { 0,0 }; // Keep this in the native format so that we can use it without copying it around. + struct { uint16_t Width, Height; }; + }; rottile_t RotTile = { -1,-1 }; uint8_t bMasked = true; // Texture (might) have holes int8_t bTranslucent = -1; // Does this texture have an active alpha channel?