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

Revision 13041, 3.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#include <osg/BlendColor>
14#include <osg/GLExtensions>
15#include <osg/State>
16#include <osg/Notify>
17#include <osg/buffered_value>
18
19using namespace osg;
20
21
22BlendColor::BlendColor() :
23    _constantColor(1.0f,1.0f,1.0f,1.0f)
24{
25}
26
27BlendColor::BlendColor(const osg::Vec4& constantColor):
28    _constantColor(constantColor)
29{
30}
31
32BlendColor::~BlendColor()
33{
34}
35
36void BlendColor::apply(State& state) const
37{
38    // get the contextID (user defined ID of 0 upwards) for the
39    // current OpenGL context.
40    const unsigned int contextID = state.getContextID();
41
42    const Extensions* extensions = getExtensions(contextID,true);
43
44    if (!extensions->isBlendColorSupported())
45    {
46        OSG_WARN<<"Warning: BlendColor::apply(..) failed, BlendColor is not support by OpenGL driver."<<std::endl;
47        return;
48    }
49
50    extensions->glBlendColor(_constantColor[0], _constantColor[1],
51                             _constantColor[2], _constantColor[3]);
52}
53
54
55
56
57
58typedef buffered_value< ref_ptr<BlendColor::Extensions> > BufferedExtensions;
59static BufferedExtensions s_extensions;
60
61BlendColor::Extensions* BlendColor::getExtensions(unsigned int contextID,bool createIfNotInitalized)
62{
63    if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID);
64    return s_extensions[contextID].get();
65}
66
67void BlendColor::setExtensions(unsigned int contextID,Extensions* extensions)
68{
69    s_extensions[contextID] = extensions;
70}
71
72
73BlendColor::Extensions::Extensions(unsigned int contextID)
74{
75    setupGLExtensions(contextID);
76}
77
78BlendColor::Extensions::Extensions(const Extensions& rhs):
79    Referenced()
80{
81    _isBlendColorSupported = rhs._isBlendColorSupported;
82    _glBlendColor = rhs._glBlendColor;
83}
84
85void BlendColor::Extensions::lowestCommonDenominator(const Extensions& rhs)
86{
87    if (!rhs._isBlendColorSupported)  _isBlendColorSupported = false;
88    if (!rhs._glBlendColor)           _glBlendColor = 0;
89}
90
91void BlendColor::Extensions::setupGLExtensions(unsigned int contextID)
92{
93    _isBlendColorSupported = OSG_GLES2_FEATURES || OSG_GL3_FEATURES ||
94                             isGLExtensionSupported(contextID,"GL_EXT_blend_color") ||
95                             strncmp((const char*)glGetString(GL_VERSION),"1.2",3)>=0;
96
97    setGLExtensionFuncPtr(_glBlendColor, "glBlendColor", "glBlendColorEXT");
98}
99
100void BlendColor::Extensions::glBlendColor(GLclampf red , GLclampf green , GLclampf blue , GLclampf alpha) const
101{
102    if (_glBlendColor)
103    {
104        _glBlendColor(red, green, blue, alpha);
105    }
106    else
107    {
108        OSG_WARN<<"Error: glBlendColor not supported by OpenGL driver"<<std::endl;
109    }
110}
111
Note: See TracBrowser for help on using the browser.