CullFace 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_CULLFACE
  14. #define OSG_CULLFACE 1
  15. #include <osg/GL>
  16. #include <osg/StateAttribute>
  17. namespace osg {
  18. /** Class to globally enable/disable OpenGL's polygon culling mode.
  19. */
  20. class OSG_EXPORT CullFace : public StateAttribute
  21. {
  22. public :
  23. enum Mode {
  24. FRONT = GL_FRONT,
  25. BACK = GL_BACK,
  26. FRONT_AND_BACK = GL_FRONT_AND_BACK
  27. };
  28. CullFace(Mode mode=BACK):
  29. _mode(mode) {}
  30. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  31. CullFace(const CullFace& cf,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  32. StateAttribute(cf,copyop),
  33. _mode(cf._mode) {}
  34. META_StateAttribute(osg, CullFace, CULLFACE);
  35. /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
  36. virtual int compare(const StateAttribute& sa) const
  37. {
  38. // check the types are equal and then create the rhs variable
  39. // used by the COMPARE_StateAttribute_Parameter macros below.
  40. COMPARE_StateAttribute_Types(CullFace,sa)
  41. // compare each parameter in turn against the rhs.
  42. COMPARE_StateAttribute_Parameter(_mode)
  43. return 0; // passed all the above comparison macros, must be equal.
  44. }
  45. virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
  46. {
  47. usage.usesMode(GL_CULL_FACE);
  48. return true;
  49. }
  50. inline void setMode(Mode mode) { _mode = mode; }
  51. inline Mode getMode() const { return _mode; }
  52. virtual void apply(State& state) const;
  53. protected:
  54. virtual ~CullFace();
  55. Mode _mode;
  56. };
  57. }
  58. #endif