/* ** texture.cpp ** The base texture class ** **--------------------------------------------------------------------------- ** Copyright 2004-2007 Randy Heit ** Copyright 2006-2018 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions ** are met: ** ** 1. Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** 2. Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. ** 3. The name of the author may not be used to endorse or promote products ** derived from this software without specific prior written permission. ** ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **--------------------------------------------------------------------------- ** ** */ #include "doomtype.h" #include "files.h" #include "w_wad.h" #include "templates.h" #include "i_system.h" #include "r_data/r_translate.h" #include "bitmap.h" #include "colormatcher.h" #include "c_dispatch.h" #include "v_video.h" #include "m_fixed.h" #include "hwrenderer/textures/hw_material.h" #include "hwrenderer/textures/hw_ihwtexture.h" FTexture *CreateBrightmapTexture(FTexture*); // Make sprite offset adjustment user-configurable per renderer. int r_spriteadjustSW, r_spriteadjustHW; CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { r_spriteadjustHW = !!(self & 2); r_spriteadjustSW = !!(self & 1); TexMan.SpriteAdjustChanged(); } //========================================================================== // // // //========================================================================== uint8_t FTexture::GrayMap[256]; void FTexture::InitGrayMap() { for (int i = 0; i < 256; ++i) { GrayMap[i] = ColorMatcher.Pick(i, i, i); } } //========================================================================== // // // //========================================================================== typedef FTexture * (*CreateFunc)(FileReader & file, int lumpnum); struct TexCreateInfo { CreateFunc TryCreate; ETextureType usetype; }; FTexture *IMGZTexture_TryCreate(FileReader &, int lumpnum); FTexture *PNGTexture_TryCreate(FileReader &, int lumpnum); FTexture *JPEGTexture_TryCreate(FileReader &, int lumpnum); FTexture *DDSTexture_TryCreate(FileReader &, int lumpnum); FTexture *PCXTexture_TryCreate(FileReader &, int lumpnum); FTexture *TGATexture_TryCreate(FileReader &, int lumpnum); FTexture *RawPageTexture_TryCreate(FileReader &, int lumpnum); FTexture *FlatTexture_TryCreate(FileReader &, int lumpnum); FTexture *PatchTexture_TryCreate(FileReader &, int lumpnum); FTexture *EmptyTexture_TryCreate(FileReader &, int lumpnum); FTexture *AutomapTexture_TryCreate(FileReader &, int lumpnum); // Examines the lump contents to decide what type of texture to create, // and creates the texture. FTexture * FTexture::CreateTexture (int lumpnum, ETextureType usetype) { static TexCreateInfo CreateInfo[]={ { IMGZTexture_TryCreate, ETextureType::Any }, { PNGTexture_TryCreate, ETextureType::Any }, { JPEGTexture_TryCreate, ETextureType::Any }, { DDSTexture_TryCreate, ETextureType::Any }, { PCXTexture_TryCreate, ETextureType::Any }, { TGATexture_TryCreate, ETextureType::Any }, { RawPageTexture_TryCreate, ETextureType::MiscPatch }, { FlatTexture_TryCreate, ETextureType::Flat }, { PatchTexture_TryCreate, ETextureType::Any }, { EmptyTexture_TryCreate, ETextureType::Any }, { AutomapTexture_TryCreate, ETextureType::MiscPatch }, }; if (lumpnum == -1) return NULL; auto data = Wads.OpenLumpReader (lumpnum); for(size_t i = 0; i < countof(CreateInfo); i++) { if ((CreateInfo[i].usetype == usetype || CreateInfo[i].usetype == ETextureType::Any)) { FTexture * tex = CreateInfo[i].TryCreate(data, lumpnum); if (tex != NULL) { tex->UseType = usetype; if (usetype == ETextureType::Flat) { int w = tex->GetWidth(); int h = tex->GetHeight(); // Auto-scale flats with dimensions 128x128 and 256x256. // In hindsight, a bad idea, but RandomLag made it sound better than it really is. // Now we're stuck with this stupid behaviour. if (w==128 && h==128) { tex->Scale.X = tex->Scale.Y = 2; tex->bWorldPanning = true; } else if (w==256 && h==256) { tex->Scale.X = tex->Scale.Y = 4; tex->bWorldPanning = true; } } return tex; } } } return NULL; } FTexture * FTexture::CreateTexture (const char *name, int lumpnum, ETextureType usetype) { FTexture *tex = CreateTexture(lumpnum, usetype); if (tex != NULL && name != NULL) { tex->Name = name; tex->Name.ToUpper(); } return tex; } //========================================================================== // // // //========================================================================== FTexture::FTexture (const char *name, int 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) { bBrightmapChecked = false; bGlowing = false; bAutoGlowing = false; bFullbright = false; bDisableFullbright = false; bSkybox = false; bNoCompress = false; bNoExpand = false; bTranslucent = -1; _LeftOffset[0] = _LeftOffset[1] = _TopOffset[0] = _TopOffset[1] = 0; id.SetInvalid(); if (name != NULL) { Name = name; Name.ToUpper(); } else if (lumpnum < 0) { Name = FString(); } else { Wads.GetLumpName (Name, lumpnum); } } FTexture::~FTexture () { FTexture *link = Wads.GetLinkedTexture(SourceLump); if (link == this) Wads.SetLinkedTexture(SourceLump, nullptr); if (areas != nullptr) delete[] areas; areas = nullptr; for (int i = 0; i < 2; i++) { if (Material[i] != nullptr) delete Material[i]; Material[i] = nullptr; if (SystemTexture[i] != nullptr) delete SystemTexture[i]; SystemTexture[i] = nullptr; } } void FTexture::Unload() { } //========================================================================== // // // //========================================================================== FTextureFormat FTexture::GetFormat() { return TEX_Pal; } void FTexture::SetFrontSkyLayer () { bNoRemap0 = true; } //========================================================================== // // // //========================================================================== 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 = Get8BitPixels(style); int srcwidth = Width; int srcheight = Height; int step_x = Height; int step_y = 1; FClipRect cr = {0, 0, dwidth, dheight}; if (style.Flags & STYLEF_RedIsAlpha) translation = nullptr; // do not apply translations to alpha textures. if (ClipCopyPixelRect(&cr, xpos, ypos, pixels, srcwidth, srcheight, step_x, step_y, rotate)) { dest += ypos + dheight * xpos; if (translation == NULL) { for (int x = 0; x < srcwidth; x++) { int pos = x * dheight; for (int y = 0; y < srcheight; y++, pos++) { // the optimizer is doing a good enough job here so there's no need to optimize this by hand uint8_t v = pixels[y * step_y + x * step_x]; if (v != 0) dest[pos] = v; } } } else { for (int x = 0; x < srcwidth; x++) { int pos = x * dheight; for (int y = 0; y < srcheight; y++, pos++) { uint8_t v = pixels[y * step_y + x * step_x]; if (v != 0) dest[pos] = translation[v]; } } } } } //========================================================================== // // Converts a texture between row-major and column-major format // by flipping it about the X=Y axis. // //========================================================================== void FTexture::FlipSquareBlock (uint8_t *block, int x, int y) { int i, j; if (x != y) return; for (i = 0; i < x; ++i) { uint8_t *corner = block + x*i + i; int count = x - i; if (count & 1) { count--; swapvalues (corner[count], corner[count*x]); } for (j = 0; j < count; j += 2) { swapvalues (corner[j], corner[j*x]); swapvalues (corner[j+1], corner[(j+1)*x]); } } } void FTexture::FlipSquareBlockBgra(uint32_t *block, int x, int y) { int i, j; if (x != y) return; for (i = 0; i < x; ++i) { uint32_t *corner = block + x*i + i; int count = x - i; if (count & 1) { count--; swapvalues(corner[count], corner[count*x]); } for (j = 0; j < count; j += 2) { swapvalues(corner[j], corner[j*x]); swapvalues(corner[j + 1], corner[(j + 1)*x]); } } } void FTexture::FlipSquareBlockRemap (uint8_t *block, int x, int y, const uint8_t *remap) { int i, j; uint8_t t; if (x != y) return; for (i = 0; i < x; ++i) { uint8_t *corner = block + x*i + i; int count = x - i; if (count & 1) { count--; t = remap[corner[count]]; corner[count] = remap[corner[count*x]]; corner[count*x] = t; } for (j = 0; j < count; j += 2) { t = remap[corner[j]]; corner[j] = remap[corner[j*x]]; corner[j*x] = t; t = remap[corner[j+1]]; corner[j+1] = remap[corner[(j+1)*x]]; corner[(j+1)*x] = t; } } } void FTexture::FlipNonSquareBlock (uint8_t *dst, const uint8_t *src, int x, int y, int srcpitch) { int i, j; for (i = 0; i < x; ++i) { for (j = 0; j < y; ++j) { dst[i*y+j] = src[i+j*srcpitch]; } } } void FTexture::FlipNonSquareBlockBgra(uint32_t *dst, const uint32_t *src, int x, int y, int srcpitch) { int i, j; for (i = 0; i < x; ++i) { for (j = 0; j < y; ++j) { dst[i*y + j] = src[i + j*srcpitch]; } } } void FTexture::FlipNonSquareBlockRemap (uint8_t *dst, const uint8_t *src, int x, int y, int srcpitch, const uint8_t *remap) { int i, j; for (i = 0; i < x; ++i) { for (j = 0; j < y; ++j) { dst[i*y+j] = remap[src[i+j*srcpitch]]; } } } //========================================================================== // // // //========================================================================== void FTexture::FillBuffer(uint8_t *buff, int pitch, int height, FTextureFormat fmt) { const uint8_t *pix; int x, y, w, h, stride; w = GetWidth(); h = GetHeight(); switch (fmt) { case TEX_Pal: case TEX_Gray: pix = Get8BitPixels(fmt == TEX_Pal? DefaultRenderStyle() : LegacyRenderStyles[STYLE_Shaded]); stride = pitch - w; for (y = 0; y < h; ++y) { const uint8_t *pix2 = pix; for (x = 0; x < w; ++x) { *buff++ = *pix2; pix2 += h; } pix++; buff += stride; } break; case TEX_RGB: { FCopyInfo inf = {OP_OVERWRITE, BLEND_NONE, {0}, 0, 0}; FBitmap bmp(buff, pitch, pitch/4, height); CopyTrueColorPixels(&bmp, 0, 0, 0, &inf); break; } default: I_Error("FTexture::FillBuffer: Unsupported format %d", fmt); } } //=========================================================================== // // FTexture::CopyTrueColorPixels // // this is the generic case that can handle // any properly implemented texture for software rendering. // Its drawback is that it is limited to the base palette which is // why all classes that handle different palettes should subclass this // method // //=========================================================================== int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { PalEntry *palette = screen->GetPalette(); for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values bmp->CopyPixelData(x, y, Get8BitPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, palette, inf); for(int i=1;i<256;i++) palette[i].a = 0; return 0; } int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf) { bmp->CopyPixelData(x, y, Get8BitPixels(DefaultRenderStyle()), Width, Height, Height, 1, rotate, remap, inf); return 0; } //========================================================================== // // // //========================================================================== bool FTexture::UseBasePalette() { return true; } FTexture *FTexture::GetRedirect() { return this; } FTexture *FTexture::GetRawTexture() { return this; } void FTexture::SetScaledSize(int fitwidth, int fitheight) { Scale.X = double(Width) / fitwidth; Scale.Y =double(Height) / fitheight; // compensate for roundoff errors if (int(Scale.X * fitwidth) != Width) Scale.X += (1 / 65536.); if (int(Scale.Y * fitheight) != Height) Scale.Y += (1 / 65536.); } //=========================================================================== // // Gets the average color of a texture for use as a sky cap color // //=========================================================================== PalEntry FTexture::averageColor(const uint32_t *data, int size, int maxout) { int i; unsigned int r, g, b; // First clear them. r = g = b = 0; if (size == 0) { return PalEntry(255, 255, 255); } for (i = 0; i < size; i++) { b += BPART(data[i]); g += GPART(data[i]); r += RPART(data[i]); } r = r / size; g = g / size; b = b / size; int maxv = MAX(MAX(r, g), b); if (maxv && maxout) { r = ::Scale(r, maxout, maxv); g = ::Scale(g, maxout, maxv); b = ::Scale(b, maxout, maxv); } return PalEntry(255, r, g, b); } PalEntry FTexture::GetSkyCapColor(bool bottom) { if (!bSWSkyColorDone) { bSWSkyColorDone = true; FBitmap bitmap; bitmap.Create(GetWidth(), GetHeight()); CopyTrueColorPixels(&bitmap, 0, 0); int w = GetWidth(); int h = GetHeight(); const uint32_t *buffer = (const uint32_t *)bitmap.GetPixels(); if (buffer) { CeilingSkyColor = averageColor((uint32_t *)buffer, w * MIN(30, h), 0); if (h>30) { FloorSkyColor = averageColor(((uint32_t *)buffer) + (h - 30)*w, w * 30, 0); } else FloorSkyColor = CeilingSkyColor; } } return bottom ? FloorSkyColor : CeilingSkyColor; } //==================================================================== // // CheckRealHeight // // Checks the posts in a texture and returns the lowest row (plus one) // of the texture that is actually used. // //==================================================================== int FTexture::CheckRealHeight() { auto pixels = Get8BitPixels(DefaultRenderStyle()); for(int h = GetHeight()-1; h>= 0; h--) { for(int w = 0; w < GetWidth(); w++) { if (pixels[h + w * GetHeight()] != 0) { // Scale maxy before returning it h = int((h * 2) / Scale.Y); h = (h >> 1) + (h & 1); return h; } } } return 0; } //========================================================================== // // Search auto paths for extra material textures // //========================================================================== void FTexture::AddAutoMaterials() { struct AutoTextureSearchPath { const char *path; FTexture *FTexture::*pointer; }; static AutoTextureSearchPath autosearchpaths[] = { { "brightmaps/", &FTexture::Brightmap }, // For backwards compatibility, only for short names { "materials/brightmaps/", &FTexture::Brightmap }, { "materials/normalmaps/", &FTexture::Normal }, { "materials/specular/", &FTexture::Specular }, { "materials/metallic/", &FTexture::Metallic }, { "materials/roughness/", &FTexture::Roughness }, { "materials/ao/", &FTexture::AmbientOcclusion } }; int startindex = bFullNameTexture ? 1 : 0; FString searchname = Name; if (bFullNameTexture) { auto dot = searchname.LastIndexOf('.'); auto slash = searchname.LastIndexOf('/'); if (dot > slash) searchname.Truncate(dot); } for (size_t i = 0; i < countof(autosearchpaths); i++) { auto &layer = autosearchpaths[i]; if (this->*(layer.pointer) == nullptr) // only if no explicit assignment had been done. { FStringf lookup("%s%s%s", layer.path, bFullNameTexture ? "" : "auto/", searchname.GetChars()); auto lump = Wads.CheckNumForFullName(lookup, false, ns_global, true); if (lump != -1) { auto bmtex = TexMan.FindTexture(Wads.GetLumpFullName(lump), ETextureType::Any, FTextureManager::TEXMAN_TryAny); if (bmtex != nullptr) { bmtex->bMasked = false; this->*(layer.pointer) = bmtex; } } } } } //=========================================================================== // // Checks if the texture has a default brightmap and creates it if so // //=========================================================================== void FTexture::CreateDefaultBrightmap() { if (!bBrightmapChecked) { // Check for brightmaps if (UseBasePalette() && TexMan.HasGlobalBrightmap && UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar && Brightmap == NULL && bWarped == 0 && Get8BitPixels(DefaultRenderStyle()) ) { // May have one - let's check when we use this texture const uint8_t *texbuf = Get8BitPixels(DefaultRenderStyle()); const int white = ColorMatcher.Pick(255, 255, 255); int size = GetWidth() * GetHeight(); for (int i = 0; i512) return false; startdraw = -1; lendraw = 0; for (y = 0; y 0) { FloatRect * rcs = new FloatRect[gapc]; for (x = 0; x < gapc; x++) { // gaps are stored as texture (u/v) coordinates rcs[x].width = rcs[x].left = -1.0f; rcs[x].top = (float)gaps[x][0] / (float)h; rcs[x].height = (float)gaps[x][1] / (float)h; } areas = rcs; } else areas = nullptr; areacount = gapc; return true; } //---------------------------------------------------------------------------- // // // //---------------------------------------------------------------------------- void FTexture::CheckTrans(unsigned char * buffer, int size, int trans) { if (bTranslucent == -1) { bTranslucent = trans; if (trans == -1) { uint32_t * dwbuf = (uint32_t*)buffer; for (int i = 0; i> 24; if (alpha != 0xff && alpha != 0) { bTranslucent = 1; return; } } bTranslucent = 0; } } } //=========================================================================== // // smooth the edges of transparent fields in the texture // //=========================================================================== #ifdef WORDS_BIGENDIAN #define MSB 0 #define SOME_MASK 0xffffff00 #else #define MSB 3 #define SOME_MASK 0x00ffffff #endif #define CHKPIX(ofs) (l1[(ofs)*4+MSB]==255 ? (( ((uint32_t*)l1)[0] = ((uint32_t*)l1)[ofs]&SOME_MASK), trans=true ) : false) bool FTexture::SmoothEdges(unsigned char * buffer, int w, int h) { int x, y; bool trans = buffer[MSB] == 0; // If I set this to false here the code won't detect textures // that only contain transparent pixels. bool semitrans = false; unsigned char * l1; if (h <= 1 || w <= 1) return false; // makes (a) no sense and (b) doesn't work with this code! l1 = buffer; if (l1[MSB] == 0 && !CHKPIX(1)) CHKPIX(w); else if (l1[MSB]<255) semitrans = true; l1 += 4; for (x = 1; xbMasked = false; // also clear in the base texture if there is a redirection. } if (bMasked && !ispatch) FindHoles(buffer, w, h); } return true; } //=========================================================================== // // Initializes the buffer for the texture data // //=========================================================================== unsigned char * FTexture::CreateTexBuffer(int translation, int & w, int & h, int flags) { unsigned char * buffer = nullptr; int W, H; int isTransparent = -1; if (flags & CTF_CheckHires) { buffer = LoadHiresTexture(&w, &h); if (buffer != nullptr) return buffer; } int exx = !!(flags & CTF_Expand); W = w = GetWidth() + 2 * exx; H = h = GetHeight() + 2 * exx; buffer = new unsigned char[W*(H + 1) * 4]; memset(buffer, 0, W * (H + 1) * 4); FBitmap bmp(buffer, W * 4, W, H); if (translation <= 0) { int trans = CopyTrueColorPixels(&bmp, exx, exx, 0, nullptr); CheckTrans(buffer, W*H, trans); isTransparent = bTranslucent; } else { // When using translations everything must be mapped to the base palette. // so use CopyTrueColorTranslated CopyTrueColorTranslated(&bmp, exx, exx, 0, FUniquePalette::GetPalette(translation)); isTransparent = 0; // This is not conclusive for setting the texture's transparency info. } if (flags & CTF_ProcessData) { buffer = CreateUpsampledTextureBuffer(buffer, W, H, w, h, !!isTransparent); ProcessData(buffer, w, h, false); } return buffer; } //=========================================================================== // // Dummy texture for the 0-entry. // //=========================================================================== bool FTexture::GetTranslucency() { if (bTranslucent == -1) { if (!bHasCanvas) { int w, h; unsigned char *buffer = CreateTexBuffer(0, w, h); delete[] buffer; } else { bTranslucent = 0; } } return !!bTranslucent; } //=========================================================================== // // Sprite adjust has changed. // This needs to alter the material's sprite rect. // //=========================================================================== void FTexture::SetSpriteAdjust() { for (auto mat : Material) { if (mat != nullptr) mat->SetSpriteRect(); } } //=========================================================================== // // empty stubs to be overloaded by child classes. // //=========================================================================== const uint8_t *FTexture::Get8BitPixels(FRenderStyle style) { return nullptr; } //=========================================================================== // // Dummy texture for the 0-entry. // //=========================================================================== FDummyTexture::FDummyTexture () { Width = 64; Height = 64; UseType = ETextureType::Null; } void FDummyTexture::SetSize (int width, int height) { Width = width; Height = height; } //========================================================================== // // // //========================================================================== FWrapperTexture::FWrapperTexture(int w, int h, int bits) { Width = w; Height = h; Format = bits; UseType = ETextureType::SWCanvas; bNoCompress = true; SystemTexture[0] = screen->CreateHardwareTexture(this); } //=========================================================================== // // Coordinate helper. // The only reason this is even needed is that many years ago someone // was convinced that having per-texel panning on walls was a good idea. // If it wasn't for this relatively useless feature the entire positioning // code for wall textures could be a lot simpler. // //=========================================================================== //=========================================================================== // // // //=========================================================================== float FTexCoordInfo::RowOffset(float rowoffset) const { float tscale = fabs(mTempScale.Y); float scale = fabs(mScale.Y); if (tscale == 1.f) { if (scale == 1.f || mWorldPanning) return rowoffset; else return rowoffset / scale; } else { if (mWorldPanning) return rowoffset / tscale; else return rowoffset / scale; } } //=========================================================================== // // // //=========================================================================== float FTexCoordInfo::TextureOffset(float textureoffset) const { float tscale = fabs(mTempScale.X); float scale = fabs(mScale.X); if (tscale == 1.f) { if (scale == 1.f || mWorldPanning) return textureoffset; else return textureoffset / scale; } else { if (mWorldPanning) return textureoffset / tscale; else return textureoffset / scale; } } //=========================================================================== // // Returns the size for which texture offset coordinates are used. // //=========================================================================== float FTexCoordInfo::TextureAdjustWidth() const { if (mWorldPanning) { float tscale = fabs(mTempScale.X); if (tscale == 1.f) return (float)mRenderWidth; else return mWidth / fabs(tscale); } else return (float)mWidth; } //=========================================================================== // // Retrieve texture coordinate info for per-wall scaling // //=========================================================================== void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y) { if (x == 1.f) { mRenderWidth = tex->GetScaledWidth(); mScale.X = (float)tex->Scale.X; mTempScale.X = 1.f; } else { float scale_x = x * (float)tex->Scale.X; mRenderWidth = xs_CeilToInt(tex->GetWidth() / scale_x); mScale.X = scale_x; mTempScale.X = x; } if (y == 1.f) { mRenderHeight = tex->GetScaledHeight(); mScale.Y = (float)tex->Scale.Y; mTempScale.Y = 1.f; } else { float scale_y = y * (float)tex->Scale.Y; mRenderHeight = xs_CeilToInt(tex->GetHeight() / scale_y); mScale.Y = scale_y; mTempScale.Y = y; } if (tex->bHasCanvas) { mScale.Y = -mScale.Y; mRenderHeight = -mRenderHeight; } mWorldPanning = tex->bWorldPanning; mWidth = tex->GetWidth(); } ///////////// class TextureCache { struct ItemCacheInfo { int palettedCount; // counts use of final paletted textures int palettedCountCompose; // counts use of images needed for composition (can be freed after precaching) int rgbaCount; // counts use of final true color software textures int rawCount; // counts use of raw images needed for composition (can be freed after precaching) int textureCount; // counts use of hardware textures }; TMap> pixelCachePaletted; // 8 bit column major for composition and software rendering TMap> pixelCacheRgba; // 32 bit column major for software true color rendering TMap> pixelCacheRaw; // 32 bit row major for composition TMap hwTextureCache; // native system textures. TMap cacheMarker; void PrecacheLevel(); };