Depth 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_DEPTH
  14. #define OSG_DEPTH 1
  15. #include <osg/StateAttribute>
  16. namespace osg {
  17. /** Encapsulate OpenGL glDepthFunc/Mask/Range functions.
  18. */
  19. class OSG_EXPORT Depth : public StateAttribute
  20. {
  21. public :
  22. enum Function
  23. {
  24. NEVER = GL_NEVER,
  25. LESS = GL_LESS,
  26. EQUAL = GL_EQUAL,
  27. LEQUAL = GL_LEQUAL,
  28. GREATER = GL_GREATER,
  29. NOTEQUAL = GL_NOTEQUAL,
  30. GEQUAL = GL_GEQUAL,
  31. ALWAYS = GL_ALWAYS
  32. };
  33. Depth(Function func=LESS,double zNear=0.0, double zFar=1.0,bool writeMask=true);
  34. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  35. Depth(const Depth& dp,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  36. StateAttribute(dp,copyop),
  37. _func(dp._func),
  38. _zNear(dp._zNear),
  39. _zFar(dp._zFar),
  40. _depthWriteMask(dp._depthWriteMask) {}
  41. META_StateAttribute(osg, Depth, DEPTH);
  42. /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
  43. virtual int compare(const StateAttribute& sa) const
  44. {
  45. // check the types are equal and then create the rhs variable
  46. // used by the COMPARE_StateAttribute_Parameter macros below.
  47. COMPARE_StateAttribute_Types(Depth,sa)
  48. // compare each parameter in turn against the rhs.
  49. COMPARE_StateAttribute_Parameter(_func)
  50. COMPARE_StateAttribute_Parameter(_depthWriteMask)
  51. COMPARE_StateAttribute_Parameter(_zNear)
  52. COMPARE_StateAttribute_Parameter(_zFar)
  53. return 0; // passed all the above comparison macros, must be equal.
  54. }
  55. virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
  56. {
  57. usage.usesMode(GL_DEPTH_TEST);
  58. return true;
  59. }
  60. inline void setFunction(Function func) { _func = func; }
  61. inline Function getFunction() const { return _func; }
  62. inline void setRange(double zNear, double zFar)
  63. {
  64. _zNear = zNear;
  65. _zFar = zFar;
  66. }
  67. inline void setZNear(double zNear) { _zNear=zNear; }
  68. inline double getZNear() const { return _zNear; }
  69. inline void setZFar(double zFar) { _zFar=zFar; }
  70. inline double getZFar() const { return _zFar; }
  71. inline void setWriteMask(bool mask) { _depthWriteMask = mask; }
  72. inline bool getWriteMask() const { return _depthWriteMask; }
  73. virtual void apply(State& state) const;
  74. protected:
  75. virtual ~Depth();
  76. Function _func;
  77. double _zNear;
  78. double _zFar;
  79. bool _depthWriteMask;
  80. };
  81. }
  82. #endif