Emulate alpha and intensity formats the same way we do for luminance

This commit is contained in:
baldurk
2014-12-30 23:48:15 +00:00
parent ea5d17989c
commit 29f7234219
4 changed files with 84 additions and 6 deletions
+1 -1
View File
@@ -458,7 +458,7 @@ ResourceFormat MakeResourceFormat(WrappedOpenGL &gl, GLenum target, GLenum fmt)
ret.strname = ToStr::Get(fmt).substr(3); // 3 == strlen("GL_")
// special handling for formats that don't query neatly
if(fmt == eGL_LUMINANCE8_EXT)
if(fmt == eGL_LUMINANCE8_EXT || fmt == eGL_INTENSITY8_EXT || fmt == eGL_ALPHA8_EXT)
{
ret.compByteWidth = 1;
ret.compCount = 1;
+30 -5
View File
@@ -25,10 +25,6 @@
#include "gl_hookset.h"
#include "gl_resources.h"
// no longer in glcorearb.h or glext.h
const GLenum eGL_LUMINANCE = (GLenum)0x1909;
const GLenum eGL_LUMINANCE_ALPHA = (GLenum)0x190A;
size_t GetByteSize(GLsizei w, GLsizei h, GLsizei d, GLenum format, GLenum type)
{
size_t elemSize = 0;
@@ -95,6 +91,7 @@ size_t GetByteSize(GLsizei w, GLsizei h, GLsizei d, GLenum format, GLenum type)
case eGL_BLUE:
case eGL_BLUE_INTEGER:
case eGL_LUMINANCE:
case eGL_ALPHA:
case eGL_DEPTH_COMPONENT:
case eGL_STENCIL_INDEX:
return w*h*d*elemSize;
@@ -134,6 +131,8 @@ GLenum GetBaseFormat(GLenum internalFormat)
case eGL_R16F:
case eGL_R32F:
return eGL_RED;
case eGL_ALPHA8_EXT:
return eGL_ALPHA;
case eGL_R8I:
case eGL_R16I:
case eGL_R32I:
@@ -313,6 +312,8 @@ GLenum GetDataType(GLenum internalFormat)
return eGL_FLOAT_32_UNSIGNED_INT_24_8_REV;
case eGL_STENCIL_INDEX8:
return eGL_UNSIGNED_BYTE;
case eGL_ALPHA8_EXT:
return eGL_UNSIGNED_BYTE;
default:
break;
}
@@ -445,40 +446,64 @@ void EmulateLuminanceFormat(const GLHookSet &gl, GLuint tex, GLenum target, GLen
{
GLenum swizzle[] = { eGL_RED, eGL_GREEN, eGL_BLUE, eGL_ALPHA };
bool dataFormatLum = (dataFormat == eGL_LUMINANCE || dataFormat == eGL_LUMINANCE_ALPHA);
bool dataFormatLum = (dataFormat == eGL_LUMINANCE || dataFormat == eGL_LUMINANCE_ALPHA || dataFormat == eGL_ALPHA || dataFormat == eGL_INTENSITY);
switch((int)internalFormat)
{
case eGL_INTENSITY:
case eGL_INTENSITY8_EXT:
internalFormat = eGL_R8;
if(dataFormatLum) dataFormat = eGL_RED;
swizzle[0] = swizzle[1] = swizzle[2] = swizzle[3] = eGL_RED; // intensity replicates across all 4 of RGBA
break;
case eGL_INTENSITY16_EXT:
internalFormat = eGL_R16;
if(dataFormatLum) dataFormat = eGL_RED;
swizzle[0] = swizzle[1] = swizzle[2] = swizzle[3] = eGL_RED; // intensity replicates across all 4 of RGBA
break;
case eGL_ALPHA:
case eGL_ALPHA8_EXT:
internalFormat = eGL_R8;
if(dataFormatLum) dataFormat = eGL_RED;
swizzle[0] = swizzle[1] = swizzle[2] = eGL_NONE;
swizzle[3] = eGL_RED; // single component alpha channel
break;
case eGL_LUMINANCE:
case eGL_LUMINANCE8_EXT:
internalFormat = eGL_R8;
if(dataFormatLum) dataFormat = eGL_RED;
swizzle[0] = swizzle[1] = swizzle[2] = eGL_RED;
swizzle[3] = (GLenum)1; // alpha explicitly set to 1 in luminance formats
break;
case eGL_SLUMINANCE8_EXT:
internalFormat = eGL_SRGB8;
if(dataFormatLum) dataFormat = eGL_RED;
swizzle[0] = swizzle[1] = swizzle[2] = eGL_RED;
swizzle[3] = (GLenum)1; // alpha explicitly set to 1 in luminance formats
break;
case eGL_LUMINANCE16_EXT:
internalFormat = eGL_R16;
if(dataFormatLum) dataFormat = eGL_RED;
swizzle[0] = swizzle[1] = swizzle[2] = eGL_RED;
swizzle[3] = (GLenum)1; // alpha explicitly set to 1 in luminance formats
break;
case eGL_LUMINANCE32F_ARB:
internalFormat = eGL_R32F;
if(dataFormatLum) dataFormat = eGL_RED;
swizzle[0] = swizzle[1] = swizzle[2] = eGL_RED;
swizzle[3] = (GLenum)1; // alpha explicitly set to 1 in luminance formats
break;
case eGL_LUMINANCE32I_EXT:
internalFormat = eGL_R32I;
if(dataFormatLum) dataFormat = eGL_RED;
swizzle[0] = swizzle[1] = swizzle[2] = eGL_RED;
swizzle[3] = (GLenum)1; // alpha explicitly set to 1 in luminance formats
break;
case eGL_LUMINANCE32UI_EXT:
internalFormat = eGL_R32UI;
if(dataFormatLum) dataFormat = eGL_RED;
swizzle[0] = swizzle[1] = swizzle[2] = eGL_RED;
swizzle[3] = (GLenum)1; // alpha explicitly set to 1 in luminance formats
break;
case eGL_LUMINANCE_ALPHA:
case eGL_LUMINANCE8_ALPHA8_EXT:
+5
View File
@@ -36,6 +36,11 @@ GLenum GetBaseFormat(GLenum internalFormat);
GLenum GetDataType(GLenum internalFormat);
GLenum GetSizedFormat(const GLHookSet &gl, GLenum target, GLenum internalFormat);
// no longer in glcorearb.h or glext.h
const GLenum eGL_LUMINANCE = (GLenum)0x1909;
const GLenum eGL_LUMINANCE_ALPHA = (GLenum)0x190A;
const GLenum eGL_INTENSITY = (GLenum)0x8049;
void EmulateLuminanceFormat(const GLHookSet &gl, GLuint tex, GLenum target, GLenum &internalFormat, GLenum &dataFormat);
int GetNumMips(const GLHookSet &gl, GLenum target, GLuint tex, GLuint w, GLuint h, GLuint d);
@@ -4150,6 +4150,22 @@ bool WrappedOpenGL::Serialise_glTextureSubImage1DEXT(GLuint texture, GLenum targ
{
if(!UnpackBufBound && m_State == READING && m_CurEventID == 0)
m_Real.glBindBuffer(eGL_PIXEL_UNPACK_BUFFER, 0);
if(Format == eGL_LUMINANCE)
{
Format = eGL_RED;
}
else if(Format == eGL_LUMINANCE_ALPHA)
{
Format = eGL_RG;
}
else if(Format == eGL_ALPHA)
{
// check if format was converted from alpha-only format to R8, and substitute
ResourceId liveId = GetResourceManager()->GetLiveID(id);
if(m_Textures[liveId].internalFormat == eGL_R8)
Format = eGL_RED;
}
m_Real.glTextureSubImage1DEXT(GetResourceManager()->GetLiveResource(id).name, Target, Level, xoff, Width, Format, Type, buf ? buf : (const void *)bufoffs);
@@ -4343,6 +4359,22 @@ bool WrappedOpenGL::Serialise_glTextureSubImage2DEXT(GLuint texture, GLenum targ
{
if(!UnpackBufBound && m_State == READING && m_CurEventID == 0)
m_Real.glBindBuffer(eGL_PIXEL_UNPACK_BUFFER, 0);
if(Format == eGL_LUMINANCE)
{
Format = eGL_RED;
}
else if(Format == eGL_LUMINANCE_ALPHA)
{
Format = eGL_RG;
}
else if(Format == eGL_ALPHA)
{
// check if format was converted from alpha-only format to R8, and substitute
ResourceId liveId = GetResourceManager()->GetLiveID(id);
if(m_Textures[liveId].internalFormat == eGL_R8)
Format = eGL_RED;
}
m_Real.glTextureSubImage2DEXT(GetResourceManager()->GetLiveResource(id).name, Target, Level, xoff, yoff, Width, Height, Format, Type, buf ? buf : (const void *)bufoffs);
@@ -4538,6 +4570,22 @@ bool WrappedOpenGL::Serialise_glTextureSubImage3DEXT(GLuint texture, GLenum targ
{
if(!UnpackBufBound && m_State == READING && m_CurEventID == 0)
m_Real.glBindBuffer(eGL_PIXEL_UNPACK_BUFFER, 0);
if(Format == eGL_LUMINANCE)
{
Format = eGL_RED;
}
else if(Format == eGL_LUMINANCE_ALPHA)
{
Format = eGL_RG;
}
else if(Format == eGL_ALPHA)
{
// check if format was converted from alpha-only format to R8, and substitute
ResourceId liveId = GetResourceManager()->GetLiveID(id);
if(m_Textures[liveId].internalFormat == eGL_R8)
Format = eGL_RED;
}
m_Real.glTextureSubImage3DEXT(GetResourceManager()->GetLiveResource(id).name, Target, Level, xoff, yoff, zoff, Width, Height, Depth, Format, Type, buf ? buf : (const void *)bufoffs);