19 #include <osg/StateAttribute>
20 #include <osg/GraphicsContext>
21 #include <osg/ref_ptr>
25 #include <osg/buffered_value>
26 #include <osg/GLExtensions>
33 #ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
34 #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
39 #ifndef GL_TEXTURE_SWIZZLE_RGBA
40 #define GL_TEXTURE_SWIZZLE_RGBA 0x8E46
43 #ifndef GL_ARB_texture_compression
44 #define GL_COMPRESSED_ALPHA_ARB 0x84E9
45 #define GL_COMPRESSED_LUMINANCE_ARB 0x84EA
46 #define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB
47 #define GL_COMPRESSED_INTENSITY_ARB 0x84EC
48 #define GL_COMPRESSED_RGB_ARB 0x84ED
49 #define GL_COMPRESSED_RGBA_ARB 0x84EE
50 #define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF
51 #define GL_TEXTURE_COMPRESSED_ARB 0x86A1
52 #define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2
53 #define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3
56 #ifndef GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB
57 #define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0
60 #ifndef GL_EXT_texture_compression_s3tc
61 #define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
62 #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
63 #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
64 #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
67 #ifndef GL_EXT_texture_compression_rgtc
68 #define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB
69 #define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC
70 #define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD
71 #define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE
74 #ifndef GL_IMG_texture_compression_pvrtc
75 #define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
76 #define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
77 #define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
78 #define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
81 #ifndef GL_OES_compressed_ETC1_RGB8_texture
82 #define GL_ETC1_RGB8_OES 0x8D64
85 #ifndef GL_ARB_INTERNAL_TEXTURE_FORMAT
86 #define GL_RGBA32F_ARB 0x8814
87 #define GL_RGB32F_ARB 0x8815
88 #define GL_ALPHA32F_ARB 0x8816
89 #define GL_INTENSITY32F_ARB 0x8817
90 #define GL_LUMINANCE32F_ARB 0x8818
91 #define GL_LUMINANCE_ALPHA32F_ARB 0x8819
92 #define GL_RGBA16F_ARB 0x881A
93 #define GL_RGB16F_ARB 0x881B
94 #define GL_ALPHA16F_ARB 0x881C
95 #define GL_INTENSITY16F_ARB 0x881D
96 #define GL_LUMINANCE16F_ARB 0x881E
97 #define GL_LUMINANCE_ALPHA16F_ARB 0x881F
100 #ifndef GL_HALF_FLOAT
101 #define GL_HALF_FLOAT 0x140B
104 #ifndef GL_NV_texture_shader
105 #define GL_HILO_NV 0x86F4
106 #define GL_DSDT_NV 0x86F5
107 #define GL_DSDT_MAG_NV 0x86F6
108 #define GL_DSDT_MAG_VIB_NV 0x86F7
109 #define GL_HILO16_NV 0x86F8
110 #define GL_SIGNED_HILO_NV 0x86F9
111 #define GL_SIGNED_HILO16_NV 0x86FA
112 #define GL_SIGNED_RGBA_NV 0x86FB
113 #define GL_SIGNED_RGBA8_NV 0x86FC
114 #define GL_SIGNED_RGB_NV 0x86FE
115 #define GL_SIGNED_RGB8_NV 0x86FF
116 #define GL_SIGNED_LUMINANCE_NV 0x8701
117 #define GL_SIGNED_LUMINANCE8_NV 0x8702
118 #define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703
119 #define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704
120 #define GL_SIGNED_ALPHA_NV 0x8705
121 #define GL_SIGNED_ALPHA8_NV 0x8706
122 #define GL_SIGNED_INTENSITY_NV 0x8707
123 #define GL_SIGNED_INTENSITY8_NV 0x8708
124 #define GL_DSDT8_NV 0x8709
125 #define GL_DSDT8_MAG8_NV 0x870A
126 #define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B
127 #define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C
128 #define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D
131 #ifndef GL_NV_float_buffer
132 #define GL_FLOAT_R_NV 0x8880
133 #define GL_FLOAT_RG_NV 0x8881
134 #define GL_FLOAT_RGB_NV 0x8882
135 #define GL_FLOAT_RGBA_NV 0x8883
136 #define GL_FLOAT_R16_NV 0x8884
137 #define GL_FLOAT_R32_NV 0x8885
138 #define GL_FLOAT_RG16_NV 0x8886
139 #define GL_FLOAT_RG32_NV 0x8887
140 #define GL_FLOAT_RGB16_NV 0x8888
141 #define GL_FLOAT_RGB32_NV 0x8889
142 #define GL_FLOAT_RGBA16_NV 0x888A
143 #define GL_FLOAT_RGBA32_NV 0x888B
146 #ifndef GL_ATI_texture_float
147 #define GL_RGBA_FLOAT32_ATI 0x8814
148 #define GL_RGB_FLOAT32_ATI 0x8815
149 #define GL_ALPHA_FLOAT32_ATI 0x8816
150 #define GL_INTENSITY_FLOAT32_ATI 0x8817
151 #define GL_LUMINANCE_FLOAT32_ATI 0x8818
152 #define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819
153 #define GL_RGBA_FLOAT16_ATI 0x881A
154 #define GL_RGB_FLOAT16_ATI 0x881B
155 #define GL_ALPHA_FLOAT16_ATI 0x881C
156 #define GL_INTENSITY_FLOAT16_ATI 0x881D
157 #define GL_LUMINANCE_FLOAT16_ATI 0x881E
158 #define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F
161 #ifndef GL_MIRRORED_REPEAT_IBM
162 #define GL_MIRRORED_REPEAT_IBM 0x8370
165 #ifndef GL_CLAMP_TO_EDGE
166 #define GL_CLAMP_TO_EDGE 0x812F
170 #define GL_CLAMP 0x2900
173 #ifndef GL_CLAMP_TO_BORDER_ARB
174 #define GL_CLAMP_TO_BORDER_ARB 0x812D
179 #define GL_INTENSITY 0x8049
182 #ifndef GL_GENERATE_MIPMAP_SGIS
183 #define GL_GENERATE_MIPMAP_SGIS 0x8191
184 #define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192
187 #ifndef GL_TEXTURE_3D
188 #define GL_TEXTURE_3D 0x806F
192 #ifndef GL_TEXTURE_CUBE_MAP
193 #define GL_TEXTURE_CUBE_MAP 0x8513
194 #define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
195 #define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
196 #define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
197 #define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
198 #define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
199 #define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
200 #define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
201 #define GL_PROXY_TEXTURE_CUBE_MAP 0x851B
202 #define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
205 #ifndef GL_TEXTURE_BINDING_3D
206 #define GL_TEXTURE_BINDING_3D 0x806A
209 #ifndef GL_DEPTH_TEXTURE_MODE_ARB
210 #define GL_DEPTH_TEXTURE_MODE_ARB 0x884B
213 #ifndef GL_TEXTURE_COMPARE_MODE_ARB
214 #define GL_TEXTURE_COMPARE_MODE_ARB 0x884C
216 #ifndef GL_TEXTURE_COMPARE_FUNC_ARB
217 #define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D
219 #ifndef GL_COMPARE_R_TO_TEXTURE_ARB
220 #define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E
223 #ifndef TEXTURE_COMPARE_FAIL_VALUE_ARB
224 #define TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF
227 #if !defined( GL_MAX_TEXTURE_UNITS )
228 #define GL_MAX_TEXTURE_UNITS 0x84E2
231 #ifndef GL_TEXTURE_DEPTH
232 #define GL_TEXTURE_DEPTH 0x8071
235 #ifndef GL_TEXTURE_2D_MULTISAMPLE
236 #define GL_TEXTURE_2D_MULTISAMPLE 0x9100
240 #ifndef GL_EXT_texture_integer
241 #define GL_RGBA32UI_EXT 0x8D70
242 #define GL_RGB32UI_EXT 0x8D71
243 #define GL_ALPHA32UI_EXT 0x8D72
244 #define GL_INTENSITY32UI_EXT 0x8D73
245 #define GL_LUMINANCE32UI_EXT 0x8D74
246 #define GL_LUMINANCE_ALPHA32UI_EXT 0x8D75
248 #define GL_RGBA16UI_EXT 0x8D76
249 #define GL_RGB16UI_EXT 0x8D77
250 #define GL_ALPHA16UI_EXT 0x8D78
251 #define GL_INTENSITY16UI_EXT 0x8D79
252 #define GL_LUMINANCE16UI_EXT 0x8D7A
253 #define GL_LUMINANCE_ALPHA16UI_EXT 0x8D7B
255 #define GL_RGBA8UI_EXT 0x8D7C
256 #define GL_RGB8UI_EXT 0x8D7D
257 #define GL_ALPHA8UI_EXT 0x8D7E
258 #define GL_INTENSITY8UI_EXT 0x8D7F
259 #define GL_LUMINANCE8UI_EXT 0x8D80
260 #define GL_LUMINANCE_ALPHA8UI_EXT 0x8D81
262 #define GL_RGBA32I_EXT 0x8D82
263 #define GL_RGB32I_EXT 0x8D83
264 #define GL_ALPHA32I_EXT 0x8D84
265 #define GL_INTENSITY32I_EXT 0x8D85
266 #define GL_LUMINANCE32I_EXT 0x8D86
267 #define GL_LUMINANCE_ALPHA32I_EXT 0x8D87
269 #define GL_RGBA16I_EXT 0x8D88
270 #define GL_RGB16I_EXT 0x8D89
271 #define GL_ALPHA16I_EXT 0x8D8A
272 #define GL_INTENSITY16I_EXT 0x8D8B
273 #define GL_LUMINANCE16I_EXT 0x8D8C
274 #define GL_LUMINANCE_ALPHA16I_EXT 0x8D8D
276 #define GL_RGBA8I_EXT 0x8D8E
277 #define GL_RGB8I_EXT 0x8D8F
278 #define GL_ALPHA8I_EXT 0x8D90
279 #define GL_INTENSITY8I_EXT 0x8D91
280 #define GL_LUMINANCE8I_EXT 0x8D92
281 #define GL_LUMINANCE_ALPHA8I_EXT 0x8D93
283 #define GL_RED_INTEGER_EXT 0x8D94
284 #define GL_GREEN_INTEGER_EXT 0x8D95
285 #define GL_BLUE_INTEGER_EXT 0x8D96
286 #define GL_ALPHA_INTEGER_EXT 0x8D97
287 #define GL_RGB_INTEGER_EXT 0x8D98
288 #define GL_RGBA_INTEGER_EXT 0x8D99
289 #define GL_BGR_INTEGER_EXT 0x8D9A
290 #define GL_BGRA_INTEGER_EXT 0x8D9B
291 #define GL_LUMINANCE_INTEGER_EXT 0x8D9C
292 #define GL_LUMINANCE_ALPHA_INTEGER_EXT 0x8D9D
294 #define GL_RGBA_INTEGER_MODE_EXT 0x8D9E
297 #ifndef GL_VERSION_1_1
298 #define GL_R3_G3_B2 0x2A10
299 #define GL_RGB4 0x804F
300 #define GL_RGB5 0x8050
301 #define GL_RGB8 0x8051
302 #define GL_RGB10 0x8052
303 #define GL_RGB12 0x8053
304 #define GL_RGB16 0x8054
305 #define GL_RGBA2 0x8055
306 #define GL_RGBA4 0x8056
307 #define GL_RGB5_A1 0x8057
308 #define GL_RGBA8 0x8058
309 #define GL_RGB10_A2 0x8059
310 #define GL_RGBA12 0x805A
311 #define GL_RGBA16 0x805B
312 #define GL_BGR_EXT 0x80E0
313 #define GL_BGRA_EXT 0x80E1
316 #ifndef GL_ARB_texture_rg
318 #define GL_RG_INTEGER 0x8228
320 #define GL_R16 0x822A
321 #define GL_RG8 0x822B
322 #define GL_RG16 0x822C
323 #define GL_R16F 0x822D
324 #define GL_R32F 0x822E
325 #define GL_RG16F 0x822F
326 #define GL_RG32F 0x8230
327 #define GL_R8I 0x8231
328 #define GL_R8UI 0x8232
329 #define GL_R16I 0x8233
330 #define GL_R16UI 0x8234
331 #define GL_R32I 0x8235
332 #define GL_R32UI 0x8236
333 #define GL_RG8I 0x8237
334 #define GL_RG8UI 0x8238
335 #define GL_RG16I 0x8239
336 #define GL_RG16UI 0x823A
337 #define GL_RG32I 0x823B
338 #define GL_RG32UI 0x823C
341 #ifndef GL_ARB_shader_image_load_store
342 #define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001
343 #define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002
344 #define GL_UNIFORM_BARRIER_BIT 0x00000004
345 #define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008
346 #define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020
347 #define GL_COMMAND_BARRIER_BIT 0x00000040
348 #define GL_PIXEL_BUFFER_BARRIER_BIT 0x00000080
349 #define GL_TEXTURE_UPDATE_BARRIER_BIT 0x00000100
350 #define GL_BUFFER_UPDATE_BARRIER_BIT 0x00000200
351 #define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400
352 #define GL_TRANSFORM_FEEDBACK_BARRIER_BIT 0x00000800
353 #define GL_ATOMIC_COUNTER_BARRIER_BIT 0x00001000
354 #define GL_ALL_BARRIER_BITS 0xFFFFFFFF
355 #define GL_MAX_IMAGE_UNITS 0x8F38
356 #define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS 0x8F39
357 #define GL_IMAGE_BINDING_NAME 0x8F3A
358 #define GL_IMAGE_BINDING_LEVEL 0x8F3B
359 #define GL_IMAGE_BINDING_LAYERED 0x8F3C
360 #define GL_IMAGE_BINDING_LAYER 0x8F3D
361 #define GL_IMAGE_BINDING_ACCESS 0x8F3E
362 #define GL_IMAGE_1D 0x904C
363 #define GL_IMAGE_2D 0x904D
364 #define GL_IMAGE_3D 0x904E
365 #define GL_IMAGE_2D_RECT 0x904F
366 #define GL_IMAGE_CUBE 0x9050
367 #define GL_IMAGE_BUFFER 0x9051
368 #define GL_IMAGE_1D_ARRAY 0x9052
369 #define GL_IMAGE_2D_ARRAY 0x9053
370 #define GL_IMAGE_CUBE_MAP_ARRAY 0x9054
371 #define GL_IMAGE_2D_MULTISAMPLE 0x9055
372 #define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056
373 #define GL_INT_IMAGE_1D 0x9057
374 #define GL_INT_IMAGE_2D 0x9058
375 #define GL_INT_IMAGE_3D 0x9059
376 #define GL_INT_IMAGE_2D_RECT 0x905A
377 #define GL_INT_IMAGE_CUBE 0x905B
378 #define GL_INT_IMAGE_BUFFER 0x905C
379 #define GL_INT_IMAGE_1D_ARRAY 0x905D
380 #define GL_INT_IMAGE_2D_ARRAY 0x905E
381 #define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F
382 #define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060
383 #define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061
384 #define GL_UNSIGNED_INT_IMAGE_1D 0x9062
385 #define GL_UNSIGNED_INT_IMAGE_2D 0x9063
386 #define GL_UNSIGNED_INT_IMAGE_3D 0x9064
387 #define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065
388 #define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066
389 #define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067
390 #define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068
391 #define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069
392 #define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A
393 #define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B
394 #define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C
395 #define GL_MAX_IMAGE_SAMPLES 0x906D
396 #define GL_IMAGE_BINDING_FORMAT 0x906E
397 #define GL_IMAGE_FORMAT_COMPATIBILITY_TYPE 0x90C7
398 #define GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE 0x90C8
399 #define GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS 0x90C9
400 #define GL_MAX_VERTEX_IMAGE_UNIFORMS 0x90CA
401 #define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS 0x90CB
402 #define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS 0x90CC
403 #define GL_MAX_GEOMETRY_IMAGE_UNIFORMS 0x90CD
404 #define GL_MAX_FRAGMENT_IMAGE_UNIFORMS 0x90CE
405 #define GL_MAX_COMBINED_IMAGE_UNIFORMS 0x90CF
428 virtual const char*
className()
const {
return "Texture"; }
440 virtual GLenum getTextureTarget()
const = 0;
444 #ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
469 void setWrap(WrapParameter which, WrapMode wrap);
471 WrapMode getWrap(WrapParameter which)
const;
494 LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR,
495 LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
496 NEAREST = GL_NEAREST,
497 NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
498 NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST
502 void setFilter(FilterParameter which, FilterMode filter);
505 FilterMode getFilter(FilterParameter which)
const;
512 void setMaxAnisotropy(
float anis);
518 inline void setSwizzle(
const Vec4i& swizzle) { _swizzle = swizzle; dirtyTextureParameters(); };
570 USE_S3TC_DXT1a_COMPRESSION
587 _internalFormatMode = USE_USER_DEFINED_FORMAT;
589 computeInternalFormatType();
594 inline GLint
getInternalFormat()
const {
if (_internalFormat==0) computeInternalFormat();
return _internalFormat; }
597 bool isCompressedInternalFormat()
const;
621 SIGNED_INTEGER = 0x2,
624 UNSIGNED_INTEGER = 0x4
635 return _textureObjectBuffer[contextID].get();
640 _textureObjectBuffer[contextID] = to;
645 void dirtyTextureObject();
649 bool areAllTextureObjectsLoaded()
const;
655 return _texParametersDirtyList[contextID];
661 void dirtyTextureParameters();
670 void allocateMipmapLevels();
683 : unit(0), level(0), layered(GL_FALSE), layer(0), access(0), format(0) {}
699 void bindToImageUnit(
unsigned int unit, GLenum access, GLenum
format=0,
int level=0,
bool layered=
false,
int layer=0);
714 GREATER = GL_GREATER,
715 NOTEQUAL = GL_NOTEQUAL,
725 LUMINANCE = GL_LUMINANCE,
741 virtual void setImage(
unsigned int face,
Image* image) = 0;
744 virtual Image* getImage(
unsigned int face) = 0;
747 virtual const Image* getImage(
unsigned int face)
const = 0;
750 virtual unsigned int getNumImages()
const = 0;
763 virtual void apply(
State& state)
const = 0;
766 virtual void compileGLObjects(
State& state)
const;
769 virtual void resizeGLObjectBuffers(
unsigned int maxSize);
774 virtual void releaseGLObjects(
State* state=0)
const;
789 void applyTexImage2D_load(
State& state, GLenum target,
const Image* image, GLsizei
width, GLsizei
height,GLsizei numMipmapLevels)
const;
794 void applyTexImage2D_subload(
State& state, GLenum target,
const Image* image, GLsizei
width, GLsizei
height, GLint inInternalFormat, GLsizei numMipmapLevels)
const;
803 GENERATE_MIPMAP_TEX_PARAMETER
810 virtual void computeInternalFormat()
const = 0;
813 void computeInternalFormatWithImage(
const osg::Image& image)
const;
816 void computeRequiredTextureDimensions(
State& state,
const osg::Image& image,GLsizei&
width, GLsizei&
height,GLsizei& numMipmapLevels)
const;
819 void computeInternalFormatType()
const;
822 void applyTexParameters(GLenum target,
State& state)
const;
826 bool isHardwareMipmapGenerationEnabled(
const State& state)
const;
830 return (_unrefImageDataAfterApply && state.
getMaxTexturePoolSize()==0 && areAllTextureObjectsLoaded());
835 GenerateMipmapMode mipmapBeforeTexImage(
const State& state,
bool hardwareMipmapOn)
const;
836 void mipmapAfterTexImage(
State& state, GenerateMipmapMode beforeResult)
const;
840 void generateMipmap(
State& state)
const;
843 virtual void allocateMipmap(
State& state)
const = 0;
846 int compareTexture(
const Texture& rhs)
const;
849 int compareTextureObjects(
const Texture& rhs)
const;
899 GLint numMipmapLevels,
906 _numMipmapLevels(numMipmapLevels),
907 _internalFormat(internalFormat),
912 _size(0) { computeSize(); }
915 #define LESSTHAN(A,B) if (A<B) return true; if (B<A) return false;
916 #define FINALLESSTHAN(A,B) return (A<B);
932 return _target == rhs.
_target &&
941 inline void set(GLint numMipmapLevels,
948 _numMipmapLevels = numMipmapLevels;
958 GLint numMipmapLevels,
965 return (_target == target) &&
966 (_numMipmapLevels == numMipmapLevels) &&
967 (_internalFormat == internalFormat) &&
969 (_height == height) &&
1017 GLint numMipmapLevels,
1024 _profile(target,numMipmapLevels,internalFormat,width,height,depth,border),
1033 GLint numMipmapLevels,
1040 return isReusable() &&
1041 _profile.match(target,numMipmapLevels,internalFormat,width,height,depth,border);
1047 inline GLenum
id()
const {
return _id; }
1048 inline GLenum
target()
const {
return _profile._target; }
1050 inline unsigned int size()
const {
return _profile._size; }
1060 void setAllocated(GLint numMipmapLevels,
1069 inline bool isReusable()
const {
return _allocated && _profile._width!=0; }
1096 void handlePendingOrphandedTextureObjects();
1098 void deleteAllTextureObjects();
1099 void discardAllTextureObjects();
1100 void flushAllDeletedTextureObjects();
1101 void discardAllDeletedTextureObjects();
1102 void flushDeletedTextureObjects(
double currentTime,
double& availableTime);
1112 unsigned int size()
const {
return _profile._size * _numOfTextureObjects; }
1114 bool makeSpace(
unsigned int& size);
1116 bool checkConsistency()
const;
1120 unsigned int computeNumTextureObjectsInList()
const;
1122 unsigned int getNumOrphans()
const {
return static_cast<unsigned int>(_orphanedTextureObjects.size()); }
1123 unsigned int getNumPendingOrphans()
const {
return static_cast<unsigned int>(_pendingOrphanedTextureObjects.size()); }
1164 void setMaxTexturePoolSize(
unsigned int size);
1167 bool hasSpace(
unsigned int size)
const {
return (_currTexturePoolSize+size)<=_maxTexturePoolSize; }
1168 bool makeSpace(
unsigned int size);
1173 GLint numMipmapLevels,
1179 void handlePendingOrphandedTextureObjects();
1180 void deleteAllTextureObjects();
1181 void discardAllTextureObjects();
1182 void flushAllDeletedTextureObjects();
1183 void discardAllDeletedTextureObjects();
1184 void flushDeletedTextureObjects(
double currentTime,
double& availableTime);
1191 void reportStats(std::ostream& out);
1192 void recomputeStats(std::ostream& out)
const;
1193 bool checkConsistency()
const;
1210 typedef std::map< TextureProfile, osg::ref_ptr<TextureObjectSet> >
TextureSetMap;
1237 unsigned int contextID,
1239 GLint numMipmapLevels,
1246 TextureObject* generateAndAssignTextureObject(
unsigned int contextID, GLenum target)
const;
1248 TextureObject* generateAndAssignTextureObject(
unsigned int contextID,
1250 GLint numMipmapLevels,
1257 static void deleteAllTextureObjects(
unsigned int contextID);
1258 static void discardAllTextureObjects(
unsigned int contextID);
1259 static void flushAllDeletedTextureObjects(
unsigned int contextID);
1260 static void discardAllDeletedTextureObjects(
unsigned int contextID);
1261 static void flushDeletedTextureObjects(
unsigned int contextID,
double currentTime,
double& availableTime);
1262 static void releaseTextureObject(
unsigned int contextID,
TextureObject* to);
virtual bool isTextureAttribute() const
unsigned int getNumOfTextureObjects() const
virtual bool isSameKindAs(const osg::Object *obj) const
void setInternalFormatMode(InternalFormatMode mode)
TextureProfile(GLenum target)
InternalFormatType _internalFormatType
GLint getBorderWidth() const
TexParameterDirtyList _texParametersDirtyList
unsigned int _numActiveTextureObjects
void setShadowTextureMode(ShadowTextureMode mode)
This class provides an object-oriented thread mutex interface.
bool getShadowComparison() const
void setTexture(Texture *texture)
unsigned int & getNumberDeleted()
virtual int getTextureHeight() const
unsigned int getNumPendingOrphans() const
GLint GLenum internalFormat
const GraphicsContext * getReadPBuffer() const
Texture * getTexture() const
TextureObjectBuffer _textureObjectBuffer
buffered_value< unsigned int > TexParameterDirtyList
#define GL_WRITE_ONLY_ARB
void setUseHardwareMipMapGeneration(bool useHardwareMipMapGeneration)
GLint GLenum GLsizei GLsizei GLsizei depth
bool _unrefImageDataAfterApply
GraphicsContext * getReadPBuffer()
unsigned int & getNumberOrphanedTextureObjects()
ref_ptr< GraphicsContext > _readPBuffer
OpenThreads::Mutex _mutex
bool _use_shadow_comparison
double & getGenerateTime()
TextureObject(Texture *texture, GLuint id, GLenum target, GLint numMipmapLevels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border)
virtual const Texture * asTexture() const
unsigned int getContextID() const
void setShadowComparison(bool flag)
InternalFormatType getInternalFormatType() const
unsigned int _numOrphanedTextureObjects
void setNumberOrphanedTextureObjects(unsigned int size)
void setTextureObject(unsigned int contextID, TextureObject *to)
bool match(GLenum target, GLint numMipmapLevels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border)
GLint getInternalFormat() const
unsigned int & getTextureParameterDirty(unsigned int contextID) const
TextureObjectManager * _parent
unsigned int getNumberOrphanedTextureObjects() const
TextureObject * _previous
void setNumberActiveTextureObjects(unsigned int size)
unsigned int _numOfTextureObjects
unsigned int _frameNumber
unsigned int & getFrameNumber()
InternalFormatMode _internalFormatMode
T * clone(const T *t, const osg::CopyOp ©op=osg::CopyOp::SHALLOW_COPY)
void setSwizzle(const Vec4i &swizzle)
TextureObject * getTextureObject(unsigned int contextID) const
TextureProfile(GLenum target, GLint numMipmapLevels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border)
virtual void usesTextureMode(GLMode mode)=0
#define GL_CLAMP_TO_BORDER_ARB
void set(GLint numMipmapLevels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border)
std::list< ref_ptr< TextureObject > > TextureObjectList
void setUnRefImageDataAfterApply(bool flag)
virtual Texture * asTexture()
bool _useHardwareMipMapGeneration
GLenum getSourceType() const
virtual const char * libraryName() const
bool getUnRefImageDataAfterApply() const
GLint GLenum GLsizei width
bool hasSpace(unsigned int size) const
unsigned int _maxTexturePoolSize
bool getClientStorageHint() const
TexParameterDirtyList _texMipmapGenerationDirtyList
void setShadowAmbient(float shadow_ambient)
void setTimeStamp(double timestamp)
T * cloneType(const T *t)
void setClientStorageHint(bool flag)
ImageAttachment _imageAttachment
bool _resizeNonPowerOfTwoHint
#define GL_MIRRORED_REPEAT_IBM
InternalFormatMode getInternalFormatMode() const
virtual int getTextureDepth() const
unsigned int getNumberActiveTextureObjects() const
#define FINALLESSTHAN(A, B)
float getMaxAnisotropy() const
bool getResizeNonPowerOfTwoHint() const
buffered_object< ref_ptr< TextureObject > > TextureObjectBuffer
TextureObject(Texture *texture, GLuint id, const TextureProfile &profile)
bool match(GLenum target, GLint numMipmapLevels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border)
TextureObject(Texture *texture, GLuint id, GLenum target)
void setAllocated(bool allocated=true)
unsigned int _numGenerated
ShadowCompareFunc _shadow_compare_func
void setCurrTexturePoolSize(unsigned int size)
unsigned int & getCurrTexturePoolSize()
const ImageAttachment & getImageAttachment() const
GLint GLenum GLsizei GLsizei height
unsigned int & getNumberGenerated()
const Vec4d & getBorderColor() const
void setSourceType(GLenum sourceType)
void setReadPBuffer(GraphicsContext *context)
bool getUseHardwareMipMapGeneration() const
unsigned int getMaxTexturePoolSize() const
virtual int getTextureWidth() const
unsigned int getCurrTexturePoolSize() const
unsigned int & getNumberApplied()
double getTimeStamp() const
TextureObjectList _orphanedTextureObjects
#define GL_READ_WRITE_ARB
unsigned int & getNumberActiveTextureObjects()
void setInternalFormat(GLint internalFormat)
bool isSafeToUnrefImageData(const State &state) const
virtual const char * className() const
unsigned int size() const
unsigned int size() const
virtual Type getType() const
const Vec4i & getSwizzle() const
const TextureProfile & getProfile() const
GLenum getSourceFormat() const
unsigned int & getNumberFrames()
ShadowTextureMode getShadowTextureMode() const
unsigned int getNumOrphans() const
GLint GLenum GLsizei GLsizei GLsizei GLint border
unsigned int _frameLastUsed
ShadowCompareFunc getShadowCompareFunc() const
TextureSetMap _textureSetMap
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
void setShadowCompareFunc(ShadowCompareFunc func)
void setBorderColor(const Vec4d &color)
void setBorderWidth(GLint width)
TextureObjectList _pendingOrphanedTextureObjects
unsigned int _currTexturePoolSize
TextureObjectManager * getParent()
unsigned int getMaxTexturePoolSize() const
std::map< TextureProfile, osg::ref_ptr< TextureObjectSet > > TextureSetMap
void setResizeNonPowerOfTwoHint(bool flag)
float getShadowAmbient() const
void setSourceFormat(GLenum sourceFormat)
ImageAttachment & getImageAttachment()
ShadowTextureMode _shadow_texture_mode
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format