openscenegraph
BlendColor
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_BLENDCOLOR
15#define OSG_BLENDCOLOR 1
16
17#include <osg/GL>
18#include <osg/StateAttribute>
19#include <osg/ref_ptr>
20#include <osg/Vec4>
21
22
23namespace osg {
24
25/** Encapsulates OpenGL blend/transparency state. */
26class OSG_EXPORT BlendColor : public StateAttribute
27{
28 public :
29
30 BlendColor();
31
32 BlendColor(const osg::Vec4& constantColor);
33
34 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
35 BlendColor(const BlendColor& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
36 StateAttribute(trans,copyop),
37 _constantColor(trans._constantColor) {}
38
39 META_StateAttribute(osg, BlendColor,BLENDCOLOR);
40
41 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
42 virtual int compare(const StateAttribute& sa) const
43 {
44 // Check for equal types, then create the rhs variable
45 // used by the COMPARE_StateAttribute_Parameter macros below.
46 COMPARE_StateAttribute_Types(BlendColor,sa)
47
48 // Compare each parameter in turn against the rhs.
49 COMPARE_StateAttribute_Parameter(_constantColor)
50
51 return 0; // Passed all the above comparison macros, so must be equal.
52 }
53
54 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
55 {
56 usage.usesMode(GL_BLEND);
57 return true;
58 }
59
60 void setConstantColor(const osg::Vec4& color) { _constantColor = color; }
61
62 inline osg::Vec4& getConstantColor() { return _constantColor; }
63
64 inline const osg::Vec4& getConstantColor() const { return _constantColor; }
65
66 virtual void apply(State& state) const;
67
68 protected :
69
70 virtual ~BlendColor();
71
72 osg::Vec4 _constantColor;
73};
74
75}
76
77#endif