diff --git a/src/hwrenderer/textures/hw_material.cpp b/src/hwrenderer/textures/hw_material.cpp index 530be9458..fe1cda7cf 100644 --- a/src/hwrenderer/textures/hw_material.cpp +++ b/src/hwrenderer/textures/hw_material.cpp @@ -160,7 +160,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) mShaderIndex = SHADER_Default; sourcetex = tex = tx; - if (tx->UseType == ETextureType::SWCanvas && tx->WidthBits == 0) + if (tx->UseType == ETextureType::SWCanvas && static_cast(tx)->GetColorFormat() == 0) { mShaderIndex = SHADER_Paletted; } diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index e25a72613..6067e2f9e 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -70,9 +70,6 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox) SourceVox = vox; Width = 16; Height = 16; - WidthBits = 4; - HeightBits = 4; - WidthMask = 15; bNoCompress = true; } diff --git a/src/swrenderer/textures/r_swtexture.cpp b/src/swrenderer/textures/r_swtexture.cpp index 67a48beef..79560d5b2 100644 --- a/src/swrenderer/textures/r_swtexture.cpp +++ b/src/swrenderer/textures/r_swtexture.cpp @@ -41,6 +41,40 @@ +//========================================================================== +// +// +// +//========================================================================== + +void FSoftwareTexture::CalcBitSize () +{ + // WidthBits is rounded down, and HeightBits is rounded up + int i; + + for (i = 0; (1 << i) < GetWidth(); ++i) + { } + + WidthBits = i; + + // Having WidthBits that would allow for columns past the end of the + // texture is not allowed, even if it means the entire texture is + // not drawn. + if (GetWidth() < (1 << WidthBits)) + { + WidthBits--; + } + WidthMask = (1 << WidthBits) - 1; + + //
The minimum height is 2, because we cannot shift right 32 bits. + // Scratch that. Somebody actually made a 1x1 texture, so now we have to handle it. + for (i = 0; (1 << i) < GetHeight(); ++i) + { } + + HeightBits = i; +} + + //========================================================================== // // @@ -61,7 +95,7 @@ const uint32_t *FSoftwareTexture::GetColumnBgra(unsigned int column, const FSoft const uint32_t *FSoftwareTexture::GetPixelsBgra() { - if (PixelsBgra.empty() || CheckModified(DefaultRenderStyle())) + if (PixelsBgra.Size() == 0 || CheckModified(DefaultRenderStyle())) { if (!GetColumn(DefaultRenderStyle(), 0, nullptr)) return nullptr; @@ -71,7 +105,7 @@ const uint32_t *FSoftwareTexture::GetPixelsBgra() mTexture->CopyTrueColorPixels(&bitmap, 0, 0); GenerateBgraFromBitmap(bitmap); } - return PixelsBgra.data(); + return PixelsBgra.Data(); } //========================================================================== @@ -191,7 +225,7 @@ void FSoftwareTexture::GenerateBgraFromBitmap(const FBitmap &bitmap) // Transpose const uint32_t *src = (const uint32_t *)bitmap.GetPixels(); - uint32_t *dest = PixelsBgra.data(); + uint32_t *dest = PixelsBgra.Data(); for (int x = 0; x < GetWidth(); x++) { for (int y = 0; y < GetHeight(); y++) @@ -213,7 +247,7 @@ void FSoftwareTexture::CreatePixelsBgraWithMipmaps() int h = MAX(GetHeight() >> i, 1); buffersize += w * h; } - PixelsBgra.resize(buffersize, 0xffff0000); + PixelsBgra.Resize(buffersize); } int FSoftwareTexture::MipmapLevels() @@ -249,7 +283,7 @@ void FSoftwareTexture::GenerateBgraMipmaps() }; int levels = MipmapLevels(); - std::vector image(PixelsBgra.size()); + std::vector image(PixelsBgra.Size()); // Convert to normalized linear colorspace { @@ -335,7 +369,7 @@ void FSoftwareTexture::GenerateBgraMipmaps() // Convert to bgra8 sRGB colorspace { Color4f *src = image.data() + GetWidth() * GetHeight(); - uint32_t *dest = PixelsBgra.data() + GetWidth() * GetHeight(); + uint32_t *dest = PixelsBgra.Data() + GetWidth() * GetHeight(); for (int i = 1; i < levels; i++) { int w = MAX(GetWidth() >> i, 1); @@ -362,7 +396,7 @@ void FSoftwareTexture::GenerateBgraMipmaps() void FSoftwareTexture::GenerateBgraMipmapsFast() { - uint32_t *src = PixelsBgra.data(); + uint32_t *src = PixelsBgra.Data(); uint32_t *dest = src + GetWidth() * GetHeight(); int levels = MipmapLevels(); for (int i = 1; i < levels; i++) @@ -413,9 +447,9 @@ const uint8_t *FSoftwareTexture::GetColumn(FRenderStyle style, unsigned int colu auto Pixeldata = GetPixels(style); if ((unsigned)column >= (unsigned)GetWidth()) { - if (mTexture->WidthMask + 1 == GetWidth()) + if (WidthMask + 1 == GetWidth()) { - column &= mTexture->WidthMask; + column &= WidthMask; } else { diff --git a/src/swrenderer/textures/r_swtexture.h b/src/swrenderer/textures/r_swtexture.h index 3d350e9c5..8c3e5a2f1 100644 --- a/src/swrenderer/textures/r_swtexture.h +++ b/src/swrenderer/textures/r_swtexture.h @@ -15,9 +15,11 @@ class FSoftwareTexture protected: FTexture *mTexture; FTexture *mSource; - uint8_t *Pixels[2]; - std::vector PixelsBgra; + TArray PixelsBgra; FSoftwareTextureSpan **Spandata[2] = { nullptr, nullptr }; + uint8_t WidthBits = 0, HeightBits = 0; + uint16_t WidthMask = 0; + public: @@ -25,6 +27,7 @@ public: { mTexture = tex; mSource = tex; + CalcBitSize(); } virtual ~FSoftwareTexture() @@ -48,14 +51,15 @@ public: return mTexture->bMasked; } + void CalcBitSize(); bool UseBasePalette() const { return mTexture->UseBasePalette(); } int GetSkyOffset() const { return mTexture->GetSkyOffset(); } PalEntry GetSkyCapColor(bool bottom) const { return mTexture->GetSkyCapColor(bottom); } int GetWidth () { return mTexture->GetWidth(); } int GetHeight () { return mTexture->GetHeight(); } - int GetWidthBits() { return mTexture->WidthBits; } - int GetHeightBits() { return mTexture->HeightBits; } + int GetWidthBits() { return WidthBits; } + int GetHeightBits() { return HeightBits; } bool Mipmapped() { return mTexture->Mipmapped(); } int GetScaledWidth () { return mTexture->GetScaledWidth(); } @@ -98,7 +102,7 @@ public: void Unload() { mTexture->Unload(); - PixelsBgra = std::vector(); + PixelsBgra.Reset(); } // Returns true if the next call to GetPixels() will return an image different from the diff --git a/src/textures/formats/automaptexture.cpp b/src/textures/formats/automaptexture.cpp index 4d6ddfeaf..b779da1d9 100644 --- a/src/textures/formats/automaptexture.cpp +++ b/src/textures/formats/automaptexture.cpp @@ -80,7 +80,6 @@ FAutomapTexture::FAutomapTexture (int lumpnum) { Width = 320; Height = uint16_t(Wads.LumpLength(lumpnum) / 320); - CalcBitSize (); } //========================================================================== diff --git a/src/textures/formats/buildtexture.cpp b/src/textures/formats/buildtexture.cpp index 3df85f90b..69ec03d2c 100644 --- a/src/textures/formats/buildtexture.cpp +++ b/src/textures/formats/buildtexture.cpp @@ -81,7 +81,6 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8 Height = height; _LeftOffset[1] = _LeftOffset[0] = left; _TopOffset[1] = _TopOffset[0] = top; - CalcBitSize (); Name.Format("%sBTIL%04d", pathprefix.GetChars(), tilenum); UseType = ETextureType::Override; } diff --git a/src/textures/formats/canvastexture.cpp b/src/textures/formats/canvastexture.cpp index c760d7351..eb3982702 100644 --- a/src/textures/formats/canvastexture.cpp +++ b/src/textures/formats/canvastexture.cpp @@ -41,15 +41,8 @@ FCanvasTexture::FCanvasTexture (const char *name, int width, int height) Name = name; Width = width; Height = height; - CalcBitSize (); bMasked = false; - /* - DummySpans[0].TopOffset = 0; - DummySpans[0].Length = height; - DummySpans[1].TopOffset = 0; - DummySpans[1].Length = 0; - */ UseType = ETextureType::Wall; bNeedsUpdate = true; bDidUpdate = false; @@ -63,33 +56,6 @@ FCanvasTexture::~FCanvasTexture () Unload (); } -#if 0 -const uint8_t *FCanvasTexture::GetColumn(FRenderStyle style, unsigned int column, const FSoftwareTextureSpan **spans_out) -{ - bNeedsUpdate = true; - if (Canvas == NULL) - { - MakeTexture (style); - } - if ((unsigned)column >= (unsigned)Width) - { - if (WidthMask + 1 == Width) - { - column &= WidthMask; - } - else - { - column %= Width; - } - } - if (spans_out != NULL) - { - *spans_out = DummySpans; - } - return Pixels + column*Height; -} -#endif - const uint8_t *FCanvasTexture::GetPixels (FRenderStyle style) { bNeedsUpdate = true; diff --git a/src/textures/formats/ddstexture.cpp b/src/textures/formats/ddstexture.cpp index c0988bec7..04f36adbb 100644 --- a/src/textures/formats/ddstexture.cpp +++ b/src/textures/formats/ddstexture.cpp @@ -292,7 +292,6 @@ FDDSTexture::FDDSTexture (FileReader &lump, int lumpnum, void *vsurfdesc) Width = uint16_t(surf->Width); Height = uint16_t(surf->Height); - CalcBitSize (); if (surf->PixelFormat.Flags & DDPF_FOURCC) { diff --git a/src/textures/formats/emptytexture.cpp b/src/textures/formats/emptytexture.cpp index 19698551f..d49cdbf09 100644 --- a/src/textures/formats/emptytexture.cpp +++ b/src/textures/formats/emptytexture.cpp @@ -81,9 +81,7 @@ FEmptyTexture::FEmptyTexture (int lumpnum) : FWorldTexture(NULL, lumpnum) { bMasked = true; - WidthBits = HeightBits = 1; Width = Height = 1; - WidthMask = 0; PixelsAreStatic = 3; } diff --git a/src/textures/formats/flattexture.cpp b/src/textures/formats/flattexture.cpp index 1d2a47e56..0e29defc1 100644 --- a/src/textures/formats/flattexture.cpp +++ b/src/textures/formats/flattexture.cpp @@ -92,9 +92,7 @@ FFlatTexture::FFlatTexture (int lumpnum) bMasked = false; bTranslucent = false; - WidthBits = HeightBits = bits; Width = Height = 1 << bits; - WidthMask = (1 << bits) - 1; } //========================================================================== diff --git a/src/textures/formats/imgztexture.cpp b/src/textures/formats/imgztexture.cpp index b01de82a6..2d0894de3 100644 --- a/src/textures/formats/imgztexture.cpp +++ b/src/textures/formats/imgztexture.cpp @@ -113,7 +113,6 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1 _LeftOffset[1] = _LeftOffset[0] = l; _TopOffset[1] = _TopOffset[0] = t; isalpha = _isalpha; - CalcBitSize (); } //========================================================================== @@ -132,7 +131,6 @@ uint8_t *FIMGZTexture::MakeTexture (FRenderStyle style) int dest_adv = Height; int dest_rew = Width * Height - 1; - CalcBitSize (); auto Pixels = new uint8_t[Width*Height]; dest_p = Pixels; diff --git a/src/textures/formats/jpegtexture.cpp b/src/textures/formats/jpegtexture.cpp index f3f626622..56165a731 100644 --- a/src/textures/formats/jpegtexture.cpp +++ b/src/textures/formats/jpegtexture.cpp @@ -253,7 +253,6 @@ FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height) Width = width; Height = height; - CalcBitSize (); } //========================================================================== diff --git a/src/textures/formats/multipatchtexture.cpp b/src/textures/formats/multipatchtexture.cpp index cb12f9ba5..31c8ffd21 100644 --- a/src/textures/formats/multipatchtexture.cpp +++ b/src/textures/formats/multipatchtexture.cpp @@ -254,7 +254,6 @@ FMultiPatchTexture::FMultiPatchTexture (const void *texdef, FPatchLookup *patchl Width = SAFESHORT(mtexture.d->width); Height = SAFESHORT(mtexture.d->height); Name = (char *)mtexture.d->name; - CalcBitSize (); Scale.X = mtexture.d->ScaleX ? mtexture.d->ScaleX / 8. : 1.; Scale.Y = mtexture.d->ScaleY ? mtexture.d->ScaleY / 8. : 1.; @@ -400,9 +399,7 @@ uint8_t *GetBlendMap(PalEntry blend, uint8_t *blendwork) uint8_t *FMultiPatchTexture::MakeTexture (FRenderStyle style) { - // Add a little extra space at the end if the texture's height is not - // a power of 2, in case somebody accidentally makes it repeat vertically. - int numpix = Width * Height + (1 << HeightBits) - Height; + int numpix = Width * Height; uint8_t blendwork[256]; bool buildrgb = bComplex; @@ -620,7 +617,6 @@ void FMultiPatchTexture::CheckForHacks () Height == 128) { Height = 200; - HeightBits = 8; return; } @@ -1220,8 +1216,6 @@ FMultiPatchTexture::FMultiPatchTexture (FScanner &sc, ETextureType usetype) Printf("Texture %s has invalid dimensions (%d, %d)\n", Name.GetChars(), Width, Height); Width = Height = 1; } - CalcBitSize (); - sc.SetCMode(false); } diff --git a/src/textures/formats/patchtexture.cpp b/src/textures/formats/patchtexture.cpp index 2fe928b05..ed6630ffb 100644 --- a/src/textures/formats/patchtexture.cpp +++ b/src/textures/formats/patchtexture.cpp @@ -159,7 +159,6 @@ FPatchTexture::FPatchTexture (int lumpnum, patch_t * header, bool isalphatex) _LeftOffset[1] = _LeftOffset[0] = header->leftoffset; _TopOffset[1] = _TopOffset[0] = header->topoffset; DetectBadPatches(); - CalcBitSize (); } //========================================================================== @@ -208,9 +207,7 @@ uint8_t *FPatchTexture::MakeTexture (FRenderStyle style) return Pixels; } - // Add a little extra space at the end if the texture's height is not - // a power of 2, in case somebody accidentally makes it repeat vertically. - int numpix = Width * Height + (1 << HeightBits) - Height; + int numpix = Width * Height; numspans = Width; diff --git a/src/textures/formats/pcxtexture.cpp b/src/textures/formats/pcxtexture.cpp index 4f7972312..f97cf03b8 100644 --- a/src/textures/formats/pcxtexture.cpp +++ b/src/textures/formats/pcxtexture.cpp @@ -148,7 +148,6 @@ FPCXTexture::FPCXTexture(int lumpnum, PCXHeader & hdr) bMasked = false; Width = LittleShort(hdr.xmax) - LittleShort(hdr.xmin) + 1; Height = LittleShort(hdr.ymax) - LittleShort(hdr.ymin) + 1; - CalcBitSize(); } //========================================================================== diff --git a/src/textures/formats/pngtexture.cpp b/src/textures/formats/pngtexture.cpp index bdb232c0c..2071fedf0 100644 --- a/src/textures/formats/pngtexture.cpp +++ b/src/textures/formats/pngtexture.cpp @@ -209,7 +209,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename Width = width; Height = height; - CalcBitSize (); memset(trans, 255, 256); diff --git a/src/textures/formats/rawpagetexture.cpp b/src/textures/formats/rawpagetexture.cpp index 0d42544fe..9a829acc3 100644 --- a/src/textures/formats/rawpagetexture.cpp +++ b/src/textures/formats/rawpagetexture.cpp @@ -159,9 +159,6 @@ FRawPageTexture::FRawPageTexture (int lumpnum) { Width = 320; Height = 200; - WidthBits = 8; - HeightBits = 8; - WidthMask = 255; // Special case hack for Heretic's E2 end pic. This is not going to be exposed as an editing feature because the implications would be horrible. if (Name.CompareNoCase("E2END") == 0 && gameinfo.gametype == GAME_Heretic) diff --git a/src/textures/formats/shadertexture.cpp b/src/textures/formats/shadertexture.cpp index 1b1ab5c6f..123ddd223 100644 --- a/src/textures/formats/shadertexture.cpp +++ b/src/textures/formats/shadertexture.cpp @@ -51,7 +51,6 @@ public: Name.Format("BarShader%c%c", vertical ? 'v' : 'h', reverse ? 'r' : 'f'); Width = vertical ? 2 : 256; Height = vertical ? 256 : 2; - CalcBitSize(); bMasked = false; bTranslucent = false; PixelsAreStatic = 2; // The alpha buffer is static, but if this gets used as a regular texture, a separate buffer needs to be made. diff --git a/src/textures/formats/tgatexture.cpp b/src/textures/formats/tgatexture.cpp index 36e0144ab..44bac1bfd 100644 --- a/src/textures/formats/tgatexture.cpp +++ b/src/textures/formats/tgatexture.cpp @@ -136,7 +136,6 @@ FTGATexture::FTGATexture (int lumpnum, TGAHeader * hdr) Height = hdr->height; // Alpha channel is used only for 32 bit RGBA and paletted images with RGBA palettes. bMasked = (hdr->img_desc&15)==8 && (hdr->bpp==32 || (hdr->img_type==1 && hdr->cm_size==32)); - CalcBitSize(); } //========================================================================== diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 6cfb04c19..ea5e41769 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -177,10 +177,10 @@ FTexture * FTexture::CreateTexture (const char *name, int lumpnum, ETextureType FTexture::FTexture (const char *name, int lumpnum) : - WidthBits(0), HeightBits(0), Scale(1,1), SourceLump(lumpnum), + Scale(1,1), SourceLump(lumpnum), UseType(ETextureType::Any), bNoDecals(false), bNoRemap0(false), bWorldPanning(false), bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bKeepAround(false), bFullNameTexture(false), - Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0), WidthMask(0) + Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) { bBrightmapChecked = false; bGlowing = false; @@ -254,39 +254,6 @@ void FTexture::SetFrontSkyLayer () // //========================================================================== -void FTexture::CalcBitSize () -{ - // WidthBits is rounded down, and HeightBits is rounded up - int i; - - for (i = 0; (1 << i) < Width; ++i) - { } - - WidthBits = i; - - // Having WidthBits that would allow for columns past the end of the - // texture is not allowed, even if it means the entire texture is - // not drawn. - if (Width < (1 << WidthBits)) - { - WidthBits--; - } - WidthMask = (1 << WidthBits) - 1; - - //
The minimum height is 2, because we cannot shift right 32 bits. - // Scratch that. Somebody actually made a 1x1 texture, so now we have to handle it. - for (i = 0; (1 << i) < Height; ++i) - { } - - HeightBits = i; -} - -//========================================================================== -// -// -// -//========================================================================== - void FTexture::CopyToBlock (uint8_t *dest, int dwidth, int dheight, int xpos, int ypos, int rotate, const uint8_t *translation, FRenderStyle style) { const uint8_t *pixels = GetPixels(style); @@ -1102,9 +1069,6 @@ FDummyTexture::FDummyTexture () { Width = 64; Height = 64; - HeightBits = 6; - WidthBits = 6; - WidthMask = 63; UseType = ETextureType::Null; } @@ -1112,7 +1076,6 @@ void FDummyTexture::SetSize (int width, int height) { Width = width; Height = height; - CalcBitSize (); } @@ -1126,7 +1089,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) { Width = w; Height = h; - WidthBits = bits; + Format = bits; UseType = ETextureType::SWCanvas; bNoCompress = true; SystemTexture[0] = screen->CreateHardwareTexture(this); diff --git a/src/textures/textures.h b/src/textures/textures.h index 32e989afa..c93d79609 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -315,8 +315,6 @@ public: protected: //int16_t LeftOffset, TopOffset; - uint8_t WidthBits, HeightBits; - DVector2 Scale; int SourceLump; @@ -455,16 +453,13 @@ protected: _TopOffset[1] = BaseTexture->_TopOffset[1]; _LeftOffset[0] = BaseTexture->_LeftOffset[0]; _LeftOffset[1] = BaseTexture->_LeftOffset[1]; - WidthBits = BaseTexture->WidthBits; - HeightBits = BaseTexture->HeightBits; Scale = BaseTexture->Scale; - WidthMask = (1 << WidthBits) - 1; } void SetScaledSize(int fitwidth, int fitheight); protected: - uint16_t Width, Height, WidthMask; + uint16_t Width, Height; int16_t _LeftOffset[2], _TopOffset[2]; static uint8_t GrayMap[256]; uint8_t *GetRemap(FRenderStyle style, bool srcisgrayscale = false) @@ -516,7 +511,6 @@ protected: FTexture (const char *name = NULL, int lumpnum = -1); - void CalcBitSize (); void CopyInfo(FTexture *other) { CopySize(other); @@ -813,6 +807,7 @@ public: // A wrapper around a hardware texture, to allow using it in the 2D drawing interface. class FWrapperTexture : public FTexture { + int Format; public: FWrapperTexture(int w, int h, int bits = 1); IHardwareTexture *GetSystemTexture(int slot) @@ -822,7 +817,7 @@ public: int GetColorFormat() const { - return WidthBits; + return Format; } }; diff --git a/src/v_font.cpp b/src/v_font.cpp index 82b2ed19d..4985b2407 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -1659,7 +1659,6 @@ FFontChar2::FFontChar2 (int sourcelump, int sourcepos, int width, int height, in Height = height; _LeftOffset[1] = _LeftOffset[0] = leftofs; _TopOffset[1] = _TopOffset[0] = topofs; - CalcBitSize (); } //==========================================================================