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

Revision 13041, 5.2 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_CLAMPCOLOR
15#define OSG_CLAMPCOLOR 1
16
17#include <osg/StateAttribute>
18
19#ifndef GL_ARB_color_buffer_float
20#define GL_RGBA_FLOAT_MODE_ARB                  0x8820
21#define GL_CLAMP_VERTEX_COLOR_ARB               0x891A
22#define GL_CLAMP_FRAGMENT_COLOR_ARB             0x891B
23#define GL_CLAMP_READ_COLOR_ARB                 0x891C
24#define GL_FIXED_ONLY_ARB                       0x891D
25#endif
26
27#ifndef GL_FIXED_ONLY
28#define GL_FIXED_ONLY                           GL_FIXED_ONLY_ARB
29#define GL_CLAMP_VERTEX_COLOR                   GL_CLAMP_VERTEX_COLOR_ARB
30#define GL_CLAMP_READ_COLOR                     GL_CLAMP_READ_COLOR_ARB
31#define GL_CLAMP_FRAGMENT_COLOR                 GL_CLAMP_FRAGMENT_COLOR_ARB
32#endif
33
34#if defined(OSG_GL3_AVAILABLE)
35    #define GL_CLAMP_VERTEX_COLOR             0x891A
36    #define GL_CLAMP_FRAGMENT_COLOR           0x891B
37#endif
38
39namespace osg {
40
41/** Encapsulates OpenGL ClampColor state. */
42class OSG_EXPORT ClampColor : public StateAttribute
43{
44    public :
45
46        ClampColor();
47
48        ClampColor(GLenum vertexMode, GLenum fragmentMode, GLenum readMode);
49
50        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
51        ClampColor(const ClampColor& rhs,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
52            StateAttribute(rhs,copyop),
53            _clampVertexColor(rhs._clampVertexColor),
54            _clampFragmentColor(rhs._clampFragmentColor),
55            _clampReadColor(rhs._clampReadColor) {}
56
57        META_StateAttribute(osg, ClampColor,CLAMPCOLOR);
58
59        /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
60        virtual int compare(const StateAttribute& sa) const
61        {
62            // Check for equal types, then create the rhs variable
63            // used by the COMPARE_StateAttribute_Parameter macros below.
64            COMPARE_StateAttribute_Types(ClampColor,sa)
65
66            // Compare each parameter in turn against the rhs.
67            COMPARE_StateAttribute_Parameter(_clampVertexColor)
68            COMPARE_StateAttribute_Parameter(_clampFragmentColor)
69            COMPARE_StateAttribute_Parameter(_clampReadColor)
70
71            return 0; // Passed all the above comparison macros, so must be equal.
72        }
73
74        void setClampVertexColor(GLenum mode) { _clampVertexColor = mode; }
75        GLenum getClampVertexColor() const { return _clampVertexColor; }
76
77        void setClampFragmentColor(GLenum mode) { _clampFragmentColor = mode; }
78        GLenum getClampFragmentColor() const { return _clampFragmentColor; }
79
80        void setClampReadColor(GLenum mode) { _clampReadColor = mode; }
81        GLenum getClampReadColor() const { return _clampReadColor; }
82
83
84        virtual void apply(State& state) const;
85        /** Encapsulates queries of extension availability, obtains extension
86          * function pointers, and provides convenience wrappers for
87          * calling extension functions. */
88        class OSG_EXPORT Extensions : public osg::Referenced
89        {
90            public:
91                Extensions(unsigned int contextID);
92
93                Extensions(const Extensions& rhs);
94
95                void lowestCommonDenominator(const Extensions& rhs);
96
97                void setupGLExtensions(unsigned int contextID);
98
99                void setClampColorSupported(bool flag) { _isClampColorSupported=flag; }
100                bool isClampColorSupported() const { return _isClampColorSupported; }
101
102                void glClampColor(GLenum target, GLenum mode) const;
103
104            protected:
105
106                ~Extensions() {}
107
108                typedef void (GL_APIENTRY * GLClampColorProc) (GLenum target, GLenum mode);
109                bool                _isClampColorSupported;
110                GLClampColorProc    _glClampColor;
111
112        };
113
114        /** Returns the Extensions object for the given context.
115          * If createIfNotInitalized is true and the Extensions object doesn't
116          * exist, getExtensions() creates it on the given context.
117          * Returns NULL if createIfNotInitalized is false and the Extensions
118          * object doesn't exist. */
119        static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
120
121        /** setExtensions() allows users to override the extensions across graphics contexts.
122          * Typically used when you have different extensions supported across graphics pipes,
123          * but need to ensure that they all use the same low common denominator extensions. */
124        static void setExtensions(unsigned int contextID,Extensions* extensions);
125
126
127    protected :
128
129        virtual ~ClampColor();
130
131        GLenum _clampVertexColor;
132        GLenum _clampFragmentColor;
133        GLenum _clampReadColor;
134
135};
136
137}
138
139#endif
Note: See TracBrowser for help on using the browser.