Remove GL_TEXTURE_COMPRESSED_IMAGE_SIZE vendor check

* This is even messier than I thought - I didn't realise, but it in fact
  varied depending on if the image was initialised with glTexStorage or
  glTexImage (or possibly glCompressedTexImage2D).
* Either way, the query is much too unreliable to try and use and work
  around, so instead we'll just use the GetCompressedByteSize function
  and work out the size ourselves.
This commit is contained in:
baldurk
2017-01-17 11:02:38 +00:00
parent bb538a7d76
commit 749434872d
4 changed files with 9 additions and 98 deletions
-62
View File
@@ -115,68 +115,6 @@ void DoVendorChecks(const GLHookSet &gl, GLWindowingData context)
}
}
if(gl.glGetIntegerv && gl.glGenTextures && gl.glBindTexture && gl.glCompressedTexImage2D &&
gl.glGetTexLevelParameteriv && gl.glDeleteTextures)
{
// We need to determine if GL_TEXTURE_COMPRESSED_IMAGE_SIZE for a compressed cubemap face target
// will return the size of the whole cubemap, or just one face. Since we fetch the cubemap
// data face-by-face the distinction is important.
// So we create a 4x4 cubemap with no mips that's DXT1 (BC1) compressed, which is 0.5 bytes per
// pixel.
// So 4*4*0.5 = 8 bytes per face. If the returned size is 8 or 48 we can determine which result
// the
// query returns. It's probably safe to assume it's consistent then for all sizes and formats of
// cubemaps.
// I'm not sure what the correct answer is, intuitively it feels like when you query for the
// size of
// a single face target, it should give you the size of that face. The spec doesn't seem to say
// though
GLuint prevtex = 0; // should almost certainly be 0, but let's be careful anyway.
gl.glGetIntegerv(eGL_TEXTURE_BINDING_CUBE_MAP, (GLint *)&prevtex);
GLuint dummy = 0;
gl.glGenTextures(1, &dummy);
gl.glBindTexture(eGL_TEXTURE_CUBE_MAP, dummy);
byte empty[8] = {};
gl.glCompressedTexImage2D(eGL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, eGL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
4, 4, 0, 8, empty);
gl.glCompressedTexImage2D(eGL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, eGL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
4, 4, 0, 8, empty);
gl.glCompressedTexImage2D(eGL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, eGL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
4, 4, 0, 8, empty);
gl.glCompressedTexImage2D(eGL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, eGL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
4, 4, 0, 8, empty);
gl.glCompressedTexImage2D(eGL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, eGL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
4, 4, 0, 8, empty);
gl.glCompressedTexImage2D(eGL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, eGL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
4, 4, 0, 8, empty);
GLint compSize = 0;
gl.glGetTexLevelParameteriv(eGL_TEXTURE_CUBE_MAP_POSITIVE_X, 0,
eGL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compSize);
if(compSize == 8)
{
VendorCheck[VendorCheck_EXT_compressed_cube_size] = false;
}
else if(compSize == 48)
{
VendorCheck[VendorCheck_EXT_compressed_cube_size] = true;
RDCWARN("Compressed cubemap size returns whole cubemap");
}
else
{
RDCERR("Unexpected compressed size of +X face of BC1 compressed 4x4 cubemap mip 0! %d",
compSize);
}
gl.glDeleteTextures(1, &dummy);
gl.glBindTexture(eGL_TEXTURE_CUBE_MAP, prevtex);
}
if(gl.glGetIntegerv && gl.glGetError)
{
// clear all error flags.
-1
View File
@@ -221,7 +221,6 @@ extern bool ExtensionSupported[GLExt_Count];
enum VendorCheckEnum
{
VendorCheck_AMD_vertex_buffer_query,
VendorCheck_EXT_compressed_cube_size,
VendorCheck_NV_avoid_D32S8_copy,
VendorCheck_EXT_fbo_shared,
VendorCheck_EXT_vao_shared,
+7 -27
View File
@@ -793,16 +793,9 @@ void GLResourceManager::PrepareTextureInitialContents(ResourceId liveid, Resourc
for(int trg = 0; trg < count; trg++)
{
GLint compSize;
gl.glGetTextureLevelParameterivEXT(res.name, targets[trg], i,
eGL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compSize);
size_t size = GetCompressedByteSize(w, h, d, details.internalFormat, i);
size_t size = compSize;
// sometimes cubemaps return the compressed image size for the whole texture, but we
// read it face by face
if(VendorCheck[VendorCheck_EXT_compressed_cube_size] &&
details.curType == eGL_TEXTURE_CUBE_MAP)
if(details.curType == eGL_TEXTURE_CUBE_MAP)
size /= 6;
byte *buf = new byte[size];
@@ -1147,16 +1140,10 @@ bool GLResourceManager::Serialise_InitialState(ResourceId resid, GLResource res)
for(int trg = 0; trg < count; trg++)
{
GLint compSize;
gl.glGetTextureLevelParameterivEXT(tex, targets[trg], i,
eGL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compSize);
size_t size = GetCompressedByteSize(details.width, details.height, details.depth,
details.internalFormat, i);
size_t size = compSize;
// sometimes cubemaps return the compressed image size for the whole texture, but we
// read it
// face by face
if(VendorCheck[VendorCheck_EXT_compressed_cube_size] && t == eGL_TEXTURE_CUBE_MAP)
if(t == eGL_TEXTURE_CUBE_MAP)
size /= 6;
byte *buf = new byte[size];
@@ -1788,16 +1775,9 @@ void GLResourceManager::Apply_InitialState(GLResource live, InitialContentData i
for(int trg = 0; trg < count; trg++)
{
GLint compSize;
gl.glGetTextureLevelParameterivEXT(tex, targets[trg], i,
eGL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compSize);
size_t size = GetCompressedByteSize(w, h, d, details.internalFormat, i);
size_t size = compSize;
// sometimes cubemaps return the compressed image size for the whole texture, but we
// read it face by face
if(VendorCheck[VendorCheck_EXT_compressed_cube_size] &&
details.curType == eGL_TEXTURE_CUBE_MAP)
if(details.curType == eGL_TEXTURE_CUBE_MAP)
size /= 6;
byte *buf = new byte[size];
+2 -8
View File
@@ -936,15 +936,9 @@ void APIENTRY _glCopyImageSubData(GLuint srcName, GLenum srcTarget, GLint srcLev
count = 1;
}
GLint compSize;
internalGL->glGetTextureLevelParameterivEXT(srcName, targets[0], srcLevel,
eGL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compSize);
size_t size = GetCompressedByteSize(srcWidth, srcHeight, srcDepth, fmt, srcLevel);
size_t size = compSize;
// sometimes cubemaps return the compressed image size for the whole texture, but we
// read it face by face
if(VendorCheck[VendorCheck_EXT_compressed_cube_size] && srcTarget == eGL_TEXTURE_CUBE_MAP)
if(srcTarget == eGL_TEXTURE_CUBE_MAP)
size /= 6;
byte *buf = new byte[size];