Added PolygonStipple class from Mike, with mods from Robert to make data

management local.
This commit is contained in:
Robert Osfield
2002-09-19 10:30:15 +00:00
parent 68384e984b
commit ce51fb1841
6 changed files with 137 additions and 0 deletions

View File

@@ -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

View File

@@ -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 <osg/StateAttribute>
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<GLMode>& 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

View File

@@ -131,6 +131,7 @@ class SG_EXPORT StateAttribute : public Object
POINT,
LINEWIDTH,
LINESTIPPLE,
POLYGONSTIPPLE,
SHADEMODEL,
TEXENV,
TEXGEN,

View File

@@ -4,6 +4,7 @@
#include <osg/Vec3>
#include <osg/MatrixTransform>
#include <osg/Texture2D>
#include <osg/PolygonStipple>
#include <osgDB/ReadFile>
@@ -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);

View File

@@ -59,6 +59,7 @@ CXXFILES =\
Point.cpp\
PolygonMode.cpp\
PolygonOffset.cpp\
PolygonStipple.cpp\
PositionAttitudeTransform.cpp\
Primitive.cpp\
Projection.cpp\

View File

@@ -0,0 +1,69 @@
#include <osg/GL>
#include <osg/PolygonStipple>
#include <osg/Notify>
#include <algorithm>
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;
else 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);
}