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:
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,
|
||||
|
||||
Reference in New Issue
Block a user