void UpdateParticle()
{
//printf("current particle buffer tfo %d %d\n",currentParticleTFO, currentParticleTFOForDraw);
int currentOldParticleBufferIndex = currentParticleTFOForDraw;
if (particleCount==-1)
{
particleCount++;
}
else
{
glGetQueryObjectiv(queryObject, GL_QUERY_RESULT,&particleCount);
}
GL_CALL(glEnable(GL_RASTERIZER_DISCARD));
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, updateParticleTFO[currentParticleTFO]);
glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, queryObject);
glUseProgram(updateParticleProgram);
glBeginTransformFeedback(GL_POINTS);
//new emitted particle update
if (bEmitNewParticle)
{
bEmitNewParticle = false;
//update particle : write new particle to some buffer via transform feedback technique
glBindBuffer(GL_ARRAY_BUFFER, tfoNewParticleBuffer);
glEnableVertexAttribArray(updateParticleProgramPosLocation);
glVertexAttribPointer(updateParticleProgramPosLocation, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDrawTransformFeedback(GL_POINTS, tfoNewParticle);
}
//update old particle : write old particle to some buffer via transform feedback technique
if (particleCount>0)
{
glBindBuffer(GL_ARRAY_BUFFER, updateParticleTFOBuffer[currentOldParticleBufferIndex]);
glEnableVertexAttribArray(updateParticleProgramPosLocation);
glVertexAttribPointer(updateParticleProgramPosLocation, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDrawTransformFeedback(GL_POINTS, updateParticleTFO[currentOldParticleBufferIndex]);
}
glEndTransformFeedback();
glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
glUseProgram(0);
glDisable(GL_RASTERIZER_DISCARD);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
currentParticleTFOForDraw = currentParticleTFO;
//glBindBuffer(GL_ARRAY_BUFFER, updateParticleTFOBuffer[currentParticleTFOForDraw]);
//FloatBundle*vertexes = (FloatBundle*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
//printf("%f,%f,%f,%f\n",vertexes[0].v[0], vertexes[0].v[1], vertexes[0].v[3], vertexes[0].v[3]);
//glUnmapBuffer(GL_ARRAY_BUFFER);
//glBindBuffer(GL_ARRAY_BUFFER, 0);
currentParticleTFO = (currentParticleTFO + 1) % 2;
}
transform feedback object 理解
最新推荐文章于 2024-11-07 23:44:50 发布