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 "
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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); }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user