diff --git a/examples/osgshadercomposition/osgshadercomposition.cpp b/examples/osgshadercomposition/osgshadercomposition.cpp index 34ee98fd1..750129ec1 100644 --- a/examples/osgshadercomposition/osgshadercomposition.cpp +++ b/examples/osgshadercomposition/osgshadercomposition.cpp @@ -62,12 +62,6 @@ osg::Node* createSceneGraph(osg::ArgumentParser& arguments) sa->addUniform(new osg::Uniform("baseTexture",0)); -#if 1 - osg::ShaderAttribute* sa_dummy = new osg::ShaderAttribute; - sa_dummy->setType(osg::StateAttribute::Type(10001)); - stateset->setAttribute(sa_dummy); -#endif - } // inherit the ShaderComponents entirely from above @@ -92,7 +86,6 @@ osg::Node* createSceneGraph(osg::ArgumentParser& arguments) osg::StateSet* stateset = pat->getOrCreateStateSet(); stateset->setMode(GL_BLEND, osg::StateAttribute::ON); -#if 1 osg::ShaderAttribute* sa = new osg::ShaderAttribute; sa->setType(osg::StateAttribute::Type(10001)); stateset->setAttribute(sa); @@ -103,7 +96,6 @@ osg::Node* createSceneGraph(osg::ArgumentParser& arguments) sa->addShader(fragment_shader); } -#endif group->addChild(pat); } @@ -162,8 +154,6 @@ osg::Node* createSceneGraph(osg::ArgumentParser& arguments) group->addChild(pat); - group->addChild(pat); - } return group; @@ -175,15 +165,11 @@ int main( int argc, char **argv ) osgViewer::Viewer viewer(arguments); - OSG_NOTICE<<"********** Constructing scene graph ************ "< scenegraph = createSceneGraph(arguments); if (!scenegraph) return 1; viewer.setSceneData(scenegraph.get()); - OSG_NOTICE<(obj)!=NULL; } + virtual const char* libraryName() const { return "osg"; } + virtual const char* className() const { return "ShaderAttribute"; } /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ virtual int compare(const StateAttribute& sa) const; diff --git a/include/osg/State b/include/osg/State index cf22d5f2a..ddd8e0a21 100644 --- a/include/osg/State +++ b/include/osg/State @@ -1352,6 +1352,8 @@ class OSG_EXPORT State : public Referenced, public Observer bool checkGLErrors(StateAttribute::GLMode mode) const; bool checkGLErrors(const StateAttribute* attribute) const; + /** print out the internal details of osg::State - useful for debugging.*/ + void print(std::ostream& fout) const; /** Initialize extension used by osg:::State.*/ void initializeExtensionProcs(); @@ -1424,6 +1426,8 @@ class OSG_EXPORT State : public Referenced, public Observer global_default_value = false; } + void print(std::ostream& fout) const; + bool valid; bool changed; bool last_applied_value; @@ -1442,6 +1446,8 @@ class OSG_EXPORT State : public Referenced, public Observer } + void print(std::ostream& fout) const; + /** apply an attribute if required, passing in attribute and appropriate attribute stack */ bool changed; const StateAttribute* last_applied_attribute; @@ -1458,6 +1464,8 @@ class OSG_EXPORT State : public Referenced, public Observer UniformStack() {} + void print(std::ostream& fout) const; + UniformVec uniformVec; }; @@ -1546,6 +1554,13 @@ class OSG_EXPORT State : public Referenced, public Observer as.last_applied_attribute = attribute; attribute->apply(*this); + const ShaderComponent* sc = attribute->getShaderComponent(); + if (as.last_applied_shadercomponent != sc) + { + as.last_applied_shadercomponent = sc; + _shaderCompositionDirty = true; + } + if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(attribute); return true; @@ -1566,6 +1581,13 @@ class OSG_EXPORT State : public Referenced, public Observer if (as.global_default_attribute.valid()) { as.global_default_attribute->apply(*this); + const ShaderComponent* sc = as.global_default_attribute->getShaderComponent(); + if (as.last_applied_shadercomponent != sc) + { + as.last_applied_shadercomponent = sc; + _shaderCompositionDirty = true; + } + if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(as.global_default_attribute.get()); } return true; @@ -1584,6 +1606,12 @@ class OSG_EXPORT State : public Referenced, public Observer if (as.global_default_attribute.valid()) { as.global_default_attribute->apply(*this); + const ShaderComponent* sc = as.global_default_attribute->getShaderComponent(); + if (as.last_applied_shadercomponent != sc) + { + as.last_applied_shadercomponent = sc; + _shaderCompositionDirty = true; + } if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(as.global_default_attribute.get()); } return true; diff --git a/src/osg/ShaderAttribute.cpp b/src/osg/ShaderAttribute.cpp index 8afc98141..685df2940 100644 --- a/src/osg/ShaderAttribute.cpp +++ b/src/osg/ShaderAttribute.cpp @@ -38,6 +38,14 @@ ShaderAttribute::~ShaderAttribute() { } +osg::Object* ShaderAttribute::cloneType() const +{ + ShaderAttribute* sa = new ShaderAttribute; + sa->setType(getType()); + OSG_NOTICE<<" cloneType ="< -// T mymax(const T& a,const T& b) -// { -// return (((a) > (b)) ? (a) : (b)); -// } - void State::apply(const StateSet* dstate) { if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors("start of State::apply(StateSet*)"); @@ -598,6 +590,8 @@ void State::applyShaderComposition() { if (_shaderCompositionDirty) { + print(notify(osg::INFO)); + // build lits of current ShaderComponents ShaderComponents shaderComponents; @@ -1483,3 +1477,213 @@ void State::drawQuads(GLint first, GLsizei count, GLsizei primCount) glDrawElementsInstanced(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, &(indices[offsetFirst]), primCount); } +void State::ModeStack::print(std::ostream& fout) const +{ + fout<<" valid = "<className()<<", "<getName()<className()<<", "<getName()<first<<", "<second<<")"; + } + fout<<" }"<first<<", "<second<<")"; + } + fout<<" }"< _shaderComposer; +#endif + +#if 0 + osg::Program* _currentShaderCompositionProgram; + StateSet::UniformList _currentShaderCompositionUniformList; +#endif + +#if 0 + ref_ptr _frameStamp; + + ref_ptr _identity; + ref_ptr _initialViewMatrix; + ref_ptr _projection; + ref_ptr _modelView; + ref_ptr _modelViewCache; + + bool _useModelViewAndProjectionUniforms; + ref_ptr _modelViewMatrixUniform; + ref_ptr _projectionMatrixUniform; + ref_ptr _modelViewProjectionMatrixUniform; + ref_ptr _normalMatrixUniform; + + Matrix _initialInverseViewMatrix; + + ref_ptr _displaySettings; + + bool* _abortRenderingPtr; + CheckForGLErrors _checkGLErrors; + + + bool _useVertexAttributeAliasing; + VertexAttribAlias _vertexAlias; + VertexAttribAlias _normalAlias; + VertexAttribAlias _colorAlias; + VertexAttribAlias _secondaryColorAlias; + VertexAttribAlias _fogCoordAlias; + VertexAttribAliasList _texCoordAliasList; + + Program::AttribBindingList _attributeBindingList; +#endif + fout<<"ModeMap _modeMap {"<second.print(fout); + fout<<" }"<first.first<<", "<first.second<<") AttributeStack {"<second.print(fout); + fout<<" }"<second.print(fout); + fout<<" }"<getName()<<" "<<*itr< EnabledTexCoordArrayList; + typedef std::vector EnabledVertexAttribArrayList; + + EnabledArrayPair _vertexArray; + EnabledArrayPair _normalArray; + EnabledArrayPair _colorArray; + EnabledArrayPair _secondaryColorArray; + EnabledArrayPair _fogArray; + EnabledTexCoordArrayList _texCoordArrayList; + EnabledVertexAttribArrayList _vertexAttribArrayList; + + unsigned int _currentActiveTextureUnit; + unsigned int _currentClientActiveTextureUnit; + GLBufferObject* _currentVBO; + GLBufferObject* _currentEBO; + GLBufferObject* _currentPBO; + + mutable bool _isSecondaryColorSupportResolved; + mutable bool _isSecondaryColorSupported; + bool computeSecondaryColorSupported() const; + + mutable bool _isFogCoordSupportResolved; + mutable bool _isFogCoordSupported; + bool computeFogCoordSupported() const; + + mutable bool _isVertexBufferObjectSupportResolved; + mutable bool _isVertexBufferObjectSupported; + bool computeVertexBufferObjectSupported() const; +#endif + +#if 0 + unsigned int _dynamicObjectCount; + osg::ref_ptr _completeDynamicObjectRenderingCallback; + + GLBeginEndAdapter _glBeginEndAdapter; + ArrayDispatchers _arrayDispatchers; +#endif +}