Added support for APPLE_client_storage of textures.
This commit is contained in:
parent
136db7b63a
commit
358743f999
@ -184,6 +184,13 @@ class SG_EXPORT Texture : public osg::StateAttribute
|
||||
/** Get the automatic unreference of image data after the texture has been set up in apply.*/
|
||||
inline bool getUnRefImageDataAfterApply() const { return _unrefImageDataAfterApply; }
|
||||
|
||||
/** Set whether to use client storage of the texture where supported by OpenGL drivers.
|
||||
* Note, if UseClientStorageHint is set, and the OpenGL drivers support it, the osg::Image(s) associated with
|
||||
* this texture cannot be deleted, so the UnRefImageDataAfterApply flag is then ignored.*/
|
||||
inline void setClientStorageHint(bool flag) { _clientStorageHint = flag; }
|
||||
|
||||
/** Get whether to use client storage of the texture where supported by OpenGL drivers.*/
|
||||
inline bool getClientStorageHint() const { return _clientStorageHint; }
|
||||
|
||||
enum InternalFormatMode {
|
||||
USE_IMAGE_DATA_FORMAT,
|
||||
@ -337,6 +344,9 @@ class SG_EXPORT Texture : public osg::StateAttribute
|
||||
void setGetCompressedTexImageProc(void* ptr) { _glGetCompressedTexImage = ptr; }
|
||||
void glGetCompressedTexImage(GLenum target, GLint level, GLvoid *data) const;
|
||||
|
||||
bool isClientStorageSupported() const { return _isClientStorageSupported; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
~Extensions() {}
|
||||
@ -351,6 +361,7 @@ class SG_EXPORT Texture : public osg::StateAttribute
|
||||
bool _isGenerateMipMapSupported;
|
||||
bool _isShadowSupported;
|
||||
bool _isShadowAmbientSupported;
|
||||
bool _isClientStorageSupported;
|
||||
|
||||
GLint _maxTextureSize;
|
||||
|
||||
@ -414,6 +425,7 @@ class SG_EXPORT Texture : public osg::StateAttribute
|
||||
float _maxAnisotropy;
|
||||
bool _useHardwareMipMapGeneration;
|
||||
bool _unrefImageDataAfterApply;
|
||||
bool _clientStorageHint;
|
||||
|
||||
Vec4 _borderColor;
|
||||
GLint _borderWidth;
|
||||
@ -426,6 +438,7 @@ class SG_EXPORT Texture : public osg::StateAttribute
|
||||
ShadowTextureMode _shadow_texture_mode;
|
||||
float _shadow_ambient;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
class TextureObject : public osg::Referenced
|
||||
|
@ -24,6 +24,18 @@ using namespace osg;
|
||||
#define GL_TEXTURE_WRAP_R 0x8072
|
||||
#endif
|
||||
|
||||
#ifndef GL_UNPACK_CLIENT_STORAGE_APPLE
|
||||
#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2
|
||||
#endif
|
||||
|
||||
#ifndef GL_APPLE_vertex_array_range
|
||||
#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D
|
||||
#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E
|
||||
#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F
|
||||
#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521
|
||||
#define GL_STORAGE_CACHED_APPLE 0x85BE
|
||||
#define GL_STORAGE_SHARED_APPLE 0x85BF
|
||||
#endif
|
||||
|
||||
Texture::TextureObject* Texture::TextureObjectManager::generateTextureObject(unsigned int /*contextID*/,GLenum target)
|
||||
{
|
||||
@ -172,6 +184,7 @@ Texture::Texture():
|
||||
_maxAnisotropy(1.0f),
|
||||
_useHardwareMipMapGeneration(true),
|
||||
_unrefImageDataAfterApply(false),
|
||||
_clientStorageHint(false),
|
||||
_borderColor(0.0, 0.0, 0.0, 0.0),
|
||||
_borderWidth(0),
|
||||
_internalFormatMode(USE_IMAGE_DATA_FORMAT),
|
||||
@ -193,6 +206,7 @@ Texture::Texture(const Texture& text,const CopyOp& copyop):
|
||||
_maxAnisotropy(text._maxAnisotropy),
|
||||
_useHardwareMipMapGeneration(text._useHardwareMipMapGeneration),
|
||||
_unrefImageDataAfterApply(text._unrefImageDataAfterApply),
|
||||
_clientStorageHint(text._clientStorageHint),
|
||||
_borderColor(text._borderColor),
|
||||
_borderWidth(text._borderWidth),
|
||||
_internalFormatMode(text._internalFormatMode),
|
||||
@ -227,6 +241,9 @@ int Texture::compareTexture(const Texture& rhs) const
|
||||
COMPARE_StateAttribute_Parameter(_shadow_compare_func)
|
||||
COMPARE_StateAttribute_Parameter(_shadow_texture_mode)
|
||||
COMPARE_StateAttribute_Parameter(_shadow_ambient)
|
||||
|
||||
COMPARE_StateAttribute_Parameter(_unrefImageDataAfterApply)
|
||||
COMPARE_StateAttribute_Parameter(_clientStorageHint)
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -584,6 +601,18 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking());
|
||||
|
||||
bool useClientStorage = extensions->isClientStorageSupported() && getClientStorageHint();
|
||||
if (useClientStorage)
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE,GL_TRUE);
|
||||
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_PRIORITY,0.0f);
|
||||
|
||||
#ifdef GL_TEXTURE_STORAGE_HINT_APPLE
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
unsigned char* data = (unsigned char*)image->data();
|
||||
|
||||
|
||||
@ -749,6 +778,10 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
if (useClientStorage)
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE,GL_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1051,6 +1084,8 @@ Texture::Extensions::Extensions(const Extensions& rhs):
|
||||
|
||||
_isShadowSupported = rhs._isShadowSupported;
|
||||
_isShadowAmbientSupported = rhs._isShadowAmbientSupported;
|
||||
|
||||
_isClientStorageSupported = rhs._isClientStorageSupported;
|
||||
}
|
||||
|
||||
void Texture::Extensions::lowestCommonDenominator(const Extensions& rhs)
|
||||
@ -1073,8 +1108,10 @@ void Texture::Extensions::lowestCommonDenominator(const Extensions& rhs)
|
||||
if (!rhs._glCompressedTexSubImage2D) _glCompressedTexSubImage2D = 0;
|
||||
if (!rhs._glGetCompressedTexImage) _glGetCompressedTexImage = 0;
|
||||
|
||||
if (!rhs._isShadowSupported) _isShadowSupported = 0;
|
||||
if (!rhs._isShadowAmbientSupported) _isShadowAmbientSupported = 0;
|
||||
if (!rhs._isShadowSupported) _isShadowSupported = false;
|
||||
if (!rhs._isShadowAmbientSupported) _isShadowAmbientSupported = false;
|
||||
|
||||
if (!rhs._isClientStorageSupported) _isClientStorageSupported = false;
|
||||
}
|
||||
|
||||
void Texture::Extensions::setupGLExtenions()
|
||||
@ -1094,6 +1131,8 @@ void Texture::Extensions::setupGLExtenions()
|
||||
_isShadowSupported = isGLExtensionSupported("GL_ARB_shadow");
|
||||
_isShadowAmbientSupported = isGLExtensionSupported("GL_ARB_shadow_ambient");
|
||||
|
||||
_isClientStorageSupported = isGLExtensionSupported("GL_APPLE_client_storage");
|
||||
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&_maxTextureSize);
|
||||
|
||||
char *ptr;
|
||||
|
Loading…
Reference in New Issue
Block a user