From 8414a16e52e9784707618c7988481e92e50e65fb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 3 Sep 2007 15:43:58 +0000 Subject: [PATCH] From Sherman Wilcox, added extension checking support for compressed texture subloading. --- include/osg/Texture | 2 ++ src/osg/TextureRectangle.cpp | 43 +++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/include/osg/Texture b/include/osg/Texture index 2afa5cbfc..107b692e5 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -514,6 +514,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute void setCompressedTexImage2DProc(void* ptr) { _glCompressedTexImage2D = ptr; } void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) const; + bool isCompressedTexSubImage2DSupported() const { return _glCompressedTexSubImage2D!=0; } + void setCompressedTexSubImage2DProc(void* ptr) { _glCompressedTexSubImage2D = ptr; } void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei type, const GLvoid *data) const; diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp index 5aa1a4274..b04738c1c 100644 --- a/src/osg/TextureRectangle.cpp +++ b/src/osg/TextureRectangle.cpp @@ -297,17 +297,17 @@ void TextureRectangle::applyTexImage_load(GLenum target, Image* image, State& st if(isCompressedInternalFormat(_internalFormat) && extensions->isCompressedTexImage2DSupported()) { extensions->glCompressedTexImage2D(target, 0, _internalFormat, - image->s(), image->t(), 0, - image->getImageSizeInBytes(), - image->data() - dataMinusOffset + dataPlusOffset); + image->s(), image->t(), 0, + image->getImageSizeInBytes(), + image->data() - dataMinusOffset + dataPlusOffset); } else { glTexImage2D(target, 0, _internalFormat, - image->s(), image->t(), 0, - (GLenum)image->getPixelFormat(), - (GLenum)image->getDataType(), - image->data() - dataMinusOffset + dataPlusOffset ); + image->s(), image->t(), 0, + (GLenum)image->getPixelFormat(), + (GLenum)image->getDataType(), + image->data() - dataMinusOffset + dataPlusOffset ); } @@ -341,6 +341,8 @@ void TextureRectangle::applyTexImage_subload(GLenum target, Image* image, State& // get the contextID (user defined ID of 0 upwards) for the // current OpenGL context. const unsigned int contextID = state.getContextID(); + const Extensions* extensions = getExtensions(contextID,true); + // update the modified count to show that it is upto date. getModifiedCount(contextID) = image->getModifiedCount(); @@ -374,14 +376,25 @@ void TextureRectangle::applyTexImage_subload(GLenum target, Image* image, State& pbo = 0; } - - // UH: ignoring compressed for now. - glTexSubImage2D(target, 0, - 0,0, - image->s(), image->t(), - (GLenum)image->getPixelFormat(), - (GLenum)image->getDataType(), - image->data() - dataMinusOffset + dataPlusOffset ); + + if(isCompressedInternalFormat(_internalFormat) && extensions->isCompressedTexSubImage2DSupported()) + { + extensions->glCompressedTexSubImage2D(target, 0, + 0,0, + image->s(), image->t(), + (GLenum)image->getPixelFormat(), + (GLenum)image->getDataType(), + image->data() - dataMinusOffset + dataPlusOffset); + } + else + { + glTexSubImage2D(target, 0, + 0,0, + image->s(), image->t(), + (GLenum)image->getPixelFormat(), + (GLenum)image->getDataType(), + image->data() - dataMinusOffset + dataPlusOffset ); + } if (pbo) {