BlendFunc
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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_BLENDFUNC
#define OSG_BLENDFUNC 1
#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
#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
namespace osg {
class OSG_EXPORT BlendFunc : public StateAttribute
{
public :
BlendFunc();
BlendFunc(GLenum source, GLenum destination);
BlendFunc(GLenum source, GLenum destination, GLenum source_alpha, GLenum destination_alpha);
BlendFunc(const BlendFunc& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(trans,copyop),
_source_factor(trans._source_factor),
_destination_factor(trans._destination_factor),
_source_factor_alpha(trans._source_factor_alpha),
_destination_factor_alpha(trans._destination_factor_alpha) {}
META_StateAttribute(osg, BlendFunc,BLENDFUNC);
virtual int compare(const StateAttribute& sa) const
{
// Check for equal types, then create the rhs variable
// used by the COMPARE_StateAttribute_Parameter macros below.
COMPARE_StateAttribute_Types(BlendFunc,sa)
// Compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_source_factor)
COMPARE_StateAttribute_Parameter(_destination_factor)
COMPARE_StateAttribute_Parameter(_source_factor_alpha)
COMPARE_StateAttribute_Parameter(_destination_factor_alpha)
return 0; // Passed all the above comparison macros, so must be equal.
}
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
{
usage.usesMode(GL_BLEND);
return true;
}
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,
CONSTANT_COLOR = GL_CONSTANT_COLOR,
ONE_MINUS_CONSTANT_COLOR = GL_ONE_MINUS_CONSTANT_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 )
{
_source_factor = source;
_destination_factor = destination;
_source_factor_alpha = source;
_destination_factor_alpha = destination;
}
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; }
inline GLenum getSource() const { return _source_factor; }
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; }
void setDestination(GLenum destination) { _destination_factor = _destination_factor_alpha = destination; }
inline GLenum getDestination() const { return _destination_factor; }
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; }
virtual void apply(State& state) const;
protected :
virtual ~BlendFunc();
GLenum _source_factor;
GLenum _destination_factor;
GLenum _source_factor_alpha;
GLenum _destination_factor_alpha;
};
}
#endif
GL_ONE_MINUS_CONSTANT_ALPHA
#define GL_ONE_MINUS_CONSTANT_ALPHA
Definition BlendFunc:23
GL_CONSTANT_COLOR
#define GL_CONSTANT_COLOR
Definition BlendFunc:20
GL_CONSTANT_ALPHA
#define GL_CONSTANT_ALPHA
Definition BlendFunc:22
GL_ONE_MINUS_CONSTANT_COLOR
#define GL_ONE_MINUS_CONSTANT_COLOR
Definition BlendFunc:21
StateAttribute
COMPARE_StateAttribute_Parameter
#define COMPARE_StateAttribute_Parameter(parameter)
Definition StateAttribute:69
COMPARE_StateAttribute_Types
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
Definition StateAttribute:57
osg::BlendFunc::setDestinationAlpha
void setDestinationAlpha(GLenum destination)
Definition BlendFunc:155
osg::BlendFunc::~BlendFunc
virtual ~BlendFunc()
osg::BlendFunc::setFunction
void setFunction(GLenum source_rgb, GLenum destination_rgb, GLenum source_alpha, GLenum destination_alpha)
Definition BlendFunc:132
osg::BlendFunc::setDestinationRGB
void setDestinationRGB(GLenum destination)
Definition BlendFunc:152
osg::BlendFunc::_destination_factor
GLenum _destination_factor
Definition BlendFunc:165
osg::BlendFunc::setSource
void setSource(GLenum source)
Definition BlendFunc:140
osg::BlendFunc::setSourceRGB
void setSourceRGB(GLenum source)
Definition BlendFunc:143
osg::BlendFunc::getDestination
GLenum getDestination() const
Definition BlendFunc:150
osg::BlendFunc::BlendFunc
BlendFunc()
osg::BlendFunc::BlendFuncMode
BlendFuncMode
Definition BlendFunc:106
osg::BlendFunc::SRC_COLOR
@ SRC_COLOR
Definition BlendFunc:116
osg::BlendFunc::ONE_MINUS_SRC_ALPHA
@ ONE_MINUS_SRC_ALPHA
Definition BlendFunc:112
osg::BlendFunc::ZERO
@ ZERO
Definition BlendFunc:121
osg::BlendFunc::ONE_MINUS_DST_COLOR
@ ONE_MINUS_DST_COLOR
Definition BlendFunc:111
osg::BlendFunc::CONSTANT_COLOR
@ CONSTANT_COLOR
Definition BlendFunc:117
osg::BlendFunc::ONE_MINUS_DST_ALPHA
@ ONE_MINUS_DST_ALPHA
Definition BlendFunc:110
osg::BlendFunc::SRC_ALPHA
@ SRC_ALPHA
Definition BlendFunc:114
osg::BlendFunc::DST_ALPHA
@ DST_ALPHA
Definition BlendFunc:107
osg::BlendFunc::DST_COLOR
@ DST_COLOR
Definition BlendFunc:108
osg::BlendFunc::ONE_MINUS_CONSTANT_COLOR
@ ONE_MINUS_CONSTANT_COLOR
Definition BlendFunc:118
osg::BlendFunc::ONE
@ ONE
Definition BlendFunc:109
osg::BlendFunc::SRC_ALPHA_SATURATE
@ SRC_ALPHA_SATURATE
Definition BlendFunc:115
osg::BlendFunc::CONSTANT_ALPHA
@ CONSTANT_ALPHA
Definition BlendFunc:119
osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA
@ ONE_MINUS_CONSTANT_ALPHA
Definition BlendFunc:120
osg::BlendFunc::ONE_MINUS_SRC_COLOR
@ ONE_MINUS_SRC_COLOR
Definition BlendFunc:113
osg::BlendFunc::getSource
GLenum getSource() const
Definition BlendFunc:141
osg::BlendFunc::apply
virtual void apply(State &state) const
osg::BlendFunc::getSourceRGB
GLenum getSourceRGB() const
Definition BlendFunc:144
osg::BlendFunc::META_StateAttribute
META_StateAttribute(osg, BlendFunc, BLENDFUNC)
osg::BlendFunc::setSourceAlpha
void setSourceAlpha(GLenum source)
Definition BlendFunc:146
osg::BlendFunc::_destination_factor_alpha
GLenum _destination_factor_alpha
Definition BlendFunc:167
osg::BlendFunc::BlendFunc
BlendFunc(GLenum source, GLenum destination)
osg::BlendFunc::compare
virtual int compare(const StateAttribute &sa) const
Definition BlendFunc:85
osg::BlendFunc::BlendFunc
BlendFunc(GLenum source, GLenum destination, GLenum source_alpha, GLenum destination_alpha)
osg::BlendFunc::setDestination
void setDestination(GLenum destination)
Definition BlendFunc:149
osg::BlendFunc::setFunction
void setFunction(GLenum source, GLenum destination)
Definition BlendFunc:124
osg::BlendFunc::getDestinationAlpha
GLenum getDestinationAlpha() const
Definition BlendFunc:156
osg::BlendFunc::getSourceAlpha
GLenum getSourceAlpha() const
Definition BlendFunc:147
osg::BlendFunc::_source_factor
GLenum _source_factor
Definition BlendFunc:164
osg::BlendFunc::getModeUsage
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
Definition BlendFunc:100
osg::BlendFunc::BlendFunc
BlendFunc(const BlendFunc &trans, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition BlendFunc:75
osg::BlendFunc::getDestinationRGB
GLenum getDestinationRGB() const
Definition BlendFunc:153
osg::BlendFunc::_source_factor_alpha
GLenum _source_factor_alpha
Definition BlendFunc:166
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::StateAttribute::StateAttribute
StateAttribute()
osg::StateAttribute::BLENDFUNC
@ BLENDFUNC
Definition StateAttribute:149
osg::State
Definition State:80
osg
Definition AlphaFunc:19
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
osg::StateAttribute::ModeUsage
Definition StateAttribute:308
osg::StateAttribute::ModeUsage::usesMode
virtual void usesMode(GLMode mode)=0