1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSG_CULLFACE
15#define OSG_CULLFACE 1
16
17#include <osg/GL>
18#include <osg/StateAttribute>
19
20namespace osg {
21
22/** Class to globally enable/disable OpenGL's polygon culling mode.
23 */
24class OSG_EXPORT CullFace : public StateAttribute
25{
26    public :
27
28        enum Mode {
29            FRONT = GL_FRONT,
30            BACK = GL_BACK,
31            FRONT_AND_BACK = GL_FRONT_AND_BACK
32        };
33
34        CullFace(Mode mode=BACK):
35            _mode(mode) {}
36
37        /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
38        CullFace(const CullFace& cf,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
39            StateAttribute(cf,copyop),
40            _mode(cf._mode) {}
41
42        META_StateAttribute(osg, CullFace, CULLFACE);
43
44        /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
45        virtual int compare(const StateAttribute& sa) const
46        {
47            // check the types are equal and then create the rhs variable
48            // used by the COMPARE_StateAttribute_Parameter macros below.
49            COMPARE_StateAttribute_Types(CullFace,sa)
50
51            // compare each parameter in turn against the rhs.
52            COMPARE_StateAttribute_Parameter(_mode)
53
54            return 0; // passed all the above comparison macros, must be equal.
55        }
56
57        virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
58        {
59            usage.usesMode(GL_CULL_FACE);
60            return true;
61        }
62
63        inline void setMode(Mode mode) { _mode = mode; }
64
65        inline Mode getMode() const { return _mode; }
66
67        virtual void apply(State& state) const;
68
69    protected:
70
71        virtual ~CullFace();
72
73        Mode _mode;
74
75};
76
77}
78
79#endif
80