openscenegraph
TexEnv
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_TEXENV
15#define OSG_TEXENV 1
16
17#include <osg/GL>
18#include <osg/StateAttribute>
19#include <osg/Vec4>
20
21#ifndef OSG_GL_FIXED_FUNCTION_AVAILABLE
22 #define GL_MODULATE 0x2100
23 #define GL_ADD 0x0104
24 #define GL_MODULATE 0x2100
25 #define GL_DECAL 0x2101
26#endif
27
28namespace osg {
29
30/** TexEnv encapsulates the OpenGL glTexEnv (texture environment) state.
31*/
32class OSG_EXPORT TexEnv : public StateAttribute
33{
34 public :
35
36 enum Mode {
37 DECAL = GL_DECAL,
38 MODULATE = GL_MODULATE,
39 BLEND = GL_BLEND,
40 REPLACE = GL_REPLACE,
41 ADD = GL_ADD
42 };
43
44 TexEnv(Mode mode=MODULATE);
45
46 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
47 TexEnv(const TexEnv& texenv,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
48 StateAttribute(texenv,copyop),
49 _mode(texenv._mode),
50 _color(texenv._color) {}
51
52
53 META_StateAttribute(osg, TexEnv, TEXENV);
54
55 virtual bool isTextureAttribute() const { return true; }
56
57 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
58 virtual int compare(const StateAttribute& sa) const
59 {
60 // Check for equal types, then create the rhs variable
61 // used by the COMPARE_StateAttribute_Parameter macros below.
62 COMPARE_StateAttribute_Types(TexEnv,sa)
63
64 // Compare each parameter in turn against the rhs.
65 COMPARE_StateAttribute_Parameter(_mode)
66 COMPARE_StateAttribute_Parameter(_color)
67
68 return 0; // Passed all the above comparison macros, so must be equal.
69 }
70
71
72 void setMode( Mode mode ) { _mode = mode; }
73
74 Mode getMode() const { return _mode; }
75
76 void setColor( const Vec4& color ) { _color = color; }
77
78 Vec4& getColor() { return _color; }
79
80 const Vec4& getColor() const { return _color; }
81
82
83 virtual void apply(State& state) const;
84
85 protected :
86
87 virtual ~TexEnv( void );
88
89 Mode _mode;
90 osg::Vec4 _color;
91};
92
93}
94
95#endif