root/OpenSceneGraph/trunk/src/osg/ClampColor.cpp @ 13041

Revision 13041, 3.4 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#include <osg/ClampColor>
14#include <osg/GLExtensions>
15#include <osg/State>
16#include <osg/Notify>
17#include <osg/buffered_value>
18
19
20using namespace osg;
21
22ClampColor::ClampColor():
23   _clampVertexColor(GL_FIXED_ONLY),
24   _clampFragmentColor(GL_FIXED_ONLY),
25   _clampReadColor(GL_FIXED_ONLY)
26{
27}
28
29ClampColor::ClampColor(GLenum vertexMode, GLenum fragmentMode, GLenum readMode):
30   _clampVertexColor(vertexMode),
31   _clampFragmentColor(fragmentMode),
32   _clampReadColor(readMode)
33{
34}
35
36ClampColor::~ClampColor()
37{
38}
39
40void 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 unsigned int contextID = state.getContextID();
46
47    const Extensions* extensions = getExtensions(contextID,true);
48
49    if (!extensions->isClampColorSupported())
50    {
51        OSG_WARN<<"Warning: ClampColor::apply(..) failed, ClampColor is not support by OpenGL driver."<<std::endl;
52        return;
53    }
54
55    extensions->glClampColor(GL_CLAMP_VERTEX_COLOR, _clampVertexColor);
56    extensions->glClampColor(GL_CLAMP_FRAGMENT_COLOR, _clampFragmentColor);
57    extensions->glClampColor(GL_CLAMP_READ_COLOR, _clampReadColor);
58}
59
60
61typedef buffered_value< ref_ptr<ClampColor::Extensions> > BufferedExtensions;
62static BufferedExtensions s_extensions;
63
64ClampColor::Extensions* ClampColor::getExtensions(unsigned int contextID,bool createIfNotInitalized)
65{
66    if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID);
67    return s_extensions[contextID].get();
68}
69
70void ClampColor::setExtensions(unsigned int contextID,Extensions* extensions)
71{
72    s_extensions[contextID] = extensions;
73}
74
75
76ClampColor::Extensions::Extensions(unsigned int contextID)
77{
78    setupGLExtensions(contextID);
79}
80
81ClampColor::Extensions::Extensions(const Extensions& rhs):
82    Referenced()
83{
84    _isClampColorSupported = rhs._isClampColorSupported;
85    _glClampColor = rhs._glClampColor;
86}
87
88void ClampColor::Extensions::lowestCommonDenominator(const Extensions& rhs)
89{
90    if (!rhs._isClampColorSupported) _isClampColorSupported = false;
91    if (!rhs._glClampColor)          _glClampColor = 0;
92}
93
94void ClampColor::Extensions::setupGLExtensions(unsigned int contextID)
95{
96    _isClampColorSupported = OSG_GL3_FEATURES ||
97                             isGLExtensionSupported(contextID,"GL_ARB_color_buffer_float") ||
98                             strncmp((const char*)glGetString(GL_VERSION),"2.0",3)>=0;
99
100    setGLExtensionFuncPtr(_glClampColor, "glClampColor", "glClampColorARB");
101}
102
103void ClampColor::Extensions::glClampColor(GLenum target, GLenum mode) const
104{
105    if (_glClampColor)
106    {
107        _glClampColor(target,mode);
108    }
109    else
110    {
111        OSG_WARN<<"Error: glClampColor not supported by OpenGL driver"<<std::endl;
112    }
113}
114
Note: See TracBrowser for help on using the browser.