Rewrote the osg::Drawable::AttributeFunctor and PrimtiveFunctor to make
them more consistent with each other. This does mean an API change, so dependanct code in the OSG has been updated accordingly.
This commit is contained in:
@@ -849,91 +849,79 @@ void GeoSet::setInterleavedArray( const InterleaveArrayType format, float *ia, I
|
||||
|
||||
set_fast_path();
|
||||
}
|
||||
|
||||
Drawable::AttributeBitMask GeoSet::suppportsAttributeOperation() const
|
||||
{
|
||||
// we do support coords,normals,texcoords and colors so return true.
|
||||
return COORDS | NORMALS | COLORS | TEXTURE_COORDS;
|
||||
}
|
||||
|
||||
Drawable::AttributeBitMask GeoSet::applyAttributeOperation(AttributeFunctor& auf)
|
||||
void GeoSet::accept(AttributeFunctor& auf)
|
||||
{
|
||||
if (_numcoords == 0) computeNumVerts();
|
||||
|
||||
AttributeBitMask amb = auf.getAttributeBitMask();
|
||||
AttributeBitMask ramb = 0;
|
||||
|
||||
if ((amb & COORDS) && _coords && _numcoords)
|
||||
if (_coords && _numcoords)
|
||||
{
|
||||
if (auf.apply(COORDS,_coords,_coords+_numcoords)) ramb = COORDS;
|
||||
auf.apply(VERTICES,_numcoords,_coords);
|
||||
}
|
||||
|
||||
if ((amb & NORMALS) && _normals && _numnormals)
|
||||
if (_normals && _numnormals)
|
||||
{
|
||||
if (auf.apply(NORMALS,_normals,_normals+_numnormals)) ramb = NORMALS;
|
||||
auf.apply(NORMALS,_numnormals,_normals);
|
||||
}
|
||||
|
||||
if ((amb & COLORS) && _colors && _numcolors)
|
||||
if (_colors && _numcolors)
|
||||
{
|
||||
if (auf.apply(COLORS,_colors,_colors+_numcolors)) ramb = COLORS;
|
||||
auf.apply(COLORS,_numcolors,_colors);
|
||||
}
|
||||
|
||||
if ((amb & TEXTURE_COORDS) && _tcoords && _numtcoords)
|
||||
if (_tcoords && _numtcoords)
|
||||
{
|
||||
if (auf.apply(TEXTURE_COORDS,_tcoords,_tcoords+_numtcoords)) ramb = TEXTURE_COORDS;
|
||||
auf.apply(TEXTURE_COORDS_0,_numtcoords,_tcoords);
|
||||
}
|
||||
|
||||
return ramb;
|
||||
}
|
||||
|
||||
|
||||
void GeoSet::applyPrimitiveOperation(PrimitiveFunctor& functor)
|
||||
void GeoSet::accept(PrimitiveFunctor& functor)
|
||||
{
|
||||
// will easily convert into a Geometry.
|
||||
|
||||
if (!_coords || !_numcoords) return;
|
||||
|
||||
functor.setVertexArray(_numcoords,_coords);
|
||||
|
||||
if( _needprimlen )
|
||||
// will easily convert into a Geometry.
|
||||
|
||||
if (!_coords || !_numcoords) return;
|
||||
|
||||
functor.setVertexArray(_numcoords,_coords);
|
||||
|
||||
if( _needprimlen )
|
||||
{
|
||||
// LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP,
|
||||
// TRIANGLE_FAN, QUAD_STRIP, POLYGONS
|
||||
int index = 0;
|
||||
if( _primLengths == (int *)0 )
|
||||
{
|
||||
// LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP,
|
||||
// TRIANGLE_FAN, QUAD_STRIP, POLYGONS
|
||||
int index = 0;
|
||||
if( _primLengths == (int *)0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for( int i = 0; i < _numprims; i++ )
|
||||
{
|
||||
if( _cindex.valid() )
|
||||
{
|
||||
|
||||
if (_cindex._is_ushort)
|
||||
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] );
|
||||
else
|
||||
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._uint[index] );
|
||||
}
|
||||
else
|
||||
functor.drawArrays( (GLenum)_oglprimtype, index, _primLengths[i] );
|
||||
|
||||
index += _primLengths[i];
|
||||
}
|
||||
return;
|
||||
}
|
||||
else // POINTS, LINES, TRIANGLES, QUADS
|
||||
|
||||
for( int i = 0; i < _numprims; i++ )
|
||||
{
|
||||
if( _cindex.valid())
|
||||
if( _cindex.valid() )
|
||||
{
|
||||
|
||||
if (_cindex._is_ushort)
|
||||
functor.drawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._ushort );
|
||||
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] );
|
||||
else
|
||||
functor.drawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._uint );
|
||||
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._uint[index] );
|
||||
}
|
||||
else
|
||||
functor.drawArrays( (GLenum)_oglprimtype, 0, _numcoords );
|
||||
functor.drawArrays( (GLenum)_oglprimtype, index, _primLengths[i] );
|
||||
|
||||
index += _primLengths[i];
|
||||
}
|
||||
|
||||
}
|
||||
else // POINTS, LINES, TRIANGLES, QUADS
|
||||
{
|
||||
if( _cindex.valid())
|
||||
{
|
||||
if (_cindex._is_ushort)
|
||||
functor.drawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._ushort );
|
||||
else
|
||||
functor.drawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._uint );
|
||||
}
|
||||
else
|
||||
functor.drawArrays( (GLenum)_oglprimtype, 0, _numcoords );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -192,35 +192,22 @@ void Geometry::drawImmediateMode(State& state)
|
||||
|
||||
}
|
||||
|
||||
Drawable::AttributeBitMask Geometry::suppportsAttributeOperation() const
|
||||
{
|
||||
// we do support coords,normals,texcoords and colors so return true.
|
||||
return COORDS | NORMALS | COLORS | TEXTURE_COORDS;
|
||||
}
|
||||
|
||||
|
||||
/** return the attributes successully applied in applyAttributeUpdate.*/
|
||||
Drawable::AttributeBitMask Geometry::applyAttributeOperation(AttributeFunctor& auf)
|
||||
void Geometry::accept(AttributeFunctor& af)
|
||||
{
|
||||
AttributeBitMask amb = auf.getAttributeBitMask();
|
||||
AttributeBitMask ramb = 0;
|
||||
|
||||
if ((amb & COORDS) && _vertexArray.valid() && !_vertexArray->empty())
|
||||
if (_vertexArray.valid() && !_vertexArray->empty())
|
||||
{
|
||||
if (auf.apply(COORDS,&(*(_vertexArray->begin())),&(*(_vertexArray->end())))) ramb = COORDS;
|
||||
af.apply(VERTICES,_vertexArray->size(),&(_vertexArray->front()));
|
||||
}
|
||||
|
||||
if ((amb & NORMALS) && _normalArray.valid() && !_normalArray->empty())
|
||||
if (_normalArray.valid() && !_normalArray->empty())
|
||||
{
|
||||
if (auf.apply(NORMALS,&(*(_normalArray->begin())),&(*(_normalArray->end())))) ramb = NORMALS;
|
||||
af.apply(NORMALS,_normalArray->size(),&(_normalArray->front()));
|
||||
}
|
||||
|
||||
// colors and texture coords to implement...
|
||||
|
||||
return ramb;
|
||||
// need to add other attriubtes
|
||||
}
|
||||
|
||||
void Geometry::applyPrimitiveOperation(PrimitiveFunctor& functor)
|
||||
void Geometry::accept(PrimitiveFunctor& functor)
|
||||
{
|
||||
if (!_vertexArray.valid() || _vertexArray->empty()) return;
|
||||
|
||||
@@ -230,7 +217,7 @@ void Geometry::applyPrimitiveOperation(PrimitiveFunctor& functor)
|
||||
itr!=_primitives.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->applyPrimitiveOperation(functor);
|
||||
(*itr)->accept(functor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -115,6 +115,20 @@ void ImpostorSprite::setTexture(Texture* tex,int s,int t)
|
||||
}
|
||||
|
||||
|
||||
void ImpostorSprite::accept(AttributeFunctor& af)
|
||||
{
|
||||
af.apply(VERTICES,4,_coords);
|
||||
af.apply(TEXTURE_COORDS_0,4,_texcoords);
|
||||
}
|
||||
|
||||
void ImpostorSprite::accept(PrimitiveFunctor& functor)
|
||||
{
|
||||
functor.setVertexArray(4,_coords);
|
||||
functor.drawArrays( GL_QUADS, 0, 4);
|
||||
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Helper class for managing the reuse of ImpostorSprite resources.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@@ -267,3 +281,4 @@ ImpostorSprite* ImpostorSpriteManager::createOrReuseImpostorSprite(int s,int t,i
|
||||
return is;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ void DrawArrays::draw() const
|
||||
glDrawArrays(_mode,_first,_count);
|
||||
}
|
||||
|
||||
void DrawArrays::applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
|
||||
void DrawArrays::accept(Drawable::PrimitiveFunctor& functor)
|
||||
{
|
||||
functor.drawArrays(_mode,_first,_count);
|
||||
}
|
||||
@@ -24,7 +24,7 @@ void DrawArrayLengths::draw() const
|
||||
}
|
||||
}
|
||||
|
||||
void DrawArrayLengths::applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
|
||||
void DrawArrayLengths::accept(Drawable::PrimitiveFunctor& functor)
|
||||
{
|
||||
GLint first = _first;
|
||||
for(VectorSizei::iterator itr=begin();
|
||||
@@ -43,7 +43,7 @@ void DrawElementsUByte::draw() const
|
||||
glDrawElements(_mode,size(),GL_UNSIGNED_BYTE,&front());
|
||||
}
|
||||
|
||||
void DrawElementsUByte::applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
|
||||
void DrawElementsUByte::accept(Drawable::PrimitiveFunctor& functor)
|
||||
{
|
||||
if (!empty()) functor.drawElements(_mode,size(),&front());
|
||||
}
|
||||
@@ -64,7 +64,7 @@ void DrawElementsUShort::draw() const
|
||||
glDrawElements(_mode,size(),GL_UNSIGNED_SHORT,&front());
|
||||
}
|
||||
|
||||
void DrawElementsUShort::applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
|
||||
void DrawElementsUShort::accept(Drawable::PrimitiveFunctor& functor)
|
||||
{
|
||||
if (!empty()) functor.drawElements(_mode,size(),&front());
|
||||
}
|
||||
@@ -85,7 +85,7 @@ void DrawElementsUInt::draw() const
|
||||
glDrawElements(_mode,size(),GL_UNSIGNED_INT,&front());
|
||||
}
|
||||
|
||||
void DrawElementsUInt::applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
|
||||
void DrawElementsUInt::accept(Drawable::PrimitiveFunctor& functor)
|
||||
{
|
||||
if (!empty()) functor.drawElements(_mode,size(),&front());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user