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); }
UINT GetMipForSubresource(ID3D11Resource *res, int Subresource) { D3D11_RESOURCE_DIMENSION dim; // check for wrapped types first as they will be most common and don't // require a virtual call if(WrappedID3D11Texture1D::IsAlloc(res)) dim = D3D11_RESOURCE_DIMENSION_TEXTURE1D; else if(WrappedID3D11Texture2D::IsAlloc(res)) dim = D3D11_RESOURCE_DIMENSION_TEXTURE2D; else if(WrappedID3D11Texture3D::IsAlloc(res)) dim = D3D11_RESOURCE_DIMENSION_TEXTURE3D; else res->GetType(&dim); ID3D11Texture1D *tex1 = (dim == D3D11_RESOURCE_DIMENSION_TEXTURE1D) ? (ID3D11Texture1D *)res : NULL; ID3D11Texture2D *tex2 = (dim == D3D11_RESOURCE_DIMENSION_TEXTURE2D) ? (ID3D11Texture2D *)res : NULL; ID3D11Texture3D *tex3 = (dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D) ? (ID3D11Texture3D *)res : NULL; RDCASSERT(tex1 || tex2 || tex3); UINT mipLevel = Subresource; if(tex1) { D3D11_TEXTURE1D_DESC desc; tex1->GetDesc(&desc); int mipLevels = desc.MipLevels; if(mipLevels == 0) mipLevels = CalcNumMips(desc.Width, 1, 1); mipLevel %= mipLevels; } else if(tex2) { D3D11_TEXTURE2D_DESC desc; tex2->GetDesc(&desc); int mipLevels = desc.MipLevels; if(mipLevels == 0) mipLevels = CalcNumMips(desc.Width, desc.Height, 1); mipLevel %= mipLevels; } else if(tex3) { D3D11_TEXTURE3D_DESC desc; tex3->GetDesc(&desc); int mipLevels = desc.MipLevels; if(mipLevels == 0) mipLevels = CalcNumMips(desc.Width, desc.Height, desc.Depth); mipLevel %= mipLevels; } return mipLevel; }