From ce51fb18412a9d8e6c1c2b87a5e19fcbfaf66e90 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 19 Sep 2002 10:30:15 +0000 Subject: [PATCH] Added PolygonStipple class from Mike, with mods from Robert to make data management local. --- VisualStudio/osg/osg.dsp | 8 ++++ include/osg/PolygonStipple | 52 ++++++++++++++++++++ include/osg/StateAttribute | 1 + src/Demos/osggeometry/osggeometry.cpp | 6 +++ src/osg/Makefile | 1 + src/osg/PolygonStipple.cpp | 69 +++++++++++++++++++++++++++ 6 files changed, 137 insertions(+) create mode 100644 include/osg/PolygonStipple create mode 100644 src/osg/PolygonStipple.cpp diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index def59ae8e..1c39f6aa7 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -317,6 +317,10 @@ SOURCE=..\..\src\osg\PolygonOffset.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osg\PolygonStipple.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osg\PositionAttitudeTransform.cpp # End Source File # Begin Source File @@ -681,6 +685,10 @@ SOURCE=..\..\Include\Osg\PolygonOffset # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\PolygonStipple +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\Polytope # End Source File # Begin Source File diff --git a/include/osg/PolygonStipple b/include/osg/PolygonStipple new file mode 100644 index 000000000..8f6622d11 --- /dev/null +++ b/include/osg/PolygonStipple @@ -0,0 +1,52 @@ +// -*- Mode: c++ -*- +//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield +//Distributed under the terms of the GNU Library General Public License (LGPL) +//as published by the Free Software Foundation. + +#ifndef OSG_POLYGONSTIPPLE +#define OSG_POLYGONSTIPPLE 1 + +#include + +namespace osg +{ + +class SG_EXPORT PolygonStipple : public StateAttribute +{ + public : + + PolygonStipple(); + + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ + PolygonStipple(const PolygonStipple& lw,const CopyOp& copyop=CopyOp::SHALLOW_COPY); + + META_StateAttribute(osg, PolygonStipple, POLYGONSTIPPLE); + + /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ + virtual int compare(const StateAttribute& sa) const; + + virtual void getAssociatedModes(std::vector& modes) const + { + modes.push_back(GL_POLYGON_STIPPLE); + } + + /** set the mask up, copying 128 bytes (32x32 bitfield) from mask into the local _mask.*/ + void setMask(const GLubyte* mask); + + /** get a pointer to the mask.*/ + inline const GLubyte* getMask() const {return _mask;} + + + virtual void apply(State& state) const; + + protected : + + virtual ~PolygonStipple(); + + GLubyte _mask[128]; + +}; + +} + +#endif diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index 5604abad1..f16b2d4fd 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -131,6 +131,7 @@ class SG_EXPORT StateAttribute : public Object POINT, LINEWIDTH, LINESTIPPLE, + POLYGONSTIPPLE, SHADEMODEL, TEXENV, TEXGEN, diff --git a/src/Demos/osggeometry/osggeometry.cpp b/src/Demos/osggeometry/osggeometry.cpp index 01e2b79c4..eea8c0da4 100644 --- a/src/Demos/osggeometry/osggeometry.cpp +++ b/src/Demos/osggeometry/osggeometry.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -489,6 +490,11 @@ osg::Node* createScene() polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::TRIANGLE_STRIP,6,6)); polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::TRIANGLE_FAN,12,5)); + // polygon stipple + osg::StateSet* stateSet = new osg::StateSet(); + polyGeom->setStateSet(stateSet); + osg::PolygonStipple* polygonStipple = new osg::PolygonStipple; + stateSet->setAttributeAndModes(polygonStipple,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); printTriangles("Triangles/Strip/Fan",*polyGeom); diff --git a/src/osg/Makefile b/src/osg/Makefile index 2504554d0..ce73a790e 100644 --- a/src/osg/Makefile +++ b/src/osg/Makefile @@ -59,6 +59,7 @@ CXXFILES =\ Point.cpp\ PolygonMode.cpp\ PolygonOffset.cpp\ + PolygonStipple.cpp\ PositionAttitudeTransform.cpp\ Primitive.cpp\ Projection.cpp\ diff --git a/src/osg/PolygonStipple.cpp b/src/osg/PolygonStipple.cpp new file mode 100644 index 000000000..1c7747a0b --- /dev/null +++ b/src/osg/PolygonStipple.cpp @@ -0,0 +1,69 @@ +#include +#include +#include + +#include + +using namespace osg; + +static GLubyte defaultPolygonStippleMask[] = +{ + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99, + 0x44, 0x44, 0x44, 0x44, 0x99, 0x99, 0x99, 0x99 +}; + +PolygonStipple::PolygonStipple() +{ + setMask(defaultPolygonStippleMask); +} + +PolygonStipple::PolygonStipple(const PolygonStipple& ps,const CopyOp& copyop): + StateAttribute(ps,copyop) +{ + setMask(ps.getMask()); +} + +PolygonStipple::~PolygonStipple() +{ +} + +int PolygonStipple::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(PolygonStipple,sa) + + // compare each parameter in turn against the rhs. + for(unsigned int i=0;i<128;++i) + { + if (_mask[i]rhs._mask[i]) return 1; + } + + return 0; // passed all the above comparison macro's, must be equal. +} + +void PolygonStipple::setMask(const GLubyte* givenMask) +{ + std::copy(givenMask,givenMask+128,_mask); +} + +void PolygonStipple::apply(State&) const +{ + glPolygonStipple(_mask); +} +