diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 10fe6e84d..c862d27e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1008,7 +1008,6 @@ set (PCH_SOURCES gl/textures/gl_texture.cpp gl/textures/gl_material.cpp gl/textures/gl_hirestex.cpp - gl/textures/gl_bitmap.cpp gl/textures/gl_samplers.cpp gl/textures/gl_translate.cpp gl/textures/gl_hqresize.cpp diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index b57e3f4f4..9b0073c12 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -72,7 +72,6 @@ #include "gl/scene/gl_scenedrawer.h" #include "gl/scene/gl_portal.h" #include "gl/shaders/gl_shader.h" -#include "gl/textures/gl_bitmap.h" #include "gl/textures/gl_texture.h" #include "gl/textures/gl_material.h" diff --git a/src/gl/textures/gl_bitmap.cpp b/src/gl/textures/gl_bitmap.cpp deleted file mode 100644 index f6909c952..000000000 --- a/src/gl/textures/gl_bitmap.cpp +++ /dev/null @@ -1,150 +0,0 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2004-2016 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// -/* -** gl_bitmap.cpp -** Bitmap class for texture composition -** -*/ - - -#include "v_palette.h" -#include "templates.h" -#include "gl/textures/gl_translate.h" -#include "gl/textures/gl_bitmap.h" -#include "gl/system/gl_interface.h" - -//=========================================================================== -// -// multi-format pixel copy with colormap application -// requires one of the previously defined conversion classes to work -// -//=========================================================================== -template -void iCopyColors(unsigned char * pout, const unsigned char * pin, int count, int step, uint8_t tr, uint8_t tg, uint8_t tb) -{ - int i; - unsigned char a; - - for(i=0;i, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors, - iCopyColors -}; - -//=========================================================================== -// -// True Color texture copy function -// This excludes all the cases that force downconversion to the -// base palette because they wouldn't be used anyway. -// -//=========================================================================== -void FGLBitmap::CopyPixelDataRGB(int originx, int originy, - const uint8_t * patch, int srcwidth, int srcheight, int step_x, int step_y, - int rotate, int ct, FCopyInfo *inf, int r, int g, int b) -{ - if (ClipCopyPixelRect(&ClipRect, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate)) - { - uint8_t *buffer = GetPixels() + 4*originx + Pitch*originy; - for (int y=0;y 0) - { - PalEntry *ptrans = GLTranslationPalette::GetPalette(translation); - if (ptrans && !alphatrans) - { - for (i = 0; i < 256; i++) - { - penew[i] = (ptrans[i] & 0xffffff) | (palette[i] & 0xff000000); - } - } - else if (ptrans) - { - memcpy(penew, ptrans, 256 * sizeof(PalEntry)); - } - } - else - { - memcpy(penew, palette, 256*sizeof(PalEntry)); - } - - // convert the image according to the translated palette. - for (y=0;yCopyTrueColorPixels(&bmp, 0, 0); hirestexture->CheckTrans(buffer, w*h, trans); @@ -210,38 +210,58 @@ unsigned char * FGLTexture::CreateTexBuffer(int translation, int & w, int & h, F buffer=new unsigned char[W*(H+1)*4]; memset(buffer, 0, W * (H+1) * 4); - FGLBitmap bmp(buffer, W*4, W, H); - bmp.SetTranslationInfo(translation, alphatrans); + FBitmap bmp(buffer, W*4, W, H); - if (tex->bComplex) + if (translation <= 0) { - FBitmap imgCreate; - - // The texture contains special processing so it must be composited using the - // base bitmap class and then be converted as a whole. - if (imgCreate.Create(W, H)) + // Q: Is this special treatment still needed? Needs to be checked. + if (tex->bComplex) { - memset(imgCreate.GetPixels(), 0, W * H * 4); - int trans = tex->CopyTrueColorPixels(&imgCreate, exx, exx); - bmp.CopyPixelDataRGB(0, 0, imgCreate.GetPixels(), W, H, 4, W * 4, 0, CF_BGRA); + FBitmap imgCreate; + + // The texture contains special processing so it must be fully composited before being converted as a whole. + if (imgCreate.Create(W, H)) + { + memset(imgCreate.GetPixels(), 0, W * H * 4); + int trans = tex->CopyTrueColorPixels(&imgCreate, exx, exx); + bmp.CopyPixelDataRGB(0, 0, imgCreate.GetPixels(), W, H, 4, W * 4, 0, CF_BGRA); + tex->CheckTrans(buffer, W*H, trans); + isTransparent = tex->gl_info.mIsTransparent; + if (bIsTransparent == -1) bIsTransparent = isTransparent; + } + } + else + { + int trans = tex->CopyTrueColorPixels(&bmp, exx, exx); tex->CheckTrans(buffer, W*H, trans); isTransparent = tex->gl_info.mIsTransparent; if (bIsTransparent == -1) bIsTransparent = isTransparent; } } - else if (translation<=0) - { - int trans = tex->CopyTrueColorPixels(&bmp, exx, exx); - tex->CheckTrans(buffer, W*H, trans); - isTransparent = tex->gl_info.mIsTransparent; - if (bIsTransparent == -1) bIsTransparent = isTransparent; - } else { // When using translations everything must be mapped to the base palette. - // Since FTexture's method is doing exactly that by calling GetPixels let's use that here - // to do all the dirty work for us. ;) - tex->FTexture::CopyTrueColorPixels(&bmp, exx, exx); + // so use CopyTrueColorTranslated + PalEntry penew[256]; + PalEntry *pal; + + // Todo: Give all palettes proper alpha and make sure the software renderer can handle it. + PalEntry *ptrans = GLTranslationPalette::GetPalette(translation); + if (ptrans && !alphatrans) + { + for (int i = 1; i < 256; i++) + { + penew[i] = (ptrans[i] | 0xff000000); + } + penew[0] = 0; + pal = penew; + } + else if (ptrans) + { + pal = ptrans; + } + + tex->CopyTrueColorTranslated(&bmp, exx, exx, 0, pal); isTransparent = 0; // This is not conclusive for setting the texture's transparency info. } diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index b671edbf7..af1a6178f 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -538,7 +538,7 @@ void FBrightmapTexture::Unload () int FBrightmapTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) { - SourcePic->CopyTrueColorTranslated(bmp, x, y, rotate, &GlobalBrightmap); + SourcePic->CopyTrueColorTranslated(bmp, x, y, rotate, GlobalBrightmap.Palette); return 0; } diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp index 18fb5446b..cdeb645e3 100644 --- a/src/textures/bitmap.cpp +++ b/src/textures/bitmap.cpp @@ -444,10 +444,17 @@ void FBitmap::CopyPixelData(int originx, int originy, const uint8_t * patch, int PalEntry penew[256]; memset(penew, 0, sizeof(penew)); - if (inf && inf->blend) + if (inf) { - iCopyColors((uint8_t*)penew, (const uint8_t*)palette, 256, 4, inf, 0, 0, 0); - palette = penew; + if (inf->blend) + { + iCopyColors((uint8_t*)penew, (const uint8_t*)palette, 256, 4, inf, 0, 0, 0); + palette = penew; + } + else if (inf->palette) + { + palette = inf->palette; + } } copypalettedfuncs[inf==NULL? OP_COPY : inf->op](buffer, patch, srcwidth, srcheight, Pitch, diff --git a/src/textures/bitmap.h b/src/textures/bitmap.h index 9a6dcd853..0811eaa70 100644 --- a/src/textures/bitmap.h +++ b/src/textures/bitmap.h @@ -349,6 +349,7 @@ struct FCopyInfo blend_t blendcolor[4]; blend_t alpha; blend_t invalpha; + PalEntry *palette; }; struct bOverwrite diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index 63b86d7a9..a765d2d41 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -620,7 +620,7 @@ int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rota if (Parts[i].Translation != NULL) { // Using a translation forces downconversion to the base palette - ret = Parts[i].Texture->CopyTrueColorTranslated(bmp, x+Parts[i].OriginX, y+Parts[i].OriginY, Parts[i].Rotate, Parts[i].Translation, &info); + ret = Parts[i].Texture->CopyTrueColorTranslated(bmp, x+Parts[i].OriginX, y+Parts[i].OriginY, Parts[i].Rotate, Parts[i].Translation->Palette, &info); } else { diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 162d0ca43..b446c43c6 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -811,10 +811,9 @@ int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyI return 0; } -int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, FRemapTable *remap, FCopyInfo *inf) +int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf) { - PalEntry *palette = remap->Palette; - bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, palette, inf); + bmp->CopyPixelData(x, y, GetPixels(), Width, Height, Height, 1, rotate, remap, inf); return 0; } diff --git a/src/textures/textures.h b/src/textures/textures.h index 1c5a1ddf8..96bd8d3ca 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -242,7 +242,7 @@ public: virtual bool Mipmapped() { return true; } virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL); - int CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, FRemapTable *remap, FCopyInfo *inf = NULL); + int CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf = NULL); virtual bool UseBasePalette(); virtual int GetSourceLump() { return SourceLump; } virtual FTexture *GetRedirect(bool wantwarped);