From 9a9149ed9e242ce5d0b9248133315d3f94b2516c Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 16 Mar 2006 03:43:35 +0000 Subject: [PATCH] fix assertion --- .../glstuff/glGraphicsStateGuardian_src.cxx | 30 ++++++++++++++++++- .../src/glstuff/glGraphicsStateGuardian_src.h | 1 + panda/src/glstuff/glTextureContext_src.cxx | 4 ++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 5a3891fee2..48ebd5f04e 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -4773,6 +4773,26 @@ get_internal_image_format(Texture *tex) const { } } +//////////////////////////////////////////////////////////////////// +// Function: GLGraphicsStateGuardian::is_mipmap_filter +// Access: Protected, Static +// Description: Returns true if the indicated GL minfilter type +// represents a mipmap format, false otherwise. +//////////////////////////////////////////////////////////////////// +bool CLP(GraphicsStateGuardian):: +is_mipmap_filter(GLenum min_filter) { + switch (min_filter) { + case GL_NEAREST_MIPMAP_NEAREST: + case GL_LINEAR_MIPMAP_NEAREST: + case GL_NEAREST_MIPMAP_LINEAR: + case GL_LINEAR_MIPMAP_LINEAR: + return true; + + default: + return false; + } +} + //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::is_compressed_format // Access: Protected, Static @@ -6653,6 +6673,9 @@ get_texture_memory_size(Texture *tex) const { scale = 6; } + GLint minfilter; + GLP(GetTexParameteriv)(target, GL_TEXTURE_MIN_FILTER, &minfilter); + GLint internal_format; GLP(GetTexLevelParameteriv)(page_target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_format); @@ -6706,7 +6729,12 @@ get_texture_memory_size(Texture *tex) const { size_t num_bits = (red_size + green_size + blue_size + alpha_size + luminance_size + depth_size + intensity_size); size_t num_bytes = (num_bits + 7) / 8; - return num_bytes * width * height * depth * scale; + size_t result = num_bytes * width * height * depth * scale; + if (is_mipmap_filter(minfilter)) { + result = (result * 4) / 3; + } + + return result; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 5a9450de6f..e900ae0db4 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -247,6 +247,7 @@ protected: static GLenum get_component_type(Texture::ComponentType component_type); GLint get_external_image_format(Texture *tex) const; GLint get_internal_image_format(Texture *tex) const; + static bool is_mipmap_filter(GLenum min_filter); static bool is_compressed_format(GLenum format); static GLint get_texture_apply_mode_type(TextureStage::Mode am); static GLint get_texture_combine_type(TextureStage::CombineMode cm); diff --git a/panda/src/glstuff/glTextureContext_src.cxx b/panda/src/glstuff/glTextureContext_src.cxx index aac0929197..70434ff12d 100644 --- a/panda/src/glstuff/glTextureContext_src.cxx +++ b/panda/src/glstuff/glTextureContext_src.cxx @@ -31,6 +31,8 @@ TypeHandle CLP(TextureContext)::_type_handle; //////////////////////////////////////////////////////////////////// size_t CLP(TextureContext):: estimate_texture_memory() { - nassertr(_texture_memory_size != 0, TextureContext::estimate_texture_memory()); + if (_texture_memory_size == 0) { + return TextureContext::estimate_texture_memory(); + } return _texture_memory_size; }