From 5e6e243c6712eedaff3b8b6c06b3bce0201a6ed1 Mon Sep 17 00:00:00 2001 From: baldurk Date: Sun, 30 Nov 2014 14:46:22 +0000 Subject: [PATCH] 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). --- renderdoc/driver/gl/gl_resources.cpp | 38 ++++++++++++++++++++++++++++ renderdoc/driver/gl/gl_resources.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/renderdoc/driver/gl/gl_resources.cpp b/renderdoc/driver/gl/gl_resources.cpp index aa125aae8..15da907b8 100644 --- a/renderdoc/driver/gl/gl_resources.cpp +++ b/renderdoc/driver/gl/gl_resources.cpp @@ -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) diff --git a/renderdoc/driver/gl/gl_resources.h b/renderdoc/driver/gl/gl_resources.h index 2de334324..d4cc06bab 100644 --- a/renderdoc/driver/gl/gl_resources.h +++ b/renderdoc/driver/gl/gl_resources.h @@ -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);