Validator 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. //osgFX - Copyright (C) 2003 Marco Jez
  14. #ifndef OSGFX_VALIDATOR_
  15. #define OSGFX_VALIDATOR_
  16. #include <osgFX/Effect>
  17. #include <osg/ref_ptr>
  18. #include <osg/StateAttribute>
  19. #include <vector>
  20. namespace osgFX
  21. {
  22. /**
  23. This class is used internally by osgFX::Effect to choose between different
  24. techniques dynamically. The apply() method will call each technique's
  25. validate() method and store the results in a buffered array. The Effect
  26. class will then choose the first technique that could be validated in all
  27. active rendering contexts.
  28. */
  29. class OSGFX_EXPORT Validator: public osg::StateAttribute {
  30. public:
  31. Validator();
  32. Validator(Effect* effect);
  33. Validator(const Validator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
  34. META_StateAttribute(osgFX, Validator, VALIDATOR);
  35. void apply(osg::State& state) const;
  36. void compileGLObjects(osg::State& state) const;
  37. inline int compare(const osg::StateAttribute& sa) const;
  38. inline void disable() { _effect = 0; }
  39. protected:
  40. virtual ~Validator() {}
  41. Validator& operator=(const Validator&) { return *this; }
  42. private:
  43. mutable Effect* _effect;
  44. };
  45. // INLINE METHODS
  46. inline int Validator::compare(const osg::StateAttribute& sa) const
  47. {
  48. // check the types are equal and then create the rhs variable
  49. //used by the COMPARE_StateAttribute_Parameter macros below.
  50. COMPARE_StateAttribute_Types(Validator,sa)
  51. // compare parameters
  52. COMPARE_StateAttribute_Parameter(_effect)
  53. return 0;
  54. }
  55. }
  56. #endif