Added ImageProcessor interface class and plugin mechnanism for ImageProcessor implementations to osgDB::Registry.

Add NVidiaTextureTools based plugin that provides an ImageProcessor implementation within an nvtt plugin.
This commit is contained in:
Robert Osfield
2011-01-13 14:59:29 +00:00
parent f61a6aa4e7
commit 1b67e3ad1f
8 changed files with 575 additions and 1 deletions

View File

@@ -0,0 +1,54 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGDB_IMAGEPROCESSOR
#define OSGDB_IMAGEPROCESSOR 1
#include <osg/Object>
namespace osgDB {
class ImageProcessor : public osg::Object
{
public:
ImageProcessor():
osg::Object(true) {}
ImageProcessor(const ImageProcessor& rw,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(rw,copyop) {}
virtual ~ImageProcessor() {}
META_Object(osgDB,ImageProcessor);
enum CompressionMethod
{
USE_CPU, /// Use CPU for compression even when GPU compression is available
USE_GPU /// Use GPU for compression when available (i.e CUDA), otherwise fallback to CPU
};
enum CompressionQuality
{
FASTEST,
NORMAL,
PRODUCTION,
HIGHEST
};
virtual void compress(osg::Image& image, osg::Texture::InternalFormatMode compressedFormat, bool generateMipMap, bool resizeToPowerOfTwo, CompressionMethod method, CompressionQuality quality) {}
virtual void generateMipMap(osg::Image& image, bool resizeToPowerOfTwo, CompressionMethod method) {}
};
}
#endif

View File

@@ -27,6 +27,7 @@
#include <osgDB/ObjectWrapper>
#include <osgDB/FileCache>
#include <osgDB/SharedStateManager>
#include <osgDB/ImageProcessor>
#include <vector>
#include <map>
@@ -59,7 +60,6 @@ struct type_wrapper: basic_type_wrapper {
}
};
/**
Registry is a singleton factory which stores
the reader/writers which are linked in
@@ -101,6 +101,9 @@ class OSGDB_EXPORT Registry : public osg::Referenced
void addReaderWriter(ReaderWriter* rw);
void removeReaderWriter(ReaderWriter* rw);
void addImageProcessor(ImageProcessor* ip);
void removeImageProcessor(ImageProcessor* ip);
/** create the platform specific library name associated with file.*/
std::string createLibraryNameForFile(const std::string& fileName);
@@ -142,6 +145,21 @@ class OSGDB_EXPORT Registry : public osg::Referenced
const ReaderWriterList& getReaderWriterList() const { return _rwList; }
typedef std::vector< osg::ref_ptr<ImageProcessor> > ImageProcessorList;
/** get a image processor if available.*/
ImageProcessor* getImageProcessor();
/** get a image processor which is associated specified extension.*/
ImageProcessor* getImageProcessorForExtension(const std::string& ext);
/** get list of all registered ImageProcessors.*/
ImageProcessorList& getImageProcessorList() { return _ipList; }
/** get const list of all registered ImageProcessors.*/
const ImageProcessorList& getImageProcessorList() const { return _ipList; }
typedef class osgDB::FindFileCallback FindFileCallback;
typedef class osgDB::ReadFileCallback ReadFileCallback;
typedef class osgDB::WriteFileCallback WriteFileCallback;
@@ -555,6 +573,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
OpenThreads::ReentrantMutex _pluginMutex;
ReaderWriterList _rwList;
ImageProcessorList _ipList;
DynamicLibraryList _dlList;
bool _openingLibrary;
@@ -624,6 +643,34 @@ class RegisterReaderWriterProxy
};
/** Proxy class for automatic registration of reader/writers with the Registry.*/
template<class T>
class RegisterImageProcessorProxy
{
public:
RegisterImageProcessorProxy()
{
if (Registry::instance())
{
_rw = new T;
Registry::instance()->addImageProcessor(_rw.get());
}
}
~RegisterImageProcessorProxy()
{
if (Registry::instance())
{
Registry::instance()->removeImageProcessor(_rw.get());
}
}
T* get() { return _rw.get(); }
protected:
osg::ref_ptr<T> _rw;
};
struct PluginFunctionProxy
{
PluginFunctionProxy(CPluginFunction function) { (function)(); }
@@ -657,6 +704,9 @@ struct PluginFunctionProxy
extern "C" void osgdb_##ext(void) {} \
static osgDB::RegisterReaderWriterProxy<classname> g_proxy_##classname;
#define REGISTER_OSGIMAGEPROCESSOR(ext, classname) \
extern "C" void osgdb_##ext(void) {} \
static osgDB::RegisterImageProcessorProxy<classname> g_proxy_##classname;
}