TexMat 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #ifndef OSG_TEXMAT
  14. #define OSG_TEXMAT 1
  15. #include <osg/StateAttribute>
  16. #include <osg/Matrix>
  17. namespace osg {
  18. /** A texture matrix state class that encapsulates OpenGL texture matrix
  19. * functionality. */
  20. class OSG_EXPORT TexMat : public StateAttribute
  21. {
  22. public :
  23. TexMat();
  24. TexMat(const Matrix& matrix):_matrix(matrix),_scaleByTextureRectangleSize(false) {}
  25. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  26. TexMat(const TexMat& texmat,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  27. StateAttribute(texmat,copyop),
  28. _matrix(texmat._matrix),
  29. _scaleByTextureRectangleSize(texmat._scaleByTextureRectangleSize) {}
  30. META_StateAttribute(osg, TexMat, TEXMAT);
  31. virtual bool isTextureAttribute() const { return true; }
  32. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  33. virtual int compare(const StateAttribute& sa) const
  34. {
  35. // Check for equal types, then create the rhs variable
  36. // used by the COMPARE_StateAttribute_Parameter macros below.
  37. COMPARE_StateAttribute_Types(TexMat,sa)
  38. // Compare each parameter in turn against the rhs.
  39. COMPARE_StateAttribute_Parameter(_matrix)
  40. return 0; // Passed all the above comparison macros, so must be equal.
  41. }
  42. /** Set the texture matrix */
  43. inline void setMatrix(const Matrix& matrix) { _matrix = matrix; }
  44. /** Get the texture matrix */
  45. inline Matrix& getMatrix() { return _matrix; }
  46. /** Get the const texture matrix */
  47. inline const Matrix& getMatrix() const { return _matrix; }
  48. /** Switch on/off the post scaling of the TexMat matrix by the size of the last applied texture rectangle.
  49. * Use a TexMat alongside a TextureRectangle with this scaling applied allows one to treat a TextureRectnagles texture coordinate
  50. * range as if it were the usual non dimensional 0.0 to 1.0 range.
  51. * 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
  52. * the TexMat matrix has been loaded.*/
  53. void setScaleByTextureRectangleSize(bool flag) { _scaleByTextureRectangleSize = flag; }
  54. /** Get whether the post scaling of the TexMat matrix, by the size of the last applied texture rectangle, is switched on/off.*/
  55. bool getScaleByTextureRectangleSize() const { return _scaleByTextureRectangleSize; }
  56. /** Apply texture matrix to OpenGL state. */
  57. virtual void apply(State& state) const;
  58. protected:
  59. virtual ~TexMat( void );
  60. Matrix _matrix;
  61. bool _scaleByTextureRectangleSize;
  62. };
  63. }
  64. #endif