Scissor 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_Scissor
  14. #define OSG_Scissor 1
  15. #include <osg/StateAttribute>
  16. namespace osg {
  17. /** Encapsulate OpenGL glScissor. */
  18. class OSG_EXPORT Scissor : public StateAttribute
  19. {
  20. public :
  21. Scissor();
  22. Scissor(int x,int y,int width,int height):
  23. _x(x),
  24. _y(y),
  25. _width(width),
  26. _height(height) {}
  27. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  28. Scissor(const Scissor& vp,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  29. StateAttribute(vp,copyop),
  30. _x(vp._x),
  31. _y(vp._y),
  32. _width(vp._width),
  33. _height(vp._height) {}
  34. META_StateAttribute(osg, Scissor, SCISSOR);
  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(Scissor,sa)
  41. // compare each parameter in turn against the rhs.
  42. COMPARE_StateAttribute_Parameter(_x)
  43. COMPARE_StateAttribute_Parameter(_y)
  44. COMPARE_StateAttribute_Parameter(_width)
  45. COMPARE_StateAttribute_Parameter(_height)
  46. return 0; // passed all the above comparison macros, must be equal.
  47. }
  48. virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
  49. {
  50. usage.usesMode(GL_SCISSOR_TEST);
  51. return true;
  52. }
  53. inline void setScissor(int x,int y,int width,int height)
  54. {
  55. _x = x;
  56. _y = y;
  57. _width = width;
  58. _height = height;
  59. }
  60. void getScissor(int& x,int& y,int& width,int& height) const
  61. {
  62. x = _x;
  63. y = _y;
  64. width = _width;
  65. height = _height;
  66. }
  67. inline int& x() { return _x; }
  68. inline int x() const { return _x; }
  69. inline int& y() { return _y; }
  70. inline int y() const { return _y; }
  71. inline int& width() { return _width; }
  72. inline int width() const { return _width; }
  73. inline int& height() { return _height; }
  74. inline int height() const { return _height; }
  75. virtual void apply(State& state) const;
  76. protected:
  77. virtual ~Scissor();
  78. int _x;
  79. int _y;
  80. int _width;
  81. int _height;
  82. };
  83. }
  84. #endif