root/OpenSceneGraph/trunk/include/osg/Point @ 13041

Revision 13041, 5.9 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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_POINT
15#define OSG_POINT 1
16
17#include <osg/Vec3>
18#include <osg/StateAttribute>
19
20#ifndef GL_POINT_SMOOTH
21    #define GL_POINT_SMOOTH     0x0B10
22#endif
23
24#ifndef GL_POINT_SMOOTH_HINT
25    #define GL_POINT_SMOOTH_HINT 0x0C51
26#endif
27
28namespace osg {
29
30/** Point - encapsulates the OpenGL point smoothing and size state.*/
31class OSG_EXPORT Point : public StateAttribute
32{
33    public :
34
35        Point();
36
37        Point(float size);
38
39        /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
40        Point(const Point& point,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
41            StateAttribute(point,copyop),
42            _size(point._size),
43            _fadeThresholdSize(point._fadeThresholdSize),
44            _distanceAttenuation(point._distanceAttenuation),
45            _minSize(point._minSize),
46            _maxSize(point._maxSize) {}
47
48        META_StateAttribute(osg, Point, POINT);
49
50        /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
51        virtual int compare(const StateAttribute& sa) const
52        {
53            // check the types are equal and then create the rhs variable
54            // used by the COMPARE_StateAttribute_Parameter macros below.
55            COMPARE_StateAttribute_Types(Point,sa)
56
57            // compare each parameter in turn against the rhs.
58            COMPARE_StateAttribute_Parameter(_size)
59            COMPARE_StateAttribute_Parameter(_fadeThresholdSize)
60            COMPARE_StateAttribute_Parameter(_distanceAttenuation)
61            COMPARE_StateAttribute_Parameter(_minSize)
62            COMPARE_StateAttribute_Parameter(_maxSize)
63
64            return 0; // passed all the above comparison macros, must be equal.
65        }
66
67        virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
68        {
69            usage.usesMode(GL_POINT_SMOOTH);
70            return true;
71        }
72
73        void setSize(float size);
74        inline float getSize() const { return _size; }
75
76        void setFadeThresholdSize(float fadeThresholdSize);
77        inline float getFadeThresholdSize() const { return _fadeThresholdSize; }
78
79        void setDistanceAttenuation(const Vec3& distanceAttenuation);
80        inline const Vec3& getDistanceAttenuation() const { return _distanceAttenuation; }
81
82        void setMinSize(float minSize);
83        inline float getMinSize() const {return _minSize;}
84
85        void setMaxSize(float maxSize);
86        inline float getMaxSize() const {return _maxSize;}
87
88        virtual void apply(State& state) const;
89
90        /** Encapsulates queries of extension availability, obtains extension
91          * function pointers, and provides convenience wrappers for
92          * calling extension functions. */
93        class OSG_EXPORT Extensions : public osg::Referenced
94        {
95            public:
96                Extensions(unsigned int contextID);
97
98                Extensions(const Extensions& rhs);
99
100                void lowestCommonDenominator(const Extensions& rhs);
101
102                void setupGLExtensions(unsigned int contextID);
103
104                void setPointParametersSupported(bool flag) { _isPointParametersSupported=flag; }
105                bool isPointParametersSupported() const { return _isPointParametersSupported; }
106
107                void setPointSpriteCoordOriginSupported(bool flag) { _isPointSpriteCoordOriginSupported=flag; }
108                bool isPointSpriteCoordOriginSupported() const { return _isPointSpriteCoordOriginSupported; }
109
110                void glPointParameteri(GLenum pname, GLint param) const;
111                void glPointParameterf(GLenum pname, GLfloat param) const;
112                void glPointParameterfv(GLenum pname, const GLfloat *params) const;
113
114            protected:
115
116                ~Extensions() {}
117
118                bool _isPointParametersSupported;
119                bool _isPointSpriteCoordOriginSupported;
120
121                typedef void (GL_APIENTRY * GLPointParameteriProc) (GLenum pname, GLint param);
122                typedef void (GL_APIENTRY * GLPointParameterfProc) (GLenum pname, GLfloat param);
123                typedef void (GL_APIENTRY * GLPointParameterfvProc) (GLenum pname, const GLfloat *params);
124
125                GLPointParameteriProc   _glPointParameteri;
126                GLPointParameterfProc   _glPointParameterf;
127                GLPointParameterfvProc  _glPointParameterfv;
128
129        };
130
131        /** Returns the Extensions object for the given context.
132          * If createIfNotInitalized is true and the Extensions object doesn't
133          * exist, getExtensions() creates it on the given context.
134          * Returns NULL if createIfNotInitalized is false and the Extensions
135          * object doesn't exist. */
136        static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
137
138        /** setExtensions() allows users to override the extensions across graphics contexts.
139          * Typically used when you have different extensions supported across graphics pipes,
140          * but need to ensure that they all use the same low common denominator extensions. */
141        static void setExtensions(unsigned int contextID,Extensions* extensions);
142
143    protected :
144
145        virtual ~Point();
146
147        float       _size;
148        float       _fadeThresholdSize;
149        Vec3        _distanceAttenuation;
150        float        _minSize;
151        float        _maxSize;
152
153};
154
155}
156
157#endif
Note: See TracBrowser for help on using the browser.