From Alberto Farre, added support for GL_EXT_blend_color, GL_ARB_multisample,
GL_NV_multisample_filter_hint extension in the form of osg::BlendColor and osg::Multisample state attribute classes.
This commit is contained in:
@@ -46,7 +46,7 @@ MAKEDEPEND = ignore
|
||||
VERSION_MAJOR = 0
|
||||
VERSION_MINOR = 9
|
||||
VERSION_RELEASE = 6
|
||||
VERSION_REVISION ?= 1
|
||||
VERSION_REVISION ?= 0
|
||||
ifneq (,$(OSG_VERSION_REVISION))
|
||||
VERSION_REVISION = $(OSG_VERSION_REVISION)
|
||||
endif
|
||||
|
||||
@@ -285,6 +285,10 @@ SOURCE=..\..\src\osg\MatrixTransform.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\Multisample.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\Node.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -433,6 +437,10 @@ SOURCE=..\..\src\osg\Transform.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\BlendColor.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\BlendFunc.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -685,11 +693,7 @@ SOURCE=..\..\include\osg\mem_ptr
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osg\MemoryAdapter
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\MemoryManager
|
||||
SOURCE=..\..\include\osg\Multisample
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -865,6 +869,10 @@ SOURCE=..\..\Include\Osg\TriangleFunctor
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\BlendColor
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\BlendFunc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
121
include/osg/BlendColor
Normal file
121
include/osg/BlendColor
Normal file
@@ -0,0 +1,121 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_BLENDCOLOR
|
||||
#define OSG_BLENDCOLOR 1
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/buffered_value>
|
||||
#include <osg/Vec4>
|
||||
|
||||
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** BlendColor - encapsulates the OpenGL blend/transparency state.*/
|
||||
class SG_EXPORT BlendColor : public StateAttribute
|
||||
{
|
||||
public :
|
||||
|
||||
BlendColor();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
BlendColor(const BlendColor& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
StateAttribute(trans,copyop),
|
||||
_constantColor(trans._constantColor) {}
|
||||
|
||||
META_StateAttribute(osg, BlendColor,BLENDCOLOR);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
{
|
||||
// check the types are equal and then create the rhs variable
|
||||
// used by the COMPARE_StateAttribute_Paramter macro's below.
|
||||
COMPARE_StateAttribute_Types(BlendColor,sa)
|
||||
|
||||
// compare each paramter in turn against the rhs.
|
||||
COMPARE_StateAttribute_Parameter(_constantColor)
|
||||
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
modes.push_back(GL_BLEND);
|
||||
}
|
||||
|
||||
void setConstantColor(osg::Vec4& color) { _constantColor = color; }
|
||||
inline osg::Vec4 getConstantColor() const { return _constantColor; }
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
|
||||
|
||||
|
||||
/** Extensions class which encapsulates the querring of extensions and
|
||||
* associated function pointers, and provide convinience wrappers to
|
||||
* check for the extensions or use the associated functions.*/
|
||||
class SG_EXPORT Extensions : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
Extensions();
|
||||
|
||||
Extensions(const Extensions& rhs);
|
||||
|
||||
void lowestCommonDenominator(const Extensions& rhs);
|
||||
|
||||
void setupGLExtenions();
|
||||
|
||||
void setBlendColorSupported(bool flag) { _isBlendColorSupported=flag; }
|
||||
bool isBlendColorSupported() const { return _isBlendColorSupported; }
|
||||
|
||||
void setBlendColorProc(void* ptr) { _glBlendColor = ptr; }
|
||||
void glBlendColor(GLclampf red , GLclampf green , GLclampf blue , GLclampf alpha) const;
|
||||
|
||||
protected:
|
||||
|
||||
~Extensions() {}
|
||||
|
||||
bool _isBlendColorSupported;
|
||||
|
||||
void* _glBlendColor;
|
||||
|
||||
};
|
||||
|
||||
/** Function to call to get the extension of a specified context.
|
||||
* If the Exentsion object for that context has not yet been created then
|
||||
* and the 'createIfNotInitalized' flag been set to false then returns NULL.
|
||||
* If 'createIfNotInitalized' is true then the Extensions object is
|
||||
* automatically created. However, in this case the extension object
|
||||
* only be created with the graphics context associated with ContextID..*/
|
||||
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
|
||||
|
||||
/** setExtensions allows users to override the extensions across graphics contexts.
|
||||
* typically used when you have different extensions supported across graphics pipes
|
||||
* but need to ensure that they all use the same low common denominator extensions.*/
|
||||
static void setExtensions(unsigned int contextID,Extensions* extensions);
|
||||
|
||||
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~BlendColor();
|
||||
|
||||
osg::Vec4 _constantColor;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -16,6 +16,17 @@
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
|
||||
|
||||
#ifndef GL_VERSION_1_2
|
||||
#define GL_CONSTANT_COLOR 0x8001
|
||||
#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
|
||||
#define GL_CONSTANT_ALPHA 0x8003
|
||||
#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
|
||||
#define GL_BLEND_COLOR 0x8005
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** BlendFunc - encapsulates the OpenGL blend/transparency state.*/
|
||||
@@ -55,17 +66,19 @@ class SG_EXPORT BlendFunc : public StateAttribute
|
||||
}
|
||||
|
||||
enum BlendFuncMode {
|
||||
DST_ALPHA = GL_DST_ALPHA,
|
||||
DST_COLOR = GL_DST_COLOR,
|
||||
ONE = GL_ONE,
|
||||
ONE_MINUS_DST_ALPHA = GL_ONE_MINUS_DST_ALPHA,
|
||||
ONE_MINUS_DST_COLOR = GL_ONE_MINUS_DST_COLOR,
|
||||
ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA,
|
||||
ONE_MINUS_SRC_COLOR = GL_ONE_MINUS_SRC_COLOR,
|
||||
SRC_ALPHA = GL_SRC_ALPHA,
|
||||
SRC_ALPHA_SATURATE = GL_SRC_ALPHA_SATURATE,
|
||||
SRC_COLOR = GL_SRC_COLOR,
|
||||
ZERO = GL_ZERO
|
||||
DST_ALPHA = GL_DST_ALPHA,
|
||||
DST_COLOR = GL_DST_COLOR,
|
||||
ONE = GL_ONE,
|
||||
ONE_MINUS_DST_ALPHA = GL_ONE_MINUS_DST_ALPHA,
|
||||
ONE_MINUS_DST_COLOR = GL_ONE_MINUS_DST_COLOR,
|
||||
ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA,
|
||||
ONE_MINUS_SRC_COLOR = GL_ONE_MINUS_SRC_COLOR,
|
||||
SRC_ALPHA = GL_SRC_ALPHA,
|
||||
SRC_ALPHA_SATURATE = GL_SRC_ALPHA_SATURATE,
|
||||
SRC_COLOR = GL_SRC_COLOR,
|
||||
CONSTANT_ALPHA = GL_CONSTANT_ALPHA,
|
||||
ONE_MINUS_CONSTANT_ALPHA = GL_ONE_MINUS_CONSTANT_ALPHA,
|
||||
ZERO = GL_ZERO
|
||||
};
|
||||
|
||||
inline void setFunction( GLenum source, GLenum destination )
|
||||
|
||||
156
include/osg/Multisample
Normal file
156
include/osg/Multisample
Normal file
@@ -0,0 +1,156 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_MULTISAMPLE
|
||||
#define OSG_MULTISAMPLE 1
|
||||
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/buffered_value>
|
||||
|
||||
|
||||
#ifndef GL_ARB_multisample
|
||||
#define GL_MULTISAMPLE_ARB 0x809D
|
||||
#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E
|
||||
#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F
|
||||
#define GL_SAMPLE_COVERAGE_ARB 0x80A0
|
||||
#define GL_SAMPLE_BUFFERS_ARB 0x80A8
|
||||
#define GL_SAMPLES_ARB 0x80A9
|
||||
#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA
|
||||
#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB
|
||||
#define GL_MULTISAMPLE_BIT_ARB 0x20000000
|
||||
#endif
|
||||
#ifndef GL_NV_multisample_filter_hint
|
||||
#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534
|
||||
#endif
|
||||
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Multisample - encapsulates the OpenGL Multisample state.*/
|
||||
class SG_EXPORT Multisample : public StateAttribute
|
||||
{
|
||||
public :
|
||||
|
||||
enum Mode
|
||||
{
|
||||
FASTEST = GL_FASTEST,
|
||||
NICEST = GL_NICEST,
|
||||
DONT_CARE = GL_DONT_CARE
|
||||
};
|
||||
|
||||
Multisample();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Multisample(const Multisample& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
StateAttribute(trans,copyop),
|
||||
_coverage(trans._coverage),
|
||||
_invert(trans._invert),
|
||||
_mode(trans._mode) {}
|
||||
|
||||
META_StateAttribute(osg, Multisample,MULTISAMPLE);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
{
|
||||
// check the types are equal and then create the rhs variable
|
||||
// used by the COMPARE_StateAttribute_Paramter macro's below.
|
||||
COMPARE_StateAttribute_Types(Multisample,sa)
|
||||
|
||||
// compare each paramter in turn against the rhs.
|
||||
COMPARE_StateAttribute_Parameter(_coverage)
|
||||
COMPARE_StateAttribute_Parameter(_invert)
|
||||
COMPARE_StateAttribute_Parameter(_mode)
|
||||
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const {}
|
||||
|
||||
void setSampleCoverage(float coverage, bool invert)
|
||||
{
|
||||
_coverage = coverage;
|
||||
_invert = invert;
|
||||
}
|
||||
inline float getCoverage() const { return _coverage; }
|
||||
inline bool getInvert() const { return _invert; }
|
||||
|
||||
inline void setHint(Mode mode) { _mode = mode; }
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
|
||||
/** Extensions class which encapsulates the querring of extensions and
|
||||
* associated function pointers, and provide convinience wrappers to
|
||||
* check for the extensions or use the associated functions.*/
|
||||
class SG_EXPORT Extensions : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
Extensions();
|
||||
|
||||
Extensions(const Extensions& rhs);
|
||||
|
||||
void lowestCommonDenominator(const Extensions& rhs);
|
||||
|
||||
void setupGLExtenions();
|
||||
|
||||
void setMultisampleSupported(bool flag) { _isMultisampleSupported=flag; }
|
||||
void setMultisampleFilterHintSupported(bool flag) { _isMultisampleFilterHintSupported=flag; }
|
||||
bool isMultisampleSupported() const { return _isMultisampleSupported; }
|
||||
bool isMultisampleFilterHintSupported() const { return _isMultisampleFilterHintSupported; }
|
||||
|
||||
void setSampleCoverageProc(void* ptr) { _glSampleCoverage = ptr; }
|
||||
void glSampleCoverage(GLclampf value, GLboolean invert) const;
|
||||
|
||||
protected:
|
||||
|
||||
~Extensions() {}
|
||||
|
||||
bool _isMultisampleSupported;
|
||||
bool _isMultisampleFilterHintSupported;
|
||||
void* _glSampleCoverage;
|
||||
|
||||
};
|
||||
|
||||
/** Function to call to get the extension of a specified context.
|
||||
* If the Exentsion object for that context has not yet been created then
|
||||
* and the 'createIfNotInitalized' flag been set to false then returns NULL.
|
||||
* If 'createIfNotInitalized' is true then the Extensions object is
|
||||
* automatically created. However, in this case the extension object
|
||||
* only be created with the graphics context associated with ContextID..*/
|
||||
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
|
||||
|
||||
/** setExtensions allows users to override the extensions across graphics contexts.
|
||||
* typically used when you have different extensions supported across graphics pipes
|
||||
* but need to ensure that they all use the same low common denominator extensions.*/
|
||||
static void setExtensions(unsigned int contextID,Extensions* extensions);
|
||||
|
||||
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~Multisample();
|
||||
|
||||
float _coverage;
|
||||
bool _invert;
|
||||
Mode _mode;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ class SG_EXPORT StateAttribute : public Object
|
||||
/** Override is used to specified the override behavior of StateAttributes
|
||||
* from from parent to children.
|
||||
* See enum Value description for more details.*/
|
||||
typedef unsigned int OverrideValue;
|
||||
typedef unsigned int OverrideValue;
|
||||
|
||||
/** list values which can be used in to set either GLModeValues
|
||||
* or OverrideValues. When using in conjunction with GLModeValues
|
||||
@@ -151,6 +151,9 @@ class SG_EXPORT StateAttribute : public Object
|
||||
COLORMASK,
|
||||
DEPTH,
|
||||
VIEWPORT,
|
||||
BLENDCOLOR,
|
||||
MULTISAMPLE,
|
||||
|
||||
|
||||
CLIPPLANE,
|
||||
CLIPPLANE_0 =CLIPPLANE,
|
||||
|
||||
105
src/osg/BlendColor.cpp
Normal file
105
src/osg/BlendColor.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osg/BlendColor>
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/State>
|
||||
#include <osg/Notify>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
|
||||
BlendColor::BlendColor() :
|
||||
_constantColor(0.0f,0.0f,0.0f,0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
BlendColor::~BlendColor()
|
||||
{
|
||||
}
|
||||
|
||||
void BlendColor::apply(State& state) const
|
||||
{
|
||||
// get the contextID (user defined ID of 0 upwards) for the
|
||||
// current OpenGL context.
|
||||
const unsigned int contextID = state.getContextID();
|
||||
|
||||
const Extensions* extensions = getExtensions(contextID,true);
|
||||
|
||||
if (!extensions->isBlendColorSupported())
|
||||
{
|
||||
notify(WARN)<<"Warning: BlendColor::apply(..) failed, BlendColor is not support by OpenGL driver."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
extensions->glBlendColor(_constantColor[0], _constantColor[1],
|
||||
_constantColor[2], _constantColor[3]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef buffered_value< ref_ptr<BlendColor::Extensions> > BufferedExtensions;
|
||||
static BufferedExtensions s_extensions;
|
||||
|
||||
BlendColor::Extensions* BlendColor::getExtensions(unsigned int contextID,bool createIfNotInitalized)
|
||||
{
|
||||
if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions;
|
||||
return s_extensions[contextID].get();
|
||||
}
|
||||
|
||||
void BlendColor::setExtensions(unsigned int contextID,Extensions* extensions)
|
||||
{
|
||||
s_extensions[contextID] = extensions;
|
||||
}
|
||||
|
||||
|
||||
BlendColor::Extensions::Extensions()
|
||||
{
|
||||
setupGLExtenions();
|
||||
}
|
||||
|
||||
BlendColor::Extensions::Extensions(const Extensions& rhs):
|
||||
Referenced()
|
||||
{
|
||||
_isBlendColorSupported = rhs._isBlendColorSupported;
|
||||
}
|
||||
|
||||
void BlendColor::Extensions::lowestCommonDenominator(const Extensions& rhs)
|
||||
{
|
||||
if (!rhs._isBlendColorSupported) _isBlendColorSupported = false;
|
||||
if (!rhs._glBlendColor) _glBlendColor = 0;
|
||||
}
|
||||
|
||||
void BlendColor::Extensions::setupGLExtenions()
|
||||
{
|
||||
_isBlendColorSupported = isGLExtensionSupported("GL_EXT_blend_color") ||
|
||||
strncmp((const char*)glGetString(GL_VERSION),"1.2",3)>=0;
|
||||
|
||||
_glBlendColor = getGLExtensionFuncPtr("glBlendColor", "glBlendColorEXT");
|
||||
}
|
||||
|
||||
void BlendColor::Extensions::glBlendColor(GLclampf red , GLclampf green , GLclampf blue , GLclampf alpha) const
|
||||
{
|
||||
if (_glBlendColor)
|
||||
{
|
||||
typedef void (APIENTRY * GLBlendColorProc) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
|
||||
((GLBlendColorProc)_glBlendColor)(red, green, blue, alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
notify(WARN)<<"Error: glBlendColor not supported by OpenGL driver"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ CXXFILES =\
|
||||
Billboard.cpp\
|
||||
BoundingBox.cpp\
|
||||
BoundingSphere.cpp\
|
||||
BlendColor.cpp\
|
||||
BlendFunc.cpp\
|
||||
ClipNode.cpp\
|
||||
ClipPlane.cpp\
|
||||
@@ -51,6 +52,7 @@ CXXFILES =\
|
||||
Matrixf.cpp\
|
||||
Matrixd.cpp\
|
||||
MatrixTransform.cpp\
|
||||
Multisample.cpp\
|
||||
Node.cpp\
|
||||
NodeCallback.cpp\
|
||||
NodeVisitor.cpp\
|
||||
|
||||
108
src/osg/Multisample.cpp
Normal file
108
src/osg/Multisample.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/Multisample>
|
||||
#include <osg/State>
|
||||
#include <osg/Notify>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
|
||||
Multisample::Multisample() : _mode(DONT_CARE)
|
||||
{
|
||||
_coverage = 1;
|
||||
_invert = false;
|
||||
}
|
||||
|
||||
Multisample::~Multisample()
|
||||
{
|
||||
}
|
||||
|
||||
void Multisample::apply(State& state) const
|
||||
{
|
||||
// get the contextID (user defined ID of 0 upwards) for the
|
||||
// current OpenGL context.
|
||||
const unsigned int contextID = state.getContextID();
|
||||
|
||||
const Extensions* extensions = getExtensions(contextID,true);
|
||||
|
||||
if (!extensions->isMultisampleSupported())
|
||||
{
|
||||
notify(WARN)<<"Warning: Multisample::apply(..) failed, Multisample is not support by OpenGL driver."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if(extensions->isMultisampleFilterHintSupported())
|
||||
glHint(GL_MULTISAMPLE_FILTER_HINT_NV, _mode);
|
||||
extensions->glSampleCoverage(_coverage, _invert);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef buffered_value< ref_ptr<Multisample::Extensions> > BufferedExtensions;
|
||||
static BufferedExtensions s_extensions;
|
||||
|
||||
Multisample::Extensions* Multisample::getExtensions(unsigned int contextID,bool createIfNotInitalized)
|
||||
{
|
||||
if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions;
|
||||
return s_extensions[contextID].get();
|
||||
}
|
||||
|
||||
void Multisample::setExtensions(unsigned int contextID,Extensions* extensions)
|
||||
{
|
||||
s_extensions[contextID] = extensions;
|
||||
}
|
||||
|
||||
|
||||
Multisample::Extensions::Extensions()
|
||||
{
|
||||
setupGLExtenions();
|
||||
}
|
||||
|
||||
Multisample::Extensions::Extensions(const Extensions& rhs):
|
||||
Referenced()
|
||||
{
|
||||
_isMultisampleSupported = rhs._isMultisampleSupported;
|
||||
_isMultisampleFilterHintSupported = rhs._isMultisampleFilterHintSupported;
|
||||
}
|
||||
|
||||
void Multisample::Extensions::lowestCommonDenominator(const Extensions& rhs)
|
||||
{
|
||||
if (!rhs._isMultisampleSupported) _isMultisampleSupported = false;
|
||||
if (!rhs._isMultisampleFilterHintSupported) _isMultisampleFilterHintSupported = false;
|
||||
if (!rhs._glSampleCoverage) _glSampleCoverage = 0;
|
||||
}
|
||||
|
||||
void Multisample::Extensions::setupGLExtenions()
|
||||
{
|
||||
_isMultisampleSupported = isGLExtensionSupported("GL_ARB_multisample");
|
||||
_isMultisampleFilterHintSupported = isGLExtensionSupported("GL_NV_multisample_filter_hint");
|
||||
|
||||
_glSampleCoverage = getGLExtensionFuncPtr("glSampleCoverageARB");
|
||||
}
|
||||
|
||||
void Multisample::Extensions::glSampleCoverage(GLclampf value, GLboolean invert) const
|
||||
{
|
||||
if (_glSampleCoverage)
|
||||
{
|
||||
typedef void (APIENTRY * GLSampleCoverageProc) (GLclampf value, GLboolean invert);
|
||||
((GLSampleCoverageProc)_glSampleCoverage)(value, invert);
|
||||
}
|
||||
else
|
||||
{
|
||||
notify(WARN)<<"Error: glSampleCoverage not supported by OpenGL driver"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user