Removed Particle::Shape support for QUAD_TRIANGLESTRIP, HEXAGON, USER as these are unlikely to be used as their implementation prevents refactoring to use vertex array code paths

This commit is contained in:
Robert Osfield
2016-08-25 15:13:36 +01:00
parent c637010c9d
commit 56ed225f17
6 changed files with 54 additions and 194 deletions

View File

@@ -145,7 +145,10 @@ void osgParticle::Particle::render(osg::GLBeginEndAdapter* gl, const osg::Vec3&
gl->Vertex3f(xpos.x(), xpos.y(), xpos.z());
break;
case USER:
case QUAD:
case QUAD_TRIANGLESTRIP:
case HEXAGON:
gl->TexCoord2f(_s_coord, _t_coord);
gl->Vertex3fv((xpos-(p1+p2)).ptr());
gl->TexCoord2f(_s_coord+_s_tile, _t_coord);
@@ -156,48 +159,6 @@ void osgParticle::Particle::render(osg::GLBeginEndAdapter* gl, const osg::Vec3&
gl->Vertex3fv((xpos-(p1-p2)).ptr());
break;
case QUAD_TRIANGLESTRIP:
gl->PushMatrix();
gl->Translatef(xpos.x(), xpos.y(), xpos.z());
// we must gl.Begin() and gl.End() here, because each particle is a single strip
gl->Begin(GL_TRIANGLE_STRIP);
gl->TexCoord2f(_s_coord+_s_tile, _t_coord+_t_tile);
gl->Vertex3fv((p1+p2).ptr());
gl->TexCoord2f(_s_coord, _t_coord+_t_tile);
gl->Vertex3fv((-p1+p2).ptr());
gl->TexCoord2f(_s_coord+_s_tile, _t_coord);
gl->Vertex3fv((p1-p2).ptr());
gl->TexCoord2f(_s_coord, _t_coord);
gl->Vertex3fv((-p1-p2).ptr());
gl->End();
gl->PopMatrix();
break;
case HEXAGON:
gl->PushMatrix();
gl->Translatef(xpos.x(), xpos.y(), xpos.z());
// we must gl.Begin() and gl.End() here, because each particle is a single fan
gl->Begin(GL_TRIANGLE_FAN);
gl->TexCoord2f(_s_coord + _s_tile * 0.5f, _t_coord + _t_tile * 0.5f);
gl->Vertex3f(0,0,0);
gl->TexCoord2f(_s_coord + _s_tile * hex_texcoord_x1, _t_coord + _t_tile * hex_texcoord_y1);
gl->Vertex3fv((p1*cosPI3+p2*sinPI3).ptr());
gl->TexCoord2f(_s_coord + _s_tile * hex_texcoord_x2, _t_coord + _t_tile * hex_texcoord_y1);
gl->Vertex3fv((-p1*cosPI3+p2*sinPI3).ptr());
gl->TexCoord2f(_s_coord, _t_coord + _t_tile * 0.5f);
gl->Vertex3fv((-p1).ptr());
gl->TexCoord2f(_s_coord + _s_tile * hex_texcoord_x2, _t_coord + _t_tile * hex_texcoord_y2);
gl->Vertex3fv((-p1*cosPI3-p2*sinPI3).ptr());
gl->TexCoord2f(_s_coord + _s_tile * hex_texcoord_x1, _t_coord + _t_tile * hex_texcoord_y2);
gl->Vertex3fv((p1*cosPI3-p2*sinPI3).ptr());
gl->TexCoord2f(_s_coord + _s_tile, _t_coord + _t_tile * 0.5f);
gl->Vertex3fv((p1).ptr());
gl->TexCoord2f(_s_coord + _s_tile * hex_texcoord_x1, _t_coord + _t_tile * hex_texcoord_y1);
gl->Vertex3fv((p1*cosPI3+p2*sinPI3).ptr());
gl->End();
gl->PopMatrix();
break;
case LINE:
{
// Get the normalized direction of the particle, to be used in the
@@ -219,35 +180,6 @@ void osgParticle::Particle::render(osg::GLBeginEndAdapter* gl, const osg::Vec3&
}
}
void osgParticle::Particle::render(osg::RenderInfo& renderInfo, const osg::Vec3& xpos, const osg::Vec3& xrot) const
{
#if defined(OSG_GL_MATRICES_AVAILABLE)
if (_drawable.valid())
{
bool requiresRotation = (xrot.x()!=0.0f || xrot.y()!=0.0f || xrot.z()!=0.0f);
glColor4f(_current_color.x(),
_current_color.y(),
_current_color.z(),
_current_color.w() * _current_alpha);
glPushMatrix();
glTranslatef(xpos.x(), xpos.y(), xpos.z());
if (requiresRotation)
{
osg::Quat rotation(xrot.x(), osg::X_AXIS, xrot.y(), osg::Y_AXIS, xrot.z(), osg::Z_AXIS);
#if defined(OSG_GLES1_AVAILABLE)
glMultMatrixf(osg::Matrixf(rotation).ptr());
#else
glMultMatrixd(osg::Matrixd(rotation).ptr());
#endif
}
_drawable->draw(renderInfo);
glPopMatrix();
}
#else
OSG_NOTICE<<"Warning: Particle::render(..) not supported for user-defined shape."<<std::endl;
#endif
}
void osgParticle::Particle::setUpTexCoordsAsPartOfConnectedParticleSystem(ParticleSystem* ps)
{
if (getPreviousParticle()!=Particle::INVALID_INDEX)

View File

@@ -410,16 +410,9 @@ void osgParticle::ParticleSystem::single_pass_render(osg::RenderInfo& renderInfo
bool requiresEndRender = false;
const Particle* startParticle = &_particles[0];
if (startParticle->getShape() != Particle::USER)
{
startParticle->beginRender(gl);
requiresEndRender = true;
}
else
{
// Enable writing depth mask when drawing user-defined particles
glDepthMask(GL_TRUE);
}
startParticle->beginRender(gl);
requiresEndRender = true;
for(unsigned int i=0; i<_particles.size(); i+=_detail)
{
@@ -435,28 +428,13 @@ void osgParticle::ParticleSystem::single_pass_render(osg::RenderInfo& renderInfo
{
startParticle->endRender(gl);
startParticle = currentParticle;
if (currentParticle->getShape() != Particle::USER)
{
currentParticle->beginRender(gl);
requiresEndRender = true;
glDepthMask(GL_FALSE);
}
else
glDepthMask(GL_TRUE);
currentParticle->beginRender(gl);
requiresEndRender = true;
glDepthMask(GL_FALSE);
}
++_draw_count;
if (currentParticle->getShape() == Particle::USER)
{
if (requiresEndRender)
{
startParticle->endRender(gl);
requiresEndRender = false;
}
currentParticle->render(renderInfo, currentParticle->getPosition(), currentParticle->getAngle());
continue;
}
const osg::Vec3& angle = currentParticle->getAngle();
bool requiresRotation = (angle.x()!=0.0f || angle.y()!=0.0f || angle.z()!=0.0f);
if (requiresRotation)

View File

@@ -165,15 +165,6 @@ bool read_particle(osgDB::Input &fr, osgParticle::Particle &P)
}
++fr;
}
if (fr[0].matchWord("drawable") && fr[1].matchString("{")) {
fr += 2;
itAdvanced = true;
osg::Drawable *drawable = dynamic_cast<osg::Drawable *>(fr.readObject());
if (drawable) {
P.setDrawable(drawable);
}
++fr;
}
}
return true;
}
@@ -250,14 +241,6 @@ void write_particle(const osgParticle::Particle &P, osgDB::Output &fw)
fw.moveOut();
fw.indent() << "}" << std::endl;
if ( P.getDrawable() != NULL ) {
fw.indent() << "drawable {" << std::endl;
fw.moveIn();
fw.writeObject(*P.getDrawable());
fw.moveOut();
fw.indent() << "}" << std::endl;
}
fw.moveOut();
fw.indent() << "}" << std::endl;
}

View File

@@ -69,15 +69,19 @@ bool readParticle( osgDB::InputStream& is, osgParticle::Particle& p )
p.setAngularVelocity( angleV );
p.setTextureTile( s, t, num );
bool hasObject = false; is >> is.PROPERTY("Drawable") >> hasObject;
if ( hasObject )
if (is.getFileVersion()<145)
{
is >> is.BEGIN_BRACKET;
p.setDrawable( is.readObjectOfType<osg::Drawable>() );
bool hasObject = false; is >> is.PROPERTY("Drawable") >> hasObject;
if ( hasObject )
{
is >> is.BEGIN_BRACKET;
osg::ref_ptr<osg::Drawable> drawable = is.readObjectOfType<osg::Drawable>();
OSG_NOTICE<<"Warning: read osgParticle::Particle with USER defined Drawable which is no longer supported."<<std::endl;
is >> is.END_BRACKET;
}
is >> is.END_BRACKET;
}
is >> is.END_BRACKET;
return true;
}
@@ -111,15 +115,6 @@ bool writeParticle( osgDB::OutputStream& os, const osgParticle::Particle& p )
os << os.PROPERTY("AngularVelocity") << osg::Vec3d(p.getAngularVelocity()) << std::endl;
os << os.PROPERTY("TextureTile") << p.getTileS() << p.getTileT() << p.getNumTiles() << std::endl;
os << os.PROPERTY("Drawable") << (p.getDrawable()!=NULL);
if ( p.getDrawable()!=NULL )
{
os << os.BEGIN_BRACKET << std::endl;
os.writeObject( p.getDrawable() );
os << os.END_BRACKET;
}
os << std::endl;
os << os.END_BRACKET << std::endl;
return true;
}