LogicOp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_LOGICOP
  14. #define OSG_LOGICOP 1
  15. #include <osg/StateAttribute>
  16. #ifndef OSG_GL_FIXED_FUNCTION_AVAILABLE
  17. #define GL_CLEAR 0x1500
  18. #define GL_SET 0x150F
  19. #define GL_COPY 0x1503
  20. #define GL_COPY_INVERTED 0x150C
  21. #define GL_NOOP 0x1505
  22. #define GL_AND 0x1501
  23. #define GL_NAND 0x150E
  24. #define GL_OR 0x1507
  25. #define GL_NOR 0x1508
  26. #define GL_XOR 0x1506
  27. #define GL_EQUIV 0x1509
  28. #define GL_AND_REVERSE 0x1502
  29. #define GL_AND_INVERTED 0x1504
  30. #define GL_OR_REVERSE 0x150B
  31. #define GL_OR_INVERTED 0x150D
  32. #define GL_COLOR_LOGIC_OP 0x0BF2
  33. #endif
  34. namespace osg {
  35. /** Encapsulates OpenGL LogicOp state. */
  36. class OSG_EXPORT LogicOp : public StateAttribute
  37. {
  38. public :
  39. enum Opcode {
  40. CLEAR = GL_CLEAR,
  41. SET = GL_SET,
  42. COPY = GL_COPY,
  43. COPY_INVERTED = GL_COPY_INVERTED,
  44. NOOP = GL_NOOP,
  45. INVERT = GL_INVERT,
  46. AND = GL_AND,
  47. NAND = GL_NAND,
  48. OR = GL_OR,
  49. NOR = GL_NOR,
  50. XOR = GL_XOR,
  51. EQUIV = GL_EQUIV,
  52. AND_REVERSE = GL_AND_REVERSE,
  53. AND_INVERTED = GL_AND_INVERTED,
  54. OR_REVERSE = GL_OR_REVERSE,
  55. OR_INVERTED = GL_OR_INVERTED
  56. };
  57. LogicOp();
  58. LogicOp(Opcode opcode);
  59. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  60. LogicOp(const LogicOp& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  61. StateAttribute(trans,copyop),
  62. _opcode(trans._opcode){}
  63. META_StateAttribute(osg, LogicOp,LOGICOP);
  64. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  65. virtual int compare(const StateAttribute& sa) const
  66. {
  67. // Check for equal types, then create the rhs variable
  68. // used by the COMPARE_StateAttribute_Parameter macros below.
  69. COMPARE_StateAttribute_Types(LogicOp,sa)
  70. // Compare each parameter in turn against the rhs.
  71. COMPARE_StateAttribute_Parameter(_opcode)
  72. return 0; // Passed all the above comparison macros, so must be equal.
  73. }
  74. virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
  75. {
  76. usage.usesMode(GL_COLOR_LOGIC_OP);
  77. return true;
  78. }
  79. inline void setOpcode(Opcode opcode)
  80. {
  81. _opcode = opcode;
  82. }
  83. inline Opcode getOpcode() const { return _opcode; }
  84. virtual void apply(State& state) const;
  85. protected :
  86. virtual ~LogicOp();
  87. Opcode _opcode;
  88. };
  89. }
  90. #endif