- 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
|
|
@ -50,7 +50,6 @@
|
|||
EXTERN_CVAR(Bool, gl_render_precise)
|
||||
EXTERN_CVAR(Int, gl_lightmode)
|
||||
EXTERN_CVAR(Bool, gl_precache)
|
||||
EXTERN_CVAR(Bool, gl_texture_usehires)
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
|
|
@ -120,91 +119,6 @@ void FGLTexture::CleanUnused(SpriteHits &usedtranslations)
|
|||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Initializes the buffer for the texture data
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
unsigned char * FGLTexture::CreateTexBuffer(int translation, int & w, int & h, FTexture *hirescheck, bool createexpanded, bool alphatrans)
|
||||
{
|
||||
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 && hirescheck != NULL && !alphatrans)
|
||||
{
|
||||
buffer = hirescheck->LoadHiresTexture (&w, &h);
|
||||
if (buffer)
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
int exx = bExpandFlag && createexpanded;
|
||||
|
||||
W = w = tex->GetWidth() + 2 * exx;
|
||||
H = h = tex->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 || alphatrans || 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 = tex->CopyTrueColorPixels(&bmp, exx, exx, 0, translation >= STRange_Min? &inf : nullptr);
|
||||
tex->CheckTrans(buffer, W*H, trans);
|
||||
isTransparent = tex->bTranslucent;
|
||||
// alpha texture for legacy mode
|
||||
if (alphatrans)
|
||||
{
|
||||
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
|
||||
tex->CopyTrueColorTranslated(&bmp, exx, exx, 0, FUniquePalette::GetPalette(translation));
|
||||
isTransparent = 0;
|
||||
// This is not conclusive for setting the texture's transparency info.
|
||||
}
|
||||
|
||||
// if we just want the texture for some checks there's no need for upsampling.
|
||||
if (!createexpanded) return buffer;
|
||||
|
||||
// [BB] The hqnx upsampling (not the scaleN one) destroys partial transparency, don't upsamle textures using it.
|
||||
// [BB] Potentially upsample the buffer.
|
||||
return tex->CreateUpsampledTextureBuffer (buffer, W, H, w, h, !!isTransparent);
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Create hardware texture for world use
|
||||
|
|
@ -230,19 +144,15 @@ FHardwareTexture *FGLTexture::CreateHwTexture()
|
|||
const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int translation, FTexture *hirescheck)
|
||||
{
|
||||
int usebright = false;
|
||||
bool alphatrans = translation == INT_MAX; // This is only needed for legacy mode because no texture combine setting allows using the color as alpha.
|
||||
|
||||
if (!alphatrans)
|
||||
if (translation <= 0)
|
||||
{
|
||||
if (translation <= 0)
|
||||
{
|
||||
translation = -translation;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto remap = TranslationToTable(translation);
|
||||
translation = remap == nullptr ? 0 : remap->GetUniqueIndex();
|
||||
}
|
||||
translation = -translation;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto remap = TranslationToTable(translation);
|
||||
translation = remap == nullptr ? 0 : remap->GetUniqueIndex();
|
||||
}
|
||||
|
||||
bool needmipmap = (clampmode <= CLAMP_XY);
|
||||
|
|
@ -269,7 +179,11 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla
|
|||
|
||||
if (!tex->bHasCanvas)
|
||||
{
|
||||
buffer = CreateTexBuffer(translation, w, h, hirescheck, true, alphatrans);
|
||||
int flags = CTF_ProcessData;
|
||||
if (bExpandFlag) flags |= CTF_Expand;
|
||||
if (hirescheck) flags |= CTF_CheckHires;
|
||||
|
||||
buffer = tex->CreateTexBuffer(translation, w, h, flags);
|
||||
if (tex->bWarped && gl.legacyMode && w*h <= 256*256) // do not software-warp larger textures, especially on the old systems that still need this fallback.
|
||||
{
|
||||
// need to do software warping
|
||||
|
|
@ -280,7 +194,6 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla
|
|||
buffer = warpbuffer;
|
||||
wt->GenTime[0] = screen->FrameTime;
|
||||
}
|
||||
tex->ProcessData(buffer, w, h, false);
|
||||
}
|
||||
if (!hwtex->CreateTexture(buffer, w, h, texunit, needmipmap, translation, "FGLTexture.Bind"))
|
||||
{
|
||||
|
|
@ -584,7 +497,7 @@ bool FMaterial::TrimBorders(uint16_t *rect)
|
|||
int w;
|
||||
int h;
|
||||
|
||||
unsigned char *buffer = CreateTexBuffer(0, w, h, false, false);
|
||||
unsigned char *buffer = tex->CreateTexBuffer(0, w, h);
|
||||
|
||||
if (buffer == NULL)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue