VertexAttribDivisor 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_VERTEXATTRIBDIVISOR
  14. #define OSG_VERTEXATTRIBDIVISOR 1
  15. #include <osg/StateAttribute>
  16. #include <osg/Vec3>
  17. #include <osg/Vec4>
  18. namespace osg {
  19. /** VertexAttribDivisor state class which encapsulates OpenGL glVertexAttribDivisor() functionality. */
  20. class OSG_EXPORT VertexAttribDivisor : public StateAttribute
  21. {
  22. public :
  23. VertexAttribDivisor();
  24. VertexAttribDivisor(unsigned int index, unsigned int divisor);
  25. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  26. VertexAttribDivisor(const VertexAttribDivisor& vad,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  27. StateAttribute(vad,copyop),
  28. _index(vad._index),
  29. _divisor(vad._divisor) {}
  30. virtual osg::Object* cloneType() const { return new VertexAttribDivisor(_index, 0); }
  31. virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new VertexAttribDivisor(*this,copyop); }
  32. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const VertexAttribDivisor *>(obj)!=NULL; }
  33. virtual const char* libraryName() const { return "osg"; }
  34. virtual const char* className() const { return "VertexAttribDivisor"; }
  35. virtual Type getType() const { return VERTEX_ATTRIB_DIVISOR; }
  36. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  37. virtual int compare(const StateAttribute& sa) const
  38. {
  39. // check the types are equal and then create the rhs variable
  40. // used by the COMPARE_StateAttribute_Parameter macros below.
  41. COMPARE_StateAttribute_Types(VertexAttribDivisor,sa)
  42. // compare each parameter in turn against the rhs.
  43. COMPARE_StateAttribute_Parameter(_index)
  44. COMPARE_StateAttribute_Parameter(_divisor)
  45. return 0; // passed all the above comparison macros, must be equal.
  46. }
  47. virtual unsigned int getMember() const { return _index; }
  48. /** Set the vertex attrib index - the vertex attribute slot that the divisor should apply to. */
  49. inline void setIndex( unsigned int index ) { _index = index; }
  50. /** Get the vertex attrib index. */
  51. inline unsigned int getIndex() const { return _index; }
  52. /** Set the vertex attrib divisor. */
  53. inline void setDivisor( unsigned int divisor ) { _divisor = divisor; }
  54. /** Get the vertex attrib divisor. */
  55. inline unsigned int getDivisor() const { return _divisor; }
  56. /** Apply to the OpenGL state machine. */
  57. virtual void apply(State& state) const;
  58. protected :
  59. virtual ~VertexAttribDivisor();
  60. unsigned int _index;
  61. unsigned int _divisor;
  62. };
  63. }
  64. #endif