00001 // Filename: textureContext.cxx 00002 // Created by: drose (07Oct99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "textureContext.h" 00020 00021 #include "pixelBuffer.h" 00022 #include "texture.h" 00023 00024 TypeHandle TextureContext::_type_handle; 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: TextureContext::estimate_texture_memory 00028 // Access: Public, Virtual 00029 // Description: Estimates the amount of texture memory that will be 00030 // consumed by loading this texture. This is mainly 00031 // useful for debugging and reporting purposes. 00032 // 00033 // Returns a value in bytes. 00034 //////////////////////////////////////////////////////////////////// 00035 size_t TextureContext:: 00036 estimate_texture_memory() { 00037 PixelBuffer *pb = _texture->_pbuffer; 00038 00039 size_t pixels = pb->get_xsize() * pb->get_ysize(); 00040 00041 size_t bpp = 4; 00042 00043 /* 00044 size_t bpp = 1; 00045 switch (pb->get_format()) { 00046 case PixelBuffer::F_rgb332: 00047 case PixelBuffer::F_alpha: 00048 case PixelBuffer::F_red: 00049 case PixelBuffer::F_green: 00050 case PixelBuffer::F_blue: 00051 case PixelBuffer::F_luminance: 00052 case PixelBuffer::F_luminance_alpha: 00053 case PixelBuffer::F_luminance_alphamask: 00054 case PixelBuffer::F_color_index: 00055 case PixelBuffer::F_stencil_index: 00056 case PixelBuffer::F_depth_component: 00057 bpp = 1; 00058 break; 00059 00060 case PixelBuffer::F_rgba: 00061 case PixelBuffer::F_rgba4: 00062 case PixelBuffer::F_rgbm: 00063 case PixelBuffer::F_rgb: 00064 case PixelBuffer::F_rgb5: 00065 case PixelBuffer::F_rgba5: 00066 bpp = 2; 00067 break; 00068 00069 case PixelBuffer::F_rgb8: 00070 case PixelBuffer::F_rgba8: 00071 bpp = 4; 00072 break; 00073 00074 case PixelBuffer::F_rgba12: 00075 case PixelBuffer::F_rgb12: 00076 bpp = 6; 00077 break; 00078 } 00079 */ 00080 00081 size_t bytes = pixels * bpp; 00082 00083 bool use_mipmaps; 00084 switch (_texture->get_minfilter()) { 00085 case Texture::FT_nearest_mipmap_nearest: 00086 case Texture::FT_linear_mipmap_nearest: 00087 case Texture::FT_nearest_mipmap_linear: 00088 case Texture::FT_linear_mipmap_linear: 00089 use_mipmaps = true; 00090 break; 00091 00092 default: 00093 use_mipmaps = false; 00094 break; 00095 } 00096 00097 if (use_mipmaps) { 00098 bytes += bytes / 3; 00099 } 00100 00101 return bytes; 00102 }