root/OpenSceneGraph/trunk/src/osgWrappers/serializers/osg/Texture.cpp @ 13041

Revision 13041, 5.3 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1#include <osg/Texture>
2#include <osgDB/ObjectWrapper>
3#include <osgDB/InputStream>
4#include <osgDB/OutputStream>
5
6#define WRAP_FUNCTIONS( PROP, VALUE ) \
7    static bool check##PROP( const osg::Texture& tex ) { return true; } \
8    static bool read##PROP( osgDB::InputStream& is, osg::Texture& tex ) { \
9        DEF_GLENUM(mode); is >> mode; \
10        tex.setWrap( VALUE, (osg::Texture::WrapMode)mode.get() ); \
11        return true; \
12    } \
13    static bool write##PROP( osgDB::OutputStream& os, const osg::Texture& tex ) { \
14        os << GLENUM(tex.getWrap(VALUE)) << std::endl; \
15        return true; \
16    }
17
18WRAP_FUNCTIONS( WRAP_S, osg::Texture::WRAP_S )
19WRAP_FUNCTIONS( WRAP_T, osg::Texture::WRAP_T )
20WRAP_FUNCTIONS( WRAP_R, osg::Texture::WRAP_R )
21
22#define FILTER_FUNCTIONS( PROP, VALUE ) \
23    static bool check##PROP( const osg::Texture& tex ) { return true; } \
24    static bool read##PROP( osgDB::InputStream& is, osg::Texture& tex ) { \
25        DEF_GLENUM(mode); is >> mode; \
26        tex.setFilter( VALUE, (osg::Texture::FilterMode)mode.get() ); \
27        return true; \
28    } \
29    static bool write##PROP( osgDB::OutputStream& os, const osg::Texture& tex ) { \
30        os << GLENUM(tex.getFilter(VALUE)) << std::endl; \
31        return true; \
32    }
33
34FILTER_FUNCTIONS( MIN_FILTER, osg::Texture::MIN_FILTER )
35FILTER_FUNCTIONS( MAG_FILTER, osg::Texture::MAG_FILTER )
36
37#define GL_FORMAT_FUNCTIONS( PROP ) \
38    static bool check##PROP( const osg::Texture& tex ) { \
39        return tex.get##PROP()!=GL_NONE; \
40    } \
41    static bool read##PROP( osgDB::InputStream& is, osg::Texture& tex ) { \
42        DEF_GLENUM(mode); is >> mode; tex.set##PROP( mode.get() ); \
43        return true; \
44    } \
45    static bool write##PROP( osgDB::OutputStream& os, const osg::Texture& tex ) { \
46        os << GLENUM(tex.get##PROP()) << std::endl; \
47        return true; \
48    }
49
50GL_FORMAT_FUNCTIONS( SourceFormat )
51GL_FORMAT_FUNCTIONS( SourceType )
52
53static bool checkInternalFormat( const osg::Texture& tex )
54{ return tex.getInternalFormatMode()==osg::Texture::USE_USER_DEFINED_FORMAT; }
55
56static bool readInternalFormat( osgDB::InputStream& is, osg::Texture& tex )
57{
58    DEF_GLENUM(mode); is >> mode;
59    if ( tex.getInternalFormatMode()==osg::Texture::USE_USER_DEFINED_FORMAT )
60        tex.setInternalFormat( mode.get() );
61    return true;
62}
63
64static bool writeInternalFormat( osgDB::OutputStream& os, const osg::Texture& tex )
65{
66    if ( os.isBinary() && tex.getInternalFormatMode()!=osg::Texture::USE_USER_DEFINED_FORMAT )
67        os << GLENUM(GL_NONE) << std::endl;  // Avoid use of OpenGL extensions
68    else
69        os << GLENUM(tex.getInternalFormat()) << std::endl;
70    return true;
71}
72
73REGISTER_OBJECT_WRAPPER( Texture,
74                         /*new osg::Texture*/NULL,
75                         osg::Texture,
76                         "osg::Object osg::StateAttribute osg::Texture" )
77{
78    ADD_USER_SERIALIZER( WRAP_S );  // _wrap_s
79    ADD_USER_SERIALIZER( WRAP_T );  // _wrap_t
80    ADD_USER_SERIALIZER( WRAP_R );  // _wrap_r
81    ADD_USER_SERIALIZER( MIN_FILTER );  // _min_filter
82    ADD_USER_SERIALIZER( MAG_FILTER );  // _mag_filter
83    ADD_FLOAT_SERIALIZER( MaxAnisotropy, 1.0f );  // _maxAnisotropy
84    ADD_BOOL_SERIALIZER( UseHardwareMipMapGeneration, true );  // _useHardwareMipMapGeneration
85    ADD_BOOL_SERIALIZER( UnRefImageDataAfterApply, false );  // _unrefImageDataAfterApply
86    ADD_BOOL_SERIALIZER( ClientStorageHint, false );  // _clientStorageHint
87    ADD_BOOL_SERIALIZER( ResizeNonPowerOfTwoHint, true );  // _resizeNonPowerOfTwoHint
88    ADD_VEC4D_SERIALIZER( BorderColor, osg::Vec4d(0.0,0.0,0.0,0.0) );  // _borderColor
89    ADD_GLINT_SERIALIZER( BorderWidth, 0 );  // _borderWidth
90
91    BEGIN_ENUM_SERIALIZER( InternalFormatMode, USE_IMAGE_DATA_FORMAT );
92        ADD_ENUM_VALUE( USE_IMAGE_DATA_FORMAT );
93        ADD_ENUM_VALUE( USE_USER_DEFINED_FORMAT );
94        ADD_ENUM_VALUE( USE_ARB_COMPRESSION );
95        ADD_ENUM_VALUE( USE_S3TC_DXT1_COMPRESSION );
96        ADD_ENUM_VALUE( USE_S3TC_DXT3_COMPRESSION );
97        ADD_ENUM_VALUE( USE_S3TC_DXT5_COMPRESSION );
98        ADD_ENUM_VALUE( USE_PVRTC_2BPP_COMPRESSION );
99        ADD_ENUM_VALUE( USE_PVRTC_4BPP_COMPRESSION );
100        ADD_ENUM_VALUE( USE_ETC_COMPRESSION );
101        ADD_ENUM_VALUE( USE_RGTC1_COMPRESSION );
102        ADD_ENUM_VALUE( USE_RGTC2_COMPRESSION );
103        ADD_ENUM_VALUE( USE_S3TC_DXT1c_COMPRESSION );
104        ADD_ENUM_VALUE( USE_S3TC_DXT1a_COMPRESSION );
105    END_ENUM_SERIALIZER();  // _internalFormatMode
106
107    ADD_USER_SERIALIZER( InternalFormat );  // _internalFormat
108    ADD_USER_SERIALIZER( SourceFormat );  // _sourceFormat
109    ADD_USER_SERIALIZER( SourceType );  // _sourceType
110    ADD_BOOL_SERIALIZER( ShadowComparison, false );  // _use_shadow_comparison
111
112    BEGIN_ENUM_SERIALIZER( ShadowCompareFunc, LEQUAL );
113        ADD_ENUM_VALUE( NEVER );
114        ADD_ENUM_VALUE( LESS );
115        ADD_ENUM_VALUE( EQUAL );
116        ADD_ENUM_VALUE( LEQUAL );
117        ADD_ENUM_VALUE( GREATER );
118        ADD_ENUM_VALUE( NOTEQUAL );
119        ADD_ENUM_VALUE( GEQUAL );
120        ADD_ENUM_VALUE( ALWAYS );
121    END_ENUM_SERIALIZER();  // _shadow_compare_func
122
123    BEGIN_ENUM_SERIALIZER( ShadowTextureMode, LUMINANCE );
124        ADD_ENUM_VALUE( LUMINANCE );
125        ADD_ENUM_VALUE( INTENSITY );
126        ADD_ENUM_VALUE( ALPHA );
127    END_ENUM_SERIALIZER();  // _shadow_texture_mode
128
129    ADD_FLOAT_SERIALIZER( ShadowAmbient, 0.0f );  // _shadow_ambient
130}
Note: See TracBrowser for help on using the browser.