openscenegraph
VertexAttribDivisor
Go to the documentation of this file.
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
14#ifndef OSG_VERTEXATTRIBDIVISOR
15#define OSG_VERTEXATTRIBDIVISOR 1
16
17#include <osg/StateAttribute>
18#include <osg/Vec3>
19#include <osg/Vec4>
20
21namespace osg {
22
23/** VertexAttribDivisor state class which encapsulates OpenGL glVertexAttribDivisor() functionality. */
24class OSG_EXPORT VertexAttribDivisor : public StateAttribute
25{
26 public :
27
28 VertexAttribDivisor();
29
30 VertexAttribDivisor(unsigned int index, unsigned int divisor);
31
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),
35 _index(vad._index),
36 _divisor(vad._divisor) {}
37
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; }
44
45 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
46 virtual int compare(const 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(VertexAttribDivisor,sa)
51
52 // compare each parameter in turn against the rhs.
53 COMPARE_StateAttribute_Parameter(_index)
54 COMPARE_StateAttribute_Parameter(_divisor)
55
56 return 0; // passed all the above comparison macros, must be equal.
57 }
58
59 virtual unsigned int getMember() const { return _index; }
60
61
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; }
64
65 /** Get the vertex attrib index. */
66 inline unsigned int getIndex() const { return _index; }
67
68 /** Set the vertex attrib divisor. */
69 inline void setDivisor( unsigned int divisor ) { _divisor = divisor; }
70
71 /** Get the vertex attrib divisor. */
72 inline unsigned int getDivisor() const { return _divisor; }
73
74 /** Apply to the OpenGL state machine. */
75 virtual void apply(State& state) const;
76
77 protected :
78
79 virtual ~VertexAttribDivisor();
80
81 unsigned int _index;
82 unsigned int _divisor;
83};
84
85}
86
87#endif