1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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/DepthRangeIndexed>
14 #include <osg/GLExtensions>
15 #include <osg/State>
16 
17 using namespace osg;
18 
DepthRangeIndexed()19 DepthRangeIndexed::DepthRangeIndexed():
20     _index(0),
21     _zNear(0.0),
22     _zFar(1.0)
23 {
24 }
25 
~DepthRangeIndexed()26 DepthRangeIndexed::~DepthRangeIndexed()
27 {
28 }
29 
setIndex(unsigned int index)30 void DepthRangeIndexed::setIndex(unsigned int index)
31 {
32     if (_index==index) return;
33 
34     ReassignToParents needToReassingToParentsWhenMemberValueChanges(this);
35 
36     _index = index;
37 }
38 
apply(State & state) const39 void DepthRangeIndexed::apply(State& state) const
40 {
41     const GLExtensions* extensions = state.get<GLExtensions>();
42     if (extensions->glDepthRangeIndexed)
43     {
44         extensions->glDepthRangeIndexed(static_cast<GLuint>(_index), static_cast<GLdouble>(_zNear), static_cast<GLdouble>(_zFar));
45     }
46     else if (extensions->glDepthRangeIndexedf)
47     {
48         extensions->glDepthRangeIndexedf(static_cast<GLuint>(_index), static_cast<GLfloat>(_zNear), static_cast<GLfloat>(_zFar));
49     }
50     else
51     {
52         OSG_WARN<<"Warning: DepthRangeIndexed::apply(..) failed, glDepthRangeIndexed is not support by OpenGL driver."<<std::endl;
53     }
54 }
55 
56