- moved CreateTexBuffer out of the GL code.
This is merely a buffer creation function with no dependencies on the renderer.
This commit is contained in:
parent
711a88bab3
commit
8b79eedfea
12 changed files with 154 additions and 160 deletions
|
|
@ -59,6 +59,7 @@ CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|||
TexMan.SpriteAdjustChanged();
|
||||
}
|
||||
|
||||
EXTERN_CVAR(Bool, gl_texture_usehires)
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
|
@ -1341,6 +1342,116 @@ bool FTexture::ProcessData(unsigned char * buffer, int w, int h, bool ispatch)
|
|||
return true;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Initializes the buffer for the texture data
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
unsigned char * FTexture::CreateTexBuffer(int translation, int & w, int & h, int flags)
|
||||
{
|
||||
unsigned char * buffer;
|
||||
int W, H;
|
||||
int isTransparent = -1;
|
||||
|
||||
|
||||
// Textures that are already scaled in the texture lump will not get replaced
|
||||
// by hires textures
|
||||
if (gl_texture_usehires && (flags & CTF_CheckHires) && translation != STRange_AlphaTexture)
|
||||
{
|
||||
buffer = LoadHiresTexture(&w, &h);
|
||||
if (buffer)
|
||||
{
|
||||
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 || translation >= STRange_Min)
|
||||
{
|
||||
// Allow creation of desaturated or special-colormapped textures for the legacy renderer.
|
||||
FCopyInfo inf = { OP_COPY, BLEND_NONE,{ 0 }, 0, 0 };
|
||||
if (translation >= STRange_Desaturate && translation < STRange_Desaturate + 31) // there are 31 ranges of desaturations available
|
||||
{
|
||||
inf.blend = (EBlend)(BLEND_DESATURATE1 + translation - STRange_Desaturate);
|
||||
}
|
||||
else if (translation >= STRange_Specialcolormap && translation < STRange_Specialcolormap + SpecialColormaps.Size())
|
||||
{
|
||||
inf.blend = (EBlend)(BLEND_SPECIALCOLORMAP1 + translation - STRange_Specialcolormap);
|
||||
}
|
||||
|
||||
int trans = CopyTrueColorPixels(&bmp, exx, exx, 0, translation >= STRange_Min ? &inf : nullptr);
|
||||
CheckTrans(buffer, W*H, trans);
|
||||
isTransparent = bTranslucent;
|
||||
// alpha texture for legacy mode
|
||||
if (translation == STRange_AlphaTexture)
|
||||
{
|
||||
for (int i = 0; i < W*H; i++)
|
||||
{
|
||||
int b = buffer[4 * i];
|
||||
int g = buffer[4 * i + 1];
|
||||
int r = buffer[4 * i + 2];
|
||||
int gray = Luminance(r, g, b);
|
||||
buffer[4 * i] = 255;
|
||||
buffer[4 * i + 1] = 255;
|
||||
buffer[4 * i + 2] = 255;
|
||||
buffer[4 * i + 3] = (buffer[4 * i + 3] * gray) >> 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
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.
|
||||
}
|
||||
|
||||
// [BB] The hqnx upsampling (not the scaleN one) destroys partial transparency, don't upsamle textures using it.
|
||||
// [BB] Potentially upsample the buffer.
|
||||
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;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Dummy texture for the 0-entry.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue