1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
17#include <osg/StateAttribute>
22/** A texture matrix state class that encapsulates OpenGL texture matrix
24class OSG_EXPORT TexMat : public StateAttribute
30 TexMat(const Matrix& matrix):_matrix(matrix),_scaleByTextureRectangleSize(false) {}
32 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
33 TexMat(const TexMat& texmat,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
34 StateAttribute(texmat,copyop),
35 _matrix(texmat._matrix),
36 _scaleByTextureRectangleSize(texmat._scaleByTextureRectangleSize) {}
38 META_StateAttribute(osg, TexMat, TEXMAT);
40 virtual bool isTextureAttribute() const { return true; }
42 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
43 virtual int compare(const StateAttribute& sa) const
45 // Check for equal types, then create the rhs variable
46 // used by the COMPARE_StateAttribute_Parameter macros below.
47 COMPARE_StateAttribute_Types(TexMat,sa)
49 // Compare each parameter in turn against the rhs.
50 COMPARE_StateAttribute_Parameter(_matrix)
52 return 0; // Passed all the above comparison macros, so must be equal.
55 /** Set the texture matrix */
56 inline void setMatrix(const Matrix& matrix) { _matrix = matrix; }
58 /** Get the texture matrix */
59 inline Matrix& getMatrix() { return _matrix; }
61 /** Get the const texture matrix */
62 inline const Matrix& getMatrix() const { return _matrix; }
64 /** Switch on/off the post scaling of the TexMat matrix by the size of the last applied texture rectangle.
65 * Use a TexMat alongside a TextureRectangle with this scaling applied allows one to treat a TextureRectnagles texture coordinate
66 * range as if it were the usual non dimensional 0.0 to 1.0 range.
67 * Note, the TexMat matrix itself is not modified by the post scaling, its purely an operation passed to OpenGL to do the post scaling once the
68 * the TexMat matrix has been loaded.*/
69 void setScaleByTextureRectangleSize(bool flag) { _scaleByTextureRectangleSize = flag; }
71 /** Get whether the post scaling of the TexMat matrix, by the size of the last applied texture rectangle, is switched on/off.*/
72 bool getScaleByTextureRectangleSize() const { return _scaleByTextureRectangleSize; }
74 /** Apply texture matrix to OpenGL state. */
75 virtual void apply(State& state) const;
79 virtual ~TexMat( void );
82 bool _scaleByTextureRectangleSize;