| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 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_SHADERATTRIBUTE |
|---|
| 15 | #define OSG_SHADERATTRIBUTE 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/StateAttribute> |
|---|
| 18 | #include <osg/Shader> |
|---|
| 19 | #include <osg/Uniform> |
|---|
| 20 | |
|---|
| 21 | namespace osg { |
|---|
| 22 | |
|---|
| 23 | class OSG_EXPORT ShaderAttribute : public StateAttribute |
|---|
| 24 | { |
|---|
| 25 | public : |
|---|
| 26 | |
|---|
| 27 | ShaderAttribute(); |
|---|
| 28 | |
|---|
| 29 | /** Copy constructor using CopyOp to manage deep vs shallow copy. */ |
|---|
| 30 | ShaderAttribute(const ShaderAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY); |
|---|
| 31 | |
|---|
| 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"; } |
|---|
| 37 | |
|---|
| 38 | /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ |
|---|
| 39 | virtual int compare(const StateAttribute& sa) const; |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | void setType(Type type); |
|---|
| 43 | virtual Type getType() const { return _type; } |
|---|
| 44 | |
|---|
| 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); } |
|---|
| 50 | |
|---|
| 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(); } |
|---|
| 56 | |
|---|
| 57 | virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const; |
|---|
| 58 | |
|---|
| 59 | virtual void apply(State& state) const; |
|---|
| 60 | |
|---|
| 61 | virtual void compileGLObjects(State& state) const; |
|---|
| 62 | |
|---|
| 63 | virtual void resizeGLObjectBuffers(unsigned int maxSize); |
|---|
| 64 | |
|---|
| 65 | virtual void releaseGLObjects(State* state=0) const; |
|---|
| 66 | |
|---|
| 67 | protected : |
|---|
| 68 | |
|---|
| 69 | virtual ~ShaderAttribute(); |
|---|
| 70 | |
|---|
| 71 | typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms; |
|---|
| 72 | |
|---|
| 73 | Type _type; |
|---|
| 74 | Uniforms _uniforms; |
|---|
| 75 | }; |
|---|
| 76 | |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | #endif |
|---|