2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_TEXTURE
|
|
|
|
#define OSG_TEXTURE 1
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
#include <osg/GL>
|
|
|
|
#include <osg/Image>
|
|
|
|
#include <osg/StateAttribute>
|
2005-08-31 20:56:15 +08:00
|
|
|
#include <osg/GraphicsContext>
|
2002-08-28 23:28:11 +08:00
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <osg/Vec4>
|
2007-09-11 20:04:58 +08:00
|
|
|
#include <osg/Vec4d>
|
2013-06-03 23:10:53 +08:00
|
|
|
#include <osg/Vec4i>
|
2002-09-05 19:42:55 +08:00
|
|
|
#include <osg/buffered_value>
|
2009-11-13 17:56:47 +08:00
|
|
|
#include <osg/GL2Extensions>
|
2002-08-28 23:28:11 +08:00
|
|
|
|
2003-07-14 22:42:10 +08:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2002-08-28 23:28:11 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
// If not defined by gl.h use the definition found in:
|
2002-08-28 23:28:11 +08:00
|
|
|
// http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_filter_anisotropic.txt
|
|
|
|
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
2002-08-28 23:28:11 +08:00
|
|
|
#endif
|
|
|
|
|
2013-06-03 23:10:53 +08:00
|
|
|
// If not defined, use the definition found in:
|
|
|
|
// http://www.opengl.org/registry/specs/ARB/texture_swizzle.txt
|
|
|
|
#ifndef GL_TEXTURE_SWIZZLE_RGBA
|
|
|
|
#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46
|
|
|
|
#endif
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
#ifndef GL_ARB_texture_compression
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_COMPRESSED_ALPHA_ARB 0x84E9
|
|
|
|
#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA
|
|
|
|
#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB
|
|
|
|
#define GL_COMPRESSED_INTENSITY_ARB 0x84EC
|
|
|
|
#define GL_COMPRESSED_RGB_ARB 0x84ED
|
|
|
|
#define GL_COMPRESSED_RGBA_ARB 0x84EE
|
|
|
|
#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF
|
|
|
|
#define GL_TEXTURE_COMPRESSED_ARB 0x86A1
|
|
|
|
#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2
|
|
|
|
#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3
|
2002-08-28 23:28:11 +08:00
|
|
|
#endif
|
|
|
|
|
2003-05-26 17:29:59 +08:00
|
|
|
#ifndef GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0
|
2003-05-26 17:29:59 +08:00
|
|
|
#endif
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
#ifndef GL_EXT_texture_compression_s3tc
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
|
|
|
|
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
|
|
|
|
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
|
|
|
|
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
|
2002-08-28 23:28:11 +08:00
|
|
|
#endif
|
2004-03-14 23:08:12 +08:00
|
|
|
|
2010-08-16 22:11:49 +08:00
|
|
|
#ifndef GL_EXT_texture_compression_rgtc
|
|
|
|
#define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB
|
|
|
|
#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC
|
|
|
|
#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD
|
|
|
|
#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE
|
|
|
|
#endif
|
|
|
|
|
2010-11-04 19:02:37 +08:00
|
|
|
#ifndef GL_IMG_texture_compression_pvrtc
|
|
|
|
#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
|
|
|
|
#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
|
|
|
|
#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
|
|
|
|
#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
|
|
|
|
#endif
|
|
|
|
|
2011-04-22 01:04:50 +08:00
|
|
|
#ifndef GL_OES_compressed_ETC1_RGB8_texture
|
2012-03-22 01:36:20 +08:00
|
|
|
#define GL_ETC1_RGB8_OES 0x8D64
|
2011-04-22 01:04:50 +08:00
|
|
|
#endif
|
|
|
|
|
2005-02-22 18:16:22 +08:00
|
|
|
#ifndef GL_ARB_INTERNAL_TEXTURE_FORMAT
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_RGBA32F_ARB 0x8814
|
|
|
|
#define GL_RGB32F_ARB 0x8815
|
|
|
|
#define GL_ALPHA32F_ARB 0x8816
|
|
|
|
#define GL_INTENSITY32F_ARB 0x8817
|
|
|
|
#define GL_LUMINANCE32F_ARB 0x8818
|
|
|
|
#define GL_LUMINANCE_ALPHA32F_ARB 0x8819
|
|
|
|
#define GL_RGBA16F_ARB 0x881A
|
|
|
|
#define GL_RGB16F_ARB 0x881B
|
|
|
|
#define GL_ALPHA16F_ARB 0x881C
|
|
|
|
#define GL_INTENSITY16F_ARB 0x881D
|
|
|
|
#define GL_LUMINANCE16F_ARB 0x881E
|
|
|
|
#define GL_LUMINANCE_ALPHA16F_ARB 0x881F
|
2005-02-22 18:16:22 +08:00
|
|
|
#endif
|
|
|
|
|
2013-02-01 00:26:06 +08:00
|
|
|
#ifndef GL_HALF_FLOAT
|
|
|
|
#define GL_HALF_FLOAT 0x140B
|
2005-02-22 18:16:22 +08:00
|
|
|
#endif
|
|
|
|
|
2004-03-14 23:08:12 +08:00
|
|
|
#ifndef GL_NV_texture_shader
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_HILO_NV 0x86F4
|
|
|
|
#define GL_DSDT_NV 0x86F5
|
|
|
|
#define GL_DSDT_MAG_NV 0x86F6
|
|
|
|
#define GL_DSDT_MAG_VIB_NV 0x86F7
|
|
|
|
#define GL_HILO16_NV 0x86F8
|
|
|
|
#define GL_SIGNED_HILO_NV 0x86F9
|
|
|
|
#define GL_SIGNED_HILO16_NV 0x86FA
|
|
|
|
#define GL_SIGNED_RGBA_NV 0x86FB
|
|
|
|
#define GL_SIGNED_RGBA8_NV 0x86FC
|
|
|
|
#define GL_SIGNED_RGB_NV 0x86FE
|
|
|
|
#define GL_SIGNED_RGB8_NV 0x86FF
|
|
|
|
#define GL_SIGNED_LUMINANCE_NV 0x8701
|
|
|
|
#define GL_SIGNED_LUMINANCE8_NV 0x8702
|
|
|
|
#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703
|
|
|
|
#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704
|
|
|
|
#define GL_SIGNED_ALPHA_NV 0x8705
|
|
|
|
#define GL_SIGNED_ALPHA8_NV 0x8706
|
|
|
|
#define GL_SIGNED_INTENSITY_NV 0x8707
|
|
|
|
#define GL_SIGNED_INTENSITY8_NV 0x8708
|
|
|
|
#define GL_DSDT8_NV 0x8709
|
|
|
|
#define GL_DSDT8_MAG8_NV 0x870A
|
|
|
|
#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B
|
|
|
|
#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C
|
|
|
|
#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D
|
2004-03-14 23:08:12 +08:00
|
|
|
#endif
|
2002-08-28 23:28:11 +08:00
|
|
|
|
2004-09-01 16:49:48 +08:00
|
|
|
#ifndef GL_NV_float_buffer
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_FLOAT_R_NV 0x8880
|
|
|
|
#define GL_FLOAT_RG_NV 0x8881
|
|
|
|
#define GL_FLOAT_RGB_NV 0x8882
|
|
|
|
#define GL_FLOAT_RGBA_NV 0x8883
|
|
|
|
#define GL_FLOAT_R16_NV 0x8884
|
|
|
|
#define GL_FLOAT_R32_NV 0x8885
|
|
|
|
#define GL_FLOAT_RG16_NV 0x8886
|
|
|
|
#define GL_FLOAT_RG32_NV 0x8887
|
|
|
|
#define GL_FLOAT_RGB16_NV 0x8888
|
|
|
|
#define GL_FLOAT_RGB32_NV 0x8889
|
|
|
|
#define GL_FLOAT_RGBA16_NV 0x888A
|
|
|
|
#define GL_FLOAT_RGBA32_NV 0x888B
|
2004-09-01 16:49:48 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_ATI_texture_float
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_RGBA_FLOAT32_ATI 0x8814
|
|
|
|
#define GL_RGB_FLOAT32_ATI 0x8815
|
|
|
|
#define GL_ALPHA_FLOAT32_ATI 0x8816
|
|
|
|
#define GL_INTENSITY_FLOAT32_ATI 0x8817
|
|
|
|
#define GL_LUMINANCE_FLOAT32_ATI 0x8818
|
|
|
|
#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819
|
|
|
|
#define GL_RGBA_FLOAT16_ATI 0x881A
|
|
|
|
#define GL_RGB_FLOAT16_ATI 0x881B
|
|
|
|
#define GL_ALPHA_FLOAT16_ATI 0x881C
|
|
|
|
#define GL_INTENSITY_FLOAT16_ATI 0x881D
|
|
|
|
#define GL_LUMINANCE_FLOAT16_ATI 0x881E
|
|
|
|
#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F
|
2004-09-01 16:49:48 +08:00
|
|
|
#endif
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
#ifndef GL_MIRRORED_REPEAT_IBM
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_MIRRORED_REPEAT_IBM 0x8370
|
2002-08-28 23:28:11 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_CLAMP_TO_EDGE
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_CLAMP_TO_EDGE 0x812F
|
2002-08-28 23:28:11 +08:00
|
|
|
#endif
|
|
|
|
|
2009-10-25 19:52:01 +08:00
|
|
|
#ifndef GL_CLAMP
|
2012-03-22 01:36:20 +08:00
|
|
|
#define GL_CLAMP 0x2900
|
2009-10-25 19:52:01 +08:00
|
|
|
#endif
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
#ifndef GL_CLAMP_TO_BORDER_ARB
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_CLAMP_TO_BORDER_ARB 0x812D
|
2002-08-28 23:28:11 +08:00
|
|
|
#endif
|
|
|
|
|
2009-10-25 19:52:01 +08:00
|
|
|
#ifndef GL_INTENSITY
|
|
|
|
// OpenGL ES1 and ES2 doesn't provide GL_INTENSITY
|
|
|
|
#define GL_INTENSITY 0x8049
|
|
|
|
#endif
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
#ifndef GL_GENERATE_MIPMAP_SGIS
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_GENERATE_MIPMAP_SGIS 0x8191
|
|
|
|
#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192
|
2002-08-28 23:28:11 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_TEXTURE_3D
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_TEXTURE_3D 0x806F
|
2002-08-28 23:28:11 +08:00
|
|
|
#endif
|
2002-08-25 23:31:44 +08:00
|
|
|
|
2007-09-07 19:21:02 +08:00
|
|
|
#ifndef GL_TEXTURE_2D_ARRAY_EXT
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A
|
|
|
|
#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A
|
|
|
|
#define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B
|
|
|
|
#define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D
|
|
|
|
#define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF
|
|
|
|
#define GL_COMPARE_REF_DEPTH_TO_TEXTURE_EXT 0x884E
|
|
|
|
#define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1
|
|
|
|
#define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4
|
2007-09-07 19:21:02 +08:00
|
|
|
#endif
|
|
|
|
|
2009-11-24 21:24:30 +08:00
|
|
|
#ifndef GL_TEXTURE_CUBE_MAP
|
|
|
|
#define GL_TEXTURE_CUBE_MAP 0x8513
|
|
|
|
#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
|
|
|
|
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
|
|
|
|
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
|
|
|
|
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
|
|
|
|
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
|
|
|
|
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
|
|
|
|
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
|
|
|
|
#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B
|
|
|
|
#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
|
|
|
|
#endif
|
|
|
|
|
2004-10-06 20:02:37 +08:00
|
|
|
#ifndef GL_TEXTURE_BINDING_3D
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_TEXTURE_BINDING_3D 0x806A
|
2004-10-01 17:38:21 +08:00
|
|
|
#endif
|
|
|
|
|
2006-08-02 18:43:26 +08:00
|
|
|
#ifndef GL_DEPTH_TEXTURE_MODE_ARB
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B
|
2006-08-02 18:43:26 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_TEXTURE_COMPARE_MODE_ARB
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C
|
2007-10-05 18:46:46 +08:00
|
|
|
#endif
|
|
|
|
#ifndef GL_TEXTURE_COMPARE_FUNC_ARB
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D
|
2007-10-05 18:46:46 +08:00
|
|
|
#endif
|
|
|
|
#ifndef GL_COMPARE_R_TO_TEXTURE_ARB
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E
|
2003-12-18 03:26:16 +08:00
|
|
|
#endif
|
2003-03-04 23:47:28 +08:00
|
|
|
|
2004-01-29 19:16:49 +08:00
|
|
|
#ifndef TEXTURE_COMPARE_FAIL_VALUE_ARB
|
2007-09-07 21:25:28 +08:00
|
|
|
#define TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF
|
2004-01-29 19:16:49 +08:00
|
|
|
#endif
|
2003-03-04 23:47:28 +08:00
|
|
|
|
2004-05-07 19:28:55 +08:00
|
|
|
#if !defined( GL_MAX_TEXTURE_UNITS )
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_MAX_TEXTURE_UNITS 0x84E2
|
2004-05-07 19:28:55 +08:00
|
|
|
#endif
|
|
|
|
|
2004-07-06 14:13:34 +08:00
|
|
|
#ifndef GL_TEXTURE_DEPTH
|
2007-09-07 21:25:28 +08:00
|
|
|
#define GL_TEXTURE_DEPTH 0x8071
|
2004-07-06 14:13:34 +08:00
|
|
|
#endif
|
|
|
|
|
2010-04-23 01:02:22 +08:00
|
|
|
#ifndef GL_TEXTURE_2D_MULTISAMPLE
|
|
|
|
#define GL_TEXTURE_2D_MULTISAMPLE 0x9100
|
|
|
|
#endif
|
|
|
|
|
2010-09-24 22:53:10 +08:00
|
|
|
// Integer texture extension as in http://www.opengl.org/registry/specs/EXT/texture_integer.txt
|
2007-09-11 20:04:58 +08:00
|
|
|
#ifndef GL_EXT_texture_integer
|
|
|
|
#define GL_RGBA32UI_EXT 0x8D70
|
|
|
|
#define GL_RGB32UI_EXT 0x8D71
|
|
|
|
#define GL_ALPHA32UI_EXT 0x8D72
|
|
|
|
#define GL_INTENSITY32UI_EXT 0x8D73
|
|
|
|
#define GL_LUMINANCE32UI_EXT 0x8D74
|
|
|
|
#define GL_LUMINANCE_ALPHA32UI_EXT 0x8D75
|
|
|
|
|
|
|
|
#define GL_RGBA16UI_EXT 0x8D76
|
|
|
|
#define GL_RGB16UI_EXT 0x8D77
|
|
|
|
#define GL_ALPHA16UI_EXT 0x8D78
|
|
|
|
#define GL_INTENSITY16UI_EXT 0x8D79
|
|
|
|
#define GL_LUMINANCE16UI_EXT 0x8D7A
|
|
|
|
#define GL_LUMINANCE_ALPHA16UI_EXT 0x8D7B
|
|
|
|
|
|
|
|
#define GL_RGBA8UI_EXT 0x8D7C
|
|
|
|
#define GL_RGB8UI_EXT 0x8D7D
|
|
|
|
#define GL_ALPHA8UI_EXT 0x8D7E
|
|
|
|
#define GL_INTENSITY8UI_EXT 0x8D7F
|
|
|
|
#define GL_LUMINANCE8UI_EXT 0x8D80
|
|
|
|
#define GL_LUMINANCE_ALPHA8UI_EXT 0x8D81
|
|
|
|
|
|
|
|
#define GL_RGBA32I_EXT 0x8D82
|
|
|
|
#define GL_RGB32I_EXT 0x8D83
|
|
|
|
#define GL_ALPHA32I_EXT 0x8D84
|
|
|
|
#define GL_INTENSITY32I_EXT 0x8D85
|
|
|
|
#define GL_LUMINANCE32I_EXT 0x8D86
|
|
|
|
#define GL_LUMINANCE_ALPHA32I_EXT 0x8D87
|
|
|
|
|
|
|
|
#define GL_RGBA16I_EXT 0x8D88
|
|
|
|
#define GL_RGB16I_EXT 0x8D89
|
|
|
|
#define GL_ALPHA16I_EXT 0x8D8A
|
|
|
|
#define GL_INTENSITY16I_EXT 0x8D8B
|
|
|
|
#define GL_LUMINANCE16I_EXT 0x8D8C
|
|
|
|
#define GL_LUMINANCE_ALPHA16I_EXT 0x8D8D
|
|
|
|
|
|
|
|
#define GL_RGBA8I_EXT 0x8D8E
|
|
|
|
#define GL_RGB8I_EXT 0x8D8F
|
|
|
|
#define GL_ALPHA8I_EXT 0x8D90
|
|
|
|
#define GL_INTENSITY8I_EXT 0x8D91
|
|
|
|
#define GL_LUMINANCE8I_EXT 0x8D92
|
|
|
|
#define GL_LUMINANCE_ALPHA8I_EXT 0x8D93
|
|
|
|
|
|
|
|
#define GL_RED_INTEGER_EXT 0x8D94
|
|
|
|
#define GL_GREEN_INTEGER_EXT 0x8D95
|
|
|
|
#define GL_BLUE_INTEGER_EXT 0x8D96
|
|
|
|
#define GL_ALPHA_INTEGER_EXT 0x8D97
|
|
|
|
#define GL_RGB_INTEGER_EXT 0x8D98
|
|
|
|
#define GL_RGBA_INTEGER_EXT 0x8D99
|
|
|
|
#define GL_BGR_INTEGER_EXT 0x8D9A
|
|
|
|
#define GL_BGRA_INTEGER_EXT 0x8D9B
|
|
|
|
#define GL_LUMINANCE_INTEGER_EXT 0x8D9C
|
|
|
|
#define GL_LUMINANCE_ALPHA_INTEGER_EXT 0x8D9D
|
|
|
|
|
|
|
|
#define GL_RGBA_INTEGER_MODE_EXT 0x8D9E
|
|
|
|
#endif
|
|
|
|
|
2014-08-08 17:28:26 +08:00
|
|
|
#ifndef GL_VERSION_1_1
|
2014-11-21 01:37:52 +08:00
|
|
|
#define GL_R3_G3_B2 0x2A10
|
|
|
|
#define GL_RGB4 0x804F
|
|
|
|
#define GL_RGB5 0x8050
|
|
|
|
#define GL_RGB8 0x8051
|
|
|
|
#define GL_RGB10 0x8052
|
|
|
|
#define GL_RGB12 0x8053
|
|
|
|
#define GL_RGB16 0x8054
|
|
|
|
#define GL_RGBA2 0x8055
|
|
|
|
#define GL_RGBA4 0x8056
|
|
|
|
#define GL_RGB5_A1 0x8057
|
|
|
|
#define GL_RGBA8 0x8058
|
|
|
|
#define GL_RGB10_A2 0x8059
|
|
|
|
#define GL_RGBA12 0x805A
|
|
|
|
#define GL_RGBA16 0x805B
|
|
|
|
#define GL_BGR_EXT 0x80E0
|
|
|
|
#define GL_BGRA_EXT 0x80E1
|
2014-08-08 17:28:26 +08:00
|
|
|
#endif
|
|
|
|
|
2013-01-24 00:22:45 +08:00
|
|
|
#ifndef GL_ARB_texture_rg
|
|
|
|
#define GL_RG 0x8227
|
|
|
|
#define GL_RG_INTEGER 0x8228
|
|
|
|
#define GL_R8 0x8229
|
|
|
|
#define GL_R16 0x822A
|
|
|
|
#define GL_RG8 0x822B
|
|
|
|
#define GL_RG16 0x822C
|
|
|
|
#define GL_R16F 0x822D
|
|
|
|
#define GL_R32F 0x822E
|
|
|
|
#define GL_RG16F 0x822F
|
|
|
|
#define GL_RG32F 0x8230
|
|
|
|
#define GL_R8I 0x8231
|
|
|
|
#define GL_R8UI 0x8232
|
|
|
|
#define GL_R16I 0x8233
|
|
|
|
#define GL_R16UI 0x8234
|
|
|
|
#define GL_R32I 0x8235
|
|
|
|
#define GL_R32UI 0x8236
|
|
|
|
#define GL_RG8I 0x8237
|
|
|
|
#define GL_RG8UI 0x8238
|
|
|
|
#define GL_RG16I 0x8239
|
|
|
|
#define GL_RG16UI 0x823A
|
|
|
|
#define GL_RG32I 0x823B
|
|
|
|
#define GL_RG32UI 0x823C
|
|
|
|
#endif
|
|
|
|
|
2013-01-25 19:54:03 +08:00
|
|
|
#ifndef GL_ARB_shader_image_load_store
|
|
|
|
#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001
|
|
|
|
#define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002
|
|
|
|
#define GL_UNIFORM_BARRIER_BIT 0x00000004
|
|
|
|
#define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008
|
|
|
|
#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020
|
|
|
|
#define GL_COMMAND_BARRIER_BIT 0x00000040
|
|
|
|
#define GL_PIXEL_BUFFER_BARRIER_BIT 0x00000080
|
|
|
|
#define GL_TEXTURE_UPDATE_BARRIER_BIT 0x00000100
|
|
|
|
#define GL_BUFFER_UPDATE_BARRIER_BIT 0x00000200
|
|
|
|
#define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400
|
|
|
|
#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT 0x00000800
|
|
|
|
#define GL_ATOMIC_COUNTER_BARRIER_BIT 0x00001000
|
|
|
|
#define GL_ALL_BARRIER_BITS 0xFFFFFFFF
|
|
|
|
#define GL_MAX_IMAGE_UNITS 0x8F38
|
|
|
|
#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS 0x8F39
|
|
|
|
#define GL_IMAGE_BINDING_NAME 0x8F3A
|
|
|
|
#define GL_IMAGE_BINDING_LEVEL 0x8F3B
|
|
|
|
#define GL_IMAGE_BINDING_LAYERED 0x8F3C
|
|
|
|
#define GL_IMAGE_BINDING_LAYER 0x8F3D
|
|
|
|
#define GL_IMAGE_BINDING_ACCESS 0x8F3E
|
|
|
|
#define GL_IMAGE_1D 0x904C
|
|
|
|
#define GL_IMAGE_2D 0x904D
|
|
|
|
#define GL_IMAGE_3D 0x904E
|
|
|
|
#define GL_IMAGE_2D_RECT 0x904F
|
|
|
|
#define GL_IMAGE_CUBE 0x9050
|
|
|
|
#define GL_IMAGE_BUFFER 0x9051
|
|
|
|
#define GL_IMAGE_1D_ARRAY 0x9052
|
|
|
|
#define GL_IMAGE_2D_ARRAY 0x9053
|
|
|
|
#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054
|
|
|
|
#define GL_IMAGE_2D_MULTISAMPLE 0x9055
|
|
|
|
#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056
|
|
|
|
#define GL_INT_IMAGE_1D 0x9057
|
|
|
|
#define GL_INT_IMAGE_2D 0x9058
|
|
|
|
#define GL_INT_IMAGE_3D 0x9059
|
|
|
|
#define GL_INT_IMAGE_2D_RECT 0x905A
|
|
|
|
#define GL_INT_IMAGE_CUBE 0x905B
|
|
|
|
#define GL_INT_IMAGE_BUFFER 0x905C
|
|
|
|
#define GL_INT_IMAGE_1D_ARRAY 0x905D
|
|
|
|
#define GL_INT_IMAGE_2D_ARRAY 0x905E
|
|
|
|
#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F
|
|
|
|
#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060
|
|
|
|
#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_1D 0x9062
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_2D 0x9063
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_3D 0x9064
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B
|
|
|
|
#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C
|
|
|
|
#define GL_MAX_IMAGE_SAMPLES 0x906D
|
|
|
|
#define GL_IMAGE_BINDING_FORMAT 0x906E
|
|
|
|
#define GL_IMAGE_FORMAT_COMPATIBILITY_TYPE 0x90C7
|
|
|
|
#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE 0x90C8
|
|
|
|
#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS 0x90C9
|
|
|
|
#define GL_MAX_VERTEX_IMAGE_UNIFORMS 0x90CA
|
|
|
|
#define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS 0x90CB
|
|
|
|
#define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS 0x90CC
|
|
|
|
#define GL_MAX_GEOMETRY_IMAGE_UNIFORMS 0x90CD
|
|
|
|
#define GL_MAX_FRAGMENT_IMAGE_UNIFORMS 0x90CE
|
|
|
|
#define GL_MAX_COMBINED_IMAGE_UNIFORMS 0x90CF
|
|
|
|
#endif
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
namespace osg {
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-22 01:26:08 +08:00
|
|
|
|
2010-09-24 22:53:10 +08:00
|
|
|
/** Texture pure virtual base class that encapsulates OpenGL texture
|
2004-09-14 00:10:59 +08:00
|
|
|
* functionality common to the various types of OSG textures.
|
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Texture : public osg::StateAttribute
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public :
|
2004-09-22 01:26:08 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
Texture();
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
2002-07-29 07:28:27 +08:00
|
|
|
Texture(const Texture& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
2002-08-28 23:28:11 +08:00
|
|
|
|
|
|
|
virtual osg::Object* cloneType() const = 0;
|
|
|
|
virtual osg::Object* clone(const CopyOp& copyop) const = 0;
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Texture *>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
virtual const char* className() const { return "Texture"; }
|
2008-07-22 20:28:46 +08:00
|
|
|
|
|
|
|
/** Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.*/
|
|
|
|
virtual Texture* asTexture() { return this; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-07-22 20:28:46 +08:00
|
|
|
/** Fast alternative to dynamic_cast<> for determining if state attribute is a Texture.*/
|
|
|
|
virtual const Texture* asTexture() const { return this; }
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual Type getType() const { return TEXTURE; }
|
2002-08-28 23:28:11 +08:00
|
|
|
|
|
|
|
virtual bool isTextureAttribute() const { return true; }
|
|
|
|
|
2005-07-27 19:27:44 +08:00
|
|
|
virtual GLenum getTextureTarget() const = 0;
|
|
|
|
|
2007-03-06 01:34:36 +08:00
|
|
|
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
|
2005-07-27 19:27:44 +08:00
|
|
|
{
|
|
|
|
usage.usesTextureMode(getTextureTarget());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-08-03 23:57:39 +08:00
|
|
|
virtual int getTextureWidth() const { return 0; }
|
|
|
|
virtual int getTextureHeight() const { return 0; }
|
|
|
|
virtual int getTextureDepth() const { return 0; }
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
enum WrapParameter {
|
|
|
|
WRAP_S,
|
|
|
|
WRAP_T,
|
|
|
|
WRAP_R
|
|
|
|
};
|
|
|
|
|
|
|
|
enum WrapMode {
|
|
|
|
CLAMP = GL_CLAMP,
|
|
|
|
CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
|
|
|
|
CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER_ARB,
|
|
|
|
REPEAT = GL_REPEAT,
|
|
|
|
MIRROR = GL_MIRRORED_REPEAT_IBM
|
|
|
|
};
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the texture wrap mode. */
|
2002-09-02 20:31:35 +08:00
|
|
|
void setWrap(WrapParameter which, WrapMode wrap);
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the texture wrap mode. */
|
2002-09-02 20:31:35 +08:00
|
|
|
WrapMode getWrap(WrapParameter which) const;
|
2002-08-28 23:28:11 +08:00
|
|
|
|
|
|
|
|
2007-09-11 20:04:58 +08:00
|
|
|
/** Sets the border color. Only used when wrap mode is CLAMP_TO_BORDER.
|
|
|
|
* The border color will be casted to the appropriate type to match the
|
|
|
|
* internal pixel format of the texture. */
|
|
|
|
void setBorderColor(const Vec4d& color) { _borderColor = color; dirtyTextureParameters(); }
|
2004-09-14 00:10:59 +08:00
|
|
|
|
|
|
|
/** Gets the border color. */
|
2007-09-11 20:04:58 +08:00
|
|
|
const Vec4d& getBorderColor() const { return _borderColor; }
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the border width. */
|
2004-01-28 05:29:58 +08:00
|
|
|
void setBorderWidth(GLint width) { _borderWidth = width; dirtyTextureParameters(); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-01-28 05:29:58 +08:00
|
|
|
GLint getBorderWidth() const { return _borderWidth; }
|
2002-07-09 17:35:42 +08:00
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
enum FilterParameter {
|
|
|
|
MIN_FILTER,
|
|
|
|
MAG_FILTER
|
|
|
|
};
|
2001-09-22 10:42:08 +08:00
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
enum FilterMode {
|
|
|
|
LINEAR = GL_LINEAR,
|
|
|
|
LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR,
|
|
|
|
LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
|
|
|
|
NEAREST = GL_NEAREST,
|
|
|
|
NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
|
|
|
|
NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST
|
|
|
|
};
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the texture filter mode. */
|
2002-09-02 20:31:35 +08:00
|
|
|
void setFilter(FilterParameter which, FilterMode filter);
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the texture filter mode. */
|
2002-09-02 20:31:35 +08:00
|
|
|
FilterMode getFilter(FilterParameter which) const;
|
2002-07-29 07:28:27 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the maximum anisotropy value, default value is 1.0 for no
|
|
|
|
* anisotropic filtering. If hardware does not support anisotropic
|
2007-12-11 01:30:18 +08:00
|
|
|
* filtering, use normal filtering (equivalent to a max anisotropy
|
2004-09-14 00:10:59 +08:00
|
|
|
* value of 1.0. Valid range is 1.0f upwards. The maximum value
|
|
|
|
* depends on the graphics system. */
|
2002-08-28 23:28:11 +08:00
|
|
|
void setMaxAnisotropy(float anis);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the maximum anisotropy value. */
|
2002-08-28 23:28:11 +08:00
|
|
|
inline float getMaxAnisotropy() const { return _maxAnisotropy; }
|
|
|
|
|
2013-06-03 23:10:53 +08:00
|
|
|
/** Configure the source of texture swizzling for all channels */
|
|
|
|
inline void setSwizzle(const Vec4i& swizzle) { _swizzle = swizzle; dirtyTextureParameters(); };
|
|
|
|
|
|
|
|
/** Gets the source of texture swizzling for all channels */
|
|
|
|
inline const Vec4i& getSwizzle() const { return _swizzle; }
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the hardware mipmap generation hint. If enabled, it will
|
|
|
|
* only be used if supported in the graphics system. */
|
2003-04-01 05:41:17 +08:00
|
|
|
inline void setUseHardwareMipMapGeneration(bool useHardwareMipMapGeneration) { _useHardwareMipMapGeneration = useHardwareMipMapGeneration; }
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the hardware mipmap generation hint. */
|
2003-04-01 05:41:17 +08:00
|
|
|
inline bool getUseHardwareMipMapGeneration() const { return _useHardwareMipMapGeneration; }
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets whether or not the apply() function will unreference the image
|
2007-12-11 01:30:18 +08:00
|
|
|
* data. If enabled, and the image data is only referenced by this
|
2004-09-14 00:10:59 +08:00
|
|
|
* Texture, apply() will delete the image data. */
|
2003-04-07 20:51:00 +08:00
|
|
|
inline void setUnRefImageDataAfterApply(bool flag) { _unrefImageDataAfterApply = flag; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets whether or not apply() unreferences image data. */
|
2003-04-07 20:51:00 +08:00
|
|
|
inline bool getUnRefImageDataAfterApply() const { return _unrefImageDataAfterApply; }
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets whether to use client storage for the texture, if supported
|
|
|
|
* by the graphics system. Note: If enabled, and the graphics system
|
|
|
|
* supports it, the osg::Image(s) associated with this texture cannot
|
|
|
|
* be deleted, so the UnRefImageDataAfterApply flag would be ignored. */
|
2004-03-09 01:09:58 +08:00
|
|
|
inline void setClientStorageHint(bool flag) { _clientStorageHint = flag; }
|
2004-09-14 00:10:59 +08:00
|
|
|
|
|
|
|
/** Gets whether to use client storage for the texture. */
|
2004-03-09 01:09:58 +08:00
|
|
|
inline bool getClientStorageHint() const { return _clientStorageHint; }
|
2003-04-07 20:51:00 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Sets whether to force the texture to resize images that have dimensions
|
2005-05-06 17:04:41 +08:00
|
|
|
* that are not a power of two. If enabled, NPOT images will be resized,
|
|
|
|
* whether or not NPOT textures are supported by the hardware. If disabled,
|
|
|
|
* NPOT images will not be resized if supported by hardware. */
|
|
|
|
inline void setResizeNonPowerOfTwoHint(bool flag) { _resizeNonPowerOfTwoHint = flag; }
|
|
|
|
|
|
|
|
/** Gets whether texture will force non power to two images to be resized. */
|
|
|
|
inline bool getResizeNonPowerOfTwoHint() const { return _resizeNonPowerOfTwoHint; }
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
enum InternalFormatMode {
|
|
|
|
USE_IMAGE_DATA_FORMAT,
|
|
|
|
USE_USER_DEFINED_FORMAT,
|
|
|
|
USE_ARB_COMPRESSION,
|
|
|
|
USE_S3TC_DXT1_COMPRESSION,
|
|
|
|
USE_S3TC_DXT3_COMPRESSION,
|
2010-08-16 22:11:49 +08:00
|
|
|
USE_S3TC_DXT5_COMPRESSION,
|
2011-04-22 01:04:50 +08:00
|
|
|
USE_PVRTC_2BPP_COMPRESSION,
|
|
|
|
USE_PVRTC_4BPP_COMPRESSION,
|
|
|
|
USE_ETC_COMPRESSION,
|
2013-10-28 20:03:55 +08:00
|
|
|
USE_ETC2_COMPRESSION,
|
2010-08-16 22:11:49 +08:00
|
|
|
USE_RGTC1_COMPRESSION,
|
2011-04-12 03:11:25 +08:00
|
|
|
USE_RGTC2_COMPRESSION,
|
|
|
|
USE_S3TC_DXT1c_COMPRESSION,
|
|
|
|
USE_S3TC_DXT1a_COMPRESSION
|
2002-08-28 23:28:11 +08:00
|
|
|
};
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the internal texture format mode. Note: If the texture format is
|
|
|
|
* USE_IMAGE_DATA_FORMAT, USE_ARB_COMPRESSION, or USE_S3TC_COMPRESSION,
|
|
|
|
* the internal format mode is set automatically and will overwrite the
|
|
|
|
* previous _internalFormat. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setInternalFormatMode(InternalFormatMode mode) { _internalFormatMode = mode; }
|
2002-03-14 08:07:29 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the internal texture format mode. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline InternalFormatMode getInternalFormatMode() const { return _internalFormatMode; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the internal texture format. Implicitly sets the
|
2007-09-11 20:04:58 +08:00
|
|
|
* internalFormatMode to USE_USER_DEFINED_FORMAT.
|
|
|
|
* The corresponding internal format type will be computed. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setInternalFormat(GLint internalFormat)
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
|
|
|
_internalFormatMode = USE_USER_DEFINED_FORMAT;
|
2002-08-25 03:39:39 +08:00
|
|
|
_internalFormat = internalFormat;
|
2007-09-11 20:04:58 +08:00
|
|
|
computeInternalFormatType();
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
|
2007-09-11 20:04:58 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the internal texture format. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline GLint getInternalFormat() const { if (_internalFormat==0) computeInternalFormat(); return _internalFormat; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-11-08 23:52:21 +08:00
|
|
|
/** Return true if the internal format is one of the compressed formats.*/
|
2002-08-28 23:28:11 +08:00
|
|
|
bool isCompressedInternalFormat() const;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2005-11-08 23:52:21 +08:00
|
|
|
/** Sets the external source image format, used as a fallback when no osg::Image is attached to provide the source image format. */
|
|
|
|
inline void setSourceFormat(GLenum sourceFormat) { _sourceFormat = sourceFormat; }
|
|
|
|
|
|
|
|
/** Gets the external source image format. */
|
|
|
|
inline GLenum getSourceFormat() const { return _sourceFormat; }
|
|
|
|
|
|
|
|
/** Sets the external source data type, used as a fallback when no osg::Image is attached to provide the source image format.*/
|
|
|
|
inline void setSourceType(GLenum sourceType) { _sourceType = sourceType; }
|
|
|
|
|
|
|
|
/** Gets the external source data type.*/
|
|
|
|
inline GLenum getSourceType() const { return _sourceType; }
|
|
|
|
|
2007-09-11 20:04:58 +08:00
|
|
|
/** Texture type determined by the internal texture format */
|
|
|
|
enum InternalFormatType{
|
|
|
|
|
|
|
|
//! default OpenGL format (clamped values to [0,1) or [0,255])
|
|
|
|
NORMALIZED = 0x0,
|
2002-09-05 19:42:55 +08:00
|
|
|
|
2007-09-11 20:04:58 +08:00
|
|
|
//! float values, Shader Model 3.0 (see ARB_texture_float)
|
|
|
|
FLOAT = 0x1,
|
|
|
|
|
|
|
|
//! Signed integer values (see EXT_texture_integer)
|
|
|
|
SIGNED_INTEGER = 0x2,
|
|
|
|
|
|
|
|
//! Unsigned integer value (see EXT_texture_integer)
|
|
|
|
UNSIGNED_INTEGER = 0x4
|
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-09-11 20:04:58 +08:00
|
|
|
/** Get the internal texture format type. */
|
|
|
|
inline InternalFormatType getInternalFormatType() const { return _internalFormatType; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-07-14 22:42:10 +08:00
|
|
|
class TextureObject;
|
|
|
|
|
2010-09-24 22:53:10 +08:00
|
|
|
/** Returns a pointer to the TextureObject for the current context. */
|
2003-07-14 22:42:10 +08:00
|
|
|
inline TextureObject* getTextureObject(unsigned int contextID) const
|
2002-07-29 07:28:27 +08:00
|
|
|
{
|
2003-07-14 22:42:10 +08:00
|
|
|
return _textureObjectBuffer[contextID].get();
|
2002-07-29 07:28:27 +08:00
|
|
|
}
|
|
|
|
|
2009-09-23 02:45:24 +08:00
|
|
|
inline void setTextureObject(unsigned int contextID, TextureObject* to)
|
|
|
|
{
|
|
|
|
_textureObjectBuffer[contextID] = to;
|
|
|
|
}
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Forces a recompile on next apply() of associated OpenGL texture
|
|
|
|
* objects. */
|
2003-07-14 22:42:10 +08:00
|
|
|
void dirtyTextureObject();
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Returns true if the texture objects for all the required graphics
|
|
|
|
* contexts are loaded. */
|
2003-07-14 22:42:10 +08:00
|
|
|
bool areAllTextureObjectsLoaded() const;
|
|
|
|
|
2002-07-29 07:28:27 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the dirty flag for the current contextID. */
|
2003-02-15 00:52:47 +08:00
|
|
|
inline unsigned int& getTextureParameterDirty(unsigned int contextID) const
|
2002-09-04 16:14:04 +08:00
|
|
|
{
|
|
|
|
return _texParametersDirtyList[contextID];
|
|
|
|
}
|
|
|
|
|
2002-07-29 07:28:27 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Force a reset on next apply() of associated OpenGL texture
|
|
|
|
* parameters. */
|
2002-09-04 16:14:04 +08:00
|
|
|
void dirtyTextureParameters();
|
2002-03-28 06:51:58 +08:00
|
|
|
|
2007-09-11 20:04:58 +08:00
|
|
|
/** Force a manual allocation of the mipmap levels on the next apply() call.
|
|
|
|
* User is responsible for filling the mipmap levels with valid data.
|
|
|
|
* The OpenGL's glGenerateMipmapEXT function is used to generate the mipmap levels.
|
|
|
|
* If glGenerateMipmapEXT is not supported or texture's internal format is not supported
|
|
|
|
* by the glGenerateMipmapEXT, then empty mipmap levels will
|
2007-12-11 01:30:18 +08:00
|
|
|
* be allocated manually. The mipmap levels are also allocated if a non-mipmapped
|
2007-09-11 20:04:58 +08:00
|
|
|
* min filter is used. */
|
|
|
|
void allocateMipmapLevels();
|
|
|
|
|
2013-01-25 19:54:03 +08:00
|
|
|
/** Encapsulates texture image load/store attributes */
|
|
|
|
struct ImageAttachment
|
|
|
|
{
|
|
|
|
GLuint unit;
|
|
|
|
GLint level;
|
|
|
|
GLboolean layered;
|
|
|
|
GLint layer;
|
|
|
|
GLenum access;
|
|
|
|
GLenum format;
|
2013-12-16 19:28:10 +08:00
|
|
|
|
2013-01-25 19:54:03 +08:00
|
|
|
ImageAttachment()
|
|
|
|
: unit(0), level(0), layered(GL_FALSE), layer(0), access(0), format(0) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Type of access that will be performed on the texture image. */
|
|
|
|
enum ImageAccess
|
|
|
|
{
|
|
|
|
NOT_USED = 0,
|
|
|
|
READ_ONLY = GL_READ_ONLY_ARB,
|
|
|
|
WRITE_ONLY = GL_WRITE_ONLY_ARB,
|
|
|
|
READ_WRITE = GL_READ_WRITE_ARB
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Bind texture to an image unit (available only if GL version is 4.2 or greater)
|
|
|
|
* The format parameter for the image unit need not exactly match the texture internal format,
|
|
|
|
* but if it is set to 0, the texture internal format will be used.
|
|
|
|
* See http://www.opengl.org/registry/specs/ARB/shader_image_load_store.txt */
|
|
|
|
void bindToImageUnit(unsigned int unit, GLenum access, GLenum format=0, int level=0, bool layered=false, int layer=0);
|
|
|
|
|
|
|
|
ImageAttachment& getImageAttachment() { return _imageAttachment; }
|
|
|
|
const ImageAttachment& getImageAttachment() const { return _imageAttachment; }
|
2002-08-28 23:28:11 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets GL_TEXTURE_COMPARE_MODE_ARB to GL_COMPARE_R_TO_TEXTURE_ARB
|
|
|
|
* See http://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow.txt. */
|
2003-12-18 03:26:16 +08:00
|
|
|
void setShadowComparison(bool flag) { _use_shadow_comparison = flag; }
|
2010-01-08 19:32:55 +08:00
|
|
|
bool getShadowComparison() const { return _use_shadow_comparison; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-12-18 03:26:16 +08:00
|
|
|
enum ShadowCompareFunc {
|
2009-03-11 21:08:12 +08:00
|
|
|
NEVER = GL_NEVER,
|
|
|
|
LESS = GL_LESS,
|
|
|
|
EQUAL = GL_EQUAL,
|
2003-12-18 03:26:16 +08:00
|
|
|
LEQUAL = GL_LEQUAL,
|
2009-03-11 21:08:12 +08:00
|
|
|
GREATER = GL_GREATER,
|
|
|
|
NOTEQUAL = GL_NOTEQUAL,
|
|
|
|
GEQUAL = GL_GEQUAL,
|
|
|
|
ALWAYS = GL_ALWAYS
|
2003-12-18 03:26:16 +08:00
|
|
|
};
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets shadow texture comparison function. */
|
2003-12-18 03:26:16 +08:00
|
|
|
void setShadowCompareFunc(ShadowCompareFunc func) { _shadow_compare_func = func; }
|
2006-08-25 22:53:09 +08:00
|
|
|
ShadowCompareFunc getShadowCompareFunc() const { return _shadow_compare_func; }
|
2003-12-18 03:26:16 +08:00
|
|
|
|
|
|
|
enum ShadowTextureMode {
|
|
|
|
LUMINANCE = GL_LUMINANCE,
|
|
|
|
INTENSITY = GL_INTENSITY,
|
|
|
|
ALPHA = GL_ALPHA
|
|
|
|
};
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets shadow texture mode after comparison. */
|
2003-12-18 03:26:16 +08:00
|
|
|
void setShadowTextureMode(ShadowTextureMode mode) { _shadow_texture_mode = mode; }
|
2006-08-25 22:53:09 +08:00
|
|
|
ShadowTextureMode getShadowTextureMode() const { return _shadow_texture_mode; }
|
2003-12-18 03:26:16 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the TEXTURE_COMPARE_FAIL_VALUE_ARB texture parameter. See
|
|
|
|
* http://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow_ambient.txt. */
|
2004-01-29 19:16:49 +08:00
|
|
|
void setShadowAmbient(float shadow_ambient) { _shadow_ambient = shadow_ambient; }
|
2006-08-25 22:53:09 +08:00
|
|
|
float getShadowAmbient() const { return _shadow_ambient; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-07-27 18:11:45 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the texture image for the specified face. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual void setImage(unsigned int face, Image* image) = 0;
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the texture image for the specified face. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual Image* getImage(unsigned int face) = 0;
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the const texture image for specified face. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual const Image* getImage(unsigned int face) const = 0;
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the number of images that can be assigned to this Texture. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual unsigned int getNumImages() const = 0;
|
|
|
|
|
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Set the PBuffer graphics context to read from when using PBuffers for RenderToTexture.*/
|
2005-08-31 20:56:15 +08:00
|
|
|
void setReadPBuffer(GraphicsContext* context) { _readPBuffer = context; }
|
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Get the PBuffer graphics context to read from when using PBuffers for RenderToTexture.*/
|
2005-08-31 20:56:15 +08:00
|
|
|
GraphicsContext* getReadPBuffer() { return _readPBuffer.get(); }
|
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Get the const PBuffer graphics context to read from when using PBuffers for RenderToTexture.*/
|
2006-08-25 22:54:54 +08:00
|
|
|
const GraphicsContext* getReadPBuffer() const { return _readPBuffer.get(); }
|
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Texture is a pure virtual base class, apply must be overridden. */
|
2002-08-28 23:28:11 +08:00
|
|
|
virtual void apply(State& state) const = 0;
|
2002-08-16 23:14:43 +08:00
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
/** Calls apply(state) to compile the texture. */
|
2004-07-20 13:37:59 +08:00
|
|
|
virtual void compileGLObjects(State& state) const;
|
|
|
|
|
2007-01-04 22:11:51 +08:00
|
|
|
/** Resize any per context GLObject buffers to specified size. */
|
|
|
|
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** If State is non-zero, this function releases OpenGL objects for
|
2007-12-11 01:30:18 +08:00
|
|
|
* the specified graphics context. Otherwise, releases OpenGL objects
|
2004-09-14 00:10:59 +08:00
|
|
|
* for all graphics contexts. */
|
2004-07-20 13:37:59 +08:00
|
|
|
virtual void releaseGLObjects(State* state=0) const;
|
2002-08-16 23:14:43 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Encapsulates queries of extension availability, obtains extension
|
2007-12-11 01:30:18 +08:00
|
|
|
* function pointers, and provides convenience wrappers for
|
2012-03-22 01:36:20 +08:00
|
|
|
* calling extension functions. */
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Extensions : public osg::Referenced
|
2002-09-17 04:58:05 +08:00
|
|
|
{
|
|
|
|
public:
|
2005-04-26 21:15:27 +08:00
|
|
|
Extensions(unsigned int contextID);
|
2002-09-17 04:58:05 +08:00
|
|
|
|
2003-04-11 03:32:32 +08:00
|
|
|
void setMultiTexturingSupported(bool flag) { _isMultiTexturingSupported=flag; }
|
|
|
|
bool isMultiTexturingSupported() const { return _isMultiTexturingSupported; }
|
|
|
|
|
2003-04-10 21:41:45 +08:00
|
|
|
void setTextureFilterAnisotropicSupported(bool flag) { _isTextureFilterAnisotropicSupported=flag; }
|
2002-09-17 04:58:05 +08:00
|
|
|
bool isTextureFilterAnisotropicSupported() const { return _isTextureFilterAnisotropicSupported; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2013-06-03 23:10:53 +08:00
|
|
|
void setTextureSwizzleSupported(bool flag) { _isTextureSwizzleSupported=flag; }
|
|
|
|
bool isTextureSwizzleSupported() const { return _isTextureSwizzleSupported; }
|
|
|
|
|
2003-04-10 21:41:45 +08:00
|
|
|
void setTextureCompressionARBSupported(bool flag) { _isTextureCompressionARBSupported=flag; }
|
2002-09-17 04:58:05 +08:00
|
|
|
bool isTextureCompressionARBSupported() const { return _isTextureCompressionARBSupported; }
|
2003-04-10 21:41:45 +08:00
|
|
|
|
|
|
|
void setTextureCompressionS3TCSupported(bool flag) { _isTextureCompressionS3TCSupported=flag; }
|
2002-09-17 04:58:05 +08:00
|
|
|
bool isTextureCompressionS3TCSupported() const { return _isTextureCompressionS3TCSupported; }
|
2003-04-10 21:41:45 +08:00
|
|
|
|
2011-04-22 01:04:50 +08:00
|
|
|
void setTextureCompressionPVRTC2BPPSupported(bool flag) { _isTextureCompressionPVRTC2BPPSupported=flag; }
|
|
|
|
bool isTextureCompressionPVRTC2BPPSupported() const { return _isTextureCompressionPVRTC2BPPSupported; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2011-04-22 01:04:50 +08:00
|
|
|
void setTextureCompressionPVRTC4BPPSupported(bool flag) { _isTextureCompressionPVRTC4BPPSupported=flag; }
|
|
|
|
bool isTextureCompressionPVRTC4BPPSupported() const { return _isTextureCompressionPVRTC4BPPSupported; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2011-04-22 01:04:50 +08:00
|
|
|
void setTextureCompressionETCSupported(bool flag) { _isTextureCompressionETCSupported=flag; }
|
|
|
|
bool isTextureCompressionETCSupported() const { return _isTextureCompressionETCSupported; }
|
2013-12-16 19:28:10 +08:00
|
|
|
|
2013-10-28 20:03:55 +08:00
|
|
|
void setTextureCompressionETC2Supported(bool flag) { _isTextureCompressionETC2Supported=flag; }
|
|
|
|
bool isTextureCompressionETC2Supported() const { return _isTextureCompressionETC2Supported; }
|
2011-04-22 01:04:50 +08:00
|
|
|
|
2010-08-16 22:11:49 +08:00
|
|
|
void setTextureCompressionRGTCSupported(bool flag) { _isTextureCompressionRGTCSupported=flag; }
|
|
|
|
bool isTextureCompressionRGTCSupported() const { return _isTextureCompressionRGTCSupported; }
|
|
|
|
|
2010-11-04 19:02:37 +08:00
|
|
|
void setTextureCompressionPVRTCSupported(bool flag) { _isTextureCompressionPVRTCSupported=flag; }
|
|
|
|
bool isTextureCompressionPVRTCSupported() const { return _isTextureCompressionPVRTCSupported; }
|
|
|
|
|
2003-04-10 21:41:45 +08:00
|
|
|
void setTextureMirroredRepeatSupported(bool flag) { _isTextureMirroredRepeatSupported=flag; }
|
2002-09-17 04:58:05 +08:00
|
|
|
bool isTextureMirroredRepeatSupported() const { return _isTextureMirroredRepeatSupported; }
|
2003-04-10 21:41:45 +08:00
|
|
|
|
|
|
|
void setTextureEdgeClampSupported(bool flag) { _isTextureEdgeClampSupported=flag; }
|
2002-09-17 04:58:05 +08:00
|
|
|
bool isTextureEdgeClampSupported() const { return _isTextureEdgeClampSupported; }
|
2003-04-10 21:41:45 +08:00
|
|
|
|
|
|
|
void setTextureBorderClampSupported(bool flag) { _isTextureBorderClampSupported=flag; }
|
2002-09-17 04:58:05 +08:00
|
|
|
bool isTextureBorderClampSupported() const { return _isTextureBorderClampSupported; }
|
2003-04-10 21:41:45 +08:00
|
|
|
|
|
|
|
void setGenerateMipMapSupported(bool flag) { _isGenerateMipMapSupported=flag; }
|
2003-03-04 23:47:28 +08:00
|
|
|
bool isGenerateMipMapSupported() const { return _isGenerateMipMapSupported; }
|
2002-09-17 04:58:05 +08:00
|
|
|
|
2012-07-13 00:41:53 +08:00
|
|
|
void setPreferGenerateMipmapSGISForPowerOfTwo(bool flag) { _preferGenerateMipmapSGISForPowerOfTwo = flag; }
|
|
|
|
bool getPreferGenerateMipmapSGISForPowerOfTwo() const { return _preferGenerateMipmapSGISForPowerOfTwo; }
|
|
|
|
|
2010-04-23 01:02:22 +08:00
|
|
|
void setTextureMultisampledSupported(bool flag) { _isTextureMultisampledSupported=flag; }
|
|
|
|
bool isTextureMultisampledSupported() const { return _isTextureMultisampledSupported; }
|
|
|
|
|
2003-12-18 03:26:16 +08:00
|
|
|
void setShadowSupported(bool flag) { _isShadowSupported = flag; }
|
|
|
|
bool isShadowSupported() const { return _isShadowSupported; }
|
|
|
|
|
2004-01-29 19:16:49 +08:00
|
|
|
void setShadowAmbientSupported(bool flag) { _isShadowAmbientSupported = flag; }
|
|
|
|
bool isShadowAmbientSupported() const { return _isShadowAmbientSupported; }
|
|
|
|
|
2009-06-19 19:55:52 +08:00
|
|
|
void setTextureMaxLevelSupported(bool flag) { _isTextureMaxLevelSupported = flag; }
|
|
|
|
bool isTextureMaxLevelSupported() const { return _isTextureMaxLevelSupported; }
|
|
|
|
|
2003-04-10 21:41:45 +08:00
|
|
|
void setMaxTextureSize(GLint maxsize) { _maxTextureSize=maxsize; }
|
2002-09-17 04:58:05 +08:00
|
|
|
GLint maxTextureSize() const { return _maxTextureSize; }
|
|
|
|
|
2014-06-25 17:57:36 +08:00
|
|
|
bool isTexStorage2DSupported() const { return _glTexStorage2D != 0; }
|
|
|
|
bool isTexStorageEnabled() const { return _isTextureStorageEnabled; }
|
|
|
|
|
2002-09-17 04:58:05 +08:00
|
|
|
bool isCompressedTexImage2DSupported() const { return _glCompressedTexImage2D!=0; }
|
2007-09-03 23:43:58 +08:00
|
|
|
bool isCompressedTexSubImage2DSupported() const { return _glCompressedTexSubImage2D!=0; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-03-09 01:09:58 +08:00
|
|
|
bool isClientStorageSupported() const { return _isClientStorageSupported; }
|
2005-05-05 17:18:03 +08:00
|
|
|
|
2005-05-17 19:00:13 +08:00
|
|
|
bool isNonPowerOfTwoTextureSupported(GLenum filter) const
|
|
|
|
{
|
2012-03-22 01:36:20 +08:00
|
|
|
return (filter==GL_LINEAR || filter==GL_NEAREST) ?
|
2005-05-17 19:00:13 +08:00
|
|
|
_isNonPowerOfTwoTextureNonMipMappedSupported :
|
|
|
|
_isNonPowerOfTwoTextureMipMappedSupported;
|
|
|
|
}
|
2004-03-09 01:09:58 +08:00
|
|
|
|
2007-09-11 20:28:03 +08:00
|
|
|
void setTextureIntegerSupported(bool flag) { _isTextureIntegerEXTSupported=flag; }
|
|
|
|
bool isTextureIntegerSupported() const { return _isTextureIntegerEXTSupported; }
|
2007-09-11 20:04:58 +08:00
|
|
|
|
2013-01-25 19:54:03 +08:00
|
|
|
bool isBindImageTextureSupported() const { return _glBindImageTexture!=0; }
|
|
|
|
|
2014-06-25 17:57:36 +08:00
|
|
|
void glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height) const
|
|
|
|
{
|
|
|
|
_glTexStorage2D(target, levels, internalformat, width, height);
|
|
|
|
}
|
|
|
|
|
2010-03-15 18:32:03 +08:00
|
|
|
void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) const
|
|
|
|
{
|
|
|
|
_glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) const
|
|
|
|
{
|
|
|
|
_glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void glGetCompressedTexImage(GLenum target, GLint level, GLvoid *data) const
|
|
|
|
{
|
|
|
|
_glGetCompressedTexImage(target, level, data);
|
|
|
|
}
|
|
|
|
|
2010-04-23 01:02:22 +08:00
|
|
|
void glTexImage2DMultisample(GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations) const
|
|
|
|
{
|
|
|
|
_glTexImage2DMultisample(target, samples, internalformat, width, height, fixedsamplelocations);
|
|
|
|
}
|
|
|
|
|
2010-03-15 18:32:03 +08:00
|
|
|
void glTexParameterIiv(GLenum target, GLenum pname, const GLint* data) const
|
|
|
|
{
|
2010-03-16 04:09:23 +08:00
|
|
|
_glTexParameterIiv(target, pname, data);
|
2010-03-15 18:32:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void glTexParameterIuiv(GLenum target, GLenum pname, const GLuint* data) const
|
|
|
|
{
|
2010-03-16 04:09:23 +08:00
|
|
|
_glTexParameterIuiv(target, pname, data);
|
2010-03-15 18:32:03 +08:00
|
|
|
}
|
2007-09-11 20:04:58 +08:00
|
|
|
|
2013-01-25 19:54:03 +08:00
|
|
|
// ARB_shader_image_load_store
|
|
|
|
void glBindImageTexture(GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format) const
|
|
|
|
{
|
|
|
|
_glBindImageTexture(unit, texture, level, layered, layer, access, format);
|
|
|
|
}
|
|
|
|
|
2002-09-17 04:58:05 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
~Extensions() {}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2014-06-25 17:57:36 +08:00
|
|
|
typedef void (GL_APIENTRY * TexStorage2DArbProc) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
|
2010-04-29 05:22:44 +08:00
|
|
|
typedef void (GL_APIENTRY * CompressedTexImage2DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data);
|
|
|
|
typedef void (GL_APIENTRY * CompressedTexSubImage2DArbProc) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data);
|
|
|
|
typedef void (GL_APIENTRY * GetCompressedTexImageArbProc) (GLenum target, GLint level, GLvoid *data);
|
|
|
|
typedef void (GL_APIENTRY * TexImage2DMultisample)(GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
|
|
|
|
typedef void (GL_APIENTRY * TexParameterIivProc)(GLenum target, GLenum pname, const GLint* data);
|
|
|
|
typedef void (GL_APIENTRY * TexParameterIuivProc)(GLenum target, GLenum pname, const GLuint* data);
|
2013-01-25 19:54:03 +08:00
|
|
|
typedef void (GL_APIENTRY * BindImageTextureProc)( GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format );
|
2010-03-15 18:32:03 +08:00
|
|
|
|
|
|
|
CompressedTexImage2DArbProc _glCompressedTexImage2D;
|
|
|
|
CompressedTexSubImage2DArbProc _glCompressedTexSubImage2D;
|
|
|
|
GetCompressedTexImageArbProc _glGetCompressedTexImage;
|
2010-04-23 01:02:22 +08:00
|
|
|
TexImage2DMultisample _glTexImage2DMultisample;
|
2010-03-15 18:32:03 +08:00
|
|
|
TexParameterIivProc _glTexParameterIiv;
|
|
|
|
TexParameterIuivProc _glTexParameterIuiv;
|
|
|
|
|
2013-01-25 19:54:03 +08:00
|
|
|
// ARB_shader_image_load_store
|
|
|
|
BindImageTextureProc _glBindImageTexture;
|
2010-03-15 18:32:03 +08:00
|
|
|
|
2014-06-25 17:57:36 +08:00
|
|
|
// ARB_texture_storage
|
|
|
|
TexStorage2DArbProc _glTexStorage2D;
|
|
|
|
|
2003-04-11 03:32:32 +08:00
|
|
|
bool _isMultiTexturingSupported;
|
2002-09-17 04:58:05 +08:00
|
|
|
bool _isTextureFilterAnisotropicSupported;
|
2013-06-03 23:10:53 +08:00
|
|
|
bool _isTextureSwizzleSupported;
|
2002-09-17 04:58:05 +08:00
|
|
|
bool _isTextureCompressionARBSupported;
|
|
|
|
bool _isTextureCompressionS3TCSupported;
|
2011-04-22 01:04:50 +08:00
|
|
|
bool _isTextureCompressionPVRTC2BPPSupported;
|
|
|
|
bool _isTextureCompressionPVRTC4BPPSupported;
|
|
|
|
bool _isTextureCompressionETCSupported;
|
2013-10-28 20:03:55 +08:00
|
|
|
bool _isTextureCompressionETC2Supported;
|
2010-08-16 22:11:49 +08:00
|
|
|
bool _isTextureCompressionRGTCSupported;
|
2010-11-04 19:02:37 +08:00
|
|
|
bool _isTextureCompressionPVRTCSupported;
|
2002-09-17 04:58:05 +08:00
|
|
|
bool _isTextureMirroredRepeatSupported;
|
|
|
|
bool _isTextureEdgeClampSupported;
|
|
|
|
bool _isTextureBorderClampSupported;
|
2003-03-04 23:47:28 +08:00
|
|
|
bool _isGenerateMipMapSupported;
|
2012-07-13 00:41:53 +08:00
|
|
|
bool _preferGenerateMipmapSGISForPowerOfTwo;
|
2010-04-23 01:02:22 +08:00
|
|
|
bool _isTextureMultisampledSupported;
|
2003-12-18 03:26:16 +08:00
|
|
|
bool _isShadowSupported;
|
2004-01-29 19:16:49 +08:00
|
|
|
bool _isShadowAmbientSupported;
|
2004-03-09 01:09:58 +08:00
|
|
|
bool _isClientStorageSupported;
|
2005-05-17 19:00:13 +08:00
|
|
|
bool _isNonPowerOfTwoTextureMipMappedSupported;
|
|
|
|
bool _isNonPowerOfTwoTextureNonMipMappedSupported;
|
2007-09-11 20:04:58 +08:00
|
|
|
bool _isTextureIntegerEXTSupported;
|
2009-06-19 19:55:52 +08:00
|
|
|
bool _isTextureMaxLevelSupported;
|
2014-06-25 17:57:36 +08:00
|
|
|
bool _isTextureStorageEnabled;
|
2007-09-11 20:04:58 +08:00
|
|
|
|
2002-09-17 04:58:05 +08:00
|
|
|
GLint _maxTextureSize;
|
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the extension for the specified context. Creates the
|
|
|
|
* Extensions object for that context if it doesn't exist.
|
|
|
|
* Returns NULL if the Extensions object for the context doesn't
|
|
|
|
* exist and the createIfNotInitalized flag is false. */
|
2003-04-10 21:41:45 +08:00
|
|
|
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
|
2002-09-17 04:58:05 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Overrides Extensions objects across graphics contexts. Typically
|
|
|
|
* used to ensure the same lowest common denominator of extensions
|
2007-12-11 01:30:18 +08:00
|
|
|
* on systems with different graphics pipes. */
|
2003-02-15 03:47:59 +08:00
|
|
|
static void setExtensions(unsigned int contextID,Extensions* extensions);
|
2002-09-17 04:58:05 +08:00
|
|
|
|
2006-06-30 21:47:12 +08:00
|
|
|
/** Determine whether the given internalFormat is a compressed
|
|
|
|
* image format. */
|
|
|
|
static bool isCompressedInternalFormat(GLint internalFormat);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-06-30 21:47:12 +08:00
|
|
|
/** Determine the size of a compressed image, given the internalFormat,
|
|
|
|
* the width, the height, and the depth of the image. The block size
|
|
|
|
* and the size are output parameters. */
|
|
|
|
static void getCompressedSize(GLenum internalFormat, GLint width, GLint height, GLint depth, GLint& blockSize, GLint& size);
|
|
|
|
|
2003-07-14 22:42:10 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Helper method. Creates the texture, but doesn't set or use a
|
|
|
|
* texture binding. Note: Don't call this method directly unless
|
|
|
|
* you're implementing a subload callback. */
|
2003-07-14 22:42:10 +08:00
|
|
|
void applyTexImage2D_load(State& state, GLenum target, const Image* image, GLsizei width, GLsizei height,GLsizei numMipmapLevels) const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Helper method. Subloads images into the texture, but doesn't set
|
|
|
|
* or use a texture binding. Note: Don't call this method directly
|
|
|
|
* unless you're implementing a subload callback. */
|
2004-01-23 21:25:45 +08:00
|
|
|
void applyTexImage2D_subload(State& state, GLenum target, const Image* image, GLsizei width, GLsizei height, GLint inInternalFormat, GLsizei numMipmapLevels) const;
|
2003-04-01 05:41:17 +08:00
|
|
|
|
2010-04-23 01:02:22 +08:00
|
|
|
|
2008-05-29 21:54:59 +08:00
|
|
|
/** Returned by mipmapBeforeTexImage() to indicate what
|
|
|
|
* mipmapAfterTexImage() should do */
|
|
|
|
enum GenerateMipmapMode
|
|
|
|
{
|
|
|
|
GENERATE_MIPMAP_NONE,
|
|
|
|
GENERATE_MIPMAP,
|
|
|
|
GENERATE_MIPMAP_TEX_PARAMETER
|
|
|
|
};
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~Texture();
|
2002-08-16 21:33:32 +08:00
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
virtual void computeInternalFormat() const = 0;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-09-14 21:19:55 +08:00
|
|
|
/** Computes the internal format from Image parameters. */
|
2003-04-01 19:49:09 +08:00
|
|
|
void computeInternalFormatWithImage(const osg::Image& image) const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2010-09-14 21:19:55 +08:00
|
|
|
/** Computes the texture dimension for the given Image. */
|
2003-07-14 22:42:10 +08:00
|
|
|
void computeRequiredTextureDimensions(State& state, const osg::Image& image,GLsizei& width, GLsizei& height,GLsizei& numMipmapLevels) const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-09-14 21:19:55 +08:00
|
|
|
/** Computes the internal format type. */
|
2007-09-11 20:04:58 +08:00
|
|
|
void computeInternalFormatType() const;
|
2003-07-14 22:42:10 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Helper method. Sets texture parameters. */
|
2002-08-28 23:28:11 +08:00
|
|
|
void applyTexParameters(GLenum target, State& state) const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2008-05-28 19:19:41 +08:00
|
|
|
/** Returns true if _useHardwareMipMapGeneration is true and either
|
|
|
|
* glGenerateMipmapEXT() or GL_GENERATE_MIPMAP_SGIS are supported. */
|
|
|
|
bool isHardwareMipmapGenerationEnabled(const State& state) const;
|
|
|
|
|
2010-09-14 21:19:55 +08:00
|
|
|
/** Returns true if the associated Image should be released and it's safe to do so. */
|
|
|
|
bool isSafeToUnrefImageData(const State& state) const {
|
|
|
|
return (_unrefImageDataAfterApply && state.getMaxTexturePoolSize()==0 && areAllTextureObjectsLoaded());
|
|
|
|
}
|
|
|
|
|
2008-05-28 19:19:41 +08:00
|
|
|
/** Helper methods to be called before and after calling
|
|
|
|
* gl[Compressed][Copy]Tex[Sub]Image2D to handle generating mipmaps. */
|
|
|
|
GenerateMipmapMode mipmapBeforeTexImage(const State& state, bool hardwareMipmapOn) const;
|
|
|
|
void mipmapAfterTexImage(State& state, GenerateMipmapMode beforeResult) const;
|
|
|
|
|
|
|
|
/** Helper method to generate mipmap levels by calling of glGenerateMipmapEXT.
|
2007-09-11 20:04:58 +08:00
|
|
|
* If it is not supported, then call the virtual allocateMipmap() method */
|
|
|
|
void generateMipmap(State& state) const;
|
2002-03-15 00:01:21 +08:00
|
|
|
|
2007-09-11 20:04:58 +08:00
|
|
|
/** Allocate mipmap levels of the texture by subsequent calling of glTexImage* function. */
|
|
|
|
virtual void allocateMipmap(State& state) const = 0;
|
2009-09-23 02:45:24 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Returns -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
2002-08-28 23:28:11 +08:00
|
|
|
int compareTexture(const Texture& rhs) const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2006-08-15 03:42:22 +08:00
|
|
|
/** Returns -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
|
|
|
int compareTextureObjects(const Texture& rhs) const;
|
|
|
|
|
2003-02-15 03:47:59 +08:00
|
|
|
typedef buffered_value<unsigned int> TexParameterDirtyList;
|
2002-09-04 16:14:04 +08:00
|
|
|
mutable TexParameterDirtyList _texParametersDirtyList;
|
2007-09-11 20:04:58 +08:00
|
|
|
mutable TexParameterDirtyList _texMipmapGenerationDirtyList;
|
2009-09-23 02:45:24 +08:00
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
WrapMode _wrap_s;
|
|
|
|
WrapMode _wrap_t;
|
|
|
|
WrapMode _wrap_r;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
FilterMode _min_filter;
|
|
|
|
FilterMode _mag_filter;
|
|
|
|
float _maxAnisotropy;
|
2013-06-03 23:10:53 +08:00
|
|
|
Vec4i _swizzle;
|
2003-04-01 05:41:17 +08:00
|
|
|
bool _useHardwareMipMapGeneration;
|
2003-04-07 20:51:00 +08:00
|
|
|
bool _unrefImageDataAfterApply;
|
2004-03-09 01:09:58 +08:00
|
|
|
bool _clientStorageHint;
|
2005-05-06 17:04:41 +08:00
|
|
|
bool _resizeNonPowerOfTwoHint;
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2007-09-11 20:04:58 +08:00
|
|
|
Vec4d _borderColor;
|
2004-01-28 05:29:58 +08:00
|
|
|
GLint _borderWidth;
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2007-09-11 20:04:58 +08:00
|
|
|
InternalFormatMode _internalFormatMode;
|
|
|
|
mutable InternalFormatType _internalFormatType;
|
2002-08-28 23:28:11 +08:00
|
|
|
mutable GLint _internalFormat;
|
2005-11-08 23:52:21 +08:00
|
|
|
mutable GLenum _sourceFormat;
|
|
|
|
mutable GLenum _sourceType;
|
2009-09-23 02:45:24 +08:00
|
|
|
|
2003-12-18 03:26:16 +08:00
|
|
|
bool _use_shadow_comparison;
|
|
|
|
ShadowCompareFunc _shadow_compare_func;
|
|
|
|
ShadowTextureMode _shadow_texture_mode;
|
2004-01-29 19:16:49 +08:00
|
|
|
float _shadow_ambient;
|
2003-12-18 03:26:16 +08:00
|
|
|
|
2013-01-25 19:54:03 +08:00
|
|
|
ImageAttachment _imageAttachment;
|
|
|
|
|
2003-07-14 22:42:10 +08:00
|
|
|
public:
|
2009-09-23 02:45:24 +08:00
|
|
|
|
2009-11-20 01:27:21 +08:00
|
|
|
struct OSG_EXPORT TextureProfile
|
2003-07-14 22:42:10 +08:00
|
|
|
{
|
2009-09-23 02:45:24 +08:00
|
|
|
inline TextureProfile(GLenum target):
|
2003-07-14 22:42:10 +08:00
|
|
|
_target(target),
|
|
|
|
_numMipmapLevels(0),
|
|
|
|
_internalFormat(0),
|
|
|
|
_width(0),
|
|
|
|
_height(0),
|
|
|
|
_depth(0),
|
2009-09-23 21:51:20 +08:00
|
|
|
_border(0),
|
|
|
|
_size(0) {}
|
2009-09-23 02:45:24 +08:00
|
|
|
|
|
|
|
inline TextureProfile(GLenum target,
|
|
|
|
GLint numMipmapLevels,
|
|
|
|
GLenum internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLsizei depth,
|
|
|
|
GLint border):
|
2003-07-14 22:42:10 +08:00
|
|
|
_target(target),
|
|
|
|
_numMipmapLevels(numMipmapLevels),
|
|
|
|
_internalFormat(internalFormat),
|
|
|
|
_width(width),
|
|
|
|
_height(height),
|
|
|
|
_depth(depth),
|
2009-09-23 21:51:20 +08:00
|
|
|
_border(border),
|
|
|
|
_size(0) { computeSize(); }
|
2009-09-23 02:45:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define LESSTHAN(A,B) if (A<B) return true; if (B<A) return false;
|
|
|
|
#define FINALLESSTHAN(A,B) return (A<B);
|
|
|
|
|
|
|
|
bool operator < (const TextureProfile& rhs) const
|
|
|
|
{
|
2009-09-23 21:51:20 +08:00
|
|
|
LESSTHAN(_size,rhs._size);
|
2009-09-23 02:45:24 +08:00
|
|
|
LESSTHAN(_target,rhs._target);
|
|
|
|
LESSTHAN(_numMipmapLevels,rhs._numMipmapLevels);
|
|
|
|
LESSTHAN(_internalFormat,rhs._internalFormat);
|
|
|
|
LESSTHAN(_width,rhs._width);
|
|
|
|
LESSTHAN(_height,rhs._height);
|
|
|
|
LESSTHAN(_depth,rhs._depth);
|
|
|
|
FINALLESSTHAN(_border, rhs._border);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator == (const TextureProfile& rhs) const
|
|
|
|
{
|
|
|
|
return _target == rhs._target &&
|
|
|
|
_numMipmapLevels == rhs._numMipmapLevels &&
|
|
|
|
_internalFormat == rhs._internalFormat &&
|
|
|
|
_width == rhs._width &&
|
|
|
|
_height == rhs._height &&
|
|
|
|
_depth == rhs._depth &&
|
|
|
|
_border == rhs._border;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void set(GLint numMipmapLevels,
|
|
|
|
GLenum internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLsizei depth,
|
|
|
|
GLint border)
|
|
|
|
{
|
|
|
|
_numMipmapLevels = numMipmapLevels;
|
|
|
|
_internalFormat = internalFormat;
|
|
|
|
_width = width;
|
|
|
|
_height = height;
|
|
|
|
_depth = depth;
|
|
|
|
_border = border;
|
2010-11-05 01:53:58 +08:00
|
|
|
computeSize();
|
2009-09-23 02:45:24 +08:00
|
|
|
}
|
|
|
|
|
2003-07-14 22:42:10 +08:00
|
|
|
inline bool match(GLenum target,
|
|
|
|
GLint numMipmapLevels,
|
|
|
|
GLenum internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLsizei depth,
|
|
|
|
GLint border)
|
|
|
|
{
|
2009-09-23 02:45:24 +08:00
|
|
|
return (_target == target) &&
|
2003-07-14 22:42:10 +08:00
|
|
|
(_numMipmapLevels == numMipmapLevels) &&
|
|
|
|
(_internalFormat == internalFormat) &&
|
|
|
|
(_width == width) &&
|
|
|
|
(_height == height) &&
|
|
|
|
(_depth == depth) &&
|
|
|
|
(_border == border);
|
|
|
|
}
|
2009-09-23 02:45:24 +08:00
|
|
|
|
2009-09-23 21:51:20 +08:00
|
|
|
void computeSize();
|
|
|
|
|
|
|
|
GLenum _target;
|
|
|
|
GLint _numMipmapLevels;
|
|
|
|
GLenum _internalFormat;
|
|
|
|
GLsizei _width;
|
|
|
|
GLsizei _height;
|
|
|
|
GLsizei _depth;
|
|
|
|
GLint _border;
|
|
|
|
unsigned int _size;
|
2009-09-23 02:45:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// forward declare
|
|
|
|
class TextureObjectSet;
|
|
|
|
class TextureObjectManager;
|
|
|
|
|
2009-09-23 23:16:34 +08:00
|
|
|
class OSG_EXPORT TextureObject : public osg::Referenced
|
2009-09-23 02:45:24 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
inline TextureObject(Texture* texture, GLuint id, GLenum target):
|
|
|
|
_id(id),
|
|
|
|
_profile(target),
|
|
|
|
_set(0),
|
|
|
|
_previous(0),
|
|
|
|
_next(0),
|
|
|
|
_texture(texture),
|
|
|
|
_allocated(false),
|
|
|
|
_timeStamp(0) {}
|
|
|
|
|
|
|
|
inline TextureObject(Texture* texture, GLuint id, const TextureProfile& profile):
|
|
|
|
_id(id),
|
|
|
|
_profile(profile),
|
|
|
|
_set(0),
|
|
|
|
_previous(0),
|
|
|
|
_next(0),
|
|
|
|
_texture(texture),
|
|
|
|
_allocated(false),
|
|
|
|
_timeStamp(0) {}
|
|
|
|
|
|
|
|
inline TextureObject(Texture* texture,
|
|
|
|
GLuint id,
|
|
|
|
GLenum target,
|
|
|
|
GLint numMipmapLevels,
|
|
|
|
GLenum internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLsizei depth,
|
|
|
|
GLint border):
|
|
|
|
_id(id),
|
|
|
|
_profile(target,numMipmapLevels,internalFormat,width,height,depth,border),
|
|
|
|
_set(0),
|
|
|
|
_previous(0),
|
|
|
|
_next(0),
|
|
|
|
_texture(texture),
|
|
|
|
_allocated(false),
|
|
|
|
_timeStamp(0) {}
|
|
|
|
|
|
|
|
inline bool match(GLenum target,
|
|
|
|
GLint numMipmapLevels,
|
|
|
|
GLenum internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLsizei depth,
|
|
|
|
GLint border)
|
2003-07-14 22:42:10 +08:00
|
|
|
{
|
2009-09-23 02:45:24 +08:00
|
|
|
return isReusable() &&
|
|
|
|
_profile.match(target,numMipmapLevels,internalFormat,width,height,depth,border);
|
2003-07-14 22:42:10 +08:00
|
|
|
}
|
|
|
|
|
2009-11-26 20:33:07 +08:00
|
|
|
|
2009-09-23 02:45:24 +08:00
|
|
|
void bind();
|
|
|
|
|
|
|
|
inline GLenum id() const { return _id; }
|
|
|
|
inline GLenum target() const { return _profile._target; }
|
|
|
|
|
2009-09-23 21:51:20 +08:00
|
|
|
inline unsigned int size() const { return _profile._size; }
|
|
|
|
|
2009-09-23 02:45:24 +08:00
|
|
|
inline void setTexture(Texture* texture) { _texture = texture; }
|
|
|
|
inline Texture* getTexture() const { return _texture; }
|
|
|
|
|
|
|
|
inline void setTimeStamp(double timestamp) { _timeStamp = timestamp; }
|
|
|
|
inline double getTimeStamp() const { return _timeStamp; }
|
2003-07-14 22:42:10 +08:00
|
|
|
|
|
|
|
inline void setAllocated(bool allocated=true) { _allocated = allocated; }
|
2009-09-23 02:45:24 +08:00
|
|
|
|
2009-09-27 23:14:57 +08:00
|
|
|
void setAllocated(GLint numMipmapLevels,
|
2003-07-14 22:42:10 +08:00
|
|
|
GLenum internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLsizei depth,
|
2009-09-27 23:14:57 +08:00
|
|
|
GLint border);
|
2009-09-23 02:45:24 +08:00
|
|
|
|
2003-07-14 22:42:10 +08:00
|
|
|
inline bool isAllocated() const { return _allocated; }
|
|
|
|
|
2009-09-23 02:45:24 +08:00
|
|
|
inline bool isReusable() const { return _allocated && _profile._width!=0; }
|
2003-07-14 22:42:10 +08:00
|
|
|
|
|
|
|
|
2009-09-23 02:45:24 +08:00
|
|
|
GLuint _id;
|
|
|
|
TextureProfile _profile;
|
|
|
|
TextureObjectSet* _set;
|
|
|
|
TextureObject* _previous;
|
|
|
|
TextureObject* _next;
|
|
|
|
Texture* _texture;
|
|
|
|
bool _allocated;
|
2009-09-26 02:05:54 +08:00
|
|
|
unsigned int _frameLastUsed;
|
2009-09-23 02:45:24 +08:00
|
|
|
double _timeStamp;
|
2009-11-26 20:33:07 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~TextureObject();
|
|
|
|
|
2003-07-14 22:42:10 +08:00
|
|
|
};
|
2009-09-23 02:45:24 +08:00
|
|
|
|
2003-07-14 22:42:10 +08:00
|
|
|
typedef std::list< ref_ptr<TextureObject> > TextureObjectList;
|
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
class OSG_EXPORT TextureObjectSet : public Referenced
|
2009-09-23 02:45:24 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextureObjectSet(TextureObjectManager* parent, const TextureProfile& profile);
|
|
|
|
|
2010-12-15 03:29:01 +08:00
|
|
|
const TextureProfile& getProfile() const { return _profile; }
|
|
|
|
|
2009-09-23 02:45:24 +08:00
|
|
|
void handlePendingOrphandedTextureObjects();
|
2009-11-26 20:33:07 +08:00
|
|
|
|
|
|
|
void deleteAllTextureObjects();
|
|
|
|
void discardAllTextureObjects();
|
2009-09-23 02:45:24 +08:00
|
|
|
void flushAllDeletedTextureObjects();
|
|
|
|
void discardAllDeletedTextureObjects();
|
|
|
|
void flushDeletedTextureObjects(double currentTime, double& availableTime);
|
|
|
|
|
2009-09-26 02:05:54 +08:00
|
|
|
TextureObject* takeFromOrphans(Texture* texture);
|
2009-09-23 02:45:24 +08:00
|
|
|
TextureObject* takeOrGenerate(Texture* texture);
|
|
|
|
void moveToBack(TextureObject* to);
|
|
|
|
void addToBack(TextureObject* to);
|
|
|
|
void orphan(TextureObject* to);
|
2009-09-27 23:14:57 +08:00
|
|
|
void remove(TextureObject* to);
|
2009-10-06 21:42:12 +08:00
|
|
|
void moveToSet(TextureObject* to, TextureObjectSet* set);
|
2009-09-27 23:14:57 +08:00
|
|
|
|
2009-09-23 21:51:20 +08:00
|
|
|
unsigned int size() const { return _profile._size * _numOfTextureObjects; }
|
|
|
|
|
|
|
|
bool makeSpace(unsigned int& size);
|
2003-07-14 22:42:10 +08:00
|
|
|
|
2009-09-23 02:45:24 +08:00
|
|
|
bool checkConsistency() const;
|
|
|
|
|
2009-09-27 23:14:57 +08:00
|
|
|
TextureObjectManager* getParent() { return _parent; }
|
|
|
|
|
2010-12-15 03:29:01 +08:00
|
|
|
unsigned int computeNumTextureObjectsInList() const;
|
|
|
|
unsigned int getNumOfTextureObjects() const { return _numOfTextureObjects; }
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumOrphans() const { return static_cast<unsigned int>(_orphanedTextureObjects.size()); }
|
|
|
|
unsigned int getNumPendingOrphans() const { return static_cast<unsigned int>(_pendingOrphanedTextureObjects.size()); }
|
2010-12-15 03:29:01 +08:00
|
|
|
|
2009-09-23 02:45:24 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~TextureObjectSet();
|
|
|
|
|
|
|
|
OpenThreads::Mutex _mutex;
|
|
|
|
|
|
|
|
TextureObjectManager* _parent;
|
|
|
|
unsigned int _contextID;
|
|
|
|
TextureProfile _profile;
|
|
|
|
unsigned int _numOfTextureObjects;
|
|
|
|
TextureObjectList _orphanedTextureObjects;
|
|
|
|
TextureObjectList _pendingOrphanedTextureObjects;
|
|
|
|
|
|
|
|
TextureObject* _head;
|
|
|
|
TextureObject* _tail;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-09-23 23:16:34 +08:00
|
|
|
class OSG_EXPORT TextureObjectManager : public osg::Referenced
|
2009-09-23 02:45:24 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextureObjectManager(unsigned int contextID);
|
|
|
|
|
|
|
|
unsigned int getContextID() const { return _contextID; }
|
|
|
|
|
2009-09-26 02:05:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
void setNumberActiveTextureObjects(unsigned int size) { _numActiveTextureObjects = size; }
|
|
|
|
unsigned int& getNumberActiveTextureObjects() { return _numActiveTextureObjects; }
|
|
|
|
unsigned int getNumberActiveTextureObjects() const { return _numActiveTextureObjects; }
|
|
|
|
|
|
|
|
void setNumberOrphanedTextureObjects(unsigned int size) { _numOrphanedTextureObjects = size; }
|
|
|
|
unsigned int& getNumberOrphanedTextureObjects() { return _numOrphanedTextureObjects; }
|
|
|
|
unsigned int getNumberOrphanedTextureObjects() const { return _numOrphanedTextureObjects; }
|
|
|
|
|
2009-09-23 21:51:20 +08:00
|
|
|
void setCurrTexturePoolSize(unsigned int size) { _currTexturePoolSize = size; }
|
2009-09-26 02:05:54 +08:00
|
|
|
unsigned int& getCurrTexturePoolSize() { return _currTexturePoolSize; }
|
2009-09-23 21:51:20 +08:00
|
|
|
unsigned int getCurrTexturePoolSize() const { return _currTexturePoolSize; }
|
|
|
|
|
|
|
|
void setMaxTexturePoolSize(unsigned int size);
|
|
|
|
unsigned int getMaxTexturePoolSize() const { return _maxTexturePoolSize; }
|
|
|
|
|
|
|
|
bool hasSpace(unsigned int size) const { return (_currTexturePoolSize+size)<=_maxTexturePoolSize; }
|
|
|
|
bool makeSpace(unsigned int size);
|
2009-09-23 02:45:24 +08:00
|
|
|
|
|
|
|
TextureObject* generateTextureObject(const Texture* texture, GLenum target);
|
|
|
|
TextureObject* generateTextureObject(const Texture* texture,
|
|
|
|
GLenum target,
|
|
|
|
GLint numMipmapLevels,
|
|
|
|
GLenum internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLsizei depth,
|
|
|
|
GLint border);
|
|
|
|
void handlePendingOrphandedTextureObjects();
|
2009-11-26 20:33:07 +08:00
|
|
|
void deleteAllTextureObjects();
|
|
|
|
void discardAllTextureObjects();
|
2009-09-23 02:45:24 +08:00
|
|
|
void flushAllDeletedTextureObjects();
|
|
|
|
void discardAllDeletedTextureObjects();
|
|
|
|
void flushDeletedTextureObjects(double currentTime, double& availableTime);
|
|
|
|
void releaseTextureObject(TextureObject* to);
|
|
|
|
|
2009-09-27 23:14:57 +08:00
|
|
|
TextureObjectSet* getTextureObjectSet(const TextureProfile& profile);
|
2009-09-26 02:05:54 +08:00
|
|
|
|
|
|
|
void newFrame(osg::FrameStamp* fs);
|
|
|
|
void resetStats();
|
2010-12-15 03:29:01 +08:00
|
|
|
void reportStats(std::ostream& out);
|
2010-12-16 03:44:29 +08:00
|
|
|
void recomputeStats(std::ostream& out) const;
|
|
|
|
bool checkConsistency() const;
|
2009-09-26 02:05:54 +08:00
|
|
|
|
|
|
|
unsigned int& getFrameNumber() { return _frameNumber; }
|
|
|
|
unsigned int& getNumberFrames() { return _numFrames; }
|
|
|
|
|
|
|
|
unsigned int& getNumberDeleted() { return _numDeleted; }
|
|
|
|
double& getDeleteTime() { return _deleteTime; }
|
|
|
|
|
|
|
|
unsigned int& getNumberGenerated() { return _numGenerated; }
|
|
|
|
double& getGenerateTime() { return _generateTime; }
|
|
|
|
|
|
|
|
unsigned int& getNumberApplied() { return _numApplied; }
|
|
|
|
double& getApplyTime() { return _applyTime; }
|
|
|
|
|
|
|
|
|
2009-09-23 02:45:24 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef std::map< TextureProfile, osg::ref_ptr<TextureObjectSet> > TextureSetMap;
|
|
|
|
unsigned int _contextID;
|
2009-09-26 02:05:54 +08:00
|
|
|
unsigned int _numActiveTextureObjects;
|
|
|
|
unsigned int _numOrphanedTextureObjects;
|
2009-09-23 21:51:20 +08:00
|
|
|
unsigned int _currTexturePoolSize;
|
|
|
|
unsigned int _maxTexturePoolSize;
|
2009-09-23 02:45:24 +08:00
|
|
|
TextureSetMap _textureSetMap;
|
2009-09-26 02:05:54 +08:00
|
|
|
|
|
|
|
unsigned int _frameNumber;
|
|
|
|
|
|
|
|
unsigned int _numFrames;
|
|
|
|
unsigned int _numDeleted;
|
|
|
|
double _deleteTime;
|
|
|
|
|
|
|
|
unsigned int _numGenerated;
|
|
|
|
double _generateTime;
|
|
|
|
|
|
|
|
unsigned int _numApplied;
|
|
|
|
double _applyTime;
|
|
|
|
|
2009-09-23 02:45:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static osg::ref_ptr<Texture::TextureObjectManager>& getTextureObjectManager(unsigned int contextID);
|
|
|
|
|
|
|
|
static TextureObject* generateTextureObject(const Texture* texture, unsigned int contextID,GLenum target);
|
|
|
|
|
|
|
|
static TextureObject* generateTextureObject(const Texture* texture,
|
|
|
|
unsigned int contextID,
|
2004-09-22 05:33:52 +08:00
|
|
|
GLenum target,
|
|
|
|
GLint numMipmapLevels,
|
|
|
|
GLenum internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLsizei depth,
|
|
|
|
GLint border);
|
2003-07-14 22:42:10 +08:00
|
|
|
|
2009-11-26 20:33:07 +08:00
|
|
|
static void deleteAllTextureObjects(unsigned int contextID);
|
|
|
|
static void discardAllTextureObjects(unsigned int contextID);
|
2004-09-22 05:33:52 +08:00
|
|
|
static void flushAllDeletedTextureObjects(unsigned int contextID);
|
2008-01-08 21:24:29 +08:00
|
|
|
static void discardAllDeletedTextureObjects(unsigned int contextID);
|
2004-09-22 05:33:52 +08:00
|
|
|
static void flushDeletedTextureObjects(unsigned int contextID,double currentTime, double& availableTime);
|
2009-09-23 02:45:24 +08:00
|
|
|
static void releaseTextureObject(unsigned int contextID, TextureObject* to);
|
2004-09-22 05:33:52 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef buffered_object< ref_ptr<TextureObject> > TextureObjectBuffer;
|
2005-08-31 20:56:15 +08:00
|
|
|
mutable TextureObjectBuffer _textureObjectBuffer;
|
|
|
|
mutable ref_ptr<GraphicsContext> _readPBuffer;
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
};
|
2002-08-25 03:39:39 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-08-25 23:31:44 +08:00
|
|
|
#endif
|