OpenGL Precompute Vertices/Matrices for Particle System / Optimization










0















I have a particle system which I want to make as really fast as possible without any effects on the main display function, I basically placed all particles calculations on a separate infinite thread which I keep synchronized with WaitForEvent() (Windows), DataLock flags, etc.



I use glColorPointer, glNormalPointer, glVertexPointer etc to point to the buffered data on the GPU (glGenBuffers, glBufferData) and then glDrawElements to render them.



At the moment I don't have the code so I hope that won't be a problem but I'll try my best to get the infrastructure described:




  • Main [Init]



    1. Create a pre-calc queue 30% in size of N particles and do sequential calculations (Thread 1 #2)



  • Thread 1



    1. Wait for Calculate Event signal or if pre-calc queue is not full then continue

    2. Loop through N particles and update position / velocity, storing it in pUpdate

    3. If pre-calc queue is not full, add pUpdate to it



  • Main [Render]



    1. glActiveTexture(TEXTURE0)

    2. glCol/glNorm/glTex/glVertexPointer

    3. If pre-calc is empty use the most recent pUpdate

    4. OR use one of the pre-calc and delete

    5. Store item in buffer using glBufferSubData()

    6. DrawElements() to draw them

    7. SwapBuffers


The problem is that the Render function uses about 50 pre-calc per second (which speeds up rendering while there are enough left) before 1 could even be added. In short order the pre-calc is empty so everything slows down and the program reverts to Main-Render #3



Any ideas?










share|improve this question
























  • Why aren't you performing the particle calculations on the GPU?

    – 3Dave
    Nov 14 '18 at 22:59











  • Alright thats a start! So how I worked it out is that the shader would basically do the Velocity and Positions calculations per vertex, how would I get the updated position back to the Client side so the next time it can be done again?

    – Takii Marskii
    Nov 14 '18 at 23:03











  • There are two ways of doing it on the GPU that I know of. You can either use transform feedback to update the VBO or use a texture to store the positions and render into the texture. Eitehr way you want to avoid copying the position back to the client (cpu) as that is an expensive operation.

    – Luple
    Nov 15 '18 at 0:34












  • I don't know which OpenGL version you're using, but if it's supported your best option is a compute shader with ssbo. You first update the particles in the ssbo with the compute shader, place a barrier and then draw using the same buffer as input for vertex shader.

    – Rhu Mage
    Nov 15 '18 at 7:28











  • @Luple Thanks so much I'll go and try both methods but honestly transform feedback seems to be my favourite

    – Takii Marskii
    Nov 15 '18 at 20:59















0















I have a particle system which I want to make as really fast as possible without any effects on the main display function, I basically placed all particles calculations on a separate infinite thread which I keep synchronized with WaitForEvent() (Windows), DataLock flags, etc.



I use glColorPointer, glNormalPointer, glVertexPointer etc to point to the buffered data on the GPU (glGenBuffers, glBufferData) and then glDrawElements to render them.



At the moment I don't have the code so I hope that won't be a problem but I'll try my best to get the infrastructure described:




  • Main [Init]



    1. Create a pre-calc queue 30% in size of N particles and do sequential calculations (Thread 1 #2)



  • Thread 1



    1. Wait for Calculate Event signal or if pre-calc queue is not full then continue

    2. Loop through N particles and update position / velocity, storing it in pUpdate

    3. If pre-calc queue is not full, add pUpdate to it



  • Main [Render]



    1. glActiveTexture(TEXTURE0)

    2. glCol/glNorm/glTex/glVertexPointer

    3. If pre-calc is empty use the most recent pUpdate

    4. OR use one of the pre-calc and delete

    5. Store item in buffer using glBufferSubData()

    6. DrawElements() to draw them

    7. SwapBuffers


The problem is that the Render function uses about 50 pre-calc per second (which speeds up rendering while there are enough left) before 1 could even be added. In short order the pre-calc is empty so everything slows down and the program reverts to Main-Render #3



Any ideas?










share|improve this question
























  • Why aren't you performing the particle calculations on the GPU?

    – 3Dave
    Nov 14 '18 at 22:59











  • Alright thats a start! So how I worked it out is that the shader would basically do the Velocity and Positions calculations per vertex, how would I get the updated position back to the Client side so the next time it can be done again?

    – Takii Marskii
    Nov 14 '18 at 23:03











  • There are two ways of doing it on the GPU that I know of. You can either use transform feedback to update the VBO or use a texture to store the positions and render into the texture. Eitehr way you want to avoid copying the position back to the client (cpu) as that is an expensive operation.

    – Luple
    Nov 15 '18 at 0:34












  • I don't know which OpenGL version you're using, but if it's supported your best option is a compute shader with ssbo. You first update the particles in the ssbo with the compute shader, place a barrier and then draw using the same buffer as input for vertex shader.

    – Rhu Mage
    Nov 15 '18 at 7:28











  • @Luple Thanks so much I'll go and try both methods but honestly transform feedback seems to be my favourite

    – Takii Marskii
    Nov 15 '18 at 20:59













0












0








0








I have a particle system which I want to make as really fast as possible without any effects on the main display function, I basically placed all particles calculations on a separate infinite thread which I keep synchronized with WaitForEvent() (Windows), DataLock flags, etc.



I use glColorPointer, glNormalPointer, glVertexPointer etc to point to the buffered data on the GPU (glGenBuffers, glBufferData) and then glDrawElements to render them.



At the moment I don't have the code so I hope that won't be a problem but I'll try my best to get the infrastructure described:




  • Main [Init]



    1. Create a pre-calc queue 30% in size of N particles and do sequential calculations (Thread 1 #2)



  • Thread 1



    1. Wait for Calculate Event signal or if pre-calc queue is not full then continue

    2. Loop through N particles and update position / velocity, storing it in pUpdate

    3. If pre-calc queue is not full, add pUpdate to it



  • Main [Render]



    1. glActiveTexture(TEXTURE0)

    2. glCol/glNorm/glTex/glVertexPointer

    3. If pre-calc is empty use the most recent pUpdate

    4. OR use one of the pre-calc and delete

    5. Store item in buffer using glBufferSubData()

    6. DrawElements() to draw them

    7. SwapBuffers


The problem is that the Render function uses about 50 pre-calc per second (which speeds up rendering while there are enough left) before 1 could even be added. In short order the pre-calc is empty so everything slows down and the program reverts to Main-Render #3



Any ideas?










share|improve this question
















I have a particle system which I want to make as really fast as possible without any effects on the main display function, I basically placed all particles calculations on a separate infinite thread which I keep synchronized with WaitForEvent() (Windows), DataLock flags, etc.



I use glColorPointer, glNormalPointer, glVertexPointer etc to point to the buffered data on the GPU (glGenBuffers, glBufferData) and then glDrawElements to render them.



At the moment I don't have the code so I hope that won't be a problem but I'll try my best to get the infrastructure described:




  • Main [Init]



    1. Create a pre-calc queue 30% in size of N particles and do sequential calculations (Thread 1 #2)



  • Thread 1



    1. Wait for Calculate Event signal or if pre-calc queue is not full then continue

    2. Loop through N particles and update position / velocity, storing it in pUpdate

    3. If pre-calc queue is not full, add pUpdate to it



  • Main [Render]



    1. glActiveTexture(TEXTURE0)

    2. glCol/glNorm/glTex/glVertexPointer

    3. If pre-calc is empty use the most recent pUpdate

    4. OR use one of the pre-calc and delete

    5. Store item in buffer using glBufferSubData()

    6. DrawElements() to draw them

    7. SwapBuffers


The problem is that the Render function uses about 50 pre-calc per second (which speeds up rendering while there are enough left) before 1 could even be added. In short order the pre-calc is empty so everything slows down and the program reverts to Main-Render #3



Any ideas?







c++ opengl optimization vbo particle-system






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 23:05









genpfault

42.1k95399




42.1k95399










asked Nov 14 '18 at 22:56









Takii MarskiiTakii Marskii

87




87












  • Why aren't you performing the particle calculations on the GPU?

    – 3Dave
    Nov 14 '18 at 22:59











  • Alright thats a start! So how I worked it out is that the shader would basically do the Velocity and Positions calculations per vertex, how would I get the updated position back to the Client side so the next time it can be done again?

    – Takii Marskii
    Nov 14 '18 at 23:03











  • There are two ways of doing it on the GPU that I know of. You can either use transform feedback to update the VBO or use a texture to store the positions and render into the texture. Eitehr way you want to avoid copying the position back to the client (cpu) as that is an expensive operation.

    – Luple
    Nov 15 '18 at 0:34












  • I don't know which OpenGL version you're using, but if it's supported your best option is a compute shader with ssbo. You first update the particles in the ssbo with the compute shader, place a barrier and then draw using the same buffer as input for vertex shader.

    – Rhu Mage
    Nov 15 '18 at 7:28











  • @Luple Thanks so much I'll go and try both methods but honestly transform feedback seems to be my favourite

    – Takii Marskii
    Nov 15 '18 at 20:59

















  • Why aren't you performing the particle calculations on the GPU?

    – 3Dave
    Nov 14 '18 at 22:59











  • Alright thats a start! So how I worked it out is that the shader would basically do the Velocity and Positions calculations per vertex, how would I get the updated position back to the Client side so the next time it can be done again?

    – Takii Marskii
    Nov 14 '18 at 23:03











  • There are two ways of doing it on the GPU that I know of. You can either use transform feedback to update the VBO or use a texture to store the positions and render into the texture. Eitehr way you want to avoid copying the position back to the client (cpu) as that is an expensive operation.

    – Luple
    Nov 15 '18 at 0:34












  • I don't know which OpenGL version you're using, but if it's supported your best option is a compute shader with ssbo. You first update the particles in the ssbo with the compute shader, place a barrier and then draw using the same buffer as input for vertex shader.

    – Rhu Mage
    Nov 15 '18 at 7:28











  • @Luple Thanks so much I'll go and try both methods but honestly transform feedback seems to be my favourite

    – Takii Marskii
    Nov 15 '18 at 20:59
















Why aren't you performing the particle calculations on the GPU?

– 3Dave
Nov 14 '18 at 22:59





Why aren't you performing the particle calculations on the GPU?

– 3Dave
Nov 14 '18 at 22:59













Alright thats a start! So how I worked it out is that the shader would basically do the Velocity and Positions calculations per vertex, how would I get the updated position back to the Client side so the next time it can be done again?

– Takii Marskii
Nov 14 '18 at 23:03





Alright thats a start! So how I worked it out is that the shader would basically do the Velocity and Positions calculations per vertex, how would I get the updated position back to the Client side so the next time it can be done again?

– Takii Marskii
Nov 14 '18 at 23:03













There are two ways of doing it on the GPU that I know of. You can either use transform feedback to update the VBO or use a texture to store the positions and render into the texture. Eitehr way you want to avoid copying the position back to the client (cpu) as that is an expensive operation.

– Luple
Nov 15 '18 at 0:34






There are two ways of doing it on the GPU that I know of. You can either use transform feedback to update the VBO or use a texture to store the positions and render into the texture. Eitehr way you want to avoid copying the position back to the client (cpu) as that is an expensive operation.

– Luple
Nov 15 '18 at 0:34














I don't know which OpenGL version you're using, but if it's supported your best option is a compute shader with ssbo. You first update the particles in the ssbo with the compute shader, place a barrier and then draw using the same buffer as input for vertex shader.

– Rhu Mage
Nov 15 '18 at 7:28





I don't know which OpenGL version you're using, but if it's supported your best option is a compute shader with ssbo. You first update the particles in the ssbo with the compute shader, place a barrier and then draw using the same buffer as input for vertex shader.

– Rhu Mage
Nov 15 '18 at 7:28













@Luple Thanks so much I'll go and try both methods but honestly transform feedback seems to be my favourite

– Takii Marskii
Nov 15 '18 at 20:59





@Luple Thanks so much I'll go and try both methods but honestly transform feedback seems to be my favourite

– Takii Marskii
Nov 15 '18 at 20:59












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309957%2fopengl-precompute-vertices-matrices-for-particle-system-optimization%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309957%2fopengl-precompute-vertices-matrices-for-particle-system-optimization%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党