Initial revision

This commit is contained in:
Don BURNS
2001-01-10 16:32:10 +00:00
parent 7c12eb9361
commit 70208ebc06
461 changed files with 70936 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
#include <stdio.h>
#include <string.h>
#include <osg/OSG>
#include <osg/Geode>
#include <osg/Group>
#include <osg/Registry>
#include <osg/Notify>
#include "ConvertToPerformer.h"
#include "ConvertFromPerformer.h"
#include <Performer/pfdu.h>
#include <Performer/pr/pfTexture.h>
class ReaderWriterPFB : public osg::ReaderWriter {
public:
ReaderWriterPFB();
~ReaderWriterPFB();
void initPerformer();
virtual const char* className() { return "Performer Reader/Writer"; }
virtual bool acceptsExtension(const std::string& extension) { return extension=="pfb"; }
virtual osg::Image* readImage(const std::string& fileName)
{
osg::notify(osg::INFO)<< "ReaderWriterPFB::readImage( "<<fileName.c_str()<<" )\n";
initPerformer();
pfTexture* tex = new pfTexture;
if (tex->loadFile(fileName.c_str()))
{
int s=0;
int t=0;
int r=0;
int comp=0;
unsigned int* imageData = NULL;
tex->getImage(&imageData,&comp,&s,&t,&r);
int internalFormat = comp;
unsigned int pixelFormat =
comp == 1 ? GL_LUMINANCE :
comp == 2 ? GL_LUMINANCE_ALPHA :
comp == 3 ? GL_RGB :
comp == 4 ? GL_RGBA : (GLenum)-1;
unsigned int dataType = GL_UNSIGNED_BYTE;
osg::Image* image = new osg::Image;
image->setFileName(fileName.c_str());
image->setImage(s,t,r,
internalFormat,
pixelFormat,
dataType,
(unsigned char*)imageData);
return image;
}
return NULL;
}
virtual osg::Node* readNode(const std::string& fileName)
{
osg::notify(osg::INFO)<< "ReaderWriterPFB::readNode( "<<fileName.c_str()<<" )\n";
initPerformer();
pfNode* root = pfdLoadFile(fileName.c_str());
ConvertFromPerformer converter;
return converter.convert(root);
}
virtual bool writeNode(osg::Node& node,const std::string& fileName) {
osg::notify(osg::INFO)<< "ReaderWriterPFB::writeNode( "<<fileName.c_str()<<" )\n";
initPerformer();
ConvertToPerformer converter;
pfNode* root = converter.convert(&node);
if (root)
{
return pfdStoreFile(root,fileName.c_str())!=0;
}
else
{
return false;
}
}
protected:
bool _performerInitialised;
};
ReaderWriterPFB::ReaderWriterPFB()
{
_performerInitialised = false;
}
ReaderWriterPFB::~ReaderWriterPFB()
{
}
void ReaderWriterPFB::initPerformer()
{
if (_performerInitialised) return;
_performerInitialised = true;
pfMultiprocess(0);
pfInit();
// FileList::iterator itr;
// for(itr=filelist.begin();itr!=filelist.end();++itr)
// {
// pfdInitConverter((*itr).c_str());
// }
pfConfig();
}
// now register with sgRegistry to instantiate the above
// reader/writer.
osg::RegisterReaderWriterProxy<ReaderWriterPFB> g_readerWriter_PFB_Proxy;