root/OpenSceneGraph/trunk/src/osgPlugins/ive/Texture.cpp @ 10934

Revision 10934, 4.0 kB (checked in by robert, 5 years ago)

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
"

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 *    FILE:            Texture.cpp
4 *
5 *    DESCRIPTION:    Read/Write osg::Texture in binary format to disk.
6 *
7 *    CREATED BY:        Auto generated by iveGenerated
8 *                    and later modified by Rune Schmidt Jensen.
9 *
10 *    HISTORY:        Created 20.3.2003
11 *
12 *    Copyright 2003 VR-C
13 **********************************************************************/
14
15#include "Exception.h"
16#include "Texture.h"
17#include "Object.h"
18
19using namespace ive;
20
21void Texture::write(DataOutputStream* out){
22    // Write Texture's identification.
23    out->writeInt(IVETEXTURE);
24    // If the osg class is inherited by any other class we should also write this to file.
25    osg::Object*  obj = dynamic_cast<osg::Object*>(this);
26    if(obj)
27    {
28        ((ive::Object*)(obj))->write(out);
29    }
30    else
31        out_THROW_EXCEPTION("Texture::write(): Could not cast this osg::Texture to an osg::Object.");
32
33    // Write Texture's properties.
34    out->writeInt(_wrap_s);
35    out->writeInt(_wrap_t);
36    out->writeInt(_wrap_r);
37
38    out->writeInt(_min_filter);
39    out->writeInt(_mag_filter);
40    out->writeFloat(_maxAnisotropy);
41
42    out->writeVec4(_borderColor);
43
44    out->writeInt(_internalFormatMode);
45   
46    if ( out->getVersion() >= VERSION_0008 )
47    {
48        out->writeInt(_internalFormat);
49    }
50
51    if ( out->getVersion() >= VERSION_0009 )
52    {
53        out->writeInt(_borderWidth);
54        out->writeBool(_useHardwareMipMapGeneration);
55        out->writeBool(_unrefImageDataAfterApply);
56        out->writeBool(_clientStorageHint);
57        out->writeBool(_resizeNonPowerOfTwoHint);
58    }
59   
60    if ( out->getVersion() >= VERSION_0014 )
61    {
62        out->writeInt(_sourceFormat);
63        out->writeInt(_sourceType);
64    }
65
66    if( out->getVersion() >= VERSION_0043 )
67    {
68      out->writeBool( _use_shadow_comparison );
69      out->writeInt( _shadow_compare_func );
70      out->writeInt( _shadow_texture_mode );
71    }
72}
73
74void Texture::read(DataInputStream* in)
75{
76    // Read Texture's identification.
77    int id = in->peekInt();
78    if(id == IVETEXTURE)
79    {
80        // Read Texture's identification.
81        id = in->readInt();
82        // If the osg class is inherited by any other class we should also read this from file.
83        osg::Object*  obj = dynamic_cast<osg::Object*>(this);
84        if(obj)
85        {
86            ((ive::Object*)(obj))->read(in);
87        }
88        else
89            in_THROW_EXCEPTION("Texture::read(): Could not cast this osg::Texture to an osg::Object.");
90
91        // Read properties
92        _wrap_s = (osg::Texture::WrapMode)in->readInt();
93        _wrap_t = (osg::Texture::WrapMode)in->readInt();
94        _wrap_r = (osg::Texture::WrapMode)in->readInt();
95
96        _min_filter = (osg::Texture::FilterMode)in->readInt();
97        _mag_filter = (osg::Texture::FilterMode)in->readInt();
98        _maxAnisotropy = in->readFloat();
99
100        _borderColor = in->readVec4();
101
102        _internalFormatMode = (osg::Texture::InternalFormatMode)in->readInt();
103        if ( in->getVersion() >= VERSION_0008 )
104        {
105            _internalFormat = in->readInt();
106        }
107
108        if ( in->getVersion() >= VERSION_0009 )
109        {
110            _borderWidth = in->readInt();
111            _useHardwareMipMapGeneration = in->readBool();
112            _unrefImageDataAfterApply = in->readBool();
113            _clientStorageHint = in->readBool();
114            _resizeNonPowerOfTwoHint = in->readBool();
115        }
116
117        if ( in->getVersion() >= VERSION_0014 )
118        {
119            _sourceFormat = in->readInt();
120            _sourceType = in->readInt();
121        }
122
123        if( in->getVersion() >= VERSION_0043 )
124        {
125          _use_shadow_comparison = in->readBool();
126          _shadow_compare_func = (osg::Texture::ShadowCompareFunc)in->readInt();
127          _shadow_texture_mode = (osg::Texture::ShadowTextureMode)in->readInt();
128        }
129    }
130    else
131    {
132        in_THROW_EXCEPTION("Texture::read(): Expected Texture identification.");
133    }
134}
Note: See TracBrowser for help on using the browser.