Merge pull request #18 from Bearborg/master

Fix grayscale textures
This commit is contained in:
Jack Andersen 2019-12-27 17:25:29 -10:00 committed by GitHub
commit 1a81737d4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -49,11 +49,11 @@ bool CTexture::BufferGL()
switch (mTexelFormat)
{
case ETexelFormat::Luminance:
GLFormat = GL_LUMINANCE;
GLFormat = GL_R;
GLType = GL_UNSIGNED_BYTE;
break;
case ETexelFormat::LuminanceAlpha:
GLFormat = GL_LUMINANCE_ALPHA;
GLFormat = GL_RG;
GLType = GL_UNSIGNED_BYTE;
break;
case ETexelFormat::RGB565:
@ -104,6 +104,13 @@ bool CTexture::BufferGL()
glTexParameteri(BindTarget, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(BindTarget, GL_TEXTURE_MAX_LEVEL, mNumMipMaps - 1);
// Swizzling for luminance textures:
if (mTexelFormat == ETexelFormat::Luminance || mTexelFormat == ETexelFormat::LuminanceAlpha)
{
GLint SwizzleMask[] = {GL_RED, GL_RED, GL_RED, GLFormat == GL_RG ? GL_GREEN : GL_ONE};
glTexParameteriv(BindTarget, GL_TEXTURE_SWIZZLE_RGBA, SwizzleMask);
}
// Linear filtering on mipmaps:
glTexParameteri(BindTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(BindTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);