From 1ba7e67e2c4d14cee44dccd8a26d06743caf3bd8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Mar 2002 15:46:34 +0000 Subject: [PATCH] Added missing TextureCubeMap.cpp to cvs. --- src/osgPlugins/osg/TextureCubeMap.cpp | 94 +++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/osgPlugins/osg/TextureCubeMap.cpp diff --git a/src/osgPlugins/osg/TextureCubeMap.cpp b/src/osgPlugins/osg/TextureCubeMap.cpp new file mode 100644 index 000000000..c5e9e341c --- /dev/null +++ b/src/osgPlugins/osg/TextureCubeMap.cpp @@ -0,0 +1,94 @@ +#include "osg/TextureCubeMap" + +#include "osgDB/Registry" +#include "osgDB/Input" +#include "osgDB/Output" + +using namespace osg; +using namespace osgDB; + +// forward declare functions to use later. +bool TextureCubeMap_readLocalData(Object& obj, Input& fr); +bool TextureCubeMap_writeLocalData(const Object& obj, Output& fw); + +bool TextureCubeMap_matchWrapStr(const char* str,TextureCubeMap::WrapMode& wrap); +const char* TextureCubeMap_getWrapStr(TextureCubeMap::WrapMode wrap); +bool TextureCubeMap_matchFilterStr(const char* str,TextureCubeMap::FilterMode& filter); +const char* TextureCubeMap_getFilterStr(TextureCubeMap::FilterMode filter); +bool TextureCubeMap_matchInternalFormatModeStr(const char* str,TextureCubeMap::InternalFormatMode& mode); +const char* TextureCubeMap_getInternalFormatModeStr(TextureCubeMap::InternalFormatMode mode); +bool TextureCubeMap_matchInternalFormatValueStr(const char* str,int& value); +const char* TextureCubeMap_getInternalFormatValueStr(int value); +bool TextureCubeMap_matchSubloadModeStr(const char* str, TextureCubeMap::SubloadMode& value); +const char* TextureCubeMap_getSubloadModeStr(TextureCubeMap::SubloadMode value); + +// register the read and write functions with the osgDB::Registry. +RegisterDotOsgWrapperProxy g_TextureCubeMapProxy +( + new osg::TextureCubeMap, + "TextureCubeMap", + "Object StateAttribute TextureCubeMap Texture", + &TextureCubeMap_readLocalData, + &TextureCubeMap_writeLocalData +); + + +#define READ_IMAGE(FACE)\ + matched = false;\ + if (fr[1].matchWord(#FACE)) \ + {\ + if (fr[2].isString())\ + { \ + Image* image = fr.readImage(fr[2].getStr());\ + if (image) texture.setImage(osg::TextureCubeMap::FACE,image);\ + fr += 2;\ + iteratorAdvanced = true; \ + matched = true;\ + }\ + }\ + +bool TextureCubeMap_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + TextureCubeMap& texture = static_cast(obj); + + bool matched=true; + while (fr[0].matchWord("image") && matched) + { + READ_IMAGE(POSITIVE_X) + else READ_IMAGE(NEGATIVE_X) + else READ_IMAGE(POSITIVE_Y) + else READ_IMAGE(NEGATIVE_Y) + else READ_IMAGE(POSITIVE_Z) + else READ_IMAGE(NEGATIVE_Z) + } + + return iteratorAdvanced; +} + + +#define WRITE_IMAGE(FACE) \ + {\ + const osg::Image* image = texture.getImage(osg::TextureCubeMap::FACE);\ + if (image && !(image->getFileName().empty())) \ + {\ + fw.indent() << "image "<<#FACE<<" "<getFileName()<(obj); + + WRITE_IMAGE(POSITIVE_X) + WRITE_IMAGE(NEGATIVE_X) + WRITE_IMAGE(POSITIVE_Y) + WRITE_IMAGE(NEGATIVE_Y) + WRITE_IMAGE(POSITIVE_Z) + WRITE_IMAGE(NEGATIVE_Z) + + return true; +} + +