ParticleSystem: Using of GL_TRIANGLES for GLES2 and upper; GL_QUADS otherwise

This commit is contained in:
Konstantin S. Matveyev 2018-09-05 19:00:29 +03:00
parent f00b7180cb
commit 637e1cc33b

View File

@ -394,16 +394,16 @@ void osgParticle::ParticleSystem::drawImplementation(osg::RenderInfo& renderInfo
case osgParticle::Particle::HEXAGON: case osgParticle::Particle::HEXAGON:
case osgParticle::Particle::QUAD: case osgParticle::Particle::QUAD:
{ {
osg::Vec3 c0(xpos-p1-p2); const osg::Vec3 c0(xpos-p1-p2);
osg::Vec2 t0(s_coord, t_coord); const osg::Vec2 t0(s_coord, t_coord);
osg::Vec3 c1(xpos+p1-p2); const osg::Vec3 c1(xpos+p1-p2);
osg::Vec2 t1(s_coord+s_tile, t_coord); const osg::Vec2 t1(s_coord+s_tile, t_coord);
osg::Vec3 c2(xpos+p1+p2); const osg::Vec3 c2(xpos+p1+p2);
osg::Vec2 t2(s_coord+s_tile, t_coord+t_tile); const osg::Vec2 t2(s_coord+s_tile, t_coord+t_tile);
osg::Vec3 c3(xpos-p1+p2); const osg::Vec3 c3(xpos-p1+p2);
osg::Vec2 t3(s_coord, t_coord+t_tile); const osg::Vec2 t3(s_coord, t_coord+t_tile);
// first triangle // First 3 points (and texcoords) of quad or triangle
vertices.push_back(c0); vertices.push_back(c0);
vertices.push_back(c1); vertices.push_back(c1);
vertices.push_back(c2); vertices.push_back(c2);
@ -411,24 +411,36 @@ void osgParticle::ParticleSystem::drawImplementation(osg::RenderInfo& renderInfo
texcoords.push_back(t1); texcoords.push_back(t1);
texcoords.push_back(t2); texcoords.push_back(t2);
// second triangle #if !defined(OSG_GLES2_AVAILABLE)
const unsigned int count = 4;
const GLenum mode = GL_QUADS;
// Last point (and texcoord) of quad
vertices.push_back(c3);
texcoords.push_back(t3);
#else
// No GL_QUADS mode on GLES2 and upper
const unsigned int count = 6;
const GLenum mode = GL_TRIANGLES;
// Second triangle
vertices.push_back(c2); vertices.push_back(c2);
vertices.push_back(c3); vertices.push_back(c3);
vertices.push_back(c0); vertices.push_back(c0);
texcoords.push_back(t2); texcoords.push_back(t2);
texcoords.push_back(t3); texcoords.push_back(t3);
texcoords.push_back(t0); texcoords.push_back(t0);
#endif
for (int j = 0; j < 6; ++j) for (unsigned int j = 0; j < count; ++j)
colors.push_back(color); colors.push_back(color);
if (!primitives.empty() && primitives.back().first==GL_TRIANGLES) if (!primitives.empty() && primitives.back().first == mode)
{ {
primitives.back().second+=6; primitives.back().second += count;
} }
else else
{ {
primitives.push_back(ArrayData::ModeCount(GL_TRIANGLES,6)); primitives.push_back(ArrayData::ModeCount(mode, count));
} }
break; break;