PolygonMode 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_POLYGONMODE
  14. #define OSG_POLYGONMODE 1
  15. #include <osg/StateAttribute>
  16. #include <osg/GL>
  17. #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
  18. #define GL_POINT 0x1B00
  19. #define GL_LINE 0x1B01
  20. #define GL_FILL 0x1B02
  21. #endif
  22. namespace osg {
  23. /** State Class for setting OpenGL's polygon culling mode.
  24. */
  25. class OSG_EXPORT PolygonMode : public StateAttribute
  26. {
  27. public :
  28. enum Mode {
  29. POINT = GL_POINT,
  30. LINE = GL_LINE,
  31. FILL = GL_FILL
  32. };
  33. enum Face {
  34. FRONT_AND_BACK,
  35. FRONT,
  36. BACK
  37. };
  38. PolygonMode();
  39. PolygonMode(Face face,Mode mode);
  40. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  41. PolygonMode(const PolygonMode& pm,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  42. StateAttribute(pm,copyop),
  43. _modeFront(pm._modeFront),
  44. _modeBack(pm._modeBack) {}
  45. META_StateAttribute(osg, PolygonMode, POLYGONMODE);
  46. /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
  47. virtual int compare(const StateAttribute& sa) const
  48. {
  49. // check the types are equal and then create the rhs variable
  50. // used by the COMPARE_StateAttribute_Parameter macros below.
  51. COMPARE_StateAttribute_Types(PolygonMode,sa)
  52. // compare each parameter in turn against the rhs.
  53. COMPARE_StateAttribute_Parameter(_modeFront)
  54. COMPARE_StateAttribute_Parameter(_modeBack)
  55. return 0; // passed all the above comparison macros, must be equal.
  56. }
  57. void setMode(Face face,Mode mode);
  58. Mode getMode(Face face) const;
  59. inline bool getFrontAndBack() const { return _modeFront==_modeBack; }
  60. virtual void apply(State& state) const;
  61. protected:
  62. virtual ~PolygonMode();
  63. Mode _modeFront;
  64. Mode _modeBack;
  65. };
  66. }
  67. #endif