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 #include <osg/ClampColor>
14 #include <osg/GLExtensions>
15 #include <osg/State>
16 #include <osg/Notify>
17 #include <osg/buffered_value>
18 
19 
20 using namespace osg;
21 
ClampColor()22 ClampColor::ClampColor():
23    _clampVertexColor(GL_FIXED_ONLY),
24    _clampFragmentColor(GL_FIXED_ONLY),
25    _clampReadColor(GL_FIXED_ONLY)
26 {
27 }
28 
ClampColor(GLenum vertexMode,GLenum fragmentMode,GLenum readMode)29 ClampColor::ClampColor(GLenum vertexMode, GLenum fragmentMode, GLenum readMode):
30    _clampVertexColor(vertexMode),
31    _clampFragmentColor(fragmentMode),
32    _clampReadColor(readMode)
33 {
34 }
35 
~ClampColor()36 ClampColor::~ClampColor()
37 {
38 }
39 
apply(State & state) const40 void ClampColor::apply(State& state) const
41 {
42 
43    // get the contextID (user defined ID of 0 upwards) for the
44     // current OpenGL context.
45     const GLExtensions* extensions = state.get<GLExtensions>();
46     if (!extensions->isClampColorSupported)
47     {
48         OSG_WARN<<"Warning: ClampColor::apply(..) failed, ClampColor is not support by OpenGL driver."<<std::endl;
49         return;
50     }
51 
52 #if !defined(OSG_GL3_AVAILABLE)
53     extensions->glClampColor(GL_CLAMP_VERTEX_COLOR, _clampVertexColor);
54     extensions->glClampColor(GL_CLAMP_FRAGMENT_COLOR, _clampFragmentColor);
55 #endif
56     extensions->glClampColor(GL_CLAMP_READ_COLOR, _clampReadColor);
57 }
58