Draw a portion of a transform feedback buffer

Hello everyone.

I am using TF buffers to render precipitations.
I’d like to render more or less particles depending on precipitations intensity.

What is the best way to do that ?

Thank you.

The question you asked in your subject line is different than the one asked by your post.

To answer the former, you can chose which elements you are processing via Transform Feedback to emit with EmitStreamVertex(). You don’t have to emit them all.

To the latter, it depends on how you’re implementing it. Could be that selective emission is a good option. But it’s worth asking, why are you passing down elements that might not be rendered, and is there a way to avoid doing that altogether.

I think I know where my problem is coming from.

I implemented TF following that tutorial : OpenGL Step by Step - OpenGL Development

In this example, glDrawArrays is called only once at the first update so that the number of particles that are processed depends on the previous frame.

if (m_isFirst) {
        glDrawArrays(GL_POINTS, 0, 1);
        m_isFirst = false;
    }
    else {
        glDrawTransformFeedback(GL_POINTS, m_transformFeedback[m_currVB]);
    } 

If I want to update and draw only a part of my total amount of particles, I just have to call glDrawArrays() in my update function with the number of particles I want, right ?

[QUOTE=Vylsain;1259164]I think I know where my problem is coming from.

I implemented TF following that tutorial : OpenGL Step by Step - OpenGL Development

In this example, …the number of particles that are processed depends on the previous frame.[/QUOTE]
Right. He’s drawing the m_currVB TF, which is the TF result from the previous frame.

If I want to update and draw only a part of my total amount of particles, I just have to call glDrawArrays() in my update function with the number of particles I want, right ?

Possibly. There are a number of ways to do it. One way is to do what he’s doing and have this frame’s TF result be derived from last frame’s TF result, selectively emitting vertices (EmitVertex) as they are processed. Another option is to always throw them all down the pipe, and compute your in/out set from scratch using selective emission. There are other ways to do this too. Just depends on what maps best for your algorithm.

Ok !

The way I implemented it now seems appropriate.

Thank you Dark Photon. :wink: