2005-04-15 05:41:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
|
2003-09-17 20:04:48 +08:00
|
|
|
*
|
|
|
|
* 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/Vec4>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Encapsulates OpenGL blend/transparency state. */
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT BlendColor : public StateAttribute
|
2003-09-17 20:04:48 +08:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
BlendColor();
|
|
|
|
|
2006-02-09 20:20:42 +08:00
|
|
|
BlendColor(const osg::Vec4& constantColor);
|
|
|
|
|
2003-09-17 20:04:48 +08:00
|
|
|
/** 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);
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
2003-09-17 20:04:48 +08:00
|
|
|
virtual int compare(const StateAttribute& sa) const
|
|
|
|
{
|
2004-09-01 16:15:36 +08:00
|
|
|
// Check for equal types, then create the rhs variable
|
|
|
|
// used by the COMPARE_StateAttribute_Paramter macros below.
|
2003-09-17 20:04:48 +08:00
|
|
|
COMPARE_StateAttribute_Types(BlendColor,sa)
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
// Compare each parameter in turn against the rhs.
|
2003-09-17 20:04:48 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_constantColor)
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
return 0; // Passed all the above comparison macros, so must be equal.
|
2003-09-17 20:04:48 +08:00
|
|
|
}
|
|
|
|
|
2004-03-03 23:38:22 +08:00
|
|
|
virtual bool getModeUsage(ModeUsage& usage) const
|
2003-09-17 20:04:48 +08:00
|
|
|
{
|
2004-03-03 23:38:22 +08:00
|
|
|
usage.usesMode(GL_BLEND);
|
|
|
|
return true;
|
2003-09-17 20:04:48 +08:00
|
|
|
}
|
|
|
|
|
2003-09-26 05:54:33 +08:00
|
|
|
void setConstantColor(const osg::Vec4& color) { _constantColor = color; }
|
2003-09-17 20:04:48 +08:00
|
|
|
inline osg::Vec4 getConstantColor() const { return _constantColor; }
|
|
|
|
|
|
|
|
virtual void apply(State& state) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Encapsulates queries of extension availability, obtains extension
|
|
|
|
* function pointers, and provides convinience wrappers for
|
|
|
|
* calling extension functions. */
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Extensions : public osg::Referenced
|
2003-09-17 20:04:48 +08:00
|
|
|
{
|
|
|
|
public:
|
2005-04-26 21:15:27 +08:00
|
|
|
Extensions(unsigned int contextID);
|
2003-09-17 20:04:48 +08:00
|
|
|
|
|
|
|
Extensions(const Extensions& rhs);
|
|
|
|
|
|
|
|
void lowestCommonDenominator(const Extensions& rhs);
|
|
|
|
|
2005-04-26 21:15:27 +08:00
|
|
|
void setupGLExtenions(unsigned int contextID);
|
2003-09-17 20:04:48 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Returns the Extensions object for the given context.
|
|
|
|
* If createIfNotInitalized is true and the Exentsions object doesn't
|
|
|
|
* exist, getExtensions() creates it on the given context.
|
|
|
|
* Returns NULL if createIfNotInitalized is false and the Extensions
|
|
|
|
* object doesn't exist. */
|
2003-09-17 20:04:48 +08:00
|
|
|
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** 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. */
|
2003-09-17 20:04:48 +08:00
|
|
|
static void setExtensions(unsigned int contextID,Extensions* extensions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~BlendColor();
|
|
|
|
|
|
|
|
osg::Vec4 _constantColor;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|