1 // ModelRegistry.hxx -- interface to the OSG model registry
3 // Copyright (C) 2007 Tim Moore <timoore@redhat.com>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #ifndef _SG_MODELREGISTRY_HXX
19 #define _SG_MODELREGISTRY_HXX 1
21 #include <osg/ref_ptr>
22 #include <osgDB/ReaderWriter>
23 #include <osgDB/Registry>
25 #include <simgear/compiler.h>
32 class ModelRegistry : public osgDB::Registry::ReadFileCallback {
34 virtual osgDB::ReaderWriter::ReadResult
35 readImage(const std::string& fileName,
36 const osgDB::ReaderWriter::Options* opt);
37 virtual osgDB::ReaderWriter::ReadResult
38 readNode(const std::string& fileName,
39 const osgDB::ReaderWriter::Options* opt);
40 void addImageCallbackForExtension(const std::string& extension,
41 osgDB::Registry::ReadFileCallback*
43 void addNodeCallbackForExtension(const std::string& extension,
44 osgDB::Registry::ReadFileCallback*
46 static ModelRegistry* getInstance();
48 static osg::ref_ptr<ModelRegistry> instance;
49 typedef std::map<std::string, osg::ref_ptr<osgDB::Registry::ReadFileCallback> >
51 CallbackMap imageCallbackMap;
52 CallbackMap nodeCallbackMap;
55 // Proxy for registering extension-based callbacks
58 class ModelRegistryCallbackProxy
61 ModelRegistryCallbackProxy(std::string extension)
63 ModelRegistry::getInstance()->addNodeCallbackForExtension(extension,
68 // Callback for file extensions that load files using the default OSG
71 class OSGFileCallback : public osgDB::Registry::ReadFileCallback {
73 virtual osgDB::ReaderWriter::ReadResult
74 readImage(const std::string& fileName,
75 const osgDB::ReaderWriter::Options* opt);
76 virtual osgDB::ReaderWriter::ReadResult
77 readNode(const std::string& fileName,
78 const osgDB::ReaderWriter::Options* opt);
82 #endif // _SG_MODELREGISTRY_HXX