Add function to get true number of mips in GL texture

* If it's immutable, fetch immutable size, otherwise calculate number from
  top level width/height/depth.
* Then clamp by TEXTURE_MAX_LEVEL.
* THEN we need to go through each mip and check that it's been set if the
  texture wasn't immutable, since some mips might be uninitialised and
  that is legal, as long as those mips aren't used (e.g. by point sampling
  or as a FBO attachment).
This commit is contained in:
baldurk
2014-11-30 14:46:22 +00:00
parent fabc319b0b
commit 5e6e243c67
2 changed files with 40 additions and 0 deletions
+38
View File
@@ -332,6 +332,44 @@ GLenum GetDataType(GLenum internalFormat)
return eGL_NONE;
}
int GetNumMips(const GLHookSet &gl, GLenum target, GLuint tex, GLuint w, GLuint h, GLuint d)
{
int mips = 1;
GLint immut = 0;
gl.glGetTextureParameterivEXT(tex, target, eGL_TEXTURE_IMMUTABLE_FORMAT, &immut);
if(immut)
gl.glGetTextureParameterivEXT(tex, target, eGL_TEXTURE_IMMUTABLE_LEVELS, (GLint *)&mips);
else
mips = CalcNumMips(w, h, d);
GLint maxLevel = 1000;
gl.glGetTextureParameterivEXT(tex, target, eGL_TEXTURE_MAX_LEVEL, &maxLevel);
mips = RDCMIN(mips, maxLevel+1);
if(immut == 0)
{
// check to see if all mips are set, or clip the number of mips to those that are
// set.
if(target == eGL_TEXTURE_CUBE_MAP)
target = eGL_TEXTURE_CUBE_MAP_POSITIVE_X;
for(int i=0; i < mips; i++)
{
GLint width = 0;
gl.glGetTextureLevelParameterivEXT(tex, target, i, eGL_TEXTURE_WIDTH, &width);
if(width == 0)
{
mips = i;
break;
}
}
}
return RDCMAX(1, mips);
}
GLenum GetSizedFormat(const GLHookSet &gl, GLenum target, GLenum internalFormat)
{
switch(internalFormat)
+2
View File
@@ -36,6 +36,8 @@ GLenum GetBaseFormat(GLenum internalFormat);
GLenum GetDataType(GLenum internalFormat);
GLenum GetSizedFormat(const GLHookSet &gl, GLenum target, GLenum internalFormat);
int GetNumMips(const GLHookSet &gl, GLenum target, GLuint tex, GLuint w, GLuint h, GLuint d);
bool IsCompressedFormat(GLenum internalFormat);
bool IsDepthStencilFormat(GLenum internalFormat);
bool IsUIntFormat(GLenum internalFormat);