ShaderAttribute 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef OSG_SHADERATTRIBUTE
  14. #define OSG_SHADERATTRIBUTE 1
  15. #include <osg/StateAttribute>
  16. #include <osg/Shader>
  17. #include <osg/Uniform>
  18. namespace osg {
  19. class OSG_EXPORT ShaderAttribute : public StateAttribute
  20. {
  21. public :
  22. ShaderAttribute();
  23. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  24. ShaderAttribute(const ShaderAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
  25. virtual osg::Object* cloneType() const;
  26. virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new ShaderAttribute(*this,copyop); }
  27. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ShaderAttribute *>(obj)!=NULL; }
  28. virtual const char* libraryName() const { return "osg"; }
  29. virtual const char* className() const { return "ShaderAttribute"; }
  30. /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  31. virtual int compare(const StateAttribute& sa) const;
  32. void setType(Type type);
  33. virtual Type getType() const { return _type; }
  34. unsigned int addShader(Shader* shader) { return _shaderComponent->addShader(shader); }
  35. void removeShader(unsigned int i) { _shaderComponent->removeShader(i); }
  36. unsigned int getNumShaders() const { return _shaderComponent->getNumShaders(); }
  37. Shader* getShader(unsigned int i) { return _shaderComponent->getShader(i); }
  38. const Shader* getShader(unsigned int i) const { return _shaderComponent->getShader(i); }
  39. unsigned int addUniform(Uniform* uniform);
  40. void removeUniform(unsigned int i);
  41. unsigned int getNumUniforms() const { return _uniforms.size(); }
  42. Uniform* getUniform(unsigned int i) { return _uniforms[i].get(); }
  43. const Uniform* getUniform(unsigned int i) const { return _uniforms[i].get(); }
  44. virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const;
  45. virtual void apply(State& state) const;
  46. virtual void compileGLObjects(State& state) const;
  47. virtual void resizeGLObjectBuffers(unsigned int maxSize);
  48. virtual void releaseGLObjects(State* state=0) const;
  49. protected :
  50. virtual ~ShaderAttribute();
  51. typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms;
  52. Type _type;
  53. Uniforms _uniforms;
  54. };
  55. }
  56. #endif