root/OpenSceneGraph/trunk/src/osgDB/ObjectWrapper.cpp @ 11902

Revision 11902, 23.1 kB (checked in by robert, 4 years ago)

From Wang Rui, "I'd like to submit my latest modification of the serialization IO
functionalities. It includes two main parts: a version checking macro
for handling backward-compatiblity since 3.0, and enhencement of
current schema mechanism. I also change the option handling process to
use getPluginStringData(), and add new USE_SERIALIZER_WRAPPER macro in
the Registry header to allow for static-link usage as well.

The enhencement of schema machanism just tells the type of each
serializer while outputting them, such as:
osg::Group = Children:1

The meaning of the number can be found in the osgDB/Serializer header,
BaseSerializer::Type enum. It may help 3rdparty utilities understand
the structure of the wrapper and do some reflection work in the
future.

The new macro UPDATE_TO_VERSION can help indicate the InputStream? (no
affect on the writer) that a serializer is added/removed since certain
OSG version. An example wrapper file is also attached. The
Geode_modified.cpp is based on the serializers/osg/Geode.cpp file
(hey, don't merge it :-), but assumes that a new user serializer
'Test' is added since version 65 (that is, the OSG_SOVERSION):

REGISTER_OBJECT_WRAPPER( Geode, ... )
{

ADD_USER_SERIALIZER( Drawables ); // origin ones

UPDATE_TO_VERSION( 65 )
{

ADD_USER_SERIALIZER( Test ); // a serializer added from version 65

}

}

All kinds of ADD_... macros following UPDATE_TO_VERSION will
automatically apply the updated version. The braces here are only for
typesetting!
While reading an osgt/osgb/osgx file, OSG will now check if the file
version (recorded as the writer's soversion, instead of previous
meaningless "#Version 2") is equal or greater than Test's version, and
try reading it, or just ignore it if file version is lesser.

And we also have the REMOVE_SERIALIZER macro will mark a named
serializer as removed in some version, with which all files generated
by further versions will just ignore it:

UPDATE_TO_VERSION( 70 )
{

REMOVE_SERIALIZER( Test );

}

This means that from version 70, the serializer Test is removed (but
not actually erased from the list) and should not be read anymore. If
the read file version is less than 70 (and equal or greater than 65),
Test will still be handled when reading; otherwise it will be ignored
to keep compatiblity on different OSG versions.
"

Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13// Written by Wang Rui, (C) 2010
14
15#include <osg/Notify>
16#include <osg/BlendFunc>
17#include <osg/ClampColor>
18#include <osg/Fog>
19#include <osg/FragmentProgram>
20#include <osg/GL2Extensions>
21#include <osg/PointSprite>
22#include <osg/StateSet>
23#include <osg/StencilTwoSided>
24#include <osg/TexEnvCombine>
25#include <osg/Texture>
26#include <osg/TextureCubeMap>
27#include <osg/TextureRectangle>
28#include <osg/VertexProgram>
29
30#include <osgDB/Options>
31#include <osgDB/DataTypes>
32#include <osgDB/ObjectWrapper>
33#include <osgDB/Registry>
34
35// pull in OSG headers to just introduce their GL defines for GL3/GLES compatibility
36#include <osg/AlphaFunc>
37#include <osg/Material>
38#include <osg/LineStipple>
39#include <osg/PolygonStipple>
40#include <osg/Point>
41#include <osg/TexGen>
42#include <osg/ClipPlane>
43#include <osg/Fog>
44#include <osg/PolygonMode>
45#include <osg/PolygonOffset>
46#include <osg/Texture1D>
47#include <osg/LogicOp>
48
49#include <sstream>
50
51#ifndef GL_PERSPECTIVE_CORRECTION_HINT
52    #define GL_PERSPECTIVE_CORRECTION_HINT      0x0C50
53#endif
54
55#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
56    #define GL_POLYGON_SMOOTH_HINT              0x0C53
57    #define GL_LINE_SMOOTH_HINT                 0x0C52
58    #define GL_FRAGMENT_SHADER_DERIVATIVE_HINT  0x8B8B
59#endif
60
61using namespace osgDB;
62
63void osgDB::split( const std::string& src, StringList& list, char separator )
64{
65    std::string::size_type start = src.find_first_not_of(separator);
66    while ( start!=std::string::npos )
67    {
68        std::string::size_type end = src.find_first_of(separator, start);
69        if ( end!=std::string::npos )
70        {
71            list.push_back( std::string(src, start, end-start) );
72            start = src.find_first_not_of(separator, end);
73        }
74        else
75        {
76            list.push_back( std::string(src, start, src.size()-start) );
77            start = end;
78        }
79    }
80}
81
82////////////////////////////////////////////////////////////////////////////////////////////////////////
83//
84// ObjectWrapper
85//
86ObjectWrapper::ObjectWrapper( osg::Object* proto, const std::string& name,
87                              const std::string& associates )
88:   osg::Referenced(),
89    _proto(proto), _name(name), _version(0)
90{
91    split( associates, _associates );
92}
93
94void ObjectWrapper::markSerializerAsRemoved( const std::string& name )
95{
96    for ( SerializerList::iterator itr=_serializers.begin(); itr!=_serializers.end(); ++itr )
97    {
98        // When a serializer is marked as 'removed', it means that this serializer won't be used any more
99        // from specified OSG version (by macro UPDATE_TO_VERSION). The read() functions of higher versions
100        // will thus ignore it according to the sign and value of the _version variable.
101        if ( (*itr)->getName()==name )
102            (*itr)->_version = -_version;
103    }
104}
105
106BaseSerializer* ObjectWrapper::getSerializer( const std::string& name )
107{
108    for ( SerializerList::iterator itr=_serializers.begin(); itr!=_serializers.end(); ++itr )
109    {
110        if ( (*itr)->getName()==name )
111            return *itr;
112    }
113   
114    for ( StringList::const_iterator itr=_associates.begin(); itr!=_associates.end(); ++itr )
115    {
116        const std::string& assocName = *itr;
117        ObjectWrapper* assocWrapper = Registry::instance()->getObjectWrapperManager()->findWrapper(assocName);
118        if ( !assocWrapper )
119        {
120            osg::notify(osg::WARN) << "ObjectWrapper::getSerializer(): Unsupported associated class "
121                                   << assocName << std::endl;
122            continue;
123        }
124       
125        for ( SerializerList::iterator aitr=assocWrapper->_serializers.begin();
126              aitr!=assocWrapper->_serializers.end(); ++aitr )
127        {
128            if ( (*aitr)->getName()==name )
129                return *aitr;
130        }
131    }
132    return NULL;
133}
134
135bool ObjectWrapper::read( InputStream& is, osg::Object& obj )
136{
137    bool readOK = true;
138    for ( SerializerList::iterator itr=_serializers.begin();
139          itr!=_serializers.end(); ++itr )
140    {
141        int serializerVersion = (*itr)->_version;
142        if ( serializerVersion!=0 )
143        {
144            if ( serializerVersion<0 )
145            {
146                serializerVersion = -serializerVersion;
147               
148                // The serializer is removed from a specified version,
149                // and the file in reading is at the same or higher version, ignore it.
150                if ( is.getFileVersion()>=serializerVersion ) continue;
151            }
152            else
153            {
154                // The serializer is added at a specified version,
155                // but the file in reading is at a lower version, ignore it.
156                if ( is.getFileVersion()<serializerVersion ) continue;
157            }
158        }
159       
160        if ( (*itr)->read(is, obj) ) continue;
161        OSG_WARN << "ObjectWrapper::read(): Error reading property "
162                               << _name << "::" << (*itr)->getName() << std::endl;
163        readOK = false;
164    }
165
166    for ( FinishedObjectReadCallbackList::iterator itr=_finishedObjectReadCallbacks.begin();
167          itr!=_finishedObjectReadCallbacks.end();
168          ++itr )
169     {
170         (*itr)->objectRead(is, obj);
171     }
172   
173    return readOK;
174}
175
176bool ObjectWrapper::write( OutputStream& os, const osg::Object& obj )
177{
178    bool writeOK = true;
179    for ( SerializerList::iterator itr=_serializers.begin();
180          itr!=_serializers.end(); ++itr )
181    {
182        if ( (*itr)->write(os, obj) ) continue;
183        OSG_WARN << "ObjectWrapper::write(): Error writing property "
184                               << _name << "::" << (*itr)->getName() << std::endl;
185        writeOK = false;
186    }
187    return writeOK;
188}
189
190bool ObjectWrapper::readSchema( const StringList& properties, const std::vector<int>& )
191{
192    // FIXME: At present, I didn't do anything to determine serializers from their types...
193    if ( !_backupSerializers.size() )
194        _backupSerializers = _serializers;
195    _serializers.clear();
196   
197    unsigned int size = properties.size();
198    unsigned int serializersSize = _backupSerializers.size();
199    for ( unsigned int i=0; i<size; ++i )
200    {
201        if ( serializersSize<i )
202        {
203            OSG_WARN << "ObjectWrapper::readSchema(): Wrapper " << _name
204                                   << ": Incompatible serializers size" << std::endl;
205            break;
206        }
207       
208        const std::string& prop = properties[i];
209        if ( prop==_backupSerializers[i]->getName() )
210        {
211            _serializers.push_back( _backupSerializers[i] );
212        }
213        else
214        {
215            bool hasSerializer = false;
216            for ( SerializerList::iterator itr=_backupSerializers.begin();
217                  itr!=_backupSerializers.end(); ++itr )
218            {
219                if ( prop!=(*itr)->getName() ) continue;
220                _serializers.push_back( *itr );
221                hasSerializer = true;
222            }
223            if ( !hasSerializer )
224            {
225                OSG_WARN << "ObjectWrapper::readSchema(): Wrapper " << _name
226                                       << ": Unknown property " << prop << std::endl;
227            }
228        }
229    }
230    return size==_serializers.size();
231}
232
233void ObjectWrapper::writeSchema( StringList& properties, std::vector<int>& types )
234{
235    for ( SerializerList::iterator itr=_serializers.begin();
236          itr!=_serializers.end(); ++itr )
237    {
238        properties.push_back( (*itr)->getName() );
239    }
240   
241    for ( std::vector<int>::iterator itr=_typeList.begin();
242          itr!=_typeList.end(); ++itr )
243    {
244        types.push_back( (*itr) );
245    }
246}
247
248////////////////////////////////////////////////////////////////////////////////////////////////////////
249//
250// RegisterWrapperProxy
251//
252RegisterWrapperProxy::RegisterWrapperProxy( osg::Object* proto, const std::string& name,
253                        const std::string& associates, AddPropFunc func )
254{
255    _wrapper = new ObjectWrapper( proto, name, associates );
256    if ( func ) (*func)( _wrapper.get() );
257    Registry::instance()->getObjectWrapperManager()->addWrapper( _wrapper.get() );
258}
259
260RegisterWrapperProxy::~RegisterWrapperProxy()
261{
262    Registry::instance()->getObjectWrapperManager()->removeWrapper( _wrapper.get() );
263}
264
265////////////////////////////////////////////////////////////////////////////////////////////////////////
266//
267// ObjectWrapperManager
268//
269////////////////////////////////////////////////////////////////////////////////////////////////////////
270//
271// GlobalLookupTable
272//
273ObjectWrapperManager::ObjectWrapperManager()
274{
275    IntLookup& glTable = _globalMap["GL"];
276
277    // Modes
278    glTable.add( "GL_ALPHA_TEST", GL_ALPHA_TEST );
279    glTable.add( "GL_BLEND", GL_BLEND );
280    glTable.add( "GL_COLOR_LOGIC_OP", GL_COLOR_LOGIC_OP );
281    glTable.add( "GL_COLOR_MATERIAL", GL_COLOR_MATERIAL );
282    glTable.add( "GL_CULL_FACE", GL_CULL_FACE );
283    glTable.add( "GL_DEPTH_TEST", GL_DEPTH_TEST );
284    glTable.add( "GL_FOG", GL_FOG );
285    glTable.add( "GL_FRAGMENT_PROGRAM_ARB", GL_FRAGMENT_PROGRAM_ARB );
286    glTable.add( "GL_LINE_STIPPLE", GL_LINE_STIPPLE );
287    glTable.add( "GL_POINT_SMOOTH", GL_POINT_SMOOTH );
288    glTable.add( "GL_POINT_SPRITE_ARB", GL_POINT_SPRITE_ARB );
289    glTable.add( "GL_POLYGON_OFFSET_FILL", GL_POLYGON_OFFSET_FILL );
290    glTable.add( "GL_POLYGON_OFFSET_LINE", GL_POLYGON_OFFSET_LINE );
291    glTable.add( "GL_POLYGON_OFFSET_POINT", GL_POLYGON_OFFSET_POINT );
292    glTable.add( "GL_POLYGON_STIPPLE", GL_POLYGON_STIPPLE );
293    glTable.add( "GL_SCISSOR_TEST", GL_SCISSOR_TEST);
294    glTable.add( "GL_STENCIL_TEST", GL_STENCIL_TEST );
295    glTable.add( "GL_STENCIL_TEST_TWO_SIDE", GL_STENCIL_TEST_TWO_SIDE );
296    glTable.add( "GL_VERTEX_PROGRAM_ARB", GL_VERTEX_PROGRAM_ARB );
297
298    glTable.add( "GL_COLOR_SUM", GL_COLOR_SUM );
299    glTable.add( "GL_LIGHTING", GL_LIGHTING );
300    glTable.add( "GL_NORMALIZE", GL_NORMALIZE );
301    glTable.add( "GL_RESCALE_NORMAL", GL_RESCALE_NORMAL );
302
303    glTable.add( "GL_TEXTURE_1D", GL_TEXTURE_1D );
304    glTable.add( "GL_TEXTURE_2D", GL_TEXTURE_2D );
305    glTable.add( "GL_TEXTURE_3D", GL_TEXTURE_3D );
306    glTable.add( "GL_TEXTURE_CUBE_MAP", GL_TEXTURE_CUBE_MAP );
307    glTable.add( "GL_TEXTURE_RECTANGLE", GL_TEXTURE_RECTANGLE );
308    glTable.add( "GL_TEXTURE_GEN_Q", GL_TEXTURE_GEN_Q );
309    glTable.add( "GL_TEXTURE_GEN_R", GL_TEXTURE_GEN_R );
310    glTable.add( "GL_TEXTURE_GEN_S", GL_TEXTURE_GEN_S );
311    glTable.add( "GL_TEXTURE_GEN_T", GL_TEXTURE_GEN_T );
312
313    glTable.add( "GL_CLIP_PLANE0", GL_CLIP_PLANE0 );
314    glTable.add( "GL_CLIP_PLANE1", GL_CLIP_PLANE1 );
315    glTable.add( "GL_CLIP_PLANE2", GL_CLIP_PLANE2 );
316    glTable.add( "GL_CLIP_PLANE3", GL_CLIP_PLANE3 );
317    glTable.add( "GL_CLIP_PLANE4", GL_CLIP_PLANE4 );
318    glTable.add( "GL_CLIP_PLANE5", GL_CLIP_PLANE5 );
319
320    glTable.add( "GL_LIGHT0", GL_LIGHT0 );
321    glTable.add( "GL_LIGHT1", GL_LIGHT1 );
322    glTable.add( "GL_LIGHT2", GL_LIGHT2 );
323    glTable.add( "GL_LIGHT3", GL_LIGHT3 );
324    glTable.add( "GL_LIGHT4", GL_LIGHT4 );
325    glTable.add( "GL_LIGHT5", GL_LIGHT5 );
326    glTable.add( "GL_LIGHT6", GL_LIGHT6 );
327    glTable.add( "GL_LIGHT7", GL_LIGHT7 );
328
329    // Functions
330    glTable.add( "NEVER", GL_NEVER );
331    glTable.add( "LESS", GL_LESS );
332    glTable.add( "EQUAL", GL_EQUAL );
333    glTable.add( "LEQUAL", GL_LEQUAL );
334    glTable.add( "GREATER", GL_GREATER );
335    glTable.add( "NOTEQUAL", GL_NOTEQUAL );
336    glTable.add( "GEQUAL", GL_GEQUAL );
337    glTable.add( "ALWAYS", GL_ALWAYS );
338
339    // Texture environment states
340    glTable.add( "REPLACE", GL_REPLACE );
341    glTable.add( "MODULATE", GL_MODULATE );
342    glTable.add( "ADD", GL_ADD );
343    glTable.add( "ADD_SIGNED", GL_ADD_SIGNED_ARB );
344    glTable.add( "INTERPOLATE", GL_INTERPOLATE_ARB );
345    glTable.add( "SUBTRACT", GL_SUBTRACT_ARB );
346    glTable.add( "DOT3_RGB", GL_DOT3_RGB_ARB );
347    glTable.add( "DOT3_RGBA", GL_DOT3_RGBA_ARB );
348
349    glTable.add( "CONSTANT", GL_CONSTANT_ARB );
350    glTable.add( "PRIMARY_COLOR", GL_PRIMARY_COLOR_ARB );
351    glTable.add( "PREVIOUS", GL_PREVIOUS_ARB );
352    glTable.add( "TEXTURE", GL_TEXTURE );
353    glTable.add( "TEXTURE0", GL_TEXTURE0 );
354    glTable.add( "TEXTURE1", GL_TEXTURE0+1 );
355    glTable.add( "TEXTURE2", GL_TEXTURE0+2 );
356    glTable.add( "TEXTURE3", GL_TEXTURE0+3 );
357    glTable.add( "TEXTURE4", GL_TEXTURE0+4 );
358    glTable.add( "TEXTURE5", GL_TEXTURE0+5 );
359    glTable.add( "TEXTURE6", GL_TEXTURE0+6 );
360    glTable.add( "TEXTURE7", GL_TEXTURE0+7 );
361
362    // Texture clamp modes
363    glTable.add( "CLAMP", GL_CLAMP );
364    glTable.add( "CLAMP_TO_EDGE", GL_CLAMP_TO_EDGE );
365    glTable.add( "CLAMP_TO_BORDER", GL_CLAMP_TO_BORDER_ARB );
366    glTable.add( "REPEAT", GL_REPEAT );
367    glTable.add( "MIRROR", GL_MIRRORED_REPEAT_IBM );
368
369    // Texture filter modes
370    glTable.add( "LINEAR", GL_LINEAR );
371    glTable.add( "LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR );
372    glTable.add( "LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST );
373    glTable.add( "NEAREST", GL_NEAREST );
374    glTable.add( "NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR );
375    glTable.add( "NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST );
376
377    // Texture formats
378    glTable.add( "GL_INTENSITY", GL_INTENSITY );
379    glTable.add( "GL_LUMINANCE", GL_LUMINANCE );
380    glTable.add( "GL_ALPHA", GL_ALPHA );
381    glTable.add( "GL_LUMINANCE_ALPHA", GL_LUMINANCE_ALPHA );
382    glTable.add( "GL_RGB", GL_RGB );
383    glTable.add( "GL_RGBA", GL_RGBA );
384    glTable.add( "GL_COMPRESSED_ALPHA_ARB", GL_COMPRESSED_ALPHA_ARB );
385    glTable.add( "GL_COMPRESSED_LUMINANCE_ARB", GL_COMPRESSED_LUMINANCE_ARB );
386    glTable.add( "GL_COMPRESSED_INTENSITY_ARB", GL_COMPRESSED_INTENSITY_ARB );
387    glTable.add( "GL_COMPRESSED_LUMINANCE_ALPHA_ARB", GL_COMPRESSED_LUMINANCE_ALPHA_ARB );
388    glTable.add( "GL_COMPRESSED_RGB_ARB", GL_COMPRESSED_RGB_ARB );
389    glTable.add( "GL_COMPRESSED_RGBA_ARB", GL_COMPRESSED_RGBA_ARB );
390    glTable.add( "GL_COMPRESSED_RGB_S3TC_DXT1_EXT", GL_COMPRESSED_RGB_S3TC_DXT1_EXT );
391    glTable.add( "GL_COMPRESSED_RGBA_S3TC_DXT1_EXT", GL_COMPRESSED_RGBA_S3TC_DXT1_EXT );
392    glTable.add( "GL_COMPRESSED_RGBA_S3TC_DXT3_EXT", GL_COMPRESSED_RGBA_S3TC_DXT3_EXT );
393    glTable.add( "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT", GL_COMPRESSED_RGBA_S3TC_DXT5_EXT );
394
395    // Texture source types
396    glTable.add( "GL_BYTE", GL_BYTE );
397    glTable.add( "GL_SHORT", GL_SHORT );
398    glTable.add( "GL_INT", GL_INT );
399    glTable.add( "GL_FLOAT", GL_FLOAT );
400    glTable.add( "GL_DOUBLE", GL_DOUBLE );
401    glTable.add( "GL_UNSIGNED_BYTE", GL_UNSIGNED_BYTE );
402    glTable.add( "GL_UNSIGNED_SHORT", GL_UNSIGNED_SHORT );
403    glTable.add( "GL_UNSIGNED_INT", GL_UNSIGNED_INT );
404
405    // Blend values
406    glTable.add( "DST_ALPHA", GL_DST_ALPHA );
407    glTable.add( "DST_COLOR", GL_DST_COLOR );
408    glTable.add( "ONE", GL_ONE );
409    glTable.add( "ONE_MINUS_DST_ALPHA", GL_ONE_MINUS_DST_ALPHA );
410    glTable.add( "ONE_MINUS_DST_COLOR", GL_ONE_MINUS_DST_COLOR );
411    glTable.add( "ONE_MINUS_SRC_ALPHA", GL_ONE_MINUS_SRC_ALPHA );
412    glTable.add( "ONE_MINUS_SRC_COLOR", GL_ONE_MINUS_SRC_COLOR );
413    glTable.add( "SRC_ALPHA", GL_SRC_ALPHA );
414    glTable.add( "SRC_ALPHA_SATURATE", GL_SRC_ALPHA_SATURATE );
415    glTable.add( "SRC_COLOR", GL_SRC_COLOR );
416    glTable.add( "CONSTANT_COLOR", GL_CONSTANT_COLOR );
417    glTable.add( "ONE_MINUS_CONSTANT_COLOR", GL_ONE_MINUS_CONSTANT_COLOR );
418    glTable.add( "CONSTANT_ALPHA", GL_CONSTANT_ALPHA );
419    glTable.add( "ONE_MINUS_CONSTANT_ALPHA", GL_ONE_MINUS_CONSTANT_ALPHA );
420    glTable.add( "ZERO", GL_ZERO );
421
422    // Fog coordinate sources
423    glTable.add( "COORDINATE", GL_FOG_COORDINATE );
424    glTable.add( "DEPTH", GL_FRAGMENT_DEPTH );
425
426    // Hint targets
427    glTable.add( "FOG_HINT", GL_FOG_HINT );
428    glTable.add( "GENERATE_MIPMAP_HINT", GL_GENERATE_MIPMAP_HINT_SGIS );
429    glTable.add( "LINE_SMOOTH_HINT", GL_LINE_SMOOTH_HINT );
430    glTable.add( "PERSPECTIVE_CORRECTION_HINT", GL_PERSPECTIVE_CORRECTION_HINT );
431    glTable.add( "POINT_SMOOTH_HINT", GL_POINT_SMOOTH_HINT );
432    glTable.add( "POLYGON_SMOOTH_HINT", GL_POLYGON_SMOOTH_HINT );
433    glTable.add( "TEXTURE_COMPRESSION_HINT", GL_TEXTURE_COMPRESSION_HINT_ARB );
434    glTable.add( "FRAGMENT_SHADER_DERIVATIVE_HINT", GL_FRAGMENT_SHADER_DERIVATIVE_HINT );
435
436    // Polygon modes
437    glTable.add( "POINT", GL_POINT );
438    glTable.add( "LINE", GL_LINE );
439    glTable.add( "FILL", GL_FILL );
440
441    // Misc
442    glTable.add( "BACK", GL_BACK );
443    glTable.add( "FRONT", GL_FRONT );
444    glTable.add( "FRONT_AND_BACK", GL_FRONT_AND_BACK );
445    glTable.add( "FIXED_ONLY", GL_FIXED_ONLY );
446    glTable.add( "FASTEST", GL_FASTEST );
447    glTable.add( "NICEST", GL_NICEST );
448    glTable.add( "DONT_CARE", GL_DONT_CARE );
449
450    IntLookup& arrayTable = _globalMap["ArrayType"];
451
452    arrayTable.add( "ByteArray", ID_BYTE_ARRAY );
453    arrayTable.add( "UByteArray", ID_UBYTE_ARRAY );
454    arrayTable.add( "ShortArray", ID_SHORT_ARRAY );
455    arrayTable.add( "UShortArray", ID_USHORT_ARRAY );
456    arrayTable.add( "IntArray", ID_INT_ARRAY );
457    arrayTable.add( "UIntArray", ID_UINT_ARRAY );
458    arrayTable.add( "FloatArray", ID_FLOAT_ARRAY );
459    arrayTable.add( "DoubleArray", ID_DOUBLE_ARRAY );
460
461    arrayTable.add( "Vec2bArray", ID_VEC2B_ARRAY );
462    arrayTable.add( "Vec3bArray", ID_VEC3B_ARRAY );
463    arrayTable.add( "Vec4bArray", ID_VEC4B_ARRAY );
464    arrayTable.add( "Vec4ubArray", ID_VEC4UB_ARRAY );
465    arrayTable.add( "Vec2sArray", ID_VEC2S_ARRAY );
466    arrayTable.add( "Vec3sArray", ID_VEC3S_ARRAY );
467    arrayTable.add( "Vec4sArray", ID_VEC4S_ARRAY );
468    arrayTable.add( "Vec2fArray", ID_VEC2_ARRAY );
469    arrayTable.add( "Vec3fArray", ID_VEC3_ARRAY );
470    arrayTable.add( "Vec4fArray", ID_VEC4_ARRAY );
471    arrayTable.add( "Vec2dArray", ID_VEC2D_ARRAY );
472    arrayTable.add( "Vec3dArray", ID_VEC3D_ARRAY );
473    arrayTable.add( "Vec4dArray", ID_VEC4D_ARRAY );
474
475    IntLookup& primitiveTable = _globalMap["PrimitiveType"];
476
477    primitiveTable.add( "DrawArrays", ID_DRAWARRAYS );
478    primitiveTable.add( "DrawArraysLength", ID_DRAWARRAY_LENGTH );
479    primitiveTable.add( "DrawElementsUByte", ID_DRAWELEMENTS_UBYTE );
480    primitiveTable.add( "DrawElementsUShort", ID_DRAWELEMENTS_USHORT );
481    primitiveTable.add( "DrawElementsUInt", ID_DRAWELEMENTS_UINT );
482
483    primitiveTable.add( "GL_POINTS", GL_POINTS );
484    primitiveTable.add( "GL_LINES", GL_LINES );
485    primitiveTable.add( "GL_LINE_STRIP", GL_LINE_STRIP );
486    primitiveTable.add( "GL_LINE_LOOP", GL_LINE_LOOP );
487    primitiveTable.add( "GL_TRIANGLES", GL_TRIANGLES );
488    primitiveTable.add( "GL_TRIANGLE_STRIP", GL_TRIANGLE_STRIP );
489    primitiveTable.add( "GL_TRIANGLE_FAN", GL_TRIANGLE_FAN );
490    primitiveTable.add( "GL_QUADS", GL_QUADS );
491    primitiveTable.add( "GL_QUAD_STRIP", GL_QUAD_STRIP );
492    primitiveTable.add( "GL_POLYGON", GL_POLYGON );
493    primitiveTable.add( "GL_LINES_ADJACENCY_EXT", GL_LINES_ADJACENCY_EXT );
494    primitiveTable.add( "GL_LINE_STRIP_ADJACENCY_EXT", GL_LINE_STRIP_ADJACENCY_EXT );
495    primitiveTable.add( "GL_TRIANGLES_ADJACENCY_EXT", GL_TRIANGLES_ADJACENCY_EXT );
496    primitiveTable.add( "GL_TRIANGLE_STRIP_ADJACENCY_EXT", GL_TRIANGLE_STRIP_ADJACENCY_EXT );
497}
498
499ObjectWrapperManager::~ObjectWrapperManager()
500{
501}
502
503
504void ObjectWrapperManager::addWrapper( ObjectWrapper* wrapper )
505{
506    if ( !wrapper ) return;
507
508    WrapperMap::iterator itr = _wrappers.find( wrapper->getName() );
509    if ( itr!=_wrappers.end() )
510    {
511        OSG_WARN << "ObjectWrapperManager::addWrapper(): '" << wrapper->getName()
512                               << "' already exists." << std::endl;
513    }
514    _wrappers[wrapper->getName()] = wrapper;
515}
516
517void ObjectWrapperManager::removeWrapper( ObjectWrapper* wrapper )
518{
519    if ( !wrapper ) return;
520
521    WrapperMap::iterator itr = _wrappers.find( wrapper->getName() );
522    if ( itr!=_wrappers.end() ) _wrappers.erase( itr );
523}
524
525ObjectWrapper* ObjectWrapperManager::findWrapper( const std::string& name )
526{
527    WrapperMap::iterator itr = _wrappers.find( name );
528    if ( itr!=_wrappers.end() ) return itr->second.get();
529
530    // Load external libraries
531    std::string::size_type posDoubleColon = name.rfind("::");
532    if ( posDoubleColon!=std::string::npos )
533    {
534        std::string libName = std::string( name, 0, posDoubleColon );
535
536        std::string nodeKitLib = osgDB::Registry::instance()->createLibraryNameForNodeKit(libName);
537        if ( osgDB::Registry::instance()->loadLibrary(nodeKitLib)==osgDB::Registry::LOADED )
538            return findWrapper(name);
539
540        std::string pluginLib = osgDB::Registry::instance()->createLibraryNameForExtension(std::string("serializers_")+libName);
541        if ( osgDB::Registry::instance()->loadLibrary(pluginLib)==osgDB::Registry::LOADED )
542            return findWrapper(name);
543
544        pluginLib = osgDB::Registry::instance()->createLibraryNameForExtension(libName);
545        if ( osgDB::Registry::instance()->loadLibrary(pluginLib)==osgDB::Registry::LOADED )
546            return findWrapper(name);
547    }
548    return NULL;
549}
550
551void ObjectWrapperManager::addCompressor( BaseCompressor* compressor )
552{
553    if ( !compressor ) return;
554
555    CompressorMap::iterator itr = _compressors.find( compressor->getName() );
556    if ( itr!=_compressors.end() )
557    {
558        OSG_WARN << "ObjectWrapperManager::addCompressor(): '" << compressor->getName()
559                               << "' already exists." << std::endl;
560    }
561    _compressors[compressor->getName()] = compressor;
562}
563
564void ObjectWrapperManager::removeCompressor( BaseCompressor* compressor )
565{
566    if ( !compressor ) return;
567
568    CompressorMap::iterator itr = _compressors.find( compressor->getName() );
569    if ( itr!=_compressors.end() ) _compressors.erase( itr );
570}
571
572BaseCompressor* ObjectWrapperManager::findCompressor( const std::string& name )
573{
574    CompressorMap::iterator itr = _compressors.find( name );
575    if ( itr!=_compressors.end() ) return itr->second.get();
576
577    // Load external libraries
578    std::string nodeKitLib = osgDB::Registry::instance()->createLibraryNameForNodeKit(name);
579    if ( osgDB::Registry::instance()->loadLibrary(nodeKitLib)==osgDB::Registry::LOADED )
580        return findCompressor(name);
581
582    std::string pluginLib = osgDB::Registry::instance()->createLibraryNameForExtension(std::string("compressor_")+name);
583    if ( osgDB::Registry::instance()->loadLibrary(pluginLib)==osgDB::Registry::LOADED )
584        return findCompressor(name);
585
586    pluginLib = osgDB::Registry::instance()->createLibraryNameForExtension(name);
587    if ( osgDB::Registry::instance()->loadLibrary(pluginLib)==osgDB::Registry::LOADED )
588        return findCompressor(name);
589    return NULL;
590}
591
592////////////////////////////////////////////////////////////////////////////////////////////////////////
593//
594// RegisytrCompressorProxy
595//
596RegisterCompressorProxy::RegisterCompressorProxy( const std::string& name, BaseCompressor* compressor ):
597    _compressor(compressor)
598{
599    _compressor->setName( name );
600    Registry::instance()->getObjectWrapperManager()->addCompressor( _compressor.get() );
601}
602
603RegisterCompressorProxy::~RegisterCompressorProxy()
604{
605    Registry::instance()->getObjectWrapperManager()->removeCompressor( _compressor.get() );
606}
Note: See TracBrowser for help on using the browser.