PolygonOffset 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_POLYGONOFFSET
  14. #define OSG_POLYGONOFFSET 1
  15. #include <osg/StateAttribute>
  16. #ifndef GL_POLYGON_OFFSET_LINE
  17. #define GL_POLYGON_OFFSET_LINE 0x2A02
  18. #define GL_POLYGON_OFFSET_POINT 0x2A01
  19. #endif
  20. namespace osg {
  21. /** PolygonOffset - encapsulates the OpenGL glPolygonOffset state.*/
  22. class OSG_EXPORT PolygonOffset : public StateAttribute
  23. {
  24. public :
  25. PolygonOffset();
  26. PolygonOffset(float factor, float units);
  27. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  28. PolygonOffset(const PolygonOffset& po,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  29. StateAttribute(po,copyop),
  30. _factor(po._factor),
  31. _units(po._units) {}
  32. META_StateAttribute(osg, PolygonOffset, POLYGONOFFSET);
  33. /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
  34. virtual int compare(const StateAttribute& sa) const
  35. {
  36. // check the types are equal and then create the rhs variable
  37. // used by the COMPARE_StateAttribute_Parameter macros below.
  38. COMPARE_StateAttribute_Types(PolygonOffset,sa)
  39. // compare each parameter in turn against the rhs.
  40. COMPARE_StateAttribute_Parameter(_factor)
  41. COMPARE_StateAttribute_Parameter(_units)
  42. return 0; // passed all the above comparison macros, must be equal.
  43. }
  44. virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
  45. {
  46. usage.usesMode(GL_POLYGON_OFFSET_FILL);
  47. #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE)
  48. usage.usesMode(GL_POLYGON_OFFSET_LINE);
  49. usage.usesMode(GL_POLYGON_OFFSET_POINT);
  50. #endif
  51. return true;
  52. }
  53. inline void setFactor(float factor) { _factor = factor; }
  54. inline float getFactor() const { return _factor; }
  55. inline void setUnits(float units) { _units = units; }
  56. inline float getUnits() const { return _units; }
  57. virtual void apply(State& state) const;
  58. static void setFactorMultiplier(float multiplier);
  59. static float getFactorMultiplier();
  60. static void setUnitsMultiplier(float multiplier);
  61. static float getUnitsMultiplier();
  62. static bool areFactorAndUnitsMultipliersSet();
  63. /** Checks with the OpenGL driver to try and pick multiplier appropriate for the hardware.
  64. note, requires a valid graphics context to be current. */
  65. static void setFactorAndUnitsMultipliersUsingBestGuessForDriver();
  66. protected :
  67. virtual ~PolygonOffset();
  68. float _factor;
  69. float _units;
  70. };
  71. }
  72. #endif