From fef2628d0069835473d2fb0cdb8f2e37c973c858 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 8 Mar 2012 16:05:17 +0000 Subject: [PATCH] From Farshid Lashkari, "I've added support for reading contents of cubemap textures to the osg::Image::readImageFromCurrentTexture method. I added a new parameter to the method for specifying which face of the cubemap to read." --- include/osg/Image | 2 +- src/osg/Image.cpp | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/osg/Image b/include/osg/Image index 6e252cb2c..b071c1d26 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -176,7 +176,7 @@ class OSG_EXPORT Image : public BufferData /** 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. */ - virtual void readImageFromCurrentTexture(unsigned int contextID, bool copyMipMapsIfAvailable, GLenum type = GL_UNSIGNED_BYTE); + virtual void readImageFromCurrentTexture(unsigned int contextID, bool copyMipMapsIfAvailable, GLenum type = GL_UNSIGNED_BYTE, unsigned int face = 0); /** Scale image to specified size. */ diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index e519de38c..2a2a037cc 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -928,7 +929,7 @@ void Image::readPixels(int x,int y,int width,int height, } -void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMapsIfAvailable, GLenum type) +void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMapsIfAvailable, GLenum type, unsigned int face) { #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) // OSG_NOTICE<<"Image::readImageFromCurrentTexture()"<isTexture2DArraySupported()) { @@ -950,6 +952,30 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps } GLenum textureMode = binding1D ? GL_TEXTURE_1D : binding2D ? GL_TEXTURE_2D : binding3D ? GL_TEXTURE_3D : binding2DArray ? GL_TEXTURE_2D_ARRAY_EXT : 0; + if (bindingCubeMap) + { + switch (face) + { + case TextureCubeMap::POSITIVE_X: + textureMode = GL_TEXTURE_CUBE_MAP_POSITIVE_X; + break; + case TextureCubeMap::NEGATIVE_X: + textureMode = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; + break; + case TextureCubeMap::POSITIVE_Y: + textureMode = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; + break; + case TextureCubeMap::NEGATIVE_Y: + textureMode = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; + break; + case TextureCubeMap::POSITIVE_Z: + textureMode = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; + break; + case TextureCubeMap::NEGATIVE_Z: + textureMode = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; + break; + } + } if (textureMode==0) return;