From 7573cc6036722463f6b5d023b8027773d893af6a Mon Sep 17 00:00:00 2001 From: Don BURNS Date: Wed, 2 Feb 2005 22:13:07 +0000 Subject: [PATCH] Added Viewport State Attribute to .osg reader/writer --- src/osgPlugins/osg/GNUmakefile | 1 + src/osgPlugins/osg/Viewport.cpp | 71 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/osgPlugins/osg/Viewport.cpp diff --git a/src/osgPlugins/osg/GNUmakefile b/src/osgPlugins/osg/GNUmakefile index c63ba91bb..8d2576acb 100644 --- a/src/osgPlugins/osg/GNUmakefile +++ b/src/osgPlugins/osg/GNUmakefile @@ -68,6 +68,7 @@ CXXFILES =\ TextureCubeMap.cpp\ Transform.cpp\ VertexProgram.cpp\ + Viewport.cpp\ LIBS += $(OSG_LIBS) $(OTHER_LIBS) diff --git a/src/osgPlugins/osg/Viewport.cpp b/src/osgPlugins/osg/Viewport.cpp new file mode 100644 index 000000000..6e108fd5b --- /dev/null +++ b/src/osgPlugins/osg/Viewport.cpp @@ -0,0 +1,71 @@ +#include "osg/Viewport" + +#include "osgDB/Registry" +#include "osgDB/Input" +#include "osgDB/Output" + +using namespace osg; +using namespace osgDB; + +// forward declare functions to use later. +bool Viewport_readLocalData(Object& obj, Input& fr); +bool Viewport_writeLocalData(const Object& obj, Output& fw); + +// register the read and write functions with the osgDB::Registry. +RegisterDotOsgWrapperProxy g_ViewportProxy +( + new osg::Viewport, + "Viewport", + "Object StateAttribute Viewport", + &Viewport_readLocalData, + &Viewport_writeLocalData +); + + +bool Viewport_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + int x = 0, y = 0, width = 0, height = 0; + + + if (fr[0].matchWord("x") && fr[1].getInt(x)) + { + fr+=2; + iteratorAdvanced = true; + } + + if (fr[0].matchWord("y") && fr[1].getInt(y)) + { + fr+=2; + iteratorAdvanced = true; + } + + if (fr[0].matchWord("width") && fr[1].getInt(width)) + { + fr+=2; + iteratorAdvanced = true; + } + + if (fr[0].matchWord("height") && fr[1].getInt(height)) + { + fr+=2; + iteratorAdvanced = true; + } + + Viewport& viewport = static_cast(obj); + viewport.setViewport( x, y, width, height ); + return iteratorAdvanced; +} + + +bool Viewport_writeLocalData(const Object& obj, Output& fw) +{ + const Viewport& viewport = static_cast(obj); + + fw.indent() << "x " << viewport.x() << std::endl; + fw.indent() << "y " << viewport.y() << std::endl; + fw.indent() << "width " << viewport.width() << std::endl; + fw.indent() << "height " << viewport.height() << std::endl; + + return true; +}