From a31aa512d7d51c89f54ff9b22ff89d1ec38a6bd7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 8 Jan 2010 11:32:55 +0000 Subject: [PATCH] From Rob Radtke, "I recently ran into some issues trying to save/load a scene graph as a .ive file. The problems came about because the scene graph contained depth textures in it. I have attached a patch (against the current revision: 10919) that fixes the issues that I encountered. Both attachments contain the same patch--one is a .zip file that contains the modified files and the other is a text patch file. Here is a summary of the changes I made: 1) Add getShadowComparison() accessor function to osg::Texture class 2) Modify ReaderWriterTiff::writeTifStream() and _readColor() (in Image.cpp) to handle pixelFormat==GL_DEPTH_COMPONENT as if it were GL_LUMINANCE 3) Modify the Texture classes of the ive and osg plug-ins so that they save/load the following Texture members: _use_shadow_comparison, _shadow_compare_func and _shadow_texture_mode " --- include/osg/Texture | 3 +- src/osg/Image.cpp | 1 + src/osgPlugins/ive/IveVersion.h | 3 +- src/osgPlugins/ive/Texture.cpp | 14 ++++ src/osgPlugins/osg/Texture.cpp | 89 +++++++++++++++++++++++- src/osgPlugins/tiff/ReaderWriterTIFF.cpp | 1 + 6 files changed, 108 insertions(+), 3 deletions(-) diff --git a/include/osg/Texture b/include/osg/Texture index acb405a92..6df537820 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -537,7 +537,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute /** Sets GL_TEXTURE_COMPARE_MODE_ARB to GL_COMPARE_R_TO_TEXTURE_ARB * See http://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow.txt. */ void setShadowComparison(bool flag) { _use_shadow_comparison = flag; } - + bool getShadowComparison() const { return _use_shadow_comparison; } + enum ShadowCompareFunc { NEVER = GL_NEVER, LESS = GL_LESS, diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index b3a5e882b..30e8c56fa 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -1416,6 +1416,7 @@ Vec4 _readColor(GLenum pixelFormat, T* data,float scale) { switch(pixelFormat) { + case(GL_DEPTH_COMPONENT): //intentionally fall through and execute the code for GL_LUMINANCE case(GL_LUMINANCE): { float l = float(*data++)*scale; return Vec4(l, l, l, 1.0f); } case(GL_ALPHA): { float a = float(*data++)*scale; return Vec4(1.0f, 1.0f, 1.0f, a); } case(GL_LUMINANCE_ALPHA): { float l = float(*data++)*scale; float a = float(*data++)*scale; return Vec4(l,l,l,a); } diff --git a/src/osgPlugins/ive/IveVersion.h b/src/osgPlugins/ive/IveVersion.h index 46591828d..4edd629b3 100644 --- a/src/osgPlugins/ive/IveVersion.h +++ b/src/osgPlugins/ive/IveVersion.h @@ -51,8 +51,9 @@ #define VERSION_0040 40 #define VERSION_0041 41 #define VERSION_0042 42 +#define VERSION_0043 43 -#define VERSION VERSION_0042 +#define VERSION VERSION_0043 /* The BYTE_SEX tag is used to check the endian of the IVE file being read in. The IVE format diff --git a/src/osgPlugins/ive/Texture.cpp b/src/osgPlugins/ive/Texture.cpp index bfafddbb2..4682a9225 100644 --- a/src/osgPlugins/ive/Texture.cpp +++ b/src/osgPlugins/ive/Texture.cpp @@ -62,6 +62,13 @@ void Texture::write(DataOutputStream* out){ out->writeInt(_sourceFormat); out->writeInt(_sourceType); } + + if( out->getVersion() >= VERSION_0043 ) + { + out->writeBool( _use_shadow_comparison ); + out->writeInt( _shadow_compare_func ); + out->writeInt( _shadow_texture_mode ); + } } void Texture::read(DataInputStream* in) @@ -112,6 +119,13 @@ void Texture::read(DataInputStream* in) _sourceFormat = in->readInt(); _sourceType = in->readInt(); } + + if( in->getVersion() >= VERSION_0043 ) + { + _use_shadow_comparison = in->readBool(); + _shadow_compare_func = (osg::Texture::ShadowCompareFunc)in->readInt(); + _shadow_texture_mode = (osg::Texture::ShadowTextureMode)in->readInt(); + } } else { diff --git a/src/osgPlugins/osg/Texture.cpp b/src/osgPlugins/osg/Texture.cpp index 160565dae..9d4788283 100644 --- a/src/osgPlugins/osg/Texture.cpp +++ b/src/osgPlugins/osg/Texture.cpp @@ -26,6 +26,10 @@ bool Texture_matchInternalFormatStr(const char* str,int& value); const char* Texture_getInternalFormatStr(int value); bool Texture_matchSourceTypeStr(const char* str,int& value); const char* Texture_getSourceTypeStr(int value); +bool Texture_matchShadowCompareFuncStr(const char* str,Texture::ShadowCompareFunc& value); +const char* Texture_getShadowCompareFuncStr(Texture::ShadowCompareFunc value); +bool Texture_matchShadowTextureModeStr(const char* str,Texture::ShadowTextureMode& value); +const char* Texture_getShadowTextureModeStr(Texture::ShadowTextureMode value); // register the read and write functions with the osgDB::Registry. REGISTER_DOTOSGWRAPPER(Texture) @@ -201,6 +205,44 @@ bool Texture_readLocalData(Object& obj, Input& fr) } } + if (fr[0].matchWord("shadowComparison")) + { + if (fr[1].matchWord("TRUE")) + { + texture.setShadowComparison(true); + fr +=2 ; + iteratorAdvanced = true; + } + else if (fr[1].matchWord("FALSE")) + { + texture.setShadowComparison(false); + fr +=2 ; + iteratorAdvanced = true; + } + } + + if (fr[0].matchWord("shadowCompareFunc")) + { + Texture::ShadowCompareFunc value; + if (Texture_matchShadowCompareFuncStr(fr[1].getStr(),value)) + { + texture.setShadowCompareFunc(value); + fr+=2; + iteratorAdvanced = true; + } + } + + if (fr[0].matchWord("shadowTextureMode")) + { + Texture::ShadowTextureMode value; + if (Texture_matchShadowTextureModeStr(fr[1].getStr(),value)) + { + texture.setShadowTextureMode(value); + fr+=2; + iteratorAdvanced = true; + } + } + return iteratorAdvanced; } @@ -254,6 +296,12 @@ bool Texture_writeLocalData(const Object& obj, Output& fw) fw.indent() << "resizeNonPowerOfTwo "<< (texture.getResizeNonPowerOfTwoHint()?"TRUE":"FALSE") << std::endl; + fw.indent() << "shadowComparison "<< (texture.getShadowComparison()?"TRUE":"FALSE") << std::endl; + + fw.indent() << "shadowCompareFunc " << Texture_getShadowCompareFuncStr(texture.getShadowCompareFunc()) << std::endl; + + fw.indent() << "shadowTextureMode " << Texture_getShadowTextureModeStr(texture.getShadowTextureMode()) << std::endl; + return true; } @@ -426,7 +474,6 @@ bool Texture_matchSourceTypeStr(const char* str,int& value) return true; } - const char* Texture_getSourceTypeStr(int value) { switch(value) @@ -441,3 +488,43 @@ const char* Texture_getSourceTypeStr(int value) } return NULL; } + +bool Texture_matchShadowCompareFuncStr(const char* str, Texture::ShadowCompareFunc& value) +{ + if ( strcmp(str,"GL_LEQUAL")==0) value = Texture::LEQUAL; + else if (strcmp(str,"GL_GEQUAL")==0) value = Texture::GEQUAL; + else return false; + + return true; +} + +const char* Texture_getShadowCompareFuncStr(Texture::ShadowCompareFunc value) +{ + switch(value) + { + case( Texture::LEQUAL ): return "GL_LEQUAL"; + case( Texture::GEQUAL ): return "GL_GEQUAL"; + } + return NULL; +} + +bool Texture_matchShadowTextureModeStr(const char* str,Texture::ShadowTextureMode& value) +{ + if ( strcmp(str,"GL_LUMINANCE")==0) value = Texture::LUMINANCE; + else if (strcmp(str,"GL_INTENSITY")==0) value = Texture::INTENSITY; + else if (strcmp(str,"GL_ALPHA")==0) value = Texture::ALPHA; + else return false; + + return true; +} + +const char* Texture_getShadowTextureModeStr(Texture::ShadowTextureMode value) +{ + switch(value) + { + case( Texture::LUMINANCE ): return "GL_LUMINANCE"; + case( Texture::INTENSITY ): return "GL_INTENSITY"; + case( Texture::ALPHA ): return "GL_ALPHA"; + } + return NULL; +} diff --git a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp index 9ee299313..f737a6a54 100644 --- a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp +++ b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp @@ -783,6 +783,7 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter } switch(img.getPixelFormat()) { + case GL_DEPTH_COMPONENT: case GL_LUMINANCE: case GL_ALPHA: photometric = PHOTOMETRIC_MINISBLACK;