openscenegraph
ClampColor
Go to the documentation of this file.
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 virtual void apply(State& state) const;
84
85 protected :
86
87 virtual ~ClampColor();
88
89 GLenum _clampVertexColor;
90 GLenum _clampFragmentColor;
91 GLenum _clampReadColor;
92
93};
94
95}
96
97#endif