mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-28 23:11:58 +00:00
- removed the FGLBitmap class and replaced all uses with the regular FBitmap.
The only reason this ever existed is that the GL renderer used RGBA instead of BGRA but there's no reason why this is even necessary.
This commit is contained in:
parent
9ac7aaf7d5
commit
a1694a79c6
12 changed files with 60 additions and 221 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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<class T>
|
||||
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<count;i++)
|
||||
{
|
||||
if ((a = T::A(pin, tr, tg, tb)) != 0)
|
||||
{
|
||||
pout[0]=T::R(pin);
|
||||
pout[1]=T::G(pin);
|
||||
pout[2]=T::B(pin);
|
||||
pout[3]=a;
|
||||
}
|
||||
pout+=4;
|
||||
pin+=step;
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*CopyFunc)(unsigned char * pout, const unsigned char * pin, int count, int step, uint8_t tr, uint8_t tg, uint8_t tb);
|
||||
|
||||
static CopyFunc copyfuncs[]={
|
||||
iCopyColors<cRGB>,
|
||||
iCopyColors<cRGBT>,
|
||||
iCopyColors<cRGBA>,
|
||||
iCopyColors<cIA>,
|
||||
iCopyColors<cCMYK>,
|
||||
iCopyColors<cBGR>,
|
||||
iCopyColors<cBGRA>,
|
||||
iCopyColors<cI16>,
|
||||
iCopyColors<cRGB555>,
|
||||
iCopyColors<cPalEntry>
|
||||
};
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// 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<srcheight;y++)
|
||||
{
|
||||
copyfuncs[ct](&buffer[y*Pitch], &patch[y*step_y], srcwidth, step_x, (uint8_t)r, (uint8_t)g, (uint8_t)b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Paletted to True Color texture copy function
|
||||
//
|
||||
//===========================================================================
|
||||
void FGLBitmap::CopyPixelData(int originx, int originy, const uint8_t * patch, int srcwidth, int srcheight,
|
||||
int step_x, int step_y, int rotate, PalEntry * palette, FCopyInfo *inf)
|
||||
{
|
||||
PalEntry penew[256];
|
||||
|
||||
int x,y,pos,i;
|
||||
|
||||
if (ClipCopyPixelRect(&ClipRect, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate))
|
||||
{
|
||||
uint8_t *buffer = GetPixels() + 4*originx + Pitch*originy;
|
||||
|
||||
if (translation > 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;y<srcheight;y++)
|
||||
{
|
||||
pos=(y*Pitch);
|
||||
for (x=0;x<srcwidth;x++,pos+=4)
|
||||
{
|
||||
int v=(unsigned char)patch[y*step_y+x*step_x];
|
||||
if (penew[v].a!=0)
|
||||
{
|
||||
buffer[pos] = penew[v].r;
|
||||
buffer[pos+1] = penew[v].g;
|
||||
buffer[pos+2] = penew[v].b;
|
||||
buffer[pos+3] = penew[v].a;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
#ifndef __GL_BITMAP_H
|
||||
#define __GL_BITMAP_H
|
||||
|
||||
#include "textures/bitmap.h"
|
||||
#include "gl/textures/gl_material.h"
|
||||
|
||||
|
||||
class FGLBitmap : public FBitmap
|
||||
{
|
||||
int translation = 0;
|
||||
bool alphatrans = false;
|
||||
public:
|
||||
|
||||
FGLBitmap()
|
||||
{
|
||||
}
|
||||
FGLBitmap(uint8_t *buffer, int pitch, int width, int height)
|
||||
: FBitmap(buffer, pitch, width, height)
|
||||
{
|
||||
}
|
||||
|
||||
void SetTranslationInfo(int _trans, bool _alphatrans = false)
|
||||
{
|
||||
if (_trans != -1337) translation = _trans;
|
||||
alphatrans = _alphatrans;
|
||||
}
|
||||
|
||||
virtual void 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 = NULL,
|
||||
/* for PNG tRNS */ int r=0, int g=0, int b=0);
|
||||
|
||||
virtual void CopyPixelData(int originx, int originy, const uint8_t * patch, int srcwidth, int srcheight,
|
||||
int step_x, int step_y, int rotate, PalEntry * palette, FCopyInfo *inf = NULL);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -207,7 +207,7 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
|||
}
|
||||
}
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, texformat, rw, rh, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, texformat, rw, rh, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
if (deletebuffer) free(buffer);
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "sc_man.h"
|
||||
#include "colormatcher.h"
|
||||
#include "textures/warpbuffer.h"
|
||||
#include "textures/bitmap.h"
|
||||
|
||||
//#include "gl/gl_intern.h"
|
||||
|
||||
|
@ -43,7 +44,6 @@
|
|||
#include "gl/data/gl_data.h"
|
||||
#include "gl/textures/gl_texture.h"
|
||||
#include "gl/textures/gl_translate.h"
|
||||
#include "gl/textures/gl_bitmap.h"
|
||||
#include "gl/textures/gl_material.h"
|
||||
#include "gl/textures/gl_samplers.h"
|
||||
#include "gl/shaders/gl_shader.h"
|
||||
|
@ -120,7 +120,7 @@ unsigned char *FGLTexture::LoadHiresTexture(FTexture *tex, int *width, int *heig
|
|||
unsigned char * buffer=new unsigned char[w*(h+1)*4];
|
||||
memset(buffer, 0, w * (h+1) * 4);
|
||||
|
||||
FGLBitmap bmp(buffer, w*4, w, h);
|
||||
FBitmap bmp(buffer, w*4, w, h);
|
||||
|
||||
int trans = hirestexture->CopyTrueColorPixels(&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.
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<cPalEntry, cBGRA, bCopy>((uint8_t*)penew, (const uint8_t*)palette, 256, 4, inf, 0, 0, 0);
|
||||
palette = penew;
|
||||
if (inf->blend)
|
||||
{
|
||||
iCopyColors<cPalEntry, cBGRA, bCopy>((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,
|
||||
|
|
|
@ -349,6 +349,7 @@ struct FCopyInfo
|
|||
blend_t blendcolor[4];
|
||||
blend_t alpha;
|
||||
blend_t invalpha;
|
||||
PalEntry *palette;
|
||||
};
|
||||
|
||||
struct bOverwrite
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue