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

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