Introduced new uniforms for tracking the modelview and project matrices in shaders using non built-ins.
This commit is contained in:
@@ -2114,7 +2114,16 @@ void Geometry::accept(AttributeFunctor& af)
|
||||
{
|
||||
AttributeFunctorArrayVisitor afav(af);
|
||||
|
||||
afav.applyArray(VERTICES,_vertexData.array.get());
|
||||
if (_vertexData.array.valid())
|
||||
{
|
||||
afav.applyArray(VERTICES,_vertexData.array.get());
|
||||
}
|
||||
else if (_vertexAttribList.size()>0)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"Geometry::accept(AttributeFunctor& af): Using vertex attribute instead"<<std::endl;
|
||||
afav.applyArray(VERTICES,_vertexAttribList[0].array.get());
|
||||
}
|
||||
|
||||
afav.applyArray(NORMALS,_normalData.array.get());
|
||||
afav.applyArray(COLORS,_colorData.array.get());
|
||||
afav.applyArray(SECONDARY_COLORS,_secondaryColorData.array.get());
|
||||
@@ -2178,7 +2187,16 @@ void Geometry::accept(ConstAttributeFunctor& af) const
|
||||
{
|
||||
ConstAttributeFunctorArrayVisitor afav(af);
|
||||
|
||||
afav.applyArray(VERTICES,_vertexData.array.get());
|
||||
if (_vertexData.array.valid())
|
||||
{
|
||||
afav.applyArray(VERTICES,_vertexData.array.get());
|
||||
}
|
||||
else if (_vertexAttribList.size()>0)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"Geometry::accept(ConstAttributeFunctor& af): Using vertex attribute instead"<<std::endl;
|
||||
afav.applyArray(VERTICES,_vertexAttribList[0].array.get());
|
||||
}
|
||||
|
||||
afav.applyArray(NORMALS,_normalData.array.get());
|
||||
afav.applyArray(COLORS,_colorData.array.get());
|
||||
afav.applyArray(SECONDARY_COLORS,_secondaryColorData.array.get());
|
||||
@@ -2197,32 +2215,42 @@ void Geometry::accept(ConstAttributeFunctor& af) const
|
||||
|
||||
void Geometry::accept(PrimitiveFunctor& functor) const
|
||||
{
|
||||
if (!_vertexData.array.valid() || _vertexData.array->getNumElements()==0) return;
|
||||
const osg::Array* vertices = _vertexData.array.get();
|
||||
const osg::IndexArray* indices = _vertexData.indices.get();
|
||||
|
||||
if (!_vertexData.indices.valid())
|
||||
if (!vertices && _vertexAttribList.size()>0)
|
||||
{
|
||||
switch(_vertexData.array->getType())
|
||||
osg::notify(osg::INFO)<<"Using vertex attribute instead"<<std::endl;
|
||||
vertices = _vertexAttribList[0].array.get();
|
||||
indices = _vertexAttribList[0].indices.get();
|
||||
}
|
||||
|
||||
if (!vertices || vertices->getNumElements()==0) return;
|
||||
|
||||
if (!indices)
|
||||
{
|
||||
switch(vertices->getType())
|
||||
{
|
||||
case(Array::Vec2ArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec2*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec2*>(vertices->getDataPointer()));
|
||||
break;
|
||||
case(Array::Vec3ArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec3*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec3*>(vertices->getDataPointer()));
|
||||
break;
|
||||
case(Array::Vec4ArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec4*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec4*>(vertices->getDataPointer()));
|
||||
break;
|
||||
case(Array::Vec2dArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec2d*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec2d*>(vertices->getDataPointer()));
|
||||
break;
|
||||
case(Array::Vec3dArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec3d*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec3d*>(vertices->getDataPointer()));
|
||||
break;
|
||||
case(Array::Vec4dArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec4d*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec4d*>(vertices->getDataPointer()));
|
||||
break;
|
||||
default:
|
||||
notify(WARN)<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<<_vertexData.array->getType()<<std::endl;
|
||||
notify(WARN)<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<<vertices->getType()<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2241,33 +2269,32 @@ void Geometry::accept(PrimitiveFunctor& functor) const
|
||||
const Vec2d* vec2dArray = 0;
|
||||
const Vec3d* vec3dArray = 0;
|
||||
const Vec4d* vec4dArray = 0;
|
||||
Array::Type type = _vertexData.array->getType();
|
||||
Array::Type type = vertices->getType();
|
||||
switch(type)
|
||||
{
|
||||
case(Array::Vec2ArrayType):
|
||||
vec2Array = static_cast<const Vec2*>(_vertexData.array->getDataPointer());
|
||||
vec2Array = static_cast<const Vec2*>(vertices->getDataPointer());
|
||||
break;
|
||||
case(Array::Vec3ArrayType):
|
||||
vec3Array = static_cast<const Vec3*>(_vertexData.array->getDataPointer());
|
||||
vec3Array = static_cast<const Vec3*>(vertices->getDataPointer());
|
||||
break;
|
||||
case(Array::Vec4ArrayType):
|
||||
vec4Array = static_cast<const Vec4*>(_vertexData.array->getDataPointer());
|
||||
vec4Array = static_cast<const Vec4*>(vertices->getDataPointer());
|
||||
break;
|
||||
case(Array::Vec2dArrayType):
|
||||
vec2dArray = static_cast<const Vec2d*>(_vertexData.array->getDataPointer());
|
||||
vec2dArray = static_cast<const Vec2d*>(vertices->getDataPointer());
|
||||
break;
|
||||
case(Array::Vec3dArrayType):
|
||||
vec3dArray = static_cast<const Vec3d*>(_vertexData.array->getDataPointer());
|
||||
vec3dArray = static_cast<const Vec3d*>(vertices->getDataPointer());
|
||||
break;
|
||||
case(Array::Vec4dArrayType):
|
||||
vec4dArray = static_cast<const Vec4d*>(_vertexData.array->getDataPointer());
|
||||
vec4dArray = static_cast<const Vec4d*>(vertices->getDataPointer());
|
||||
break;
|
||||
default:
|
||||
notify(WARN)<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<<_vertexData.array->getType()<<std::endl;
|
||||
notify(WARN)<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<<vertices->getType()<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for(PrimitiveSetList::const_iterator itr=_primitives.begin();
|
||||
itr!=_primitives.end();
|
||||
++itr)
|
||||
@@ -2311,7 +2338,7 @@ void Geometry::accept(PrimitiveFunctor& functor) const
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
functor.end();
|
||||
break;
|
||||
}
|
||||
@@ -2354,7 +2381,7 @@ void Geometry::accept(PrimitiveFunctor& functor) const
|
||||
}
|
||||
++vindex;
|
||||
}
|
||||
|
||||
|
||||
functor.end();
|
||||
|
||||
}
|
||||
@@ -2487,30 +2514,40 @@ void Geometry::accept(PrimitiveFunctor& functor) const
|
||||
|
||||
void Geometry::accept(PrimitiveIndexFunctor& functor) const
|
||||
{
|
||||
if (!_vertexData.array.valid() || _vertexData.array->getNumElements()==0) return;
|
||||
const osg::Array* vertices = _vertexData.array.get();
|
||||
const osg::IndexArray* indices = _vertexData.indices.get();
|
||||
|
||||
switch(_vertexData.array->getType())
|
||||
if (!vertices && _vertexAttribList.size()>0)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"Geometry::accept(PrimitiveIndexFunctor& functor): Using vertex attribute instead"<<std::endl;
|
||||
vertices = _vertexAttribList[0].array.get();
|
||||
indices = _vertexAttribList[0].indices.get();
|
||||
}
|
||||
|
||||
if (!vertices || vertices->getNumElements()==0) return;
|
||||
|
||||
switch(vertices->getType())
|
||||
{
|
||||
case(Array::Vec2ArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec2*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec2*>(vertices->getDataPointer()));
|
||||
break;
|
||||
case(Array::Vec3ArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec3*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec3*>(vertices->getDataPointer()));
|
||||
break;
|
||||
case(Array::Vec4ArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec4*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec4*>(vertices->getDataPointer()));
|
||||
break;
|
||||
case(Array::Vec2dArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec2d*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec2d*>(vertices->getDataPointer()));
|
||||
break;
|
||||
case(Array::Vec3dArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec3d*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec3d*>(vertices->getDataPointer()));
|
||||
break;
|
||||
case(Array::Vec4dArrayType):
|
||||
functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec4d*>(_vertexData.array->getDataPointer()));
|
||||
functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec4d*>(vertices->getDataPointer()));
|
||||
break;
|
||||
default:
|
||||
notify(WARN)<<"Warning: Geometry::accept(PrimitiveIndexFunctor&) cannot handle Vertex Array type"<<_vertexData.array->getType()<<std::endl;
|
||||
notify(WARN)<<"Warning: Geometry::accept(PrimitiveIndexFunctor&) cannot handle Vertex Array type"<<vertices->getType()<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,10 @@ State::State():
|
||||
_projection = _identity;
|
||||
_modelView = _identity;
|
||||
|
||||
_modelViewMatrixUniform = new Uniform(Uniform::FLOAT_MAT4,"osg_ModelViewMatrix");
|
||||
_projectionMatrixUniform = new Uniform(Uniform::FLOAT_MAT4,"osg_ProjectionMatrix");
|
||||
_modelViewProjectionMatrixUniform = new Uniform(Uniform::FLOAT_MAT4,"osg_ModelViewProjectionMatrix");
|
||||
|
||||
_abortRenderingPtr = false;
|
||||
|
||||
_checkGLErrors = ONCE_PER_FRAME;
|
||||
@@ -90,6 +94,8 @@ State::State():
|
||||
|
||||
_maxTexturePoolSize = 0;
|
||||
_maxBufferObjectPoolSize = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
State::~State()
|
||||
@@ -420,7 +426,7 @@ void State::apply(const StateSet* dstate)
|
||||
//apply();
|
||||
//popStateSet();
|
||||
//return;
|
||||
|
||||
|
||||
if (dstate)
|
||||
{
|
||||
|
||||
@@ -440,41 +446,13 @@ void State::apply(const StateSet* dstate)
|
||||
{
|
||||
if (unit<ds_textureModeList.size()) applyModeList(getOrCreateTextureModeMap(unit),ds_textureModeList[unit]);
|
||||
else if (unit<_textureModeMapList.size()) applyModeMap(_textureModeMapList[unit]);
|
||||
|
||||
|
||||
if (unit<ds_textureAttributeList.size()) applyAttributeList(getOrCreateTextureAttributeMap(unit),ds_textureAttributeList[unit]);
|
||||
else if (unit<_textureAttributeMapList.size()) applyAttributeMap(_textureAttributeMapList[unit]);
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
|
||||
applyUniformList(_uniformMap,dstate->getUniformList());
|
||||
#else
|
||||
if (_lastAppliedProgramObject)
|
||||
{
|
||||
for(StateSetStack::iterator sitr=_stateStateStack.begin();
|
||||
sitr!=_stateStateStack.end();
|
||||
++sitr)
|
||||
{
|
||||
const StateSet* stateset = *sitr;
|
||||
const StateSet::UniformList& uniformList = stateset->getUniformList();
|
||||
for(StateSet::UniformList::const_iterator itr=uniformList.begin();
|
||||
itr!=uniformList.end();
|
||||
++itr)
|
||||
{
|
||||
_lastAppliedProgramObject->apply(*(itr->second.first));
|
||||
}
|
||||
}
|
||||
|
||||
const StateSet::UniformList& uniformList = dstate->getUniformList();
|
||||
for(StateSet::UniformList::const_iterator itr=uniformList.begin();
|
||||
itr!=uniformList.end();
|
||||
++itr)
|
||||
{
|
||||
_lastAppliedProgramObject->apply(*(itr->second.first));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -508,27 +486,7 @@ void State::apply()
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
applyUniformMap(_uniformMap);
|
||||
#else
|
||||
if (_lastAppliedProgramObject && !_stateStateStack.empty())
|
||||
{
|
||||
for(StateSetStack::iterator sitr=_stateStateStack.begin();
|
||||
sitr!=_stateStateStack.end();
|
||||
++sitr)
|
||||
{
|
||||
const StateSet* stateset = *sitr;
|
||||
const StateSet::UniformList& uniformList = stateset->getUniformList();
|
||||
for(StateSet::UniformList::const_iterator itr=uniformList.begin();
|
||||
itr!=uniformList.end();
|
||||
++itr)
|
||||
{
|
||||
_lastAppliedProgramObject->apply(*(itr->second.first));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors("end of State::apply()");
|
||||
}
|
||||
@@ -1033,3 +991,11 @@ bool State::checkGLErrors(const StateAttribute* attribute) const
|
||||
}
|
||||
|
||||
|
||||
void State::applyModelViewAndProjectionUniformsIfRequired()
|
||||
{
|
||||
if (!_lastAppliedProgramObject) return;
|
||||
|
||||
if (_modelViewMatrixUniform.valid()) _lastAppliedProgramObject->apply(*_modelViewMatrixUniform);
|
||||
if (_projectionMatrixUniform) _lastAppliedProgramObject->apply(*_projectionMatrixUniform);
|
||||
if (_modelViewProjectionMatrixUniform) _lastAppliedProgramObject->apply(*_modelViewProjectionMatrixUniform);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user