1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSG_VERTEXATTRIBDIVISOR
15#define OSG_VERTEXATTRIBDIVISOR 1
17#include <osg/StateAttribute>
23/** VertexAttribDivisor state class which encapsulates OpenGL glVertexAttribDivisor() functionality. */
24class OSG_EXPORT VertexAttribDivisor : public StateAttribute
28 VertexAttribDivisor();
30 VertexAttribDivisor(unsigned int index, unsigned int divisor);
32 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
33 VertexAttribDivisor(const VertexAttribDivisor& vad,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
34 StateAttribute(vad,copyop),
36 _divisor(vad._divisor) {}
38 virtual osg::Object* cloneType() const { return new VertexAttribDivisor(_index, 0); }
39 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new VertexAttribDivisor(*this,copyop); }
40 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const VertexAttribDivisor *>(obj)!=NULL; }
41 virtual const char* libraryName() const { return "osg"; }
42 virtual const char* className() const { return "VertexAttribDivisor"; }
43 virtual Type getType() const { return VERTEX_ATTRIB_DIVISOR; }
45 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
46 virtual int compare(const StateAttribute& sa) const
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(VertexAttribDivisor,sa)
52 // compare each parameter in turn against the rhs.
53 COMPARE_StateAttribute_Parameter(_index)
54 COMPARE_StateAttribute_Parameter(_divisor)
56 return 0; // passed all the above comparison macros, must be equal.
59 virtual unsigned int getMember() const { return _index; }
62 /** Set the vertex attrib index - the vertex attribute slot that the divisor should apply to. */
63 inline void setIndex( unsigned int index ) { _index = index; }
65 /** Get the vertex attrib index. */
66 inline unsigned int getIndex() const { return _index; }
68 /** Set the vertex attrib divisor. */
69 inline void setDivisor( unsigned int divisor ) { _divisor = divisor; }
71 /** Get the vertex attrib divisor. */
72 inline unsigned int getDivisor() const { return _divisor; }
74 /** Apply to the OpenGL state machine. */
75 virtual void apply(State& state) const;
79 virtual ~VertexAttribDivisor();
82 unsigned int _divisor;