1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 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_SHADERATTRIBUTE
15#define OSG_SHADERATTRIBUTE 1
17#include <osg/StateAttribute>
23class OSG_EXPORT ShaderAttribute : public StateAttribute
29 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
30 ShaderAttribute(const ShaderAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
32 virtual osg::Object* cloneType() const;
33 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new ShaderAttribute(*this,copyop); }
34 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ShaderAttribute *>(obj)!=NULL; }
35 virtual const char* libraryName() const { return "osg"; }
36 virtual const char* className() const { return "ShaderAttribute"; }
38 /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
39 virtual int compare(const StateAttribute& sa) const;
42 void setType(Type type);
43 virtual Type getType() const { return _type; }
45 unsigned int addShader(Shader* shader) { return _shaderComponent->addShader(shader); }
46 void removeShader(unsigned int i) { _shaderComponent->removeShader(i); }
47 unsigned int getNumShaders() const { return _shaderComponent->getNumShaders(); }
48 Shader* getShader(unsigned int i) { return _shaderComponent->getShader(i); }
49 const Shader* getShader(unsigned int i) const { return _shaderComponent->getShader(i); }
51 unsigned int addUniform(Uniform* uniform);
52 void removeUniform(unsigned int i);
53 unsigned int getNumUniforms() const { return _uniforms.size(); }
54 Uniform* getUniform(unsigned int i) { return _uniforms[i].get(); }
55 const Uniform* getUniform(unsigned int i) const { return _uniforms[i].get(); }
57 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const;
59 virtual void apply(State& state) const;
61 virtual void compileGLObjects(State& state) const;
63 virtual void resizeGLObjectBuffers(unsigned int maxSize);
65 virtual void releaseGLObjects(State* state=0) const;
69 virtual ~ShaderAttribute();
71 typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms;