| [5328] | 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| [1529] | 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| [51] | 13 | |
|---|
| [2] | 14 | #ifndef OSG_TEXTURE |
|---|
| 15 | #define OSG_TEXTURE 1 |
|---|
| 16 | |
|---|
| [1099] | 17 | #include <osg/GL> |
|---|
| 18 | #include <osg/Image> |
|---|
| 19 | #include <osg/StateAttribute> |
|---|
| [4485] | 20 | #include <osg/GraphicsContext> |
|---|
| [1099] | 21 | #include <osg/ref_ptr> |
|---|
| 22 | #include <osg/Vec4> |
|---|
| [7385] | 23 | #include <osg/Vec4d> |
|---|
| [1143] | 24 | #include <osg/buffered_value> |
|---|
| [1078] | 25 | |
|---|
| [2022] | 26 | #include <list> |
|---|
| 27 | #include <map> |
|---|
| [1099] | 28 | |
|---|
| [3407] | 29 | // If not defined by gl.h use the definition found in: |
|---|
| [1099] | 30 | // http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_filter_anisotropic.txt |
|---|
| 31 | #ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT |
|---|
| [7372] | 32 | #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE |
|---|
| [1099] | 33 | #endif |
|---|
| 34 | |
|---|
| 35 | #ifndef GL_ARB_texture_compression |
|---|
| [7372] | 36 | #define GL_COMPRESSED_ALPHA_ARB 0x84E9 |
|---|
| 37 | #define GL_COMPRESSED_LUMINANCE_ARB 0x84EA |
|---|
| 38 | #define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB |
|---|
| 39 | #define GL_COMPRESSED_INTENSITY_ARB 0x84EC |
|---|
| 40 | #define GL_COMPRESSED_RGB_ARB 0x84ED |
|---|
| 41 | #define GL_COMPRESSED_RGBA_ARB 0x84EE |
|---|
| 42 | #define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF |
|---|
| 43 | #define GL_TEXTURE_COMPRESSED_ARB 0x86A1 |
|---|
| 44 | #define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2 |
|---|
| 45 | #define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3 |
|---|
| [1099] | 46 | #endif |
|---|
| 47 | |
|---|
| [1974] | 48 | #ifndef GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB |
|---|
| [7372] | 49 | #define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0 |
|---|
| [1974] | 50 | #endif |
|---|
| 51 | |
|---|
| [1099] | 52 | #ifndef GL_EXT_texture_compression_s3tc |
|---|
| [7372] | 53 | #define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 |
|---|
| 54 | #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 |
|---|
| 55 | #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 |
|---|
| 56 | #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 |
|---|
| [1099] | 57 | #endif |
|---|
| 58 | |
|---|
| [3850] | 59 | #ifndef GL_ARB_INTERNAL_TEXTURE_FORMAT |
|---|
| [7372] | 60 | #define GL_RGBA32F_ARB 0x8814 |
|---|
| 61 | #define GL_RGB32F_ARB 0x8815 |
|---|
| 62 | #define GL_ALPHA32F_ARB 0x8816 |
|---|
| 63 | #define GL_INTENSITY32F_ARB 0x8817 |
|---|
| 64 | #define GL_LUMINANCE32F_ARB 0x8818 |
|---|
| 65 | #define GL_LUMINANCE_ALPHA32F_ARB 0x8819 |
|---|
| 66 | #define GL_RGBA16F_ARB 0x881A |
|---|
| 67 | #define GL_RGB16F_ARB 0x881B |
|---|
| 68 | #define GL_ALPHA16F_ARB 0x881C |
|---|
| 69 | #define GL_INTENSITY16F_ARB 0x881D |
|---|
| 70 | #define GL_LUMINANCE16F_ARB 0x881E |
|---|
| 71 | #define GL_LUMINANCE_ALPHA16F_ARB 0x881F |
|---|
| [3850] | 72 | #endif |
|---|
| 73 | |
|---|
| 74 | #ifndef GL_ARB_PIXEL_DATA |
|---|
| [7372] | 75 | #define GL_HALF_FLOAT_ARB 0x140B |
|---|
| [3850] | 76 | #endif |
|---|
| 77 | |
|---|
| [2813] | 78 | #ifndef GL_NV_texture_shader |
|---|
| [7372] | 79 | #define GL_HILO_NV 0x86F4 |
|---|
| 80 | #define GL_DSDT_NV 0x86F5 |
|---|
| 81 | #define GL_DSDT_MAG_NV 0x86F6 |
|---|
| 82 | #define GL_DSDT_MAG_VIB_NV 0x86F7 |
|---|
| 83 | #define GL_HILO16_NV 0x86F8 |
|---|
| 84 | #define GL_SIGNED_HILO_NV 0x86F9 |
|---|
| 85 | #define GL_SIGNED_HILO16_NV 0x86FA |
|---|
| 86 | #define GL_SIGNED_RGBA_NV 0x86FB |
|---|
| 87 | #define GL_SIGNED_RGBA8_NV 0x86FC |
|---|
| 88 | #define GL_SIGNED_RGB_NV 0x86FE |
|---|
| 89 | #define GL_SIGNED_RGB8_NV 0x86FF |
|---|
| 90 | #define GL_SIGNED_LUMINANCE_NV 0x8701 |
|---|
| 91 | #define GL_SIGNED_LUMINANCE8_NV 0x8702 |
|---|
| 92 | #define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703 |
|---|
| 93 | #define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704 |
|---|
| 94 | #define GL_SIGNED_ALPHA_NV 0x8705 |
|---|
| 95 | #define GL_SIGNED_ALPHA8_NV 0x8706 |
|---|
| 96 | #define GL_SIGNED_INTENSITY_NV 0x8707 |
|---|
| 97 | #define GL_SIGNED_INTENSITY8_NV 0x8708 |
|---|
| 98 | #define GL_DSDT8_NV 0x8709 |
|---|
| 99 | #define GL_DSDT8_MAG8_NV 0x870A |
|---|
| 100 | #define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B |
|---|
| 101 | #define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C |
|---|
| 102 | #define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D |
|---|
| [2813] | 103 | #endif |
|---|
| 104 | |
|---|
| [3357] | 105 | #ifndef GL_NV_float_buffer |
|---|
| [7372] | 106 | #define GL_FLOAT_R_NV 0x8880 |
|---|
| 107 | #define GL_FLOAT_RG_NV 0x8881 |
|---|
| 108 | #define GL_FLOAT_RGB_NV 0x8882 |
|---|
| 109 | #define GL_FLOAT_RGBA_NV 0x8883 |
|---|
| 110 | #define GL_FLOAT_R16_NV 0x8884 |
|---|
| 111 | #define GL_FLOAT_R32_NV 0x8885 |
|---|
| 112 | #define GL_FLOAT_RG16_NV 0x8886 |
|---|
| 113 | #define GL_FLOAT_RG32_NV 0x8887 |
|---|
| 114 | #define GL_FLOAT_RGB16_NV 0x8888 |
|---|
| 115 | #define GL_FLOAT_RGB32_NV 0x8889 |
|---|
| 116 | #define GL_FLOAT_RGBA16_NV 0x888A |
|---|
| 117 | #define GL_FLOAT_RGBA32_NV 0x888B |
|---|
| [3357] | 118 | #endif |
|---|
| 119 | |
|---|
| 120 | #ifndef GL_NV_half_float |
|---|
| [7372] | 121 | #define GL_HALF_FLOAT_NV 0x140B |
|---|
| [3357] | 122 | #endif |
|---|
| 123 | |
|---|
| 124 | #ifndef GL_ATI_texture_float |
|---|
| [7372] | 125 | #define GL_RGBA_FLOAT32_ATI 0x8814 |
|---|
| 126 | #define GL_RGB_FLOAT32_ATI 0x8815 |
|---|
| 127 | #define GL_ALPHA_FLOAT32_ATI 0x8816 |
|---|
| 128 | #define GL_INTENSITY_FLOAT32_ATI 0x8817 |
|---|
| 129 | #define GL_LUMINANCE_FLOAT32_ATI 0x8818 |
|---|
| 130 | #define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819 |
|---|
| 131 | #define GL_RGBA_FLOAT16_ATI 0x881A |
|---|
| 132 | #define GL_RGB_FLOAT16_ATI 0x881B |
|---|
| 133 | #define GL_ALPHA_FLOAT16_ATI 0x881C |
|---|
| 134 | #define GL_INTENSITY_FLOAT16_ATI 0x881D |
|---|
| 135 | #define GL_LUMINANCE_FLOAT16_ATI 0x881E |
|---|
| 136 | #define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F |
|---|
| [3357] | 137 | #endif |
|---|
| 138 | |
|---|
| [1099] | 139 | #ifndef GL_MIRRORED_REPEAT_IBM |
|---|
| [7372] | 140 | #define GL_MIRRORED_REPEAT_IBM 0x8370 |
|---|
| [1099] | 141 | #endif |
|---|
| 142 | |
|---|
| 143 | #ifndef GL_CLAMP_TO_EDGE |
|---|
| [7372] | 144 | #define GL_CLAMP_TO_EDGE 0x812F |
|---|
| [1099] | 145 | #endif |
|---|
| 146 | |
|---|
| 147 | #ifndef GL_CLAMP_TO_BORDER_ARB |
|---|
| [7372] | 148 | #define GL_CLAMP_TO_BORDER_ARB 0x812D |
|---|
| [1099] | 149 | #endif |
|---|
| 150 | |
|---|
| 151 | #ifndef GL_GENERATE_MIPMAP_SGIS |
|---|
| [7372] | 152 | #define GL_GENERATE_MIPMAP_SGIS 0x8191 |
|---|
| 153 | #define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 |
|---|
| [1099] | 154 | #endif |
|---|
| 155 | |
|---|
| 156 | #ifndef GL_TEXTURE_3D |
|---|
| [7372] | 157 | #define GL_TEXTURE_3D 0x806F |
|---|
| [1099] | 158 | #endif |
|---|
| 159 | |
|---|
| [7371] | 160 | #ifndef GL_TEXTURE_2D_ARRAY_EXT |
|---|
| [7372] | 161 | #define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A |
|---|
| 162 | #define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A |
|---|
| 163 | #define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B |
|---|
| 164 | #define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D |
|---|
| 165 | #define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF |
|---|
| 166 | #define GL_COMPARE_REF_DEPTH_TO_TEXTURE_EXT 0x884E |
|---|
| 167 | #define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1 |
|---|
| 168 | #define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4 |
|---|
| 169 | #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4 |
|---|
| [7371] | 170 | #endif |
|---|
| 171 | |
|---|
| [3472] | 172 | #ifndef GL_TEXTURE_BINDING_3D |
|---|
| [7372] | 173 | #define GL_TEXTURE_BINDING_3D 0x806A |
|---|
| [3454] | 174 | #endif |
|---|
| 175 | |
|---|
| [5375] | 176 | #ifndef GL_DEPTH_TEXTURE_MODE_ARB |
|---|
| [7372] | 177 | #define GL_DEPTH_TEXTURE_MODE_ARB 0x884B |
|---|
| [5375] | 178 | #endif |
|---|
| 179 | |
|---|
| [2551] | 180 | #ifndef GL_TEXTURE_COMPARE_MODE_ARB |
|---|
| [7372] | 181 | #define GL_TEXTURE_COMPARE_MODE_ARB 0x884C |
|---|
| [7567] | 182 | #endif |
|---|
| 183 | #ifndef GL_TEXTURE_COMPARE_FUNC_ARB |
|---|
| [7372] | 184 | #define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D |
|---|
| [7567] | 185 | #endif |
|---|
| 186 | #ifndef GL_COMPARE_R_TO_TEXTURE_ARB |
|---|
| [7372] | 187 | #define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E |
|---|
| [2551] | 188 | #endif |
|---|
| [1646] | 189 | |
|---|
| [2686] | 190 | #ifndef TEXTURE_COMPARE_FAIL_VALUE_ARB |
|---|
| [7372] | 191 | #define TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF |
|---|
| [2686] | 192 | #endif |
|---|
| [1646] | 193 | |
|---|
| [2959] | 194 | #if !defined( GL_MAX_TEXTURE_UNITS ) |
|---|
| [7372] | 195 | #define GL_MAX_TEXTURE_UNITS 0x84E2 |
|---|
| [2959] | 196 | #endif |
|---|
| 197 | |
|---|
| [3113] | 198 | #ifndef GL_TEXTURE_DEPTH |
|---|
| [7372] | 199 | #define GL_TEXTURE_DEPTH 0x8071 |
|---|
| [3113] | 200 | #endif |
|---|
| 201 | |
|---|
| [7385] | 202 | // Integer teture extension as in http://www.opengl.org/registry/specs/EXT/texture_integer.txt |
|---|
| 203 | #ifndef GL_EXT_texture_integer |
|---|
| 204 | #define GL_RGBA32UI_EXT 0x8D70 |
|---|
| 205 | #define GL_RGB32UI_EXT 0x8D71 |
|---|
| 206 | #define GL_ALPHA32UI_EXT 0x8D72 |
|---|
| 207 | #define GL_INTENSITY32UI_EXT 0x8D73 |
|---|
| 208 | #define GL_LUMINANCE32UI_EXT 0x8D74 |
|---|
| 209 | #define GL_LUMINANCE_ALPHA32UI_EXT 0x8D75 |
|---|
| 210 | |
|---|
| 211 | #define GL_RGBA16UI_EXT 0x8D76 |
|---|
| 212 | #define GL_RGB16UI_EXT 0x8D77 |
|---|
| 213 | #define GL_ALPHA16UI_EXT 0x8D78 |
|---|
| 214 | #define GL_INTENSITY16UI_EXT 0x8D79 |
|---|
| 215 | #define GL_LUMINANCE16UI_EXT 0x8D7A |
|---|
| 216 | #define GL_LUMINANCE_ALPHA16UI_EXT 0x8D7B |
|---|
| 217 | |
|---|
| 218 | #define GL_RGBA8UI_EXT 0x8D7C |
|---|
| 219 | #define GL_RGB8UI_EXT 0x8D7D |
|---|
| 220 | #define GL_ALPHA8UI_EXT 0x8D7E |
|---|
| 221 | #define GL_INTENSITY8UI_EXT 0x8D7F |
|---|
| 222 | #define GL_LUMINANCE8UI_EXT 0x8D80 |
|---|
| 223 | #define GL_LUMINANCE_ALPHA8UI_EXT 0x8D81 |
|---|
| 224 | |
|---|
| 225 | #define GL_RGBA32I_EXT 0x8D82 |
|---|
| 226 | #define GL_RGB32I_EXT 0x8D83 |
|---|
| 227 | #define GL_ALPHA32I_EXT 0x8D84 |
|---|
| 228 | #define GL_INTENSITY32I_EXT 0x8D85 |
|---|
| 229 | #define GL_LUMINANCE32I_EXT 0x8D86 |
|---|
| 230 | #define GL_LUMINANCE_ALPHA32I_EXT 0x8D87 |
|---|
| 231 | |
|---|
| 232 | #define GL_RGBA16I_EXT 0x8D88 |
|---|
| 233 | #define GL_RGB16I_EXT 0x8D89 |
|---|
| 234 | #define GL_ALPHA16I_EXT 0x8D8A |
|---|
| 235 | #define GL_INTENSITY16I_EXT 0x8D8B |
|---|
| 236 | #define GL_LUMINANCE16I_EXT 0x8D8C |
|---|
| 237 | #define GL_LUMINANCE_ALPHA16I_EXT 0x8D8D |
|---|
| 238 | |
|---|
| 239 | #define GL_RGBA8I_EXT 0x8D8E |
|---|
| 240 | #define GL_RGB8I_EXT 0x8D8F |
|---|
| 241 | #define GL_ALPHA8I_EXT 0x8D90 |
|---|
| 242 | #define GL_INTENSITY8I_EXT 0x8D91 |
|---|
| 243 | #define GL_LUMINANCE8I_EXT 0x8D92 |
|---|
| 244 | #define GL_LUMINANCE_ALPHA8I_EXT 0x8D93 |
|---|
| 245 | |
|---|
| 246 | #define GL_RED_INTEGER_EXT 0x8D94 |
|---|
| 247 | #define GL_GREEN_INTEGER_EXT 0x8D95 |
|---|
| 248 | #define GL_BLUE_INTEGER_EXT 0x8D96 |
|---|
| 249 | #define GL_ALPHA_INTEGER_EXT 0x8D97 |
|---|
| 250 | #define GL_RGB_INTEGER_EXT 0x8D98 |
|---|
| 251 | #define GL_RGBA_INTEGER_EXT 0x8D99 |
|---|
| 252 | #define GL_BGR_INTEGER_EXT 0x8D9A |
|---|
| 253 | #define GL_BGRA_INTEGER_EXT 0x8D9B |
|---|
| 254 | #define GL_LUMINANCE_INTEGER_EXT 0x8D9C |
|---|
| 255 | #define GL_LUMINANCE_ALPHA_INTEGER_EXT 0x8D9D |
|---|
| 256 | |
|---|
| 257 | #define GL_RGBA_INTEGER_MODE_EXT 0x8D9E |
|---|
| 258 | #endif |
|---|
| 259 | |
|---|
| [8] | 260 | namespace osg { |
|---|
| 261 | |
|---|
| [3422] | 262 | |
|---|
| [3407] | 263 | /** Texture pure virtual base class that encapsulates OpenGl texture |
|---|
| 264 | * functionality common to the various types of OSG textures. |
|---|
| 265 | */ |
|---|
| [4021] | 266 | class OSG_EXPORT Texture : public osg::StateAttribute |
|---|
| [2] | 267 | { |
|---|
| 268 | |
|---|
| 269 | public : |
|---|
| [1099] | 270 | |
|---|
| [3422] | 271 | static unsigned int s_numberTextureReusedLastInLastFrame; |
|---|
| 272 | static unsigned int s_numberNewTextureInLastFrame; |
|---|
| 273 | static unsigned int s_numberDeletedTextureInLastFrame; |
|---|
| 274 | |
|---|
| [2] | 275 | Texture(); |
|---|
| 276 | |
|---|
| [3407] | 277 | /** Copy constructor using CopyOp to manage deep vs shallow copy. */ |
|---|
| [990] | 278 | Texture(const Texture& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY); |
|---|
| [1099] | 279 | |
|---|
| 280 | virtual osg::Object* cloneType() const = 0; |
|---|
| 281 | virtual osg::Object* clone(const CopyOp& copyop) const = 0; |
|---|
| 282 | virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Texture *>(obj)!=NULL; } |
|---|
| 283 | virtual const char* libraryName() const { return "osg"; } |
|---|
| 284 | virtual const char* className() const { return "Texture"; } |
|---|
| [8655] | 285 | |
|---|
| 286 | /** Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.*/ |
|---|
| 287 | virtual Texture* asTexture() { return this; } |
|---|
| 288 | |
|---|
| 289 | /** Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.*/ |
|---|
| 290 | virtual const Texture* asTexture() const { return this; } |
|---|
| 291 | |
|---|
| [1133] | 292 | virtual Type getType() const { return TEXTURE; } |
|---|
| [1099] | 293 | |
|---|
| 294 | virtual bool isTextureAttribute() const { return true; } |
|---|
| 295 | |
|---|
| [4422] | 296 | virtual GLenum getTextureTarget() const = 0; |
|---|
| 297 | |
|---|
| [6311] | 298 | virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const |
|---|
| [4422] | 299 | { |
|---|
| 300 | usage.usesTextureMode(getTextureTarget()); |
|---|
| 301 | return true; |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| [5389] | 304 | virtual int getTextureWidth() const { return 0; } |
|---|
| 305 | virtual int getTextureHeight() const { return 0; } |
|---|
| 306 | virtual int getTextureDepth() const { return 0; } |
|---|
| 307 | |
|---|
| [1099] | 308 | enum WrapParameter { |
|---|
| 309 | WRAP_S, |
|---|
| 310 | WRAP_T, |
|---|
| 311 | WRAP_R |
|---|
| 312 | }; |
|---|
| 313 | |
|---|
| 314 | enum WrapMode { |
|---|
| 315 | CLAMP = GL_CLAMP, |
|---|
| 316 | CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE, |
|---|
| 317 | CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER_ARB, |
|---|
| 318 | REPEAT = GL_REPEAT, |
|---|
| 319 | MIRROR = GL_MIRRORED_REPEAT_IBM |
|---|
| 320 | }; |
|---|
| 321 | |
|---|
| [3407] | 322 | /** Sets the texture wrap mode. */ |
|---|
| [1133] | 323 | void setWrap(WrapParameter which, WrapMode wrap); |
|---|
| [3407] | 324 | /** Gets the texture wrap mode. */ |
|---|
| [1133] | 325 | WrapMode getWrap(WrapParameter which) const; |
|---|
| [1099] | 326 | |
|---|
| 327 | |
|---|
| [7385] | 328 | /** Sets the border color. Only used when wrap mode is CLAMP_TO_BORDER. |
|---|
| 329 | * The border color will be casted to the appropriate type to match the |
|---|
| 330 | * internal pixel format of the texture. */ |
|---|
| 331 | void setBorderColor(const Vec4d& color) { _borderColor = color; dirtyTextureParameters(); } |
|---|
| [3407] | 332 | |
|---|
| 333 | /** Gets the border color. */ |
|---|
| [7385] | 334 | const Vec4d& getBorderColor() const { return _borderColor; } |
|---|
| 335 | |
|---|
| [3407] | 336 | /** Sets the border width. */ |
|---|
| [2678] | 337 | void setBorderWidth(GLint width) { _borderWidth = width; dirtyTextureParameters(); } |
|---|
| 338 | |
|---|
| 339 | GLint getBorderWidth() const { return _borderWidth; } |
|---|
| [836] | 340 | |
|---|
| [1099] | 341 | enum FilterParameter { |
|---|
| 342 | MIN_FILTER, |
|---|
| 343 | MAG_FILTER |
|---|
| 344 | }; |
|---|
| [26] | 345 | |
|---|
| [1099] | 346 | enum FilterMode { |
|---|
| 347 | LINEAR = GL_LINEAR, |
|---|
| 348 | LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR, |
|---|
| 349 | LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST, |
|---|
| 350 | NEAREST = GL_NEAREST, |
|---|
| 351 | NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR, |
|---|
| 352 | NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST |
|---|
| 353 | }; |
|---|
| [8] | 354 | |
|---|
| 355 | |
|---|
| [3407] | 356 | /** Sets the texture filter mode. */ |
|---|
| [1133] | 357 | void setFilter(FilterParameter which, FilterMode filter); |
|---|
| [2] | 358 | |
|---|
| [3407] | 359 | /** Gets the texture filter mode. */ |
|---|
| [1133] | 360 | FilterMode getFilter(FilterParameter which) const; |
|---|
| [990] | 361 | |
|---|
| [3407] | 362 | /** Sets the maximum anisotropy value, default value is 1.0 for no |
|---|
| 363 | * anisotropic filtering. If hardware does not support anisotropic |
|---|
| [7648] | 364 | * filtering, use normal filtering (equivalent to a max anisotropy |
|---|
| [3407] | 365 | * value of 1.0. Valid range is 1.0f upwards. The maximum value |
|---|
| 366 | * depends on the graphics system. */ |
|---|
| [1099] | 367 | void setMaxAnisotropy(float anis); |
|---|
| 368 | |
|---|
| [3407] | 369 | /** Gets the maximum anisotropy value. */ |
|---|
| [1099] | 370 | inline float getMaxAnisotropy() const { return _maxAnisotropy; } |
|---|
| [8] | 371 | |
|---|
| [3407] | 372 | /** Sets the hardware mipmap generation hint. If enabled, it will |
|---|
| 373 | * only be used if supported in the graphics system. */ |
|---|
| [1773] | 374 | inline void setUseHardwareMipMapGeneration(bool useHardwareMipMapGeneration) { _useHardwareMipMapGeneration = useHardwareMipMapGeneration; } |
|---|
| 375 | |
|---|
| [3407] | 376 | /** Gets the hardware mipmap generation hint. */ |
|---|
| [1773] | 377 | inline bool getUseHardwareMipMapGeneration() const { return _useHardwareMipMapGeneration; } |
|---|
| 378 | |
|---|
| [3407] | 379 | /** Sets whether or not the apply() function will unreference the image |
|---|
| [7648] | 380 | * data. If enabled, and the image data is only referenced by this |
|---|
| [3407] | 381 | * Texture, apply() will delete the image data. */ |
|---|
| [1819] | 382 | inline void setUnRefImageDataAfterApply(bool flag) { _unrefImageDataAfterApply = flag; } |
|---|
| 383 | |
|---|
| [3407] | 384 | /** Gets whether or not apply() unreferences image data. */ |
|---|
| [1819] | 385 | inline bool getUnRefImageDataAfterApply() const { return _unrefImageDataAfterApply; } |
|---|
| 386 | |
|---|
| [3407] | 387 | /** Sets whether to use client storage for the texture, if supported |
|---|
| 388 | * by the graphics system. Note: If enabled, and the graphics system |
|---|
| 389 | * supports it, the osg::Image(s) associated with this texture cannot |
|---|
| 390 | * be deleted, so the UnRefImageDataAfterApply flag would be ignored. */ |
|---|
| [2791] | 391 | inline void setClientStorageHint(bool flag) { _clientStorageHint = flag; } |
|---|
| [3407] | 392 | |
|---|
| 393 | /** Gets whether to use client storage for the texture. */ |
|---|
| [2791] | 394 | inline bool getClientStorageHint() const { return _clientStorageHint; } |
|---|
| [1819] | 395 | |
|---|
| [4162] | 396 | /** Sets whether to force the texture to resize images that have dimensions |
|---|
| 397 | * that are not a power of two. If enabled, NPOT images will be resized, |
|---|
| 398 | * whether or not NPOT textures are supported by the hardware. If disabled, |
|---|
| 399 | * NPOT images will not be resized if supported by hardware. */ |
|---|
| 400 | inline void setResizeNonPowerOfTwoHint(bool flag) { _resizeNonPowerOfTwoHint = flag; } |
|---|
| 401 | |
|---|
| 402 | /** Gets whether texture will force non power to two images to be resized. */ |
|---|
| 403 | inline bool getResizeNonPowerOfTwoHint() const { return _resizeNonPowerOfTwoHint; } |
|---|
| 404 | |
|---|
| [1099] | 405 | enum InternalFormatMode { |
|---|
| 406 | USE_IMAGE_DATA_FORMAT, |
|---|
| 407 | USE_USER_DEFINED_FORMAT, |
|---|
| 408 | USE_ARB_COMPRESSION, |
|---|
| 409 | USE_S3TC_DXT1_COMPRESSION, |
|---|
| 410 | USE_S3TC_DXT3_COMPRESSION, |
|---|
| 411 | USE_S3TC_DXT5_COMPRESSION |
|---|
| 412 | }; |
|---|
| 413 | |
|---|
| [3407] | 414 | /** Sets the internal texture format mode. Note: If the texture format is |
|---|
| 415 | * USE_IMAGE_DATA_FORMAT, USE_ARB_COMPRESSION, or USE_S3TC_COMPRESSION, |
|---|
| 416 | * the internal format mode is set automatically and will overwrite the |
|---|
| 417 | * previous _internalFormat. */ |
|---|
| [1133] | 418 | inline void setInternalFormatMode(InternalFormatMode mode) { _internalFormatMode = mode; } |
|---|
| [8] | 419 | |
|---|
| [3407] | 420 | /** Gets the internal texture format mode. */ |
|---|
| [1133] | 421 | inline InternalFormatMode getInternalFormatMode() const { return _internalFormatMode; } |
|---|
| [2] | 422 | |
|---|
| [3407] | 423 | /** Sets the internal texture format. Implicitly sets the |
|---|
| [7385] | 424 | * internalFormatMode to USE_USER_DEFINED_FORMAT. |
|---|
| 425 | * The corresponding internal format type will be computed. */ |
|---|
| [1133] | 426 | inline void setInternalFormat(GLint internalFormat) |
|---|
| [8] | 427 | { |
|---|
| 428 | _internalFormatMode = USE_USER_DEFINED_FORMAT; |
|---|
| [1073] | 429 | _internalFormat = internalFormat; |
|---|
| [7385] | 430 | computeInternalFormatType(); |
|---|
| [8] | 431 | } |
|---|
| 432 | |
|---|
| [7385] | 433 | |
|---|
| [3407] | 434 | /** Gets the internal texture format. */ |
|---|
| [1133] | 435 | inline GLint getInternalFormat() const { if (_internalFormat==0) computeInternalFormat(); return _internalFormat; } |
|---|
| [8] | 436 | |
|---|
| [4700] | 437 | /** Return true if the internal format is one of the compressed formats.*/ |
|---|
| [1099] | 438 | bool isCompressedInternalFormat() const; |
|---|
| [8] | 439 | |
|---|
| [4700] | 440 | /** Sets the external source image format, used as a fallback when no osg::Image is attached to provide the source image format. */ |
|---|
| 441 | inline void setSourceFormat(GLenum sourceFormat) { _sourceFormat = sourceFormat; } |
|---|
| [1143] | 442 | |
|---|
| [4700] | 443 | /** Gets the external source image format. */ |
|---|
| 444 | inline GLenum getSourceFormat() const { return _sourceFormat; } |
|---|
| 445 | |
|---|
| 446 | /** Sets the external source data type, used as a fallback when no osg::Image is attached to provide the source image format.*/ |
|---|
| 447 | inline void setSourceType(GLenum sourceType) { _sourceType = sourceType; } |
|---|
| 448 | |
|---|
| 449 | /** Gets the external source data type.*/ |
|---|
| 450 | inline GLenum getSourceType() const { return _sourceType; } |
|---|
| 451 | |
|---|
| [7385] | 452 | /** Texture type determined by the internal texture format */ |
|---|
| 453 | enum InternalFormatType{ |
|---|
| [4700] | 454 | |
|---|
| [7385] | 455 | //! default OpenGL format (clamped values to [0,1) or [0,255]) |
|---|
| 456 | NORMALIZED = 0x0, |
|---|
| 457 | |
|---|
| 458 | //! float values, Shader Model 3.0 (see ARB_texture_float) |
|---|
| 459 | FLOAT = 0x1, |
|---|
| 460 | |
|---|
| 461 | //! Signed integer values (see EXT_texture_integer) |
|---|
| 462 | SIGNED_INTEGER = 0x2, |
|---|
| 463 | |
|---|
| 464 | //! Unsigned integer value (see EXT_texture_integer) |
|---|
| 465 | UNSIGNED_INTEGER = 0x4 |
|---|
| 466 | }; |
|---|
| 467 | |
|---|
| 468 | /** Get the internal texture format type. */ |
|---|
| 469 | inline InternalFormatType getInternalFormatType() const { return _internalFormatType; } |
|---|
| 470 | |
|---|
| [2022] | 471 | class TextureObject; |
|---|
| 472 | |
|---|
| [10588] | 473 | /** Returns a pointer to the TextureBbject for the current context. */ |
|---|
| [2022] | 474 | inline TextureObject* getTextureObject(unsigned int contextID) const |
|---|
| [1099] | 475 | { |
|---|
| [2022] | 476 | return _textureObjectBuffer[contextID].get(); |
|---|
| [8] | 477 | } |
|---|
| 478 | |
|---|
| [10588] | 479 | inline void setTextureObject(unsigned int contextID, TextureObject* to) |
|---|
| 480 | { |
|---|
| 481 | _textureObjectBuffer[contextID] = to; |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| [3407] | 484 | /** Forces a recompile on next apply() of associated OpenGL texture |
|---|
| 485 | * objects. */ |
|---|
| [2022] | 486 | void dirtyTextureObject(); |
|---|
| [481] | 487 | |
|---|
| [3407] | 488 | /** Returns true if the texture objects for all the required graphics |
|---|
| 489 | * contexts are loaded. */ |
|---|
| [2022] | 490 | bool areAllTextureObjectsLoaded() const; |
|---|
| 491 | |
|---|
| 492 | |
|---|
| [3407] | 493 | /** Gets the dirty flag for the current contextID. */ |
|---|
| [1601] | 494 | inline unsigned int& getTextureParameterDirty(unsigned int contextID) const |
|---|
| [1140] | 495 | { |
|---|
| 496 | return _texParametersDirtyList[contextID]; |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| [990] | 499 | |
|---|
| [3407] | 500 | /** Force a reset on next apply() of associated OpenGL texture |
|---|
| 501 | * parameters. */ |
|---|
| [1140] | 502 | void dirtyTextureParameters(); |
|---|
| [990] | 503 | |
|---|
| [7385] | 504 | /** Force a manual allocation of the mipmap levels on the next apply() call. |
|---|
| 505 | * User is responsible for filling the mipmap levels with valid data. |
|---|
| 506 | * The OpenGL's glGenerateMipmapEXT function is used to generate the mipmap levels. |
|---|
| 507 | * If glGenerateMipmapEXT is not supported or texture's internal format is not supported |
|---|
| 508 | * by the glGenerateMipmapEXT, then empty mipmap levels will |
|---|
| [7648] | 509 | * be allocated manually. The mipmap levels are also allocated if a non-mipmapped |
|---|
| [7385] | 510 | * min filter is used. */ |
|---|
| 511 | void allocateMipmapLevels(); |
|---|
| [990] | 512 | |
|---|
| [7385] | 513 | |
|---|
| [3407] | 514 | /** Sets GL_TEXTURE_COMPARE_MODE_ARB to GL_COMPARE_R_TO_TEXTURE_ARB |
|---|
| 515 | * See http://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow.txt. */ |
|---|
| [2551] | 516 | void setShadowComparison(bool flag) { _use_shadow_comparison = flag; } |
|---|
| [990] | 517 | |
|---|
| [2551] | 518 | enum ShadowCompareFunc { |
|---|
| [9905] | 519 | NEVER = GL_NEVER, |
|---|
| 520 | LESS = GL_LESS, |
|---|
| 521 | EQUAL = GL_EQUAL, |
|---|
| [2551] | 522 | LEQUAL = GL_LEQUAL, |
|---|
| [9905] | 523 | GREATER = GL_GREATER, |
|---|
| 524 | NOTEQUAL = GL_NOTEQUAL, |
|---|
| 525 | GEQUAL = GL_GEQUAL, |
|---|
| 526 | ALWAYS = GL_ALWAYS |
|---|
| [2551] | 527 | }; |
|---|
| 528 | |
|---|
| [3407] | 529 | /** Sets shadow texture comparison function. */ |
|---|
| [2551] | 530 | void setShadowCompareFunc(ShadowCompareFunc func) { _shadow_compare_func = func; } |
|---|
| [5476] | 531 | ShadowCompareFunc getShadowCompareFunc() const { return _shadow_compare_func; } |
|---|
| [2551] | 532 | |
|---|
| 533 | enum ShadowTextureMode { |
|---|
| 534 | LUMINANCE = GL_LUMINANCE, |
|---|
| 535 | INTENSITY = GL_INTENSITY, |
|---|
| 536 | ALPHA = GL_ALPHA |
|---|
| 537 | }; |
|---|
| 538 | |
|---|
| [3407] | 539 | /** Sets shadow texture mode after comparison. */ |
|---|
| [2551] | 540 | void setShadowTextureMode(ShadowTextureMode mode) { _shadow_texture_mode = mode; } |
|---|
| [5476] | 541 | ShadowTextureMode getShadowTextureMode() const { return _shadow_texture_mode; } |
|---|
| [2551] | 542 | |
|---|
| [3407] | 543 | /** Sets the TEXTURE_COMPARE_FAIL_VALUE_ARB texture parameter. See |
|---|
| 544 | * http://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow_ambient.txt. */ |
|---|
| [2686] | 545 | void setShadowAmbient(float shadow_ambient) { _shadow_ambient = shadow_ambient; } |
|---|
| [5476] | 546 | float getShadowAmbient() const { return _shadow_ambient; } |
|---|
| [1048] | 547 | |
|---|
| [3190] | 548 | |
|---|
| [3407] | 549 | /** Sets the texture image for the specified face. */ |
|---|
| [3190] | 550 | virtual void setImage(unsigned int face, Image* image) = 0; |
|---|
| 551 | |
|---|
| [3407] | 552 | /** Gets the texture image for the specified face. */ |
|---|
| [3190] | 553 | virtual Image* getImage(unsigned int face) = 0; |
|---|
| 554 | |
|---|
| [3407] | 555 | /** Gets the const texture image for specified face. */ |
|---|
| [3190] | 556 | virtual const Image* getImage(unsigned int face) const = 0; |
|---|
| 557 | |
|---|
| [3407] | 558 | /** Gets the number of images that can be assigned to this Texture. */ |
|---|
| [3190] | 559 | virtual unsigned int getNumImages() const = 0; |
|---|
| 560 | |
|---|
| 561 | |
|---|
| [7648] | 562 | /** Set the PBuffer graphics context to read from when using PBuffers for RenderToTexture.*/ |
|---|
| [4485] | 563 | void setReadPBuffer(GraphicsContext* context) { _readPBuffer = context; } |
|---|
| 564 | |
|---|
| [7648] | 565 | /** Get the PBuffer graphics context to read from when using PBuffers for RenderToTexture.*/ |
|---|
| [4485] | 566 | GraphicsContext* getReadPBuffer() { return _readPBuffer.get(); } |
|---|
| 567 | |
|---|
| [7648] | 568 | /** Get the const PBuffer graphics context to read from when using PBuffers for RenderToTexture.*/ |
|---|
| [5477] | 569 | const GraphicsContext* getReadPBuffer() const { return _readPBuffer.get(); } |
|---|
| 570 | |
|---|
| [7648] | 571 | /** Texture is a pure virtual base class, apply must be overridden. */ |
|---|
| [1099] | 572 | virtual void apply(State& state) const = 0; |
|---|
| [1048] | 573 | |
|---|
| [1099] | 574 | /** Calls apply(state) to compile the texture. */ |
|---|
| [3159] | 575 | virtual void compileGLObjects(State& state) const; |
|---|
| [1048] | 576 | |
|---|
| [5882] | 577 | /** Resize any per context GLObject buffers to specified size. */ |
|---|
| 578 | virtual void resizeGLObjectBuffers(unsigned int maxSize); |
|---|
| 579 | |
|---|
| [3407] | 580 | /** If State is non-zero, this function releases OpenGL objects for |
|---|
| [7648] | 581 | * the specified graphics context. Otherwise, releases OpenGL objects |
|---|
| [3407] | 582 | * for all graphics contexts. */ |
|---|
| [3159] | 583 | virtual void releaseGLObjects(State* state=0) const; |
|---|
| 584 | |
|---|
| [3407] | 585 | /** Encapsulates queries of extension availability, obtains extension |
|---|
| [7648] | 586 | * function pointers, and provides convenience wrappers for |
|---|
| [3407] | 587 | * calling extension functions. */ |
|---|
| [4021] | 588 | class OSG_EXPORT Extensions : public osg::Referenced |
|---|
| [1155] | 589 | { |
|---|
| 590 | public: |
|---|
| [4102] | 591 | Extensions(unsigned int contextID); |
|---|
| [1155] | 592 | |
|---|
| 593 | Extensions(const Extensions& rhs); |
|---|
| 594 | |
|---|
| 595 | void lowestCommonDenominator(const Extensions& rhs); |
|---|
| 596 | |
|---|
| [4102] | 597 | void setupGLExtensions(unsigned int contextID); |
|---|
| [1155] | 598 | |
|---|
| [1856] | 599 | void setMultiTexturingSupported(bool flag) { _isMultiTexturingSupported=flag; } |
|---|
| 600 | bool isMultiTexturingSupported() const { return _isMultiTexturingSupported; } |
|---|
| 601 | |
|---|
| [1854] | 602 | void setTextureFilterAnisotropicSupported(bool flag) { _isTextureFilterAnisotropicSupported=flag; } |
|---|
| [1155] | 603 | bool isTextureFilterAnisotropicSupported() const { return _isTextureFilterAnisotropicSupported; } |
|---|
| [1854] | 604 | |
|---|
| 605 | void setTextureCompressionARBSupported(bool flag) { _isTextureCompressionARBSupported=flag; } |
|---|
| [1155] | 606 | bool isTextureCompressionARBSupported() const { return _isTextureCompressionARBSupported; } |
|---|
| [1854] | 607 | |
|---|
| 608 | void setTextureCompressionS3TCSupported(bool flag) { _isTextureCompressionS3TCSupported=flag; } |
|---|
| [1155] | 609 | bool isTextureCompressionS3TCSupported() const { return _isTextureCompressionS3TCSupported; } |
|---|
| [1854] | 610 | |
|---|
| 611 | void setTextureMirroredRepeatSupported(bool flag) { _isTextureMirroredRepeatSupported=flag; } |
|---|
| [1155] | 612 | bool isTextureMirroredRepeatSupported() const { return _isTextureMirroredRepeatSupported; } |
|---|
| [1854] | 613 | |
|---|
| 614 | void setTextureEdgeClampSupported(bool flag) { _isTextureEdgeClampSupported=flag; } |
|---|
| [1155] | 615 | bool isTextureEdgeClampSupported() const { return _isTextureEdgeClampSupported; } |
|---|
| [1854] | 616 | |
|---|
| 617 | void setTextureBorderClampSupported(bool flag) { _isTextureBorderClampSupported=flag; } |
|---|
| [1155] | 618 | bool isTextureBorderClampSupported() const { return _isTextureBorderClampSupported; } |
|---|
| [1854] | 619 | |
|---|
| 620 | void setGenerateMipMapSupported(bool flag) { _isGenerateMipMapSupported=flag; } |
|---|
| [1646] | 621 | bool isGenerateMipMapSupported() const { return _isGenerateMipMapSupported; } |
|---|
| [1155] | 622 | |
|---|
| [2551] | 623 | void setShadowSupported(bool flag) { _isShadowSupported = flag; } |
|---|
| 624 | bool isShadowSupported() const { return _isShadowSupported; } |
|---|
| 625 | |
|---|
| [2686] | 626 | void setShadowAmbientSupported(bool flag) { _isShadowAmbientSupported = flag; } |
|---|
| 627 | bool isShadowAmbientSupported() const { return _isShadowAmbientSupported; } |
|---|
| 628 | |
|---|
| [10370] | 629 | void setTextureMaxLevelSupported(bool flag) { _isTextureMaxLevelSupported = flag; } |
|---|
| 630 | bool isTextureMaxLevelSupported() const { return _isTextureMaxLevelSupported; } |
|---|
| 631 | |
|---|
| [1854] | 632 | void setMaxTextureSize(GLint maxsize) { _maxTextureSize=maxsize; } |
|---|
| [1155] | 633 | GLint maxTextureSize() const { return _maxTextureSize; } |
|---|
| 634 | |
|---|
| [2959] | 635 | void setNumTextureUnits(GLint nunits ) { _numTextureUnits=nunits; } |
|---|
| 636 | GLint numTextureUnits() const { return _numTextureUnits; } |
|---|
| 637 | |
|---|
| [1155] | 638 | bool isCompressedTexImage2DSupported() const { return _glCompressedTexImage2D!=0; } |
|---|
| [7352] | 639 | bool isCompressedTexSubImage2DSupported() const { return _glCompressedTexSubImage2D!=0; } |
|---|
| 640 | |
|---|
| [7379] | 641 | void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) const; |
|---|
| [1773] | 642 | void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei type, const GLvoid *data) const; |
|---|
| [1794] | 643 | void glGetCompressedTexImage(GLenum target, GLint level, GLvoid *data) const; |
|---|
| [1155] | 644 | |
|---|
| [2791] | 645 | bool isClientStorageSupported() const { return _isClientStorageSupported; } |
|---|
| 646 | |
|---|
| [4248] | 647 | bool isNonPowerOfTwoTextureSupported(GLenum filter) const |
|---|
| 648 | { |
|---|
| 649 | return (filter==GL_LINEAR || filter==GL_NEAREST) ? |
|---|
| 650 | _isNonPowerOfTwoTextureNonMipMappedSupported : |
|---|
| 651 | _isNonPowerOfTwoTextureMipMappedSupported; |
|---|
| 652 | } |
|---|
| [4156] | 653 | |
|---|
| [7386] | 654 | void setTextureIntegerSupported(bool flag) { _isTextureIntegerEXTSupported=flag; } |
|---|
| 655 | bool isTextureIntegerSupported() const { return _isTextureIntegerEXTSupported; } |
|---|
| [7385] | 656 | |
|---|
| 657 | void glTexParameterIiv(GLenum target, GLenum pname, const GLint* data) const; |
|---|
| 658 | void glTexParameterIuiv(GLenum target, GLenum pname, const GLuint* data) const; |
|---|
| 659 | |
|---|
| [1155] | 660 | protected: |
|---|
| 661 | |
|---|
| 662 | ~Extensions() {} |
|---|
| 663 | |
|---|
| [1856] | 664 | bool _isMultiTexturingSupported; |
|---|
| [1155] | 665 | bool _isTextureFilterAnisotropicSupported; |
|---|
| 666 | bool _isTextureCompressionARBSupported; |
|---|
| 667 | bool _isTextureCompressionS3TCSupported; |
|---|
| 668 | bool _isTextureMirroredRepeatSupported; |
|---|
| 669 | bool _isTextureEdgeClampSupported; |
|---|
| 670 | bool _isTextureBorderClampSupported; |
|---|
| [1646] | 671 | bool _isGenerateMipMapSupported; |
|---|
| [2551] | 672 | bool _isShadowSupported; |
|---|
| [2686] | 673 | bool _isShadowAmbientSupported; |
|---|
| [2791] | 674 | bool _isClientStorageSupported; |
|---|
| [4248] | 675 | bool _isNonPowerOfTwoTextureMipMappedSupported; |
|---|
| 676 | bool _isNonPowerOfTwoTextureNonMipMappedSupported; |
|---|
| [7385] | 677 | bool _isTextureIntegerEXTSupported; |
|---|
| [10370] | 678 | bool _isTextureMaxLevelSupported; |
|---|
| [7385] | 679 | |
|---|
| [1155] | 680 | GLint _maxTextureSize; |
|---|
| [2959] | 681 | GLint _numTextureUnits; |
|---|
| [1155] | 682 | |
|---|
| [7379] | 683 | typedef void (APIENTRY * CompressedTexImage2DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); |
|---|
| 684 | typedef void (APIENTRY * CompressedTexSubImage2DArbProc) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); |
|---|
| 685 | typedef void (APIENTRY * GetCompressedTexImageArbProc) (GLenum target, GLint level, GLvoid *data); |
|---|
| [7385] | 686 | typedef void (APIENTRY * TexParameterIivProc)(GLenum target, GLenum pname, const GLint* data); |
|---|
| 687 | typedef void (APIENTRY * TexParameterIuivProc)(GLenum target, GLenum pname, const GLuint* data); |
|---|
| [1155] | 688 | |
|---|
| [7379] | 689 | CompressedTexImage2DArbProc _glCompressedTexImage2D; |
|---|
| 690 | CompressedTexSubImage2DArbProc _glCompressedTexSubImage2D; |
|---|
| 691 | GetCompressedTexImageArbProc _glGetCompressedTexImage; |
|---|
| [7385] | 692 | TexParameterIivProc _glTexParameterIiv; |
|---|
| 693 | TexParameterIuivProc _glTexParameterIuiv; |
|---|
| [7379] | 694 | |
|---|
| [1155] | 695 | }; |
|---|
| 696 | |
|---|
| [3407] | 697 | /** Gets the extension for the specified context. Creates the |
|---|
| 698 | * Extensions object for that context if it doesn't exist. |
|---|
| 699 | * Returns NULL if the Extensions object for the context doesn't |
|---|
| 700 | * exist and the createIfNotInitalized flag is false. */ |
|---|
| [1854] | 701 | static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized); |
|---|
| [1155] | 702 | |
|---|
| [3407] | 703 | /** Overrides Extensions objects across graphics contexts. Typically |
|---|
| 704 | * used to ensure the same lowest common denominator of extensions |
|---|
| [7648] | 705 | * on systems with different graphics pipes. */ |
|---|
| [1602] | 706 | static void setExtensions(unsigned int contextID,Extensions* extensions); |
|---|
| [1155] | 707 | |
|---|
| [5213] | 708 | /** Determine whether the given internalFormat is a compressed |
|---|
| 709 | * image format. */ |
|---|
| 710 | static bool isCompressedInternalFormat(GLint internalFormat); |
|---|
| 711 | |
|---|
| 712 | /** Determine the size of a compressed image, given the internalFormat, |
|---|
| 713 | * the width, the height, and the depth of the image. The block size |
|---|
| 714 | * and the size are output parameters. */ |
|---|
| 715 | static void getCompressedSize(GLenum internalFormat, GLint width, GLint height, GLint depth, GLint& blockSize, GLint& size); |
|---|
| [2022] | 716 | |
|---|
| [5213] | 717 | |
|---|
| [3407] | 718 | /** Helper method. Creates the texture, but doesn't set or use a |
|---|
| 719 | * texture binding. Note: Don't call this method directly unless |
|---|
| 720 | * you're implementing a subload callback. */ |
|---|
| [2022] | 721 | void applyTexImage2D_load(State& state, GLenum target, const Image* image, GLsizei width, GLsizei height,GLsizei numMipmapLevels) const; |
|---|
| [1773] | 722 | |
|---|
| [3407] | 723 | /** Helper method. Subloads images into the texture, but doesn't set |
|---|
| 724 | * or use a texture binding. Note: Don't call this method directly |
|---|
| 725 | * unless you're implementing a subload callback. */ |
|---|
| [2662] | 726 | void applyTexImage2D_subload(State& state, GLenum target, const Image* image, GLsizei width, GLsizei height, GLint inInternalFormat, GLsizei numMipmapLevels) const; |
|---|
| [1773] | 727 | |
|---|
| [8386] | 728 | /** Returned by mipmapBeforeTexImage() to indicate what |
|---|
| 729 | * mipmapAfterTexImage() should do */ |
|---|
| 730 | enum GenerateMipmapMode |
|---|
| 731 | { |
|---|
| 732 | GENERATE_MIPMAP_NONE, |
|---|
| 733 | GENERATE_MIPMAP, |
|---|
| 734 | GENERATE_MIPMAP_TEX_PARAMETER |
|---|
| 735 | }; |
|---|
| 736 | |
|---|
| [1099] | 737 | protected : |
|---|
| [1048] | 738 | |
|---|
| [1099] | 739 | virtual ~Texture(); |
|---|
| 740 | |
|---|
| 741 | virtual void computeInternalFormat() const = 0; |
|---|
| [1047] | 742 | |
|---|
| [1776] | 743 | void computeInternalFormatWithImage(const osg::Image& image) const; |
|---|
| [8] | 744 | |
|---|
| [2022] | 745 | void computeRequiredTextureDimensions(State& state, const osg::Image& image,GLsizei& width, GLsizei& height,GLsizei& numMipmapLevels) const; |
|---|
| [7385] | 746 | |
|---|
| 747 | void computeInternalFormatType() const; |
|---|
| [2022] | 748 | |
|---|
| [7648] | 749 | /** Helper method. Sets texture parameters. */ |
|---|
| [1099] | 750 | void applyTexParameters(GLenum target, State& state) const; |
|---|
| [2] | 751 | |
|---|
| [8373] | 752 | /** Returns true if _useHardwareMipMapGeneration is true and either |
|---|
| 753 | * glGenerateMipmapEXT() or GL_GENERATE_MIPMAP_SGIS are supported. */ |
|---|
| 754 | bool isHardwareMipmapGenerationEnabled(const State& state) const; |
|---|
| 755 | |
|---|
| 756 | /** Helper methods to be called before and after calling |
|---|
| 757 | * gl[Compressed][Copy]Tex[Sub]Image2D to handle generating mipmaps. */ |
|---|
| 758 | GenerateMipmapMode mipmapBeforeTexImage(const State& state, bool hardwareMipmapOn) const; |
|---|
| 759 | void mipmapAfterTexImage(State& state, GenerateMipmapMode beforeResult) const; |
|---|
| 760 | |
|---|
| 761 | /** Helper method to generate mipmap levels by calling of glGenerateMipmapEXT. |
|---|
| [7385] | 762 | * If it is not supported, then call the virtual allocateMipmap() method */ |
|---|
| 763 | void generateMipmap(State& state) const; |
|---|
| [449] | 764 | |
|---|
| [7385] | 765 | /** Allocate mipmap levels of the texture by subsequent calling of glTexImage* function. */ |
|---|
| 766 | virtual void allocateMipmap(State& state) const = 0; |
|---|
| [10588] | 767 | |
|---|
| [3407] | 768 | /** Returns -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ |
|---|
| [1099] | 769 | int compareTexture(const Texture& rhs) const; |
|---|
| [2] | 770 | |
|---|
| [5452] | 771 | /** Returns -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ |
|---|
| 772 | int compareTextureObjects(const Texture& rhs) const; |
|---|
| 773 | |
|---|
| [1602] | 774 | typedef buffered_value<unsigned int> TexParameterDirtyList; |
|---|
| [1140] | 775 | mutable TexParameterDirtyList _texParametersDirtyList; |
|---|
| [7385] | 776 | mutable TexParameterDirtyList _texMipmapGenerationDirtyList; |
|---|
| [10588] | 777 | |
|---|
| [1099] | 778 | WrapMode _wrap_s; |
|---|
| 779 | WrapMode _wrap_t; |
|---|
| 780 | WrapMode _wrap_r; |
|---|
| [2] | 781 | |
|---|
| [1099] | 782 | FilterMode _min_filter; |
|---|
| 783 | FilterMode _mag_filter; |
|---|
| 784 | float _maxAnisotropy; |
|---|
| [1773] | 785 | bool _useHardwareMipMapGeneration; |
|---|
| [1819] | 786 | bool _unrefImageDataAfterApply; |
|---|
| [2791] | 787 | bool _clientStorageHint; |
|---|
| [4162] | 788 | bool _resizeNonPowerOfTwoHint; |
|---|
| [1073] | 789 | |
|---|
| [7385] | 790 | Vec4d _borderColor; |
|---|
| [2678] | 791 | GLint _borderWidth; |
|---|
| [1073] | 792 | |
|---|
| [7385] | 793 | InternalFormatMode _internalFormatMode; |
|---|
| 794 | mutable InternalFormatType _internalFormatType; |
|---|
| [1099] | 795 | mutable GLint _internalFormat; |
|---|
| [4700] | 796 | mutable GLenum _sourceFormat; |
|---|
| 797 | mutable GLenum _sourceType; |
|---|
| [10588] | 798 | |
|---|
| [2551] | 799 | bool _use_shadow_comparison; |
|---|
| 800 | ShadowCompareFunc _shadow_compare_func; |
|---|
| 801 | ShadowTextureMode _shadow_texture_mode; |
|---|
| [2686] | 802 | float _shadow_ambient; |
|---|
| [2551] | 803 | |
|---|
| [2022] | 804 | public: |
|---|
| [10588] | 805 | |
|---|
| 806 | struct TextureProfile |
|---|
| [2022] | 807 | { |
|---|
| [10588] | 808 | inline TextureProfile(GLenum target): |
|---|
| [2022] | 809 | _target(target), |
|---|
| 810 | _numMipmapLevels(0), |
|---|
| 811 | _internalFormat(0), |
|---|
| 812 | _width(0), |
|---|
| 813 | _height(0), |
|---|
| 814 | _depth(0), |
|---|
| [10589] | 815 | _border(0), |
|---|
| 816 | _size(0) {} |
|---|
| [10588] | 817 | |
|---|
| 818 | inline TextureProfile(GLenum target, |
|---|
| 819 | GLint numMipmapLevels, |
|---|
| 820 | GLenum internalFormat, |
|---|
| 821 | GLsizei width, |
|---|
| 822 | GLsizei height, |
|---|
| 823 | GLsizei depth, |
|---|
| 824 | GLint border): |
|---|
| [2022] | 825 | _target(target), |
|---|
| 826 | _numMipmapLevels(numMipmapLevels), |
|---|
| 827 | _internalFormat(internalFormat), |
|---|
| 828 | _width(width), |
|---|
| 829 | _height(height), |
|---|
| 830 | _depth(depth), |
|---|
| [10589] | 831 | _border(border), |
|---|
| 832 | _size(0) { computeSize(); } |
|---|
| [10588] | 833 | |
|---|
| 834 | |
|---|
| 835 | #define LESSTHAN(A,B) if (A<B) return true; if (B<A) return false; |
|---|
| 836 | #define FINALLESSTHAN(A,B) return (A<B); |
|---|
| 837 | |
|---|
| 838 | bool operator < (const TextureProfile& rhs) const |
|---|
| 839 | { |
|---|
| [10589] | 840 | LESSTHAN(_size,rhs._size); |
|---|
| [10588] | 841 | LESSTHAN(_target,rhs._target); |
|---|
| 842 | LESSTHAN(_numMipmapLevels,rhs._numMipmapLevels); |
|---|
| 843 | LESSTHAN(_internalFormat,rhs._internalFormat); |
|---|
| 844 | LESSTHAN(_width,rhs._width); |
|---|
| 845 | LESSTHAN(_height,rhs._height); |
|---|
| 846 | LESSTHAN(_depth,rhs._depth); |
|---|
| 847 | FINALLESSTHAN(_border, rhs._border); |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | bool operator == (const TextureProfile& rhs) const |
|---|
| 851 | { |
|---|
| 852 | return _target == rhs._target && |
|---|
| 853 | _numMipmapLevels == rhs._numMipmapLevels && |
|---|
| 854 | _internalFormat == rhs._internalFormat && |
|---|
| 855 | _width == rhs._width && |
|---|
| 856 | _height == rhs._height && |
|---|
| 857 | _depth == rhs._depth && |
|---|
| 858 | _border == rhs._border; |
|---|
| 859 | } |
|---|
| 860 | |
|---|
| 861 | inline void set(GLint numMipmapLevels, |
|---|
| 862 | GLenum internalFormat, |
|---|
| 863 | GLsizei width, |
|---|
| 864 | GLsizei height, |
|---|
| 865 | GLsizei depth, |
|---|
| 866 | GLint border) |
|---|
| 867 | { |
|---|
| 868 | _numMipmapLevels = numMipmapLevels; |
|---|
| 869 | _internalFormat = internalFormat; |
|---|
| 870 | _width = width; |
|---|
| 871 | _height = height; |
|---|
| 872 | _depth = depth; |
|---|
| 873 | _border = border; |
|---|
| 874 | } |
|---|
| 875 | |
|---|
| [2022] | 876 | inline bool match(GLenum target, |
|---|
| 877 | GLint numMipmapLevels, |
|---|
| 878 | GLenum internalFormat, |
|---|
| 879 | GLsizei width, |
|---|
| 880 | GLsizei height, |
|---|
| 881 | GLsizei depth, |
|---|
| 882 | GLint border) |
|---|
| 883 | { |
|---|
| [10588] | 884 | return (_target == target) && |
|---|
| [2022] | 885 | (_numMipmapLevels == numMipmapLevels) && |
|---|
| 886 | (_internalFormat == internalFormat) && |
|---|
| 887 | (_width == width) && |
|---|
| 888 | (_height == height) && |
|---|
| 889 | (_depth == depth) && |
|---|
| 890 | (_border == border); |
|---|
| 891 | } |
|---|
| [10588] | 892 | |
|---|
| [10589] | 893 | void computeSize(); |
|---|
| 894 | |
|---|
| 895 | GLenum _target; |
|---|
| 896 | GLint _numMipmapLevels; |
|---|
| 897 | GLenum _internalFormat; |
|---|
| 898 | GLsizei _width; |
|---|
| 899 | GLsizei _height; |
|---|
| 900 | GLsizei _depth; |
|---|
| 901 | GLint _border; |
|---|
| 902 | unsigned int _size; |
|---|
| [10588] | 903 | }; |
|---|
| 904 | |
|---|
| 905 | // forward declare |
|---|
| 906 | class TextureObjectSet; |
|---|
| 907 | class TextureObjectManager; |
|---|
| 908 | |
|---|
| [10591] | 909 | class OSG_EXPORT TextureObject : public osg::Referenced |
|---|
| [10588] | 910 | { |
|---|
| 911 | public: |
|---|
| 912 | |
|---|
| 913 | inline TextureObject(Texture* texture, GLuint id, GLenum target): |
|---|
| 914 | _id(id), |
|---|
| 915 | _profile(target), |
|---|
| 916 | _set(0), |
|---|
| 917 | _previous(0), |
|---|
| 918 | _next(0), |
|---|
| 919 | _texture(texture), |
|---|
| 920 | _allocated(false), |
|---|
| 921 | _timeStamp(0) {} |
|---|
| 922 | |
|---|
| 923 | inline TextureObject(Texture* texture, GLuint id, const TextureProfile& profile): |
|---|
| 924 | _id(id), |
|---|
| 925 | _profile(profile), |
|---|
| 926 | _set(0), |
|---|
| 927 | _previous(0), |
|---|
| 928 | _next(0), |
|---|
| 929 | _texture(texture), |
|---|
| 930 | _allocated(false), |
|---|
| 931 | _timeStamp(0) {} |
|---|
| 932 | |
|---|
| 933 | inline TextureObject(Texture* texture, |
|---|
| 934 | GLuint id, |
|---|
| 935 | GLenum target, |
|---|
| 936 | GLint numMipmapLevels, |
|---|
| 937 | GLenum internalFormat, |
|---|
| 938 | GLsizei width, |
|---|
| 939 | GLsizei height, |
|---|
| 940 | GLsizei depth, |
|---|
| 941 | GLint border): |
|---|
| 942 | _id(id), |
|---|
| 943 | _profile(target,numMipmapLevels,internalFormat,width,height,depth,border), |
|---|
| 944 | _set(0), |
|---|
| 945 | _previous(0), |
|---|
| 946 | _next(0), |
|---|
| 947 | _texture(texture), |
|---|
| 948 | _allocated(false), |
|---|
| 949 | _timeStamp(0) {} |
|---|
| 950 | |
|---|
| 951 | inline bool match(GLenum target, |
|---|
| 952 | GLint numMipmapLevels, |
|---|
| 953 | GLenum internalFormat, |
|---|
| 954 | GLsizei width, |
|---|
| 955 | GLsizei height, |
|---|
| 956 | GLsizei depth, |
|---|
| 957 | GLint border) |
|---|
| [2022] | 958 | { |
|---|
| [10588] | 959 | return isReusable() && |
|---|
| 960 | _profile.match(target,numMipmapLevels,internalFormat,width,height,depth,border); |
|---|
| [2022] | 961 | } |
|---|
| [1073] | 962 | |
|---|
| [10588] | 963 | void bind(); |
|---|
| [2022] | 964 | |
|---|
| [10588] | 965 | inline GLenum id() const { return _id; } |
|---|
| 966 | inline GLenum target() const { return _profile._target; } |
|---|
| 967 | |
|---|
| [10589] | 968 | inline unsigned int size() const { return _profile._size; } |
|---|
| 969 | |
|---|
| [10588] | 970 | inline void setTexture(Texture* texture) { _texture = texture; } |
|---|
| 971 | inline Texture* getTexture() const { return _texture; } |
|---|
| 972 | |
|---|
| 973 | inline void setTimeStamp(double timestamp) { _timeStamp = timestamp; } |
|---|
| 974 | inline double getTimeStamp() const { return _timeStamp; } |
|---|
| 975 | |
|---|
| [2022] | 976 | inline void setAllocated(bool allocated=true) { _allocated = allocated; } |
|---|
| [10588] | 977 | |
|---|
| [10597] | 978 | void setAllocated(GLint numMipmapLevels, |
|---|
| [2022] | 979 | GLenum internalFormat, |
|---|
| 980 | GLsizei width, |
|---|
| 981 | GLsizei height, |
|---|
| 982 | GLsizei depth, |
|---|
| [10597] | 983 | GLint border); |
|---|
| [10588] | 984 | |
|---|
| [2022] | 985 | inline bool isAllocated() const { return _allocated; } |
|---|
| 986 | |
|---|
| [10588] | 987 | inline bool isReusable() const { return _allocated && _profile._width!=0; } |
|---|
| [2022] | 988 | |
|---|
| 989 | |
|---|
| [10588] | 990 | GLuint _id; |
|---|
| 991 | TextureProfile _profile; |
|---|
| 992 | TextureObjectSet* _set; |
|---|
| 993 | TextureObject* _previous; |
|---|
| 994 | TextureObject* _next; |
|---|
| 995 | Texture* _texture; |
|---|
| 996 | bool _allocated; |
|---|
| [10594] | 997 | unsigned int _frameLastUsed; |
|---|
| [10588] | 998 | double _timeStamp; |
|---|
| [2022] | 999 | }; |
|---|
| [10588] | 1000 | |
|---|
| [2022] | 1001 | typedef std::list< ref_ptr<TextureObject> > TextureObjectList; |
|---|
| 1002 | |
|---|
| [10601] | 1003 | class OSG_EXPORT TextureObjectSet : public Referenced |
|---|
| [10588] | 1004 | { |
|---|
| 1005 | public: |
|---|
| 1006 | TextureObjectSet(TextureObjectManager* parent, const TextureProfile& profile); |
|---|
| [2022] | 1007 | |
|---|
| [10588] | 1008 | void handlePendingOrphandedTextureObjects(); |
|---|
| 1009 | void flushAllDeletedTextureObjects(); |
|---|
| 1010 | void discardAllDeletedTextureObjects(); |
|---|
| 1011 | void flushDeletedTextureObjects(double currentTime, double& availableTime); |
|---|
| 1012 | |
|---|
| [10594] | 1013 | TextureObject* takeFromOrphans(Texture* texture); |
|---|
| [10588] | 1014 | TextureObject* takeOrGenerate(Texture* texture); |
|---|
| 1015 | void moveToBack(TextureObject* to); |
|---|
| 1016 | void addToBack(TextureObject* to); |
|---|
| 1017 | void orphan(TextureObject* to); |
|---|
| [10597] | 1018 | void remove(TextureObject* to); |
|---|
| 1019 | |
|---|
| [10589] | 1020 | unsigned int size() const { return _profile._size * _numOfTextureObjects; } |
|---|
| [10588] | 1021 | |
|---|
| [10589] | 1022 | bool makeSpace(unsigned int& size); |
|---|
| 1023 | |
|---|
| [10588] | 1024 | bool checkConsistency() const; |
|---|
| 1025 | |
|---|
| [10597] | 1026 | TextureObjectManager* getParent() { return _parent; } |
|---|
| 1027 | |
|---|
| [10588] | 1028 | protected: |
|---|
| 1029 | |
|---|
| 1030 | virtual ~TextureObjectSet(); |
|---|
| 1031 | |
|---|
| 1032 | OpenThreads::Mutex _mutex; |
|---|
| 1033 | |
|---|
| 1034 | TextureObjectManager* _parent; |
|---|
| 1035 | unsigned int _contextID; |
|---|
| 1036 | TextureProfile _profile; |
|---|
| 1037 | unsigned int _numOfTextureObjects; |
|---|
| 1038 | TextureObjectList _orphanedTextureObjects; |
|---|
| 1039 | TextureObjectList _pendingOrphanedTextureObjects; |
|---|
| 1040 | |
|---|
| 1041 | TextureObject* _head; |
|---|
| 1042 | TextureObject* _tail; |
|---|
| 1043 | |
|---|
| 1044 | }; |
|---|
| 1045 | |
|---|
| [10591] | 1046 | class OSG_EXPORT TextureObjectManager : public osg::Referenced |
|---|
| [10588] | 1047 | { |
|---|
| 1048 | public: |
|---|
| 1049 | TextureObjectManager(unsigned int contextID); |
|---|
| 1050 | |
|---|
| 1051 | unsigned int getContextID() const { return _contextID; } |
|---|
| 1052 | |
|---|
| [10594] | 1053 | |
|---|
| 1054 | |
|---|
| 1055 | void setNumberActiveTextureObjects(unsigned int size) { _numActiveTextureObjects = size; } |
|---|
| 1056 | unsigned int& getNumberActiveTextureObjects() { return _numActiveTextureObjects; } |
|---|
| 1057 | unsigned int getNumberActiveTextureObjects() const { return _numActiveTextureObjects; } |
|---|
| 1058 | |
|---|
| 1059 | void setNumberOrphanedTextureObjects(unsigned int size) { _numOrphanedTextureObjects = size; } |
|---|
| 1060 | unsigned int& getNumberOrphanedTextureObjects() { return _numOrphanedTextureObjects; } |
|---|
| 1061 | unsigned int getNumberOrphanedTextureObjects() const { return _numOrphanedTextureObjects; } |
|---|
| 1062 | |
|---|
| [10589] | 1063 | void setCurrTexturePoolSize(unsigned int size) { _currTexturePoolSize = size; } |
|---|
| [10594] | 1064 | unsigned int& getCurrTexturePoolSize() { return _currTexturePoolSize; } |
|---|
| [10589] | 1065 | unsigned int getCurrTexturePoolSize() const { return _currTexturePoolSize; } |
|---|
| [10588] | 1066 | |
|---|
| [10589] | 1067 | void setMaxTexturePoolSize(unsigned int size); |
|---|
| 1068 | unsigned int getMaxTexturePoolSize() const { return _maxTexturePoolSize; } |
|---|
| 1069 | |
|---|
| 1070 | bool hasSpace(unsigned int size) const { return (_currTexturePoolSize+size)<=_maxTexturePoolSize; } |
|---|
| 1071 | bool makeSpace(unsigned int size); |
|---|
| 1072 | |
|---|
| [10588] | 1073 | TextureObject* generateTextureObject(const Texture* texture, GLenum target); |
|---|
| 1074 | TextureObject* generateTextureObject(const Texture* texture, |
|---|
| 1075 | GLenum target, |
|---|
| 1076 | GLint numMipmapLevels, |
|---|
| 1077 | GLenum internalFormat, |
|---|
| 1078 | GLsizei width, |
|---|
| 1079 | GLsizei height, |
|---|
| 1080 | GLsizei depth, |
|---|
| 1081 | GLint border); |
|---|
| 1082 | void handlePendingOrphandedTextureObjects(); |
|---|
| 1083 | void flushAllDeletedTextureObjects(); |
|---|
| 1084 | void discardAllDeletedTextureObjects(); |
|---|
| 1085 | void flushDeletedTextureObjects(double currentTime, double& availableTime); |
|---|
| 1086 | void releaseTextureObject(TextureObject* to); |
|---|
| 1087 | |
|---|
| [10597] | 1088 | TextureObjectSet* getTextureObjectSet(const TextureProfile& profile); |
|---|
| [10594] | 1089 | |
|---|
| 1090 | void newFrame(osg::FrameStamp* fs); |
|---|
| 1091 | void resetStats(); |
|---|
| 1092 | void reportStats(); |
|---|
| 1093 | |
|---|
| 1094 | unsigned int& getFrameNumber() { return _frameNumber; } |
|---|
| 1095 | unsigned int& getNumberFrames() { return _numFrames; } |
|---|
| 1096 | |
|---|
| 1097 | unsigned int& getNumberDeleted() { return _numDeleted; } |
|---|
| 1098 | double& getDeleteTime() { return _deleteTime; } |
|---|
| 1099 | |
|---|
| 1100 | unsigned int& getNumberGenerated() { return _numGenerated; } |
|---|
| 1101 | double& getGenerateTime() { return _generateTime; } |
|---|
| 1102 | |
|---|
| 1103 | unsigned int& getNumberApplied() { return _numApplied; } |
|---|
| 1104 | double& getApplyTime() { return _applyTime; } |
|---|
| 1105 | |
|---|
| 1106 | |
|---|
| [10588] | 1107 | protected: |
|---|
| 1108 | |
|---|
| 1109 | typedef std::map< TextureProfile, osg::ref_ptr<TextureObjectSet> > TextureSetMap; |
|---|
| 1110 | unsigned int _contextID; |
|---|
| [10594] | 1111 | unsigned int _numActiveTextureObjects; |
|---|
| 1112 | unsigned int _numOrphanedTextureObjects; |
|---|
| [10589] | 1113 | unsigned int _currTexturePoolSize; |
|---|
| 1114 | unsigned int _maxTexturePoolSize; |
|---|
| [10588] | 1115 | TextureSetMap _textureSetMap; |
|---|
| [10594] | 1116 | |
|---|
| 1117 | unsigned int _frameNumber; |
|---|
| 1118 | |
|---|
| 1119 | unsigned int _numFrames; |
|---|
| 1120 | unsigned int _numDeleted; |
|---|
| 1121 | double _deleteTime; |
|---|
| 1122 | |
|---|
| 1123 | unsigned int _numGenerated; |
|---|
| 1124 | double _generateTime; |
|---|
| 1125 | |
|---|
| 1126 | unsigned int _numApplied; |
|---|
| 1127 | double _applyTime; |
|---|
| 1128 | |
|---|
| [10588] | 1129 | }; |
|---|
| 1130 | |
|---|
| 1131 | static osg::ref_ptr<Texture::TextureObjectManager>& getTextureObjectManager(unsigned int contextID); |
|---|
| 1132 | |
|---|
| 1133 | static TextureObject* generateTextureObject(const Texture* texture, unsigned int contextID,GLenum target); |
|---|
| 1134 | |
|---|
| 1135 | static TextureObject* generateTextureObject(const Texture* texture, |
|---|
| 1136 | unsigned int contextID, |
|---|
| [3423] | 1137 | GLenum target, |
|---|
| 1138 | GLint numMipmapLevels, |
|---|
| 1139 | GLenum internalFormat, |
|---|
| 1140 | GLsizei width, |
|---|
| 1141 | GLsizei height, |
|---|
| 1142 | GLsizei depth, |
|---|
| 1143 | GLint border); |
|---|
| [2022] | 1144 | |
|---|
| 1145 | |
|---|
| [3423] | 1146 | /** Set the minimum number of texture objects to retain in the deleted display list cache. */ |
|---|
| 1147 | static void setMinimumNumberOfTextureObjectsToRetainInCache(unsigned int minimum); |
|---|
| [2022] | 1148 | |
|---|
| [3423] | 1149 | /** Get the minimum number of display lists to retain in the deleted display list cache. */ |
|---|
| 1150 | static unsigned int getMinimumNumberOfTextureObjectsToRetainInCache(); |
|---|
| [2022] | 1151 | |
|---|
| [3423] | 1152 | static void flushAllDeletedTextureObjects(unsigned int contextID); |
|---|
| [7773] | 1153 | |
|---|
| 1154 | static void discardAllDeletedTextureObjects(unsigned int contextID); |
|---|
| [10588] | 1155 | |
|---|
| [3423] | 1156 | static void flushDeletedTextureObjects(unsigned int contextID,double currentTime, double& availableTime); |
|---|
| [2022] | 1157 | |
|---|
| [10588] | 1158 | static void releaseTextureObject(unsigned int contextID, TextureObject* to); |
|---|
| [2036] | 1159 | |
|---|
| [3423] | 1160 | protected: |
|---|
| [2036] | 1161 | |
|---|
| [3423] | 1162 | typedef buffered_object< ref_ptr<TextureObject> > TextureObjectBuffer; |
|---|
| [4485] | 1163 | mutable TextureObjectBuffer _textureObjectBuffer; |
|---|
| 1164 | mutable ref_ptr<GraphicsContext> _readPBuffer; |
|---|
| [2022] | 1165 | |
|---|
| [1099] | 1166 | }; |
|---|
| [1073] | 1167 | |
|---|
| 1168 | } |
|---|
| 1169 | |
|---|
| [1078] | 1170 | #endif |
|---|