Removed remaining glBegin/glEnd usage
This commit is contained in:
parent
e96642f864
commit
5e6415696f
@ -24,6 +24,7 @@
|
||||
#include <osg/Vec4>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/GL>
|
||||
#include <osg/GLBeginEndAdapter>
|
||||
|
||||
namespace osgParticle
|
||||
{
|
||||
@ -234,13 +235,13 @@ namespace osgParticle
|
||||
bool update(double dt);
|
||||
|
||||
/// Perform some pre-rendering tasks. Called automatically by particle systems.
|
||||
inline void beginRender() const;
|
||||
inline void beginRender(osg::GLBeginEndAdapter* gl) const;
|
||||
|
||||
/// Render the particle. Called automatically by particle systems.
|
||||
void render(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;
|
||||
|
||||
/// Perform some post-rendering tasks. Called automatically by particle systems.
|
||||
inline void endRender() const;
|
||||
inline void endRender(osg::GLBeginEndAdapter* gl) const;
|
||||
|
||||
/// Get the current (interpolated) polygon size. Valid only after the first call to update().
|
||||
inline float getCurrentSize() const;
|
||||
@ -530,41 +531,41 @@ namespace osgParticle
|
||||
_massinv = 1 / m;
|
||||
}
|
||||
|
||||
inline void Particle::beginRender() const
|
||||
inline void Particle::beginRender(osg::GLBeginEndAdapter* gl) const
|
||||
{
|
||||
switch (_shape)
|
||||
{
|
||||
case POINT:
|
||||
glBegin(GL_POINTS);
|
||||
gl->Begin(GL_POINTS);
|
||||
break;
|
||||
case QUAD:
|
||||
glBegin(GL_QUADS);
|
||||
gl->Begin(GL_QUADS);
|
||||
break;
|
||||
case LINE:
|
||||
glBegin(GL_LINES);
|
||||
gl->Begin(GL_LINES);
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
inline void Particle::endRender() const
|
||||
|
||||
inline void Particle::endRender(osg::GLBeginEndAdapter* gl) const
|
||||
{
|
||||
switch (_shape)
|
||||
{
|
||||
{
|
||||
case POINT:
|
||||
case QUAD:
|
||||
case LINE:
|
||||
glEnd();
|
||||
gl->End();
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline float Particle::getCurrentSize() const
|
||||
{
|
||||
return _current_size;
|
||||
}
|
||||
|
||||
|
||||
inline void Particle::setTextureTile(int sTile, int tTile, int numTiles)
|
||||
{
|
||||
_s_tile = (sTile>0) ? 1.0f / static_cast<float>(sTile) : 1.0f;
|
||||
|
@ -115,6 +115,7 @@ void ConnectedParticleSystem::reuseParticle(int particleIndex)
|
||||
void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) const
|
||||
{
|
||||
osg::State& state = *renderInfo.getState();
|
||||
osg::GLBeginEndAdapter& gl = state.getGLBeginEndAdapter();
|
||||
|
||||
ScopedReadLock lock(_readWriteMutex);
|
||||
|
||||
@ -127,21 +128,21 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co
|
||||
float pixelSizeOfFirstParticle = unitPixelSize * particle->getCurrentSize();
|
||||
//float desiredGapBetweenDrawnParticles = 50.0f/unitPixelSize;
|
||||
//float desiredGapBetweenDrawnParticles2 = desiredGapBetweenDrawnParticles*desiredGapBetweenDrawnParticles;
|
||||
|
||||
|
||||
float maxPixelError2 = osg::square(1.0f/unitPixelSize);
|
||||
|
||||
|
||||
if (pixelSizeOfFirstParticle<1.0)
|
||||
{
|
||||
// draw the connected particles as a line
|
||||
glBegin(GL_LINE_STRIP);
|
||||
gl.Begin(GL_LINE_STRIP);
|
||||
while(particle != 0)
|
||||
{
|
||||
|
||||
const osg::Vec4& color = particle->getCurrentColor();
|
||||
const osg::Vec3& pos = particle->getPosition();
|
||||
glColor4f( color.r(), color.g(), color.b(), color.a() * particle->getCurrentAlpha());
|
||||
glTexCoord2f( particle->getSTexCoord(), 0.5f );
|
||||
glVertex3fv(pos.ptr());
|
||||
gl.Color4f( color.r(), color.g(), color.b(), color.a() * particle->getCurrentAlpha());
|
||||
gl.TexCoord2f( particle->getSTexCoord(), 0.5f );
|
||||
gl.Vertex3fv(pos.ptr());
|
||||
|
||||
const Particle* nextParticle = (particle->getNextParticle() != Particle::INVALID_INDEX) ? &_particles[particle->getNextParticle()] : 0;
|
||||
if (nextParticle)
|
||||
@ -164,7 +165,7 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co
|
||||
}
|
||||
particle = nextParticle;
|
||||
}
|
||||
glEnd();
|
||||
gl.End();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -175,15 +176,15 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co
|
||||
osg::Vec3 eyeLocal = osg::Vec3(0.0f,0.0,0.0f)*eyeToLocalTransform;
|
||||
|
||||
osg::Vec3 delta(0.0f,0.0f,1.0f);
|
||||
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
|
||||
gl.Begin(GL_QUAD_STRIP);
|
||||
while(particle != 0)
|
||||
{
|
||||
const osg::Vec4& color = particle->getCurrentColor();
|
||||
const osg::Vec3& pos = particle->getPosition();
|
||||
|
||||
const Particle* nextParticle = (particle->getNextParticle() != Particle::INVALID_INDEX) ? &_particles[particle->getNextParticle()] : 0;
|
||||
|
||||
|
||||
if (nextParticle)
|
||||
{
|
||||
const osg::Vec3& nextPos = nextParticle->getPosition();
|
||||
@ -204,27 +205,25 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co
|
||||
|
||||
delta = nextPos-pos;
|
||||
}
|
||||
|
||||
|
||||
osg::Vec3 normal( delta ^ (pos-eyeLocal));
|
||||
normal.normalize();
|
||||
normal *= particle->getCurrentSize();
|
||||
|
||||
osg::Vec3 bottom(pos-normal);
|
||||
osg::Vec3 top(pos+normal);
|
||||
|
||||
glColor4f( color.r(), color.g(), color.b(), color.a() * particle->getCurrentAlpha());
|
||||
|
||||
glTexCoord2f( particle->getSTexCoord(), 0.0f );
|
||||
glVertex3fv(bottom.ptr());
|
||||
|
||||
glTexCoord2f( particle->getSTexCoord(), 1.0f );
|
||||
glVertex3fv(top.ptr());
|
||||
gl.Color4f( color.r(), color.g(), color.b(), color.a() * particle->getCurrentAlpha());
|
||||
|
||||
gl.TexCoord2f( particle->getSTexCoord(), 0.0f );
|
||||
gl.Vertex3fv(bottom.ptr());
|
||||
|
||||
gl.TexCoord2f( particle->getSTexCoord(), 1.0f );
|
||||
gl.Vertex3fv(top.ptr());
|
||||
|
||||
particle = nextParticle;
|
||||
}
|
||||
glEnd();
|
||||
gl.End();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -123,11 +123,11 @@ bool osgParticle::Particle::update(double dt)
|
||||
return true;
|
||||
}
|
||||
|
||||
void osgParticle::Particle::render(const osg::Vec3& xpos, const osg::Vec3& px, const osg::Vec3& py, float scale) const
|
||||
void osgParticle::Particle::render(osg::GLBeginEndAdapter* gl, const osg::Vec3& xpos, const osg::Vec3& px, const osg::Vec3& py, float scale) const
|
||||
{
|
||||
glColor4f( _current_color.x(),
|
||||
_current_color.y(),
|
||||
_current_color.z(),
|
||||
gl->Color4f( _current_color.x(),
|
||||
_current_color.y(),
|
||||
_current_color.z(),
|
||||
_current_color.w() * _current_alpha);
|
||||
|
||||
osg::Vec3 p1(px * _current_size * scale);
|
||||
@ -135,73 +135,74 @@ void osgParticle::Particle::render(const osg::Vec3& xpos, const osg::Vec3& px, c
|
||||
|
||||
switch (_shape)
|
||||
{
|
||||
case POINT:
|
||||
glVertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||
case POINT:
|
||||
gl->Vertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||
break;
|
||||
|
||||
case QUAD:
|
||||
glTexCoord2f(_s_coord, _t_coord);
|
||||
glVertex3fv((xpos-(p1+p2)).ptr());
|
||||
glTexCoord2f(_s_coord+_s_tile, _t_coord);
|
||||
glVertex3fv((xpos+(p1-p2)).ptr());
|
||||
glTexCoord2f(_s_coord+_s_tile, _t_coord+_t_tile);
|
||||
glVertex3fv((xpos+(p1+p2)).ptr());
|
||||
glTexCoord2f(_s_coord, _t_coord+_t_tile);
|
||||
glVertex3fv((xpos-(p1-p2)).ptr());
|
||||
gl->TexCoord2f(_s_coord, _t_coord);
|
||||
gl->Vertex3fv((xpos-(p1+p2)).ptr());
|
||||
gl->TexCoord2f(_s_coord+_s_tile, _t_coord);
|
||||
gl->Vertex3fv((xpos+(p1-p2)).ptr());
|
||||
gl->TexCoord2f(_s_coord+_s_tile, _t_coord+_t_tile);
|
||||
gl->Vertex3fv((xpos+(p1+p2)).ptr());
|
||||
gl->TexCoord2f(_s_coord, _t_coord+_t_tile);
|
||||
gl->Vertex3fv((xpos-(p1-p2)).ptr());
|
||||
break;
|
||||
|
||||
case QUAD_TRIANGLESTRIP:
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
// we must glBegin() and glEnd() here, because each particle is a single strip
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(_s_coord+_s_tile, _t_coord+_t_tile);
|
||||
glVertex3fv((p1+p2).ptr());
|
||||
glTexCoord2f(_s_coord, _t_coord+_t_tile);
|
||||
glVertex3fv((-p1+p2).ptr());
|
||||
glTexCoord2f(_s_coord+_s_tile, _t_coord);
|
||||
glVertex3fv((p1-p2).ptr());
|
||||
glTexCoord2f(_s_coord, _t_coord);
|
||||
glVertex3fv((-p1-p2).ptr());
|
||||
glPopMatrix();
|
||||
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:
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
// we must glBegin() and glEnd() here, because each particle is a single fan
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glTexCoord2f(_s_coord + _s_tile * 0.5f, _t_coord + _t_tile * 0.5f);
|
||||
glVertex3f(0,0,0);
|
||||
glTexCoord2f(_s_coord + _s_tile * hex_texcoord_x1, _t_coord + _t_tile * hex_texcoord_y1);
|
||||
glVertex3fv((p1*cosPI3+p2*sinPI3).ptr());
|
||||
glTexCoord2f(_s_coord + _s_tile * hex_texcoord_x2, _t_coord + _t_tile * hex_texcoord_y1);
|
||||
glVertex3fv((-p1*cosPI3+p2*sinPI3).ptr());
|
||||
glTexCoord2f(_s_coord, _t_coord + _t_tile * 0.5f);
|
||||
glVertex3fv((-p1).ptr());
|
||||
glTexCoord2f(_s_coord + _s_tile * hex_texcoord_x2, _t_coord + _t_tile * hex_texcoord_y2);
|
||||
glVertex3fv((-p1*cosPI3-p2*sinPI3).ptr());
|
||||
glTexCoord2f(_s_coord + _s_tile * hex_texcoord_x1, _t_coord + _t_tile * hex_texcoord_y2);
|
||||
glVertex3fv((p1*cosPI3-p2*sinPI3).ptr());
|
||||
glTexCoord2f(_s_coord + _s_tile, _t_coord + _t_tile * 0.5f);
|
||||
glVertex3fv((p1).ptr());
|
||||
glTexCoord2f(_s_coord + _s_tile * hex_texcoord_x1, _t_coord + _t_tile * hex_texcoord_y1);
|
||||
glVertex3fv((p1*cosPI3+p2*sinPI3).ptr());
|
||||
glEnd();
|
||||
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();
|
||||
break;
|
||||
|
||||
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
|
||||
// calculation of one of the linesegment endpoints.
|
||||
float vl = _velocity.length();
|
||||
if (vl != 0) {
|
||||
osg::Vec3 v = _velocity * _current_size * scale / vl;
|
||||
|
||||
glTexCoord1f(0);
|
||||
glVertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||
glTexCoord1f(1);
|
||||
glVertex3f(xpos.x() + v.x(), xpos.y() + v.y(), xpos.z() + v.z());
|
||||
gl->TexCoord1f(0);
|
||||
gl->Vertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||
gl->TexCoord1f(1);
|
||||
gl->Vertex3f(xpos.x() + v.x(), xpos.y() + v.y(), xpos.z() + v.z());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -168,30 +168,32 @@ void osgParticle::ParticleSystem::setDefaultAttributes(const std::string& textur
|
||||
}
|
||||
|
||||
|
||||
void osgParticle::ParticleSystem::single_pass_render(osg::State& /*state*/, const osg::Matrix& modelview) const
|
||||
void osgParticle::ParticleSystem::single_pass_render(osg::State& state, const osg::Matrix& modelview) const
|
||||
{
|
||||
_draw_count = 0;
|
||||
if (_particles.size() <= 0) return;
|
||||
|
||||
osg::GLBeginEndAdapter* gl = &state.getGLBeginEndAdapter();
|
||||
|
||||
float scale = sqrtf(static_cast<float>(_detail));
|
||||
|
||||
|
||||
const Particle* startParticle = &_particles[0];
|
||||
startParticle->beginRender();
|
||||
startParticle->beginRender(gl);
|
||||
|
||||
osg::Vec3 xAxis = _align_X_axis;
|
||||
osg::Vec3 yAxis = _align_Y_axis;
|
||||
|
||||
|
||||
osg::Vec3 scaled_aligned_xAxis = _align_X_axis;
|
||||
osg::Vec3 scaled_aligned_yAxis = _align_Y_axis;
|
||||
|
||||
float xScale = 1.0f;
|
||||
float yScale = 1.0f;
|
||||
|
||||
|
||||
if (_alignment==BILLBOARD)
|
||||
{
|
||||
xAxis = osg::Matrix::transform3x3(modelview,_align_X_axis);
|
||||
yAxis = osg::Matrix::transform3x3(modelview,_align_Y_axis);
|
||||
|
||||
|
||||
float lengthX2 = xAxis.length2();
|
||||
float lengthY2 = yAxis.length2();
|
||||
|
||||
@ -220,8 +222,8 @@ void osgParticle::ParticleSystem::single_pass_render(osg::State& /*state*/, con
|
||||
{
|
||||
if (currentParticle->getShape() != startParticle->getShape())
|
||||
{
|
||||
startParticle->endRender();
|
||||
currentParticle->beginRender();
|
||||
startParticle->endRender(gl);
|
||||
currentParticle->beginRender(gl);
|
||||
startParticle = currentParticle;
|
||||
}
|
||||
++_draw_count;
|
||||
@ -244,24 +246,24 @@ void osgParticle::ParticleSystem::single_pass_render(osg::State& /*state*/, con
|
||||
yAxis = osg::Matrix::transform3x3(R,scaled_aligned_yAxis);
|
||||
yAxis = osg::Matrix::transform3x3(modelview,yAxis);
|
||||
|
||||
currentParticle->render(currentParticle->getPosition(), xAxis, yAxis, scale);
|
||||
currentParticle->render(gl,currentParticle->getPosition(), xAxis, yAxis, scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
xAxis = osg::Matrix::transform3x3(R, scaled_aligned_xAxis);
|
||||
yAxis = osg::Matrix::transform3x3(R, scaled_aligned_yAxis);
|
||||
|
||||
currentParticle->render(currentParticle->getPosition(), xAxis, yAxis, scale);
|
||||
currentParticle->render(gl,currentParticle->getPosition(), xAxis, yAxis, scale);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentParticle->render(currentParticle->getPosition(), xAxis, yAxis, scale);
|
||||
currentParticle->render(gl,currentParticle->getPosition(), xAxis, yAxis, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startParticle->endRender();
|
||||
startParticle->endRender(gl);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user