Multisample 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_MULTISAMPLE
  14. #define OSG_MULTISAMPLE 1
  15. #include <osg/GL>
  16. #include <osg/StateAttribute>
  17. #include <osg/ref_ptr>
  18. #ifndef GL_ARB_multisample
  19. #define GL_MULTISAMPLE_ARB 0x809D
  20. #define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E
  21. #define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F
  22. #define GL_SAMPLE_COVERAGE_ARB 0x80A0
  23. #define GL_SAMPLE_BUFFERS_ARB 0x80A8
  24. #define GL_SAMPLES_ARB 0x80A9
  25. #define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA
  26. #define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB
  27. #define GL_MULTISAMPLE_BIT_ARB 0x20000000
  28. #endif
  29. #ifndef GL_NV_multisample_filter_hint
  30. #define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534
  31. #endif
  32. namespace osg {
  33. /** Multisample - encapsulates the OpenGL Multisample state.*/
  34. class OSG_EXPORT Multisample : public StateAttribute
  35. {
  36. public :
  37. enum Mode
  38. {
  39. FASTEST = GL_FASTEST,
  40. NICEST = GL_NICEST,
  41. DONT_CARE = GL_DONT_CARE
  42. };
  43. Multisample();
  44. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  45. Multisample(const Multisample& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  46. StateAttribute(trans,copyop),
  47. _coverage(trans._coverage),
  48. _invert(trans._invert),
  49. _mode(trans._mode) {}
  50. META_StateAttribute(osg, Multisample,MULTISAMPLE);
  51. /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
  52. virtual int compare(const StateAttribute& sa) const
  53. {
  54. // check the types are equal and then create the rhs variable
  55. // used by the COMPARE_StateAttribute_Parameter macros below.
  56. COMPARE_StateAttribute_Types(Multisample,sa)
  57. // compare each parameter in turn against the rhs.
  58. COMPARE_StateAttribute_Parameter(_coverage)
  59. COMPARE_StateAttribute_Parameter(_invert)
  60. COMPARE_StateAttribute_Parameter(_mode)
  61. return 0; // passed all the above comparison macros, must be equal.
  62. }
  63. void setSampleCoverage(float coverage, bool invert)
  64. {
  65. _coverage = coverage;
  66. _invert = invert;
  67. }
  68. inline void setCoverage(float coverage) { _coverage=coverage; }
  69. inline float getCoverage() const { return _coverage; }
  70. inline void setInvert(bool invert) { _invert=invert; }
  71. inline bool getInvert() const { return _invert; }
  72. inline void setHint(Mode mode) { _mode = mode; }
  73. inline Mode getHint() const { return _mode; }
  74. virtual void apply(State& state) const;
  75. protected :
  76. virtual ~Multisample();
  77. float _coverage;
  78. bool _invert;
  79. Mode _mode;
  80. };
  81. }
  82. #endif