Added beginnings of shader composition with the shells of the ShaderComposer and ShaderAttribute classes. This aren't
functional yet, but a useful placeholders for future fucntionality.
This commit is contained in:
82
include/osg/ShaderAttribute
Normal file
82
include/osg/ShaderAttribute
Normal file
@@ -0,0 +1,82 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_SHADERATTRIBUTE
|
||||
#define OSG_SHADERATTRIBUTE 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/Shader>
|
||||
#include <osg/Uniform>
|
||||
|
||||
namespace osg {
|
||||
|
||||
class OSG_EXPORT ShaderAttribute : public StateAttribute
|
||||
{
|
||||
public :
|
||||
|
||||
ShaderAttribute();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
ShaderAttribute(const ShaderAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osg, ShaderAttribute);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
||||
virtual int compare(const StateAttribute& sa) const;
|
||||
|
||||
|
||||
void setType(Type type);
|
||||
virtual Type getType() const { return _type; }
|
||||
|
||||
unsigned int addShader(Shader* shader);
|
||||
void removeShader(unsigned int i);
|
||||
unsigned int getNumShaders() const { return _shaders.size(); }
|
||||
Shader* getShader(unsigned int i) { return _shaders[i].get(); }
|
||||
Shader* getShader(unsigned int i) const { return _shaders[i].get(); }
|
||||
|
||||
|
||||
unsigned int addUniform(Uniform* uniform);
|
||||
void removeUniform(unsigned int i);
|
||||
unsigned int getNumUniforms() const { return _uniforms.size(); }
|
||||
Uniform* getUniform(unsigned int i) { return _uniforms[i].get(); }
|
||||
const Uniform* getUniform(unsigned int i) const { return _uniforms[i].get(); }
|
||||
|
||||
|
||||
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const;
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
virtual void compose(ShaderComposer& composer) const;
|
||||
|
||||
virtual void compileGLObjects(State& state) const;
|
||||
|
||||
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
||||
|
||||
virtual void releaseGLObjects(State* state=0) const;
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~ShaderAttribute();
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Shader> > Shaders;
|
||||
typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms;
|
||||
|
||||
Type _type;
|
||||
Shaders _shaders;
|
||||
Uniforms _uniforms;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
43
include/osg/ShaderComposer
Normal file
43
include/osg/ShaderComposer
Normal file
@@ -0,0 +1,43 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_SHADERCOMPOSER
|
||||
#define OSG_SHADERCOMPOSER 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/Program>
|
||||
|
||||
namespace osg {
|
||||
|
||||
// forward declare osg::State
|
||||
class State;
|
||||
|
||||
class OSG_EXPORT ShaderComposer : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
ShaderComposer();
|
||||
ShaderComposer(const ShaderComposer& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
META_Object(osg, ShaderComposer)
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ShaderComposer();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <osg/BufferObject>
|
||||
#include <osg/Observer>
|
||||
|
||||
#include <osg/ShaderComposer>
|
||||
#include <osg/FrameStamp>
|
||||
#include <osg/DisplaySettings>
|
||||
#include <osg/Polytope>
|
||||
@@ -140,6 +141,17 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
/** Get the current OpenGL context unique ID.*/
|
||||
inline unsigned int getContextID() const { return _contextID; }
|
||||
|
||||
|
||||
/** Set the ShaderComposor object that implements shader composition.*/
|
||||
void setShaderComposer(ShaderComposer* sc) { _shaderComposer = sc; }
|
||||
|
||||
/** Get the ShaderComposor object.*/
|
||||
ShaderComposer* getShaderComposer() { return _shaderComposer.get(); }
|
||||
|
||||
/** Get the const ShaderComposor object.*/
|
||||
const ShaderComposer* getShaderComposer() const { return _shaderComposer.get(); }
|
||||
|
||||
|
||||
/** Push stateset onto state stack.*/
|
||||
void pushStateSet(const StateSet* dstate);
|
||||
|
||||
@@ -1339,6 +1351,8 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
|
||||
GraphicsContext* _graphicsContext;
|
||||
unsigned int _contextID;
|
||||
osg::ref_ptr<ShaderComposer> _shaderComposer;
|
||||
|
||||
ref_ptr<FrameStamp> _frameStamp;
|
||||
|
||||
ref_ptr<const RefMatrix> _identity;
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace osg {
|
||||
// forward declare NodeVisitor, State & StateSet
|
||||
class NodeVisitor;
|
||||
class State;
|
||||
class ShaderComposer;
|
||||
class StateSet;
|
||||
class Texture;
|
||||
|
||||
@@ -315,6 +316,9 @@ class OSG_EXPORT StateAttribute : public Object
|
||||
*/
|
||||
virtual void apply(State&) const {}
|
||||
|
||||
/* compose associated shaders via the ShaderComposer. */
|
||||
virtual void compose(ShaderComposer& composer) const {}
|
||||
|
||||
/** Default to nothing to compile - all state is applied immediately. */
|
||||
virtual void compileGLObjects(State&) const {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user