From 47651d3c8d4a090c76dc938bd8caeeaa7941af4f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 22 Jul 2005 09:31:19 +0000 Subject: [PATCH] Added glSissor suppor via new osg::Scissor class. Added .osg support for osg::Scissor. Added .ive support for osg::Viewport and osg::Scissor. --- VisualStudio/osg/osg.dsp | 8 ++ VisualStudio/osgPlugins/ive/ive.dsp | 16 ++++ VisualStudio/osgPlugins/osg/dot_osg.dsp | 12 +++ include/osg/Scissor | 110 ++++++++++++++++++++++++ include/osg/StateAttribute | 1 + include/osg/Viewport | 7 ++ src/osg/GNUmakefile | 1 + src/osg/Scissor.cpp | 34 ++++++++ src/osgPlugins/ive/DataInputStream.cpp | 10 +++ src/osgPlugins/ive/DataOutputStream.cpp | 8 ++ src/osgPlugins/ive/GNUmakefile | 2 + src/osgPlugins/ive/ReadWrite.h | 2 + src/osgPlugins/ive/Scissor.cpp | 63 ++++++++++++++ src/osgPlugins/ive/Scissor.h | 15 ++++ src/osgPlugins/ive/Viewport.cpp | 63 ++++++++++++++ src/osgPlugins/ive/Viewport.h | 15 ++++ src/osgPlugins/osg/GNUmakefile | 1 + src/osgPlugins/osg/Scissor.cpp | 71 +++++++++++++++ 18 files changed, 439 insertions(+) create mode 100644 include/osg/Scissor create mode 100644 src/osg/Scissor.cpp create mode 100644 src/osgPlugins/ive/Scissor.cpp create mode 100644 src/osgPlugins/ive/Scissor.h create mode 100644 src/osgPlugins/ive/Viewport.cpp create mode 100644 src/osgPlugins/ive/Viewport.h create mode 100644 src/osgPlugins/osg/Scissor.cpp diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index 4f4b9ca12..4f209af4f 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -408,6 +408,10 @@ SOURCE=..\..\src\osg\Referenced.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osg\Scissor.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osg\Sequence.cpp # End Source File # Begin Source File @@ -896,6 +900,10 @@ SOURCE=..\..\Include\Osg\Referenced # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\Scissor +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\Sequence # End Source File # Begin Source File diff --git a/VisualStudio/osgPlugins/ive/ive.dsp b/VisualStudio/osgPlugins/ive/ive.dsp index fc48f0a31..5e5c7dc0b 100755 --- a/VisualStudio/osgPlugins/ive/ive.dsp +++ b/VisualStudio/osgPlugins/ive/ive.dsp @@ -324,6 +324,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\ReaderWriterIVE.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\Scissor.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\Sequence.cpp # End Source File # Begin Source File @@ -412,6 +416,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\VertexProgram.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\Viewport.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\VisibilityGroup.cpp # End Source File # End Group @@ -704,6 +712,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\Program.h # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\Scissor.h +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\Shader.h # End Source File # Begin Source File @@ -740,6 +752,10 @@ SOURCE=..\..\..\src\osgPlugins\ive\VertexProgram.h # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\ive\Viewport.h +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\ive\VisibilityGroup.h # End Source File # End Group diff --git a/VisualStudio/osgPlugins/osg/dot_osg.dsp b/VisualStudio/osgPlugins/osg/dot_osg.dsp index c302ec237..e72a57d4b 100755 --- a/VisualStudio/osgPlugins/osg/dot_osg.dsp +++ b/VisualStudio/osgPlugins/osg/dot_osg.dsp @@ -280,6 +280,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\ReaderWriterOSG.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\osg\Scissor.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\osg\Sequence.cpp # End Source File # Begin Source File @@ -300,6 +304,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\ShapeDrawable.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\osg\Scissor.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\osg\StateSet.cpp # End Source File # Begin Source File @@ -374,6 +382,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\Uniform.cpp SOURCE=..\..\..\src\osgPlugins\osg\VertexProgram.cpp # End Source File +# Begin Source File + +SOURCE=..\..\..\src\osgPlugins\osg\Viewport.cpp +# End Source File # End Group # Begin Group "Header Files" diff --git a/include/osg/Scissor b/include/osg/Scissor new file mode 100644 index 000000000..830e98f6f --- /dev/null +++ b/include/osg/Scissor @@ -0,0 +1,110 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 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 OSG_Scissor +#define OSG_Scissor 1 + +#include + +namespace osg { + +/** Encapsulate OpenGL glScissor. */ +class OSG_EXPORT Scissor : public StateAttribute +{ + public : + Scissor(); + + Scissor(int x,int y,int width,int height): + _x(x), + _y(y), + _width(width), + _height(height) {} + + + /** Copy constructor using CopyOp to manage deep vs shallow copy. */ + Scissor(const Scissor& vp,const CopyOp& copyop=CopyOp::SHALLOW_COPY): + StateAttribute(vp,copyop), + _x(vp._x), + _y(vp._y), + _width(vp._width), + _height(vp._height) {} + + META_StateAttribute(osg, Scissor, SCISSOR); + + /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ + virtual int compare(const StateAttribute& sa) const + { + // check the types are equal and then create the rhs variable + // used by the COMPARE_StateAttribute_Paramter macro's below. + COMPARE_StateAttribute_Types(Scissor,sa) + + // compare each paramter in turn against the rhs. + COMPARE_StateAttribute_Parameter(_x) + COMPARE_StateAttribute_Parameter(_y) + COMPARE_StateAttribute_Parameter(_width) + COMPARE_StateAttribute_Parameter(_height) + + return 0; // passed all the above comparison macro's, must be equal. + } + + + virtual bool getModeUsage(ModeUsage& usage) const + { + usage.usesMode(GL_SCISSOR_TEST); + return true; + } + + inline void setScissor(int x,int y,int width,int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } + + void getScissor(int& x,int& y,int& width,int& height) const + { + x = _x; + y = _y; + width = _width; + height = _height; + } + + inline int& x() { return _x; } + inline int x() const { return _x; } + + inline int& y() { return _y; } + inline int y() const { return _y; } + + inline int& width() { return _width; } + inline int width() const { return _width; } + + inline int& height() { return _height; } + inline int height() const { return _height; } + + virtual void apply(State& state) const; + + protected: + + virtual ~Scissor(); + + int _x; + int _y; + int _width; + int _height; + +}; + +} + +#endif diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index 0c262fb35..9dfa0a9b9 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -149,6 +149,7 @@ class OSG_EXPORT StateAttribute : public Object COLORMASK, DEPTH, VIEWPORT, + SCISSOR, BLENDCOLOR, MULTISAMPLE, diff --git a/include/osg/Viewport b/include/osg/Viewport index 74cc011ca..ef7d79c3c 100644 --- a/include/osg/Viewport +++ b/include/osg/Viewport @@ -74,9 +74,16 @@ class OSG_EXPORT Viewport : public StateAttribute height = _height; } + inline int& x() { return _x; } inline int x() const { return _x; } + + inline int& y() { return _y; } inline int y() const { return _y; } + + inline int& width() { return _width; } inline int width() const { return _width; } + + inline int& height() { return _height; } inline int height() const { return _height; } inline bool valid() const { return _width!=0 && _height!=0; } diff --git a/src/osg/GNUmakefile b/src/osg/GNUmakefile index 44cd1264b..a4a5fa41a 100644 --- a/src/osg/GNUmakefile +++ b/src/osg/GNUmakefile @@ -80,6 +80,7 @@ CXXFILES =\ ProxyNode.cpp\ Quat.cpp\ Referenced.cpp\ + Scissor.cpp\ Sequence.cpp\ ShadeModel.cpp\ Shader.cpp\ diff --git a/src/osg/Scissor.cpp b/src/osg/Scissor.cpp new file mode 100644 index 000000000..429768bcd --- /dev/null +++ b/src/osg/Scissor.cpp @@ -0,0 +1,34 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 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. +*/ +#include + +using namespace osg; + +Scissor::Scissor() +{ + _x = 0; + _y = 0; + _width = 800; + _height = 600; +} + + +Scissor::~Scissor() +{ +} + +void Scissor::apply(State&) const +{ + glScissor(_x,_y,_width,_height); +} + diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index d6d469baa..a6e2e6dd0 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -41,6 +41,8 @@ #include "ProxyNode.h" #include "FrontFace.h" #include "Program.h" +#include "Viewport.h" +#include "Scissor.h" #include "Group.h" #include "MatrixTransform.h" @@ -814,6 +816,14 @@ osg::StateAttribute* DataInputStream::readStateAttribute() attribute = new osg::BlendFunc(); ((ive::BlendFunc*)(attribute))->read(this); } + else if(attributeID == IVEVIEWPORT){ + attribute = new osg::Viewport(); + ((ive::Viewport*)(attribute))->read(this); + } + else if(attributeID == IVESCISSOR){ + attribute = new osg::Scissor(); + ((ive::Scissor*)(attribute))->read(this); + } else if(attributeID == IVEMATERIAL){ attribute = new osg::Material(); ((ive::Material*)(attribute))->read(this); diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index d98375f20..1d3ce4062 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -44,6 +44,8 @@ #include "Program.h" #include "Uniform.h" #include "Shader.h" +#include "Viewport.h" +#include "Scissor.h" #include "Group.h" #include "MatrixTransform.h" @@ -638,6 +640,12 @@ void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute) else if(dynamic_cast(attribute)){ ((ive::BlendFunc*)(attribute))->write(this); } + else if(dynamic_cast(attribute)){ + ((ive::Viewport*)(attribute))->write(this); + } + else if(dynamic_cast(attribute)){ + ((ive::Scissor*)(attribute))->write(this); + } // This is a Material else if(dynamic_cast(attribute)){ ((ive::Material*)(attribute))->write(this); diff --git a/src/osgPlugins/ive/GNUmakefile b/src/osgPlugins/ive/GNUmakefile index 41c468206..677dda141 100644 --- a/src/osgPlugins/ive/GNUmakefile +++ b/src/osgPlugins/ive/GNUmakefile @@ -61,6 +61,7 @@ CXXFILES =\ ProxyNode.cpp\ ReaderWriterIVE.cpp\ Sequence.cpp\ + Scissor.cpp\ ShadeModel.cpp\ Shader.cpp\ Shape.cpp\ @@ -81,6 +82,7 @@ CXXFILES =\ Transform.cpp\ Uniform.cpp\ VertexProgram.cpp\ + Viewport.cpp\ VisibilityGroup.cpp\ LIBS += -losgFX -losgSim -losgText $(OSG_LIBS) $(OTHER_LIBS) diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index 80d4daca6..d4c5daa8d 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -67,6 +67,8 @@ namespace ive { #define IVEPROGRAM 0x00001124 #define IVESHADER 0x00001125 #define IVEUNIFORM 0x00001126 +#define IVEVIEWPORT 0x00001127 +#define IVESCISSOR 0x00001128 // Drawables #define IVEDRAWABLE 0x00001000 diff --git a/src/osgPlugins/ive/Scissor.cpp b/src/osgPlugins/ive/Scissor.cpp new file mode 100644 index 000000000..5a9e1e369 --- /dev/null +++ b/src/osgPlugins/ive/Scissor.cpp @@ -0,0 +1,63 @@ +/********************************************************************** + * + * FILE: Scissor.cpp + * + * DESCRIPTION: Read/Write osg::Scissor in binary format to disk. + * + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. + * + * HISTORY: Created 21.3.2003 + * + * Copyright 2003 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "Scissor.h" +#include "Object.h" + +using namespace ive; + +void Scissor::write(DataOutputStream* out){ + // Write Scissor's identification. + out->writeInt(IVESCISSOR); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("Scissor::write(): Could not cast this osg::Scissor to an osg::Object."); + // Write Scissor's properties. + + out->writeInt(x()); + out->writeInt(y()); + out->writeInt(width()); + out->writeInt(height()); +} + +void Scissor::read(DataInputStream* in){ + // Peek on Scissor's identification. + int id = in->peekInt(); + if(id == IVESCISSOR){ + // Read Scissor's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("Scissor::read(): Could not cast this osg::Scissor to an osg::Object."); + + // Read Scissor's properties + x() = (GLenum)in->readInt(); + y() = (GLenum)in->readInt(); + width() = (GLenum)in->readInt(); + height() = (GLenum)in->readInt(); + + } + else{ + throw Exception("Scissor::read(): Expected Scissor identification."); + } +} diff --git a/src/osgPlugins/ive/Scissor.h b/src/osgPlugins/ive/Scissor.h new file mode 100644 index 000000000..51784a84b --- /dev/null +++ b/src/osgPlugins/ive/Scissor.h @@ -0,0 +1,15 @@ +#ifndef IVE_SCISSOR +#define IVE_SCISSOR 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class Scissor : public osg::Scissor, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/Viewport.cpp b/src/osgPlugins/ive/Viewport.cpp new file mode 100644 index 000000000..475744ade --- /dev/null +++ b/src/osgPlugins/ive/Viewport.cpp @@ -0,0 +1,63 @@ +/********************************************************************** + * + * FILE: Viewport.cpp + * + * DESCRIPTION: Read/Write osg::Viewport in binary format to disk. + * + * CREATED BY: Auto generated by iveGenerated + * and later modified by Rune Schmidt Jensen. + * + * HISTORY: Created 21.3.2003 + * + * Copyright 2003 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "Viewport.h" +#include "Object.h" + +using namespace ive; + +void Viewport::write(DataOutputStream* out){ + // Write Viewport's identification. + out->writeInt(IVEVIEWPORT); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("Viewport::write(): Could not cast this osg::Viewport to an osg::Object."); + // Write Viewport's properties. + + out->writeInt(x()); + out->writeInt(y()); + out->writeInt(width()); + out->writeInt(height()); +} + +void Viewport::read(DataInputStream* in){ + // Peek on Viewport's identification. + int id = in->peekInt(); + if(id == IVEVIEWPORT){ + // Read Viewport's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if(obj){ + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("Viewport::read(): Could not cast this osg::Viewport to an osg::Object."); + + // Read Viewport's properties + x() = (GLenum)in->readInt(); + y() = (GLenum)in->readInt(); + width() = (GLenum)in->readInt(); + height() = (GLenum)in->readInt(); + + } + else{ + throw Exception("Viewport::read(): Expected Viewport identification."); + } +} diff --git a/src/osgPlugins/ive/Viewport.h b/src/osgPlugins/ive/Viewport.h new file mode 100644 index 000000000..bd8d9c506 --- /dev/null +++ b/src/osgPlugins/ive/Viewport.h @@ -0,0 +1,15 @@ +#ifndef IVE_VIEWPORT +#define IVE_VIEWPORT 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class Viewport : public osg::Viewport, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/osg/GNUmakefile b/src/osgPlugins/osg/GNUmakefile index f1227df9c..bea7cfc5d 100644 --- a/src/osgPlugins/osg/GNUmakefile +++ b/src/osgPlugins/osg/GNUmakefile @@ -47,6 +47,7 @@ CXXFILES =\ Projection.cpp\ ProxyNode.cpp\ ReaderWriterOSG.cpp\ + Scissor.cpp\ Sequence.cpp\ ShadeModel.cpp\ Shader.cpp\ diff --git a/src/osgPlugins/osg/Scissor.cpp b/src/osgPlugins/osg/Scissor.cpp new file mode 100644 index 000000000..8da3b46e7 --- /dev/null +++ b/src/osgPlugins/osg/Scissor.cpp @@ -0,0 +1,71 @@ +#include "osg/Scissor" + +#include "osgDB/Registry" +#include "osgDB/Input" +#include "osgDB/Output" + +using namespace osg; +using namespace osgDB; + +// forward declare functions to use later. +bool Scissor_readLocalData(Object& obj, Input& fr); +bool Scissor_writeLocalData(const Object& obj, Output& fw); + +// register the read and write functions with the osgDB::Registry. +RegisterDotOsgWrapperProxy g_ScissorProxy +( + new osg::Scissor, + "Scissor", + "Object StateAttribute Scissor", + &Scissor_readLocalData, + &Scissor_writeLocalData +); + + +bool Scissor_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; + } + + Scissor& scissor = static_cast(obj); + scissor.setScissor( x, y, width, height ); + return iteratorAdvanced; +} + + +bool Scissor_writeLocalData(const Object& obj, Output& fw) +{ + const Scissor& scissor = static_cast(obj); + + fw.indent() << "x " << scissor.x() << std::endl; + fw.indent() << "y " << scissor.y() << std::endl; + fw.indent() << "width " << scissor.width() << std::endl; + fw.indent() << "height " << scissor.height() << std::endl; + + return true; +}