Added PolygonStipple class from Mike, with mods from Robert to make data
management local.
This commit is contained in:
@@ -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
|
||||
|
||||
52
include/osg/PolygonStipple
Normal file
52
include/osg/PolygonStipple
Normal 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
|
||||
@@ -131,6 +131,7 @@ class SG_EXPORT StateAttribute : public Object
|
||||
POINT,
|
||||
LINEWIDTH,
|
||||
LINESTIPPLE,
|
||||
POLYGONSTIPPLE,
|
||||
SHADEMODEL,
|
||||
TEXENV,
|
||||
TEXGEN,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ CXXFILES =\
|
||||
Point.cpp\
|
||||
PolygonMode.cpp\
|
||||
PolygonOffset.cpp\
|
||||
PolygonStipple.cpp\
|
||||
PositionAttitudeTransform.cpp\
|
||||
Primitive.cpp\
|
||||
Projection.cpp\
|
||||
|
||||
69
src/osg/PolygonStipple.cpp
Normal file
69
src/osg/PolygonStipple.cpp
Normal 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user