From 0b27e5c381b87751cbefa106834441b67cdd44d7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Mar 2002 11:24:47 +0000 Subject: [PATCH] Updates to Texture and TextureCubeMap to clean up the code so they share much more of the core texture setup code. This largely invloved paramterizing the applyImmediateMode, which has also been rename applyTexImage to reflect its functionality better. --- include/osg/Texture | 19 ++- include/osg/TextureCubeMap | 5 - src/Demos/osgtexture/osgtexture.cpp | 2 +- src/osg/Texture.cpp | 132 +++++++-------- src/osg/TextureCubeMap.cpp | 244 +--------------------------- 5 files changed, 86 insertions(+), 316 deletions(-) diff --git a/include/osg/Texture b/include/osg/Texture index d5ddb0ddd..e508d25bc 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -105,7 +105,7 @@ class SG_EXPORT Texture : public StateAttribute virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const { - ds.setMode(GL_TEXTURE_2D,value); + ds.setMode(_target,value); } /** Set the texture image. */ @@ -122,7 +122,7 @@ class SG_EXPORT Texture : public StateAttribute * framebuffer contents at pos \a x, \a y with width \a width and * height \a height. \a width and \a height must be a power of two. */ - void copyTexImage2D(State& state, int x, int y, int width, int height ); + void copyTexImage2D(State& state, int x, int y, int width, int height ); /** Copy a two-dimensional texture subimage. As per glCopyTexSubImage2D. * Updates portion of an existing OpenGL texture object from the current OpenGL background @@ -130,7 +130,7 @@ class SG_EXPORT Texture : public StateAttribute * height \a height. \a width and \a height must be a power of two, * and writing into the texture with offset \a xoffset and \a yoffset. */ - void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height ); + void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height ); /** Set the texture unit. * Valid values are 0,1,2,3. @@ -182,12 +182,13 @@ class SG_EXPORT Texture : public StateAttribute NEAREST = GL_NEAREST, NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR, NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST, - ANISOTROPIC = GL_TEXTURE_MAX_ANISOTROPY_EXT + ANISOTROPIC = GL_TEXTURE_MAX_ANISOTROPY_EXT }; /** Set the texture filter mode.*/ void setFilter(const FilterParameter which, const FilterMode filter); + /** Get the texture filter mode.*/ const FilterMode getFilter(const FilterParameter which) const; @@ -288,9 +289,6 @@ class SG_EXPORT Texture : public StateAttribute virtual void compile(State& state) const; - /** Method which does the creation of the texture itself, and - * does not set or use texture binding. */ - virtual void applyImmediateMode(State& state) const; @@ -310,7 +308,12 @@ class SG_EXPORT Texture : public StateAttribute virtual ~Texture(); - void applyTexParameters(State& state) const; + /** Method which does setting of texture paramters. */ + void applyTexParameters(GLenum target, State& state) const; + + /** Method which does the creation of the texture itself, and + * does not set or use texture binding. */ + virtual void applyTexImage(GLenum target, Image* image, State& state) const; typedef std::vector TextureNameList; mutable TextureNameList _handleList; diff --git a/include/osg/TextureCubeMap b/include/osg/TextureCubeMap index a41534f46..b678b3e6b 100644 --- a/include/osg/TextureCubeMap +++ b/include/osg/TextureCubeMap @@ -45,11 +45,6 @@ class SG_EXPORT TextureCubeMap : public Texture * texture and bind it, subsequent apply will simple bind to texture.*/ virtual void apply(State& state) const; - /** Method which does the creation of the texture itself, and - * does not set or use texture binding. */ - virtual void applyImmediateMode(State& state) const; - virtual void applyFaceImmediateMode(GLenum facetarget, Image* image, State& state) const; - protected : virtual ~TextureCubeMap(); diff --git a/src/Demos/osgtexture/osgtexture.cpp b/src/Demos/osgtexture/osgtexture.cpp index e10c0795d..4696b91b9 100644 --- a/src/Demos/osgtexture/osgtexture.cpp +++ b/src/Demos/osgtexture/osgtexture.cpp @@ -48,7 +48,7 @@ class TextureCallback : public osg::NodeCallback double currTime = nv->getFrameStamp()->getReferenceTime(); if (currTime-_prevTime>1.0) { - std::cout<<"Updating texturing filter to "<setFilter(osg::Texture::MAG_FILTER,_filterRange[_currPos]); _currPos++; if (_currPos>=_filterRange.size()) _currPos=0; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index fdad18829..bc0a1a02a 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -1,5 +1,5 @@ #if defined(_MSC_VER) - #pragma warning( disable : 4786 ) + #pragma warning( disable : 4786 ) #endif #include @@ -21,6 +21,8 @@ Texture::Texture() _handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); _modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); + _target = GL_TEXTURE_2D; + _textureUnit = 0; _wrap_s = CLAMP; @@ -193,8 +195,8 @@ void Texture::apply(State& state) const { if (_subloadMode == OFF) { - glBindTexture( GL_TEXTURE_2D, handle ); - if (_texParamtersDirty) applyTexParameters(state); + glBindTexture( _target, handle ); + if (_texParamtersDirty) applyTexParameters(_target,state); } else if (_image.valid() && _image->data()) { @@ -203,9 +205,9 @@ void Texture::apply(State& state) const if (_subloadMode == AUTO || (_subloadMode == IF_DIRTY && modifiedTag != _image->getModifiedTag())) { - glBindTexture( GL_TEXTURE_2D, handle ); - if (_texParamtersDirty) applyTexParameters(state); - glTexSubImage2D(GL_TEXTURE_2D, 0, + glBindTexture( _target, handle ); + if (_texParamtersDirty) applyTexParameters(_target,state); + glTexSubImage2D(_target, 0, _subloadOffsX, _subloadOffsY, _image->s(), _image->t(), (GLenum) _image->pixelFormat(), (GLenum) _image->dataType(), @@ -219,15 +221,15 @@ void Texture::apply(State& state) const { glGenTextures( 1L, (GLuint *)&handle ); - glBindTexture( GL_TEXTURE_2D, handle ); + glBindTexture( _target, handle ); - applyImmediateMode(state); + applyTexImage(_target,_image.get(),state); // in theory the following line is redundent, but in practice // have found that the first frame drawn doesn't apply the textures // unless a second bind is called?!! // perhaps it is the first glBind which is not required... - glBindTexture( GL_TEXTURE_2D, handle ); + glBindTexture( _target, handle ); } } @@ -238,7 +240,7 @@ void Texture::compile(State& state) const } -void Texture::applyTexParameters(State&) const +void Texture::applyTexParameters(GLenum target, State&) const { WrapMode ws = _wrap_s, wt = _wrap_t; @@ -271,14 +273,14 @@ void Texture::applyTexParameters(State&) const wt = CLAMP; } - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, ws ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wt ); + glTexParameteri( target, GL_TEXTURE_WRAP_S, ws ); + glTexParameteri( target, GL_TEXTURE_WRAP_T, wt ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _min_filter); + glTexParameteri( target, GL_TEXTURE_MIN_FILTER, _min_filter); if (s_borderClampSupported) { - glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, _borderColor.ptr()); + glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, _borderColor.ptr()); } if (_mag_filter == ANISOTROPIC) @@ -294,26 +296,26 @@ void Texture::applyTexParameters(State&) const { // note, GL_TEXTURE_MAX_ANISOTROPY_EXT will either be defined // by gl.h (or via glext.h) or by include/osg/Texture. - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.f); + glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.f); } else { - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, LINEAR); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, LINEAR); } } else { - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _mag_filter); + glTexParameteri( _target, GL_TEXTURE_MAG_FILTER, _mag_filter); } _texParamtersDirty=false; } -void Texture::applyImmediateMode(State& state) const +void Texture::applyTexImage(GLenum target, Image* image, State& state) const { // if we don't have a valid image we can't create a texture! - if (!_image.valid() || !_image->data()) + if (!_image || !_image->data()) return; // get the contextID (user defined ID of 0 upwards) for the @@ -321,31 +323,31 @@ void Texture::applyImmediateMode(State& state) const const uint contextID = state.getContextID(); // update the modified tag to show that it is upto date. - getModifiedTag(contextID) = _image->getModifiedTag(); + getModifiedTag(contextID) = image->getModifiedTag(); if (_subloadMode == OFF) - _image->ensureDimensionsArePowerOfTwo(); + image->ensureDimensionsArePowerOfTwo(); - glPixelStorei(GL_UNPACK_ALIGNMENT,_image->packing()); + glPixelStorei(GL_UNPACK_ALIGNMENT,image->packing()); - applyTexParameters(state); + applyTexParameters(target,state); static bool s_ARB_Compression = isGLExtensionSupported("GL_ARB_texture_compression"); static bool s_S3TC_Compression = isGLExtensionSupported("GL_EXT_texture_compression_s3tc"); // select the internalFormat required for the texture. - int internalFormat = _image->internalFormat(); + int internalFormat = image->internalFormat(); switch(_internalFormatMode) { case(USE_IMAGE_DATA_FORMAT): - internalFormat = _image->internalFormat(); + internalFormat = image->internalFormat(); break; case(USE_ARB_COMPRESSION): if (s_ARB_Compression) { - switch(_image->pixelFormat()) + switch(image->pixelFormat()) { case(1): internalFormat = GL_COMPRESSED_ALPHA_ARB; break; case(2): internalFormat = GL_COMPRESSED_LUMINANCE_ALPHA_ARB; break; @@ -359,28 +361,28 @@ void Texture::applyImmediateMode(State& state) const case(GL_INTENSITY): internalFormat = GL_COMPRESSED_INTENSITY_ARB; break; } } - else internalFormat = _image->internalFormat(); + else internalFormat = image->internalFormat(); break; case(USE_S3TC_DXT1_COMPRESSION): if (s_S3TC_Compression) { - switch(_image->pixelFormat()) + switch(image->pixelFormat()) { case(3): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break; case(4): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break; case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; - default: internalFormat = _image->internalFormat(); break; + default: internalFormat = image->internalFormat(); break; } } - else internalFormat = _image->internalFormat(); + else internalFormat = image->internalFormat(); break; case(USE_S3TC_DXT3_COMPRESSION): if (s_S3TC_Compression) { - switch(_image->pixelFormat()) + switch(image->pixelFormat()) { case(3): case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break; @@ -389,22 +391,22 @@ void Texture::applyImmediateMode(State& state) const default: internalFormat = _image->internalFormat(); break; } } - else internalFormat = _image->internalFormat(); + else internalFormat = image->internalFormat(); break; case(USE_S3TC_DXT5_COMPRESSION): if (s_S3TC_Compression) { - switch(_image->pixelFormat()) + switch(image->pixelFormat()) { case(3): case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break; case(4): case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break; - default: internalFormat = _image->internalFormat(); break; + default: internalFormat = image->internalFormat(); break; } } - else internalFormat = _image->internalFormat(); + else internalFormat = image->internalFormat(); break; case(USE_USER_DEFINED_FORMAT): @@ -416,63 +418,63 @@ void Texture::applyImmediateMode(State& state) const if (_subloadMode == OFF) { if( _min_filter == LINEAR || _min_filter == NEAREST ) { - glTexImage2D( GL_TEXTURE_2D, 0, internalFormat, - _image->s(), _image->t(), 0, - (GLenum)_image->pixelFormat(), - (GLenum)_image->dataType(), - _image->data() ); + glTexImage2D( target, 0, internalFormat, + image->s(), image->t(), 0, + (GLenum)image->pixelFormat(), + (GLenum)image->dataType(), + image->data() ); // just estimate estimate it right now.. // note, ignores texture compression.. - _textureObjectSize = _image->s()*_image->t()*4; + _textureObjectSize = image->s()*image->t()*4; } else { - gluBuild2DMipmaps( GL_TEXTURE_2D, internalFormat, - _image->s(),_image->t(), - (GLenum)_image->pixelFormat(), (GLenum)_image->dataType(), - _image->data() ); + gluBuild2DMipmaps( target, internalFormat, + image->s(),image->t(), + (GLenum)image->pixelFormat(), (GLenum)image->dataType(), + image->data() ); // just estimate size it right now.. // crude x2 multiplier to account for minmap storage. // note, ignores texture compression.. - _textureObjectSize = _image->s()*_image->t()*4; + _textureObjectSize = image->s()*image->t()*4; } - _textureWidth = _image->s(); - _textureHeight = _image->t(); + _textureWidth = image->s(); + _textureHeight = image->t(); } else { static bool s_SGIS_GenMipmap = isGLExtensionSupported("GL_SGIS_generate_mipmap"); if (s_SGIS_GenMipmap && (_min_filter != LINEAR && _min_filter != NEAREST)) { - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); + glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); } // calculate texture dimension _textureWidth = 1; - for (; _textureWidth < (_subloadOffsX + _image->s()); _textureWidth <<= 1) + for (; _textureWidth < (_subloadOffsX + image->s()); _textureWidth <<= 1) ; _textureHeight = 1; - for (; _textureHeight < (_subloadOffsY + _image->t()); _textureHeight <<= 1) + for (; _textureHeight < (_subloadOffsY + image->t()); _textureHeight <<= 1) ; // reserve appropriate texture memory - glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, + glTexImage2D(target, 0, internalFormat, _textureWidth, _textureHeight, 0, - (GLenum) _image->pixelFormat(), (GLenum) _image->dataType(), + (GLenum) image->pixelFormat(), (GLenum) image->dataType(), NULL); - glTexSubImage2D(GL_TEXTURE_2D, 0, + glTexSubImage2D(target, 0, _subloadOffsX, _subloadOffsY, - _image->s(), _image->t(), - (GLenum) _image->pixelFormat(), (GLenum) _image->dataType(), - _image->data()); + image->s(), image->t(), + (GLenum) image->pixelFormat(), (GLenum) image->dataType(), + image->data()); } } @@ -550,13 +552,13 @@ void Texture::copyTexImage2D(State& state, int x, int y, int width, int height ) // Get a new 2d texture handle. glGenTextures( 1, &handle ); - glBindTexture( GL_TEXTURE_2D, handle ); - applyTexParameters(state); - glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, x, y, width, height, 0 ); + glBindTexture( _target, handle ); + applyTexParameters(_target,state); + glCopyTexImage2D( _target, 0, GL_RGBA, x, y, width, height, 0 ); /* Redundant, delete later */ -// glBindTexture( GL_TEXTURE_2D, handle ); +// glBindTexture( _target, handle ); _textureWidth = width; _textureHeight = height; @@ -577,12 +579,12 @@ void Texture::copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, i if (handle) { // we have a valid image - glBindTexture( GL_TEXTURE_2D, handle ); - applyTexParameters(state); - glCopyTexSubImage2D( GL_TEXTURE_2D, 0, xoffset,yoffset, x, y, width, height); + glBindTexture( _target, handle ); + applyTexParameters(_target,state); + glCopyTexSubImage2D( _target, 0, xoffset,yoffset, x, y, width, height); /* Redundant, delete later */ - glBindTexture( GL_TEXTURE_2D, handle ); + glBindTexture( _target, handle ); // inform state that this texture is the current one bound. state.have_applied(this); diff --git a/src/osg/TextureCubeMap.cpp b/src/osg/TextureCubeMap.cpp index 434db0308..53fef9b2f 100644 --- a/src/osg/TextureCubeMap.cpp +++ b/src/osg/TextureCubeMap.cpp @@ -159,10 +159,10 @@ bool TextureCubeMap::imagesValid() const void TextureCubeMap::apply(State& state) const { - static bool s_ARB_CubeMapSupported = isGLExtensionSupported("GL_ARB_texture_cube_map"); - static bool s_EXT_CubeMapSupported = isGLExtensionSupported("GL_EXT_texture_cube_map"); + static bool s_CubeMapSupported = isGLExtensionSupported("GL_ARB_texture_cube_map") || + isGLExtensionSupported("GL_EXT_texture_cube_map"); - if (!s_ARB_CubeMapSupported /*&& !s_EXT_CubeMapSupported*/) + if (!s_CubeMapSupported) return; // get the contextID (user defined ID of 0 upwards) for the @@ -180,6 +180,7 @@ void TextureCubeMap::apply(State& state) const if (_subloadMode == OFF) { glBindTexture( _target, handle ); + if (_texParamtersDirty) applyTexParameters(_target,state); } else if (imagesValid()) { @@ -187,6 +188,7 @@ void TextureCubeMap::apply(State& state) const modifiedTag = 0; glBindTexture( _target, handle ); + if (_texParamtersDirty) applyTexParameters(_target,state); for (int n=0; n<6; n++) { if ((_subloadMode == AUTO) || @@ -208,12 +210,11 @@ void TextureCubeMap::apply(State& state) const glGenTextures( 1L, (GLuint *)&handle ); glBindTexture( _target, handle ); - applyImmediateMode(state); + applyTexParameters(_target,state); for (int n=0; n<6; n++) { - applyFaceImmediateMode( - faceTarget[n], _images[n].get(), state); + applyTexImage( faceTarget[n], _images[n].get(), state); } // in theory the following line is redundent, but in practice @@ -224,234 +225,3 @@ void TextureCubeMap::apply(State& state) const } } - - -void TextureCubeMap::applyImmediateMode(State& state) const -{ - WrapMode ws = _wrap_s, wt = _wrap_t; - - // GL_IBM_texture_mirrored_repeat, fall-back REPEAT - static bool s_mirroredSupported = isGLExtensionSupported("GL_IBM_texture_mirrored_repeat"); - if (!s_mirroredSupported) - { - if (ws == MIRROR) - ws = REPEAT; - if (wt == MIRROR) - wt = REPEAT; - } - - // GL_EXT_texture_edge_clamp, fall-back CLAMP - static bool s_edgeClampSupported = isGLExtensionSupported("GL_EXT_texture_edge_clamp"); - if (!s_edgeClampSupported) - { - if (ws == CLAMP_TO_EDGE) - ws = CLAMP; - if (wt == CLAMP_TO_EDGE) - wt = CLAMP; - } - - static bool s_borderClampSupported = isGLExtensionSupported("GL_ARB_texture_border_clamp"); - if(!s_borderClampSupported) - { - if(ws == CLAMP_TO_BORDER) - ws = CLAMP; - if(wt == CLAMP_TO_BORDER) - wt = CLAMP; - } - - glTexParameteri( _target, GL_TEXTURE_WRAP_S, ws ); - glTexParameteri( _target, GL_TEXTURE_WRAP_T, wt ); - - glTexParameteri( _target, GL_TEXTURE_MIN_FILTER, _min_filter); - - if (_mag_filter == ANISOTROPIC) - { - // check for support for anisotropic filter, - // note since this is static varible it is intialised - // only on the first time entering this code block, - // is then never reevaluated on subsequent calls. - static bool s_anisotropicSupported = - isGLExtensionSupported("GL_EXT_texture_filter_anisotropic"); - - if (s_anisotropicSupported) - { - // note, GL_TEXTURE_MAX_ANISOTROPY_EXT will either be defined - // by gl.h (or via glext.h) or by include/osg/Texture. - glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.f); - } - else - { - glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, LINEAR); - } - } - else - { - glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, _mag_filter); - } -} - - - -void TextureCubeMap::applyFaceImmediateMode(GLenum facetarget, Image* image, State& state) const -{ - // get the contextID (user defined ID of 0 upwards) for the - // current OpenGL context. - const uint contextID = state.getContextID(); - - // update the modified tag to show that it is upto date. - getModifiedTag(contextID) = image->getModifiedTag(); - - - if (_subloadMode == OFF) - image->ensureDimensionsArePowerOfTwo(); - - glPixelStorei(GL_UNPACK_ALIGNMENT,image->packing()); - - static bool s_ARB_Compression = isGLExtensionSupported("GL_ARB_texture_compression"); - static bool s_S3TC_Compression = isGLExtensionSupported("GL_EXT_texture_compression_s3tc"); - - // select the internalFormat required for the texture. - int internalFormat = image->internalFormat(); - switch(_internalFormatMode) - { - case(USE_IMAGE_DATA_FORMAT): - internalFormat = image->internalFormat(); - break; - - case(USE_ARB_COMPRESSION): - if (s_ARB_Compression) - { - switch(image->pixelFormat()) - { - case(1): internalFormat = GL_COMPRESSED_ALPHA_ARB; break; - case(2): internalFormat = GL_COMPRESSED_LUMINANCE_ALPHA_ARB; break; - case(3): internalFormat = GL_COMPRESSED_RGB_ARB; break; - case(4): internalFormat = GL_COMPRESSED_RGBA_ARB; break; - case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_ARB; break; - case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_ARB; break; - case(GL_ALPHA): internalFormat = GL_COMPRESSED_ALPHA_ARB; break; - case(GL_LUMINANCE): internalFormat = GL_COMPRESSED_LUMINANCE_ARB; break; - case(GL_LUMINANCE_ALPHA): internalFormat = GL_COMPRESSED_LUMINANCE_ALPHA_ARB; break; - case(GL_INTENSITY): internalFormat = GL_COMPRESSED_INTENSITY_ARB; break; - } - } - else internalFormat = image->internalFormat(); - break; - - case(USE_S3TC_DXT1_COMPRESSION): - if (s_S3TC_Compression) - { - switch(image->pixelFormat()) - { - case(3): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break; - case(4): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; - case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break; - case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; - default: internalFormat = image->internalFormat(); break; - } - } - else internalFormat = image->internalFormat(); - break; - - case(USE_S3TC_DXT3_COMPRESSION): - if (s_S3TC_Compression) - { - switch(image->pixelFormat()) - { - case(3): - case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break; - case(4): - case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break; - default: internalFormat = image->internalFormat(); break; - } - } - else internalFormat = image->internalFormat(); - break; - - case(USE_S3TC_DXT5_COMPRESSION): - if (s_S3TC_Compression) - { - switch(image->pixelFormat()) - { - case(3): - case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break; - case(4): - case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break; - default: internalFormat = image->internalFormat(); break; - } - } - else internalFormat = image->internalFormat(); - break; - - case(USE_USER_DEFINED_FORMAT): - internalFormat = _internalFormatValue; - break; - - } - - if (_subloadMode == OFF) - { - if( _min_filter == LINEAR || _min_filter == NEAREST ) - { - glTexImage2D( facetarget, 0, internalFormat, - image->s(), image->t(), 0, - (GLenum)image->pixelFormat(), - (GLenum)image->dataType(), - image->data() ); - - // just estimate estimate it right now.. - // note, ignores texture compression.. - _textureObjectSize = image->s()*image->t()*4; - - } - else - { - - gluBuild2DMipmaps( facetarget, internalFormat, - image->s(), image->t(), - (GLenum)image->pixelFormat(), (GLenum)image->dataType(), - image->data() ); - - // just estimate size it right now.. - // crude x2 multiplier to account for minmap storage. - // note, ignores texture compression.. - _textureObjectSize = image->s()*image->t()*4; - - } - - _textureWidth = image->s(); - _textureHeight = image->t(); - } - else - { - /* target=? ABJ - static bool s_SGIS_GenMipmap = isGLExtensionSupported("GL_SGIS_generate_mipmap"); - - if (s_SGIS_GenMipmap && (_min_filter != LINEAR && _min_filter != NEAREST)) { - glTexParameteri(_target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); - } - */ - // calculate texture dimension - _textureWidth = 1; - for (; _textureWidth < (_subloadOffsX + image->s()); _textureWidth <<= 1) - ; - - _textureHeight = 1; - for (; _textureHeight < (_subloadOffsY + image->t()); _textureHeight <<= 1) - ; - - // reserve appropriate texture memory - glTexImage2D(facetarget, 0, internalFormat, - _textureWidth, _textureHeight, 0, - (GLenum) image->pixelFormat(), (GLenum) image->dataType(), - NULL); - - glTexSubImage2D(facetarget, 0, - _subloadOffsX, _subloadOffsY, - image->s(), image->t(), - (GLenum) image->pixelFormat(), (GLenum) image->dataType(), - image->data()); - } - -} -