Can anyone explain why this seems to be the source of intermittent slowdown?

Started by
9 comments, last by Sean_Seanston 9 years, 3 months ago

Are you uploading all data evertime you want to draw an object? Dont.

It's been a while since I wrote the OpenGL code, or did much else with OpenGL either, so I might be having trouble understand things clearly right now...

But... I think I see what you mean...

I think my reasoning might have been based on the assumption that the text objects might change a lot and therefore would need to be updated often, however if I understand it right looking at it now then I'm currently calling glBufferData() every time the scene is rendered, where I only need to call it at most every time the game logic is updated (and probably less often - only whenever it's changed),

i.e. I could calculate the data every logic frame -> bind the appropriate buffer, call glBufferData() to fill the buffer with data -> then continue as normal before binding the buffer during the rendering phase and calling glEnableVertexAttribArray() etc. just before glDrawArrays()?

Is that roughly correct? Seems to make sense to me, if I still understand how OpenGL works.

So, the slowdown is in the function that writes to the buffer, and you do have one VBO object per sprite drawing object, right?

I believe that's correct. Except actually that I'm using 2 VBOs ... one for the modelview matrix and one for texture coordinates. Probably a leftover from trying to keep things simple when I was coding it first and just trying to get things to work. Is that another bad idea in itself, or would it not be likely to cause any significant performance hit?

Do you understand how the GPU works? When you call the glDraw function, drawing is not finished when the function returns. It gets queued up as a GPU job. All of the memory involved with that draw call cannot be overwritten until the GPU job finishes. You don't get stuck waiting until you try to reuse it.

That's very interesting... I did not actually know that. Sounds like what's happening here alright...

I would expect OpenGL to have something like this as well. Here's a page I found that seems to be helpful:

https://www.opengl.org/wiki/Buffer_Object_Streaming

In the end, if you want to render two dynamic things at the same time, they need to use two separate buffers, two separate parts of the same buffer with the correct flags, or the second one needs to wait for the first one to finish.

A quick read of that makes it sound like it's for exactly what I was trying to do...

As for a practical solution to my specific problem; you mention using 2 separate buffers as one option, I suppose that essentially means that in this case I should probably just use a separate object (with its own VBO/s) for each distinct item of text to be drawn?

This topic is closed to new replies.

Advertisement