- changed alpha texture handling to avoid using the deprecated GL_ALPHA8 texture format unless we have a compatibility context of an older GL version.

This commit is contained in:
Christoph Oelckers 2014-06-21 12:52:19 +02:00
parent ca76c2525e
commit d5dceb6874
4 changed files with 50 additions and 9 deletions

View file

@ -153,7 +153,6 @@ void gl_LoadExtensions()
{
gl.flags|=RFL_FRAMEBUFFER;
}
}
//==========================================================================

View file

@ -41,6 +41,11 @@ struct RenderContext
{
return glslversion >= 1.3f;
}
bool hasCompatibility() // will return false, once transition to a core profile is possible and a core profile is used.
{
return true;
}
};
extern RenderContext gl;

View file

@ -42,6 +42,7 @@
#include "gl/renderer/gl_lightdata.h"
#include "gl/textures/gl_translate.h"
#include "gl/textures/gl_bitmap.h"
#include "gl/system/gl_interface.h"
//===========================================================================
//
@ -54,7 +55,7 @@ void iCopyColors(unsigned char * pout, const unsigned char * pin, bool alphatex,
{
int i;
if (!alphatex)
if (!alphatex || gl.version >= 3.3f) // GL 3.3+ uses a GL_R8 texture for alpha textures so the channels can remain as they are.
{
for(i=0;i<count;i++)
{
@ -139,12 +140,25 @@ void FGLBitmap::CopyPixelData(int originx, int originy, const BYTE * patch, int
// alpha map with 0==transparent and 1==opaque
if (alphatex)
{
for(int i=0;i<256;i++)
if (gl.version < 3.3f)
{
if (palette[i].a != 0)
penew[i]=PalEntry(i, 255,255,255);
else
penew[i]=PalEntry(0,255,255,255); // If the palette contains transparent colors keep them.
for (int i = 0; i<256; i++)
{
if (palette[i].a != 0)
penew[i] = PalEntry(i, 255, 255, 255);
else
penew[i] = PalEntry(0, 255, 255, 255); // If the palette contains transparent colors keep them.
}
}
else // on GL 3.3+ we use a GL_R8 texture so the layout is different.
{
for (int i = 0; i<256; i++)
{
if (palette[i].a != 0)
penew[i] = PalEntry(255, i, 255, 255);
else
penew[i] = PalEntry(255, 0, 255, 255); // If the palette contains transparent colors keep them.
}
}
}
else if (translation > 0)

View file

@ -190,8 +190,26 @@ void FHardwareTexture::LoadImage(unsigned char * buffer,int w, int h, unsigned i
bool deletebuffer=false;
bool use_mipmapping = TexFilter[gl_texture_filter].mipmapping;
if (alphatexture) texformat=GL_ALPHA8;
else if (forcenocompression) texformat = GL_RGBA8;
if (alphatexture)
{
// thanks to deprecation and delayed introduction of a suitable replacement feature this has become a bit messy...
if (gl.version >= 3.3f)
{
texformat = GL_R8;
}
else if (gl.version <= 3.0f || gl.hasCompatibility())
{
texformat = GL_ALPHA8;
}
else
{
texformat = GL_RGBA8;
}
}
else if (forcenocompression)
{
texformat = GL_RGBA8;
}
if (glTexID==0) glGenTextures(1,&glTexID);
glBindTexture(GL_TEXTURE_2D, glTexID);
lastbound[texunit]=glTexID;
@ -238,6 +256,11 @@ void FHardwareTexture::LoadImage(unsigned char * buffer,int w, int h, unsigned i
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapparam==GL_CLAMP? GL_CLAMP_TO_EDGE : GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapparam==GL_CLAMP? GL_CLAMP_TO_EDGE : GL_REPEAT);
if (alphatexture && gl.version >= 3.3f)
{
static const GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_RED};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
clampmode = wrapparam==GL_CLAMP? GLT_CLAMPX|GLT_CLAMPY : 0;
if (forcenofiltering)