mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-28 23:12:24 +00:00
- fixed alpha texture generation for OpenGL rendering.
The old logic used a translation table that does not work with color images, it was designed to handle 8 bit grayscale images. So now, it creates a true color buffer and then turns it into a texture with R,G,B = 255 and the alpha channel set to the grayscale value. This was also the reason why crosshairs made from 32 bit PNGs did not show correctly.
This commit is contained in:
parent
5466e2c7c5
commit
0a07f4c144
3 changed files with 27 additions and 27 deletions
|
@ -145,7 +145,7 @@ public:
|
|||
void SetMaterial(FMaterial *mat, int clampmode, int translation, int overrideshader, bool alphatexture)
|
||||
{
|
||||
// alpha textures need special treatment in the legacy renderer because withouz shaders they need a different texture.
|
||||
if (alphatexture && gl.legacyMode) translation = TRANSLATION(TRANSLATION_Standard, 8);
|
||||
if (alphatexture && gl.legacyMode) translation = INT_MAX;
|
||||
|
||||
if (mat->tex->bHasCanvas)
|
||||
{
|
||||
|
|
|
@ -213,31 +213,27 @@ unsigned char * FGLTexture::CreateTexBuffer(int translation, int & w, int & h, F
|
|||
|
||||
FBitmap bmp(buffer, W*4, W, H);
|
||||
|
||||
if (translation <= 0)
|
||||
if (translation <= 0 || alphatrans)
|
||||
{
|
||||
// Q: Is this special treatment still needed? Needs to be checked.
|
||||
if (tex->bComplex)
|
||||
int trans = tex->CopyTrueColorPixels(&bmp, exx, exx);
|
||||
tex->CheckTrans(buffer, W*H, trans);
|
||||
isTransparent = tex->gl_info.mIsTransparent;
|
||||
if (bIsTransparent == -1) bIsTransparent = isTransparent;
|
||||
// alpha texture for legacy mode
|
||||
if (alphatrans)
|
||||
{
|
||||
FBitmap imgCreate;
|
||||
|
||||
// The texture contains special processing so it must be fully composited before being converted as a whole.
|
||||
if (imgCreate.Create(W, H))
|
||||
for (int i = 0; i < W*H; i++)
|
||||
{
|
||||
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;
|
||||
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
|
||||
{
|
||||
int trans = tex->CopyTrueColorPixels(&bmp, exx, exx);
|
||||
tex->CheckTrans(buffer, W*H, trans);
|
||||
isTransparent = tex->gl_info.mIsTransparent;
|
||||
if (bIsTransparent == -1) bIsTransparent = isTransparent;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -282,13 +278,18 @@ FHardwareTexture *FGLTexture::CreateHwTexture()
|
|||
const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int translation, FTexture *hirescheck)
|
||||
{
|
||||
int usebright = false;
|
||||
bool alphatrans = 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 (translation <= 0) translation = -translation;
|
||||
else
|
||||
if (!alphatrans)
|
||||
{
|
||||
alphatrans = (gl.legacyMode && uint32_t(translation) == TRANSLATION(TRANSLATION_Standard, 8));
|
||||
translation = GLTranslationPalette::GetInternalTranslation(translation);
|
||||
if (translation <= 0)
|
||||
{
|
||||
translation = -translation;
|
||||
}
|
||||
else
|
||||
{
|
||||
translation = GLTranslationPalette::GetInternalTranslation(translation);
|
||||
}
|
||||
}
|
||||
|
||||
bool needmipmap = (clampmode <= CLAMP_XY);
|
||||
|
|
|
@ -126,7 +126,6 @@ FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum)
|
|||
if (hdr.version != 0 && hdr.version != 2 && hdr.version != 3 && hdr.version != 4 && hdr.version != 5) return NULL;
|
||||
if (hdr.bitsPerPixel != 1 && hdr.bitsPerPixel != 8 && hdr.bitsPerPixel != 4) return NULL;
|
||||
if (hdr.bitsPerPixel == 1 && hdr.numColorPlanes !=1 && hdr.numColorPlanes != 4) return NULL;
|
||||
if (hdr.bitsPerPixel == 4 && hdr.numColorPlanes != 1) return NULL;
|
||||
if (hdr.bitsPerPixel == 8 && hdr.bytesPerScanLine != ((hdr.xmax - hdr.xmin + 2)&~1)) return NULL;
|
||||
|
||||
for (int i = 0; i < 54; i++)
|
||||
|
|
Loading…
Reference in a new issue