From 865ee4429c2e51fc15177e2315392d10b07163d3 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 6 Jul 2006 14:02:14 +0000 Subject: [PATCH] From Eric Sokolowsky, "Attached is some fixes for Image::readImageFromCurrentTexture. It was failing when used with a new Image object (some of the fields were not set before they were used, and some were set to the wrong values). A new optional parameter was added to give the desired data type, which defaults to GL_UNSIGNED_BYTE, so programs should only need a recompile to work properly." --- include/osg/Image | 2 +- src/osg/Image.cpp | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/osg/Image b/include/osg/Image index 8124e977b..3e3d1b23e 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -108,7 +108,7 @@ class OSG_EXPORT Image : public Object /** Read the contents of the current bound texture, handling compressed pixelFormats if present. * Create memory for storage if required, reuse existing pixel coords if possible. */ - void readImageFromCurrentTexture(unsigned int contextID, bool copyMipMapsIfAvailable); + void readImageFromCurrentTexture(unsigned int contextID, bool copyMipMapsIfAvailable, GLenum type = GL_UNSIGNED_BYTE); /** Scale image to specified size. */ diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index 2ba7e2793..2720652be 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -428,7 +428,7 @@ void Image::readPixels(int x,int y,int width,int height, } -void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMapsIfAvailable) +void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMapsIfAvailable, GLenum type) { const osg::Texture::Extensions* extensions = osg::Texture::getExtensions(contextID,true); const osg::Texture3D::Extensions* extensions3D = osg::Texture3D::getExtensions(contextID,true); @@ -447,6 +447,7 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps GLint width; GLint height; GLint depth; + GLint packing; GLint numMipMaps = 0; if (copyMipMapsIfAvailable) @@ -516,6 +517,8 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_WIDTH, &width); glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_HEIGHT, &height); glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_DEPTH, &depth); + glGetIntegerv(GL_UNPACK_ALIGNMENT, &packing); + glPixelStorei(GL_PACK_ALIGNMENT, packing); _data = data; _s = width; @@ -523,10 +526,11 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps _r = depth; _pixelFormat = internalformat; - _dataType = internalformat; + _dataType = type; _internalTextureFormat = internalformat; _mipmapData = mipMapData; _allocationMode=USE_NEW_DELETE; + _packing = packing; for(i=0;i