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:
parent
c637010c9d
commit
56ed225f17
@ -89,9 +89,6 @@ int main( int argc, char** argv )
|
|||||||
double visibilityDistance = -1.0f;
|
double visibilityDistance = -1.0f;
|
||||||
while ( arguments.read("--visibility", visibilityDistance) ) {}
|
while ( arguments.read("--visibility", visibilityDistance) ) {}
|
||||||
|
|
||||||
bool customShape = false;
|
|
||||||
while ( arguments.read("--enable-custom") ) { customShape = true; }
|
|
||||||
|
|
||||||
bool useShaders = true;
|
bool useShaders = true;
|
||||||
while ( arguments.read("--disable-shaders") ) { useShaders = false; }
|
while ( arguments.read("--disable-shaders") ) { useShaders = false; }
|
||||||
|
|
||||||
@ -102,20 +99,8 @@ int main( int argc, char** argv )
|
|||||||
|
|
||||||
ps->getDefaultParticleTemplate().setLifeTime( 5.0f );
|
ps->getDefaultParticleTemplate().setLifeTime( 5.0f );
|
||||||
|
|
||||||
if ( customShape )
|
|
||||||
{
|
|
||||||
// osgParticle now supports making use of customized drawables. The draw() method will be executed
|
|
||||||
// and display lists will be called for each particle. It is always a huge consumption of memory, and
|
|
||||||
// hardly to use shaders to render them, so please be careful using this feature.
|
|
||||||
ps->getDefaultParticleTemplate().setShape( osgParticle::Particle::USER );
|
|
||||||
ps->getDefaultParticleTemplate().setDrawable( new osg::ShapeDrawable(new osg::Box(osg::Vec3(), 1.0f)) );
|
|
||||||
useShaders = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// The shader only supports rendering points at present.
|
// The shader only supports rendering points at present.
|
||||||
ps->getDefaultParticleTemplate().setShape( osgParticle::Particle::POINT );
|
ps->getDefaultParticleTemplate().setShape( osgParticle::Particle::POINT );
|
||||||
}
|
|
||||||
|
|
||||||
// Set the visibility distance of particles, due to their Z-value in the eye coordinates.
|
// Set the visibility distance of particles, due to their Z-value in the eye coordinates.
|
||||||
// Particles that are out of the distance (or behind the eye) will not be rendered.
|
// Particles that are out of the distance (or behind the eye) will not be rendered.
|
||||||
|
@ -63,10 +63,10 @@ namespace osgParticle
|
|||||||
enum Shape {
|
enum Shape {
|
||||||
POINT, // uses GL_POINTS as primitive
|
POINT, // uses GL_POINTS as primitive
|
||||||
QUAD, // uses GL_QUADS as primitive
|
QUAD, // uses GL_QUADS as primitive
|
||||||
QUAD_TRIANGLESTRIP, // uses GL_TRI_angleSTRIP as primitive, but each particle needs a glBegin/glEnd pair
|
QUAD_TRIANGLESTRIP, // no longer supported, falls back to QUAD
|
||||||
HEXAGON, // may save some filling time, but uses more triangles
|
HEXAGON, // no longer supported, falls back to QUAD
|
||||||
LINE, // uses GL_LINES to draw line segments that point to the direction of motion
|
LINE, // uses GL_LINES to draw line segments that point to the direction of motion
|
||||||
USER // uses a user-defined drawable as primitive
|
USER // no longer supported, falls back to QUAD
|
||||||
};
|
};
|
||||||
|
|
||||||
Particle();
|
Particle();
|
||||||
@ -246,9 +246,6 @@ namespace osgParticle
|
|||||||
/// Render the particle. Called automatically by particle systems.
|
/// Render the particle. Called automatically by particle systems.
|
||||||
void render(osg::GLBeginEndAdapter* gl, const osg::Vec3& xpos, const osg::Vec3& px, const osg::Vec3& py, float scale = 1.0f) const;
|
void render(osg::GLBeginEndAdapter* gl, const osg::Vec3& xpos, const osg::Vec3& px, const osg::Vec3& py, float scale = 1.0f) const;
|
||||||
|
|
||||||
/// Render the particle with user-defined drawable
|
|
||||||
void render(osg::RenderInfo& renderInfo, const osg::Vec3& xpos, const osg::Vec3& xrot) const;
|
|
||||||
|
|
||||||
/// Perform some post-rendering tasks. Called automatically by particle systems.
|
/// Perform some post-rendering tasks. Called automatically by particle systems.
|
||||||
inline void endRender(osg::GLBeginEndAdapter* gl) const;
|
inline void endRender(osg::GLBeginEndAdapter* gl) const;
|
||||||
|
|
||||||
@ -285,13 +282,6 @@ namespace osgParticle
|
|||||||
/// Get the depth of the particle
|
/// Get the depth of the particle
|
||||||
inline double getDepth() const { return _depth; }
|
inline double getDepth() const { return _depth; }
|
||||||
|
|
||||||
/// Set the user-defined particle drawable
|
|
||||||
inline void setDrawable(osg::Drawable* d) { _drawable = d; }
|
|
||||||
template<class T> void setDrawable(const osg::ref_ptr<T>& ri) { setDrawable(ri.get()); }
|
|
||||||
|
|
||||||
/// Get the user-defined particle drawable
|
|
||||||
inline osg::Drawable* getDrawable() const { return _drawable.get(); }
|
|
||||||
|
|
||||||
/// Sorting operator
|
/// Sorting operator
|
||||||
bool operator<(const Particle &P) const { return _depth < P._depth; }
|
bool operator<(const Particle &P) const { return _depth < P._depth; }
|
||||||
|
|
||||||
@ -346,9 +336,6 @@ namespace osgParticle
|
|||||||
|
|
||||||
// the depth of the particle is used only when sorting is enabled
|
// the depth of the particle is used only when sorting is enabled
|
||||||
double _depth;
|
double _depth;
|
||||||
|
|
||||||
// the particle drawable is used only when USER shape is enabled
|
|
||||||
osg::ref_ptr<osg::Drawable> _drawable;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// INLINE FUNCTIONS
|
// INLINE FUNCTIONS
|
||||||
|
@ -145,7 +145,10 @@ void osgParticle::Particle::render(osg::GLBeginEndAdapter* gl, const osg::Vec3&
|
|||||||
gl->Vertex3f(xpos.x(), xpos.y(), xpos.z());
|
gl->Vertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case USER:
|
||||||
case QUAD:
|
case QUAD:
|
||||||
|
case QUAD_TRIANGLESTRIP:
|
||||||
|
case HEXAGON:
|
||||||
gl->TexCoord2f(_s_coord, _t_coord);
|
gl->TexCoord2f(_s_coord, _t_coord);
|
||||||
gl->Vertex3fv((xpos-(p1+p2)).ptr());
|
gl->Vertex3fv((xpos-(p1+p2)).ptr());
|
||||||
gl->TexCoord2f(_s_coord+_s_tile, _t_coord);
|
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());
|
gl->Vertex3fv((xpos-(p1-p2)).ptr());
|
||||||
break;
|
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:
|
case LINE:
|
||||||
{
|
{
|
||||||
// Get the normalized direction of the particle, to be used in the
|
// 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)
|
void osgParticle::Particle::setUpTexCoordsAsPartOfConnectedParticleSystem(ParticleSystem* ps)
|
||||||
{
|
{
|
||||||
if (getPreviousParticle()!=Particle::INVALID_INDEX)
|
if (getPreviousParticle()!=Particle::INVALID_INDEX)
|
||||||
|
@ -410,16 +410,9 @@ void osgParticle::ParticleSystem::single_pass_render(osg::RenderInfo& renderInfo
|
|||||||
|
|
||||||
bool requiresEndRender = false;
|
bool requiresEndRender = false;
|
||||||
const Particle* startParticle = &_particles[0];
|
const Particle* startParticle = &_particles[0];
|
||||||
if (startParticle->getShape() != Particle::USER)
|
|
||||||
{
|
|
||||||
startParticle->beginRender(gl);
|
startParticle->beginRender(gl);
|
||||||
requiresEndRender = true;
|
requiresEndRender = true;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Enable writing depth mask when drawing user-defined particles
|
|
||||||
glDepthMask(GL_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(unsigned int i=0; i<_particles.size(); i+=_detail)
|
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->endRender(gl);
|
||||||
startParticle = currentParticle;
|
startParticle = currentParticle;
|
||||||
if (currentParticle->getShape() != Particle::USER)
|
|
||||||
{
|
|
||||||
currentParticle->beginRender(gl);
|
currentParticle->beginRender(gl);
|
||||||
requiresEndRender = true;
|
requiresEndRender = true;
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
glDepthMask(GL_TRUE);
|
|
||||||
}
|
|
||||||
++_draw_count;
|
++_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();
|
const osg::Vec3& angle = currentParticle->getAngle();
|
||||||
bool requiresRotation = (angle.x()!=0.0f || angle.y()!=0.0f || angle.z()!=0.0f);
|
bool requiresRotation = (angle.x()!=0.0f || angle.y()!=0.0f || angle.z()!=0.0f);
|
||||||
if (requiresRotation)
|
if (requiresRotation)
|
||||||
|
@ -165,15 +165,6 @@ bool read_particle(osgDB::Input &fr, osgParticle::Particle &P)
|
|||||||
}
|
}
|
||||||
++fr;
|
++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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -250,14 +241,6 @@ void write_particle(const osgParticle::Particle &P, osgDB::Output &fw)
|
|||||||
fw.moveOut();
|
fw.moveOut();
|
||||||
fw.indent() << "}" << std::endl;
|
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.moveOut();
|
||||||
fw.indent() << "}" << std::endl;
|
fw.indent() << "}" << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -69,15 +69,19 @@ bool readParticle( osgDB::InputStream& is, osgParticle::Particle& p )
|
|||||||
p.setAngularVelocity( angleV );
|
p.setAngularVelocity( angleV );
|
||||||
p.setTextureTile( s, t, num );
|
p.setTextureTile( s, t, num );
|
||||||
|
|
||||||
|
if (is.getFileVersion()<145)
|
||||||
|
{
|
||||||
bool hasObject = false; is >> is.PROPERTY("Drawable") >> hasObject;
|
bool hasObject = false; is >> is.PROPERTY("Drawable") >> hasObject;
|
||||||
if ( hasObject )
|
if ( hasObject )
|
||||||
{
|
{
|
||||||
is >> is.BEGIN_BRACKET;
|
is >> is.BEGIN_BRACKET;
|
||||||
p.setDrawable( is.readObjectOfType<osg::Drawable>() );
|
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;
|
is >> is.END_BRACKET;
|
||||||
|
}
|
||||||
return true;
|
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("AngularVelocity") << osg::Vec3d(p.getAngularVelocity()) << std::endl;
|
||||||
os << os.PROPERTY("TextureTile") << p.getTileS() << p.getTileT() << p.getNumTiles() << 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;
|
os << os.END_BRACKET << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user