2005-04-15 05:41:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
|
2003-01-22 00:45:36 +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.
|
|
|
|
*/
|
2002-07-12 22:25:10 +08:00
|
|
|
|
|
|
|
#ifndef OSG_BLENDFUNC
|
|
|
|
#define OSG_BLENDFUNC 1
|
|
|
|
|
|
|
|
#include <osg/StateAttribute>
|
|
|
|
|
2003-09-17 20:04:48 +08:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2006-06-30 21:50:02 +08:00
|
|
|
#ifndef GL_VERSION_1_4
|
|
|
|
#define GL_BLEND_DST_RGB 0x80C8
|
|
|
|
#define GL_BLEND_SRC_RGB 0x80C9
|
|
|
|
#define GL_BLEND_DST_ALPHA 0x80CA
|
|
|
|
#define GL_BLEND_SRC_ALPHA 0x80CB
|
|
|
|
#endif
|
2003-09-17 20:04:48 +08:00
|
|
|
|
|
|
|
|
2002-07-12 22:25:10 +08:00
|
|
|
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 BlendFunc : public StateAttribute
|
2002-07-12 22:25:10 +08:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
BlendFunc();
|
|
|
|
|
2003-05-07 02:04:27 +08:00
|
|
|
BlendFunc(GLenum source, GLenum destination);
|
2006-06-30 21:50:02 +08:00
|
|
|
BlendFunc(GLenum source, GLenum destination, GLenum source_alpha, GLenum destination_alpha);
|
2003-05-07 02:04:27 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
2002-07-12 22:25:10 +08:00
|
|
|
BlendFunc(const BlendFunc& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
StateAttribute(trans,copyop),
|
|
|
|
_source_factor(trans._source_factor),
|
2006-06-30 21:50:02 +08:00
|
|
|
_destination_factor(trans._destination_factor),
|
|
|
|
_source_factor_alpha(trans._source_factor_alpha),
|
|
|
|
_destination_factor_alpha(trans._destination_factor_alpha) {}
|
2002-07-12 22:25:10 +08:00
|
|
|
|
|
|
|
META_StateAttribute(osg, BlendFunc,BLENDFUNC);
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
2002-07-12 22:25:10 +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.
|
2002-07-12 22:25:10 +08:00
|
|
|
COMPARE_StateAttribute_Types(BlendFunc,sa)
|
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
// Compare each parameter in turn against the rhs.
|
2002-07-12 22:25:10 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_source_factor)
|
|
|
|
COMPARE_StateAttribute_Parameter(_destination_factor)
|
2006-06-30 21:50:02 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_source_factor_alpha)
|
|
|
|
COMPARE_StateAttribute_Parameter(_destination_factor_alpha)
|
2002-07-12 22:25:10 +08:00
|
|
|
|
2004-09-01 16:15:36 +08:00
|
|
|
return 0; // Passed all the above comparison macros, so must be equal.
|
2002-07-12 22:25:10 +08:00
|
|
|
}
|
|
|
|
|
2004-03-03 23:38:22 +08:00
|
|
|
virtual bool getModeUsage(ModeUsage& usage) const
|
2002-07-12 22:25:10 +08:00
|
|
|
{
|
2004-03-03 23:38:22 +08:00
|
|
|
usage.usesMode(GL_BLEND);
|
|
|
|
return true;
|
2002-07-12 22:25:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum BlendFuncMode {
|
2003-09-17 20:04:48 +08:00
|
|
|
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,
|
2004-09-01 16:59:58 +08:00
|
|
|
CONSTANT_COLOR = GL_CONSTANT_COLOR,
|
|
|
|
ONE_MINUS_CONSTANT_COLOR = GL_ONE_MINUS_CONSTANT_COLOR,
|
2003-09-17 20:04:48 +08:00
|
|
|
CONSTANT_ALPHA = GL_CONSTANT_ALPHA,
|
|
|
|
ONE_MINUS_CONSTANT_ALPHA = GL_ONE_MINUS_CONSTANT_ALPHA,
|
|
|
|
ZERO = GL_ZERO
|
2002-07-12 22:25:10 +08:00
|
|
|
};
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setFunction( GLenum source, GLenum destination )
|
2002-07-12 22:25:10 +08:00
|
|
|
{
|
|
|
|
_source_factor = source;
|
|
|
|
_destination_factor = destination;
|
2006-07-11 22:24:18 +08:00
|
|
|
_source_factor_alpha = source;
|
|
|
|
_destination_factor_alpha = destination;
|
2002-07-12 22:25:10 +08:00
|
|
|
}
|
|
|
|
|
2006-06-30 21:50:02 +08:00
|
|
|
inline void setFunction( GLenum source_rgb, GLenum destination_rgb, GLenum source_alpha, GLenum destination_alpha )
|
|
|
|
{
|
|
|
|
_source_factor = source_rgb;
|
|
|
|
_destination_factor = destination_rgb;
|
|
|
|
_source_factor_alpha = source_alpha;
|
|
|
|
_destination_factor_alpha = destination_alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSource(GLenum source) { _source_factor = _source_factor_alpha = source; }
|
2002-09-02 20:31:35 +08:00
|
|
|
inline GLenum getSource() const { return _source_factor; }
|
2006-06-30 21:50:02 +08:00
|
|
|
|
|
|
|
void setSourceRGB(GLenum source) { _source_factor = source; }
|
|
|
|
inline GLenum getSourceRGB() const { return _source_factor; }
|
|
|
|
|
|
|
|
void setSourceAlpha(GLenum source) { _source_factor_alpha = source; }
|
|
|
|
inline GLenum getSourceAlpha() const { return _source_factor_alpha; }
|
2002-07-12 22:25:10 +08:00
|
|
|
|
2006-06-30 21:50:02 +08:00
|
|
|
void setDestination(GLenum destination) { _destination_factor = _destination_factor_alpha = destination; }
|
2002-09-02 20:31:35 +08:00
|
|
|
inline GLenum getDestination() const { return _destination_factor; }
|
2002-07-12 22:25:10 +08:00
|
|
|
|
2006-06-30 21:50:02 +08:00
|
|
|
void setDestinationRGB(GLenum destination) { _destination_factor = destination; }
|
|
|
|
inline GLenum getDestinationRGB() const { return _destination_factor; }
|
|
|
|
|
|
|
|
void setDestinationAlpha(GLenum destination) { _destination_factor_alpha = destination; }
|
|
|
|
inline GLenum getDestinationAlpha() const { return _destination_factor_alpha; }
|
|
|
|
|
2002-07-12 22:25:10 +08:00
|
|
|
virtual void apply(State& state) const;
|
2006-06-30 21:50:02 +08:00
|
|
|
/** Encapsulates queries of extension availability, obtains extension
|
|
|
|
* function pointers, and provides convenience wrappers for
|
|
|
|
* calling extension functions. */
|
|
|
|
class OSG_EXPORT Extensions : public osg::Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Extensions(unsigned int contextID);
|
|
|
|
|
|
|
|
Extensions(const Extensions& rhs);
|
|
|
|
|
|
|
|
void lowestCommonDenominator(const Extensions& rhs);
|
|
|
|
|
|
|
|
void setupGLExtensions(unsigned int contextID);
|
|
|
|
|
|
|
|
void setBlendFuncSeparateSupported(bool flag) { _isBlendFuncSeparateSupported=flag; }
|
|
|
|
bool isBlendFuncSeparateSupported() const { return _isBlendFuncSeparateSupported; }
|
|
|
|
|
|
|
|
void setBlendFuncSeparateProc(void* ptr) { _glBlendFuncSeparate = ptr; }
|
|
|
|
void glBlendFuncSeparate(GLenum sfactorRGB,
|
|
|
|
GLenum dfactorRGB,
|
|
|
|
GLenum sfactorAlpha,
|
|
|
|
GLenum dfactorAlpha) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
~Extensions() {}
|
|
|
|
|
|
|
|
bool _isBlendFuncSeparateSupported;
|
|
|
|
|
|
|
|
void* _glBlendFuncSeparate;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/** 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. */
|
|
|
|
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);
|
|
|
|
|
2002-07-12 22:25:10 +08:00
|
|
|
|
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~BlendFunc();
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
GLenum _source_factor;
|
|
|
|
GLenum _destination_factor;
|
2006-06-30 21:50:02 +08:00
|
|
|
GLenum _source_factor_alpha;
|
|
|
|
GLenum _destination_factor_alpha;
|
2002-07-12 22:25:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|