1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
15#define OSG_CLIPPLANE 1
19#include <osg/StateAttribute>
22 #define GL_CLIP_PLANE0 0x3000
23 #define GL_CLIP_PLANE1 0x3001
24 #define GL_CLIP_PLANE2 0x3002
25 #define GL_CLIP_PLANE3 0x3003
26 #define GL_CLIP_PLANE4 0x3004
27 #define GL_CLIP_PLANE5 0x3005
32/** Encapsulates OpenGL glClipPlane().
34class OSG_EXPORT ClipPlane : public StateAttribute
39 inline ClipPlane(unsigned int no):_clipPlaneNum(no) {}
40 inline ClipPlane(unsigned int no,const Vec4d& plane):_clipPlaneNum(no) { setClipPlane(plane); }
41 inline ClipPlane(unsigned int no,const Plane& plane):_clipPlaneNum(no) { setClipPlane(plane); }
42 inline ClipPlane(unsigned int no,double a,double b,double c,double d): _clipPlaneNum(no) { setClipPlane(a,b,c,d); }
44 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
45 ClipPlane(const ClipPlane& cp,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
46 StateAttribute(cp,copyop)
48 _clipPlane[0]=cp._clipPlane[0];
49 _clipPlane[1]=cp._clipPlane[1];
50 _clipPlane[2]=cp._clipPlane[2];
51 _clipPlane[3]=cp._clipPlane[3];
52 _clipPlaneNum=cp._clipPlaneNum;
55 virtual osg::Object* cloneType() const { return new ClipPlane( _clipPlaneNum ); }
56 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new ClipPlane(*this,copyop); }
57 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ClipPlane *>(obj)!=NULL; }
58 virtual const char* libraryName() const { return "osg"; }
59 virtual const char* className() const { return "ClipPlane"; }
60 virtual Type getType() const { return CLIPPLANE; }
62 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
63 virtual int compare(const StateAttribute& sa) const
65 // Check for equal types, then create the rhs variable
66 // used by the COMPARE_StateAttribute_Parameter macros below.
67 COMPARE_StateAttribute_Types(ClipPlane,sa)
69 // Compare each parameter in turn against the rhs.
70 COMPARE_StateAttribute_Parameter(_clipPlaneNum)
71 COMPARE_StateAttribute_Parameter(_clipPlane[0])
72 COMPARE_StateAttribute_Parameter(_clipPlane[1])
73 COMPARE_StateAttribute_Parameter(_clipPlane[2])
74 COMPARE_StateAttribute_Parameter(_clipPlane[3])
76 return 0; // Passed all the above comparison macros, so must be equal.
79 virtual unsigned int getMember() const { return _clipPlaneNum; }
81 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
83 usage.usesMode((GLMode)(GL_CLIP_PLANE0+_clipPlaneNum));
88 /** Set the clip plane with the given Plane. */
89 void setClipPlane(const Plane& plane)
91 _clipPlane.set(plane[0],plane[1],plane[2],plane[3]);
94 /** Defines the plane as [ a b c d ]. */
95 void setClipPlane(double a,double b,double c,double d)
97 _clipPlane.set(a,b,c,d);
100 /** Set the clip plane with the given Vec4. */
101 inline void setClipPlane(const Vec4d& plane) { _clipPlane = plane; }
103 /** Gets the clip plane as a Vec4d. */
104 const Vec4d& getClipPlane() const { return _clipPlane; }
107 /** Sets the clip plane number. */
108 void setClipPlaneNum(unsigned int num);
110 /** Gets the clip plane number. */
111 unsigned int getClipPlaneNum() const;
113 /** Applies the clip plane's state to the OpenGL state machine. */
114 virtual void apply(State& state) const;
118 virtual ~ClipPlane();
121 unsigned int _clipPlaneNum;