I have to update a texture sparsely. That means, I need to update a few hundred, maybe thousand texels per frame, scattered across the texture (and mipmap levels). Currently I’m using render-to-texture via FBO, utilizing GL_POINTS in point sprite mode.
First, I collect all updates in a VBO (created with GL_STREAM_DRAW usage hint). The VBO gets updated via glMapBufferRange, GL_WRITE_BIT|GL_INVALIDATE_BIT. I write into that buffer sequentially. Once I’m done buffering all updates for the current mipmap level, I call glUnmapBuffer followed by a glDrawArrays call.
In order to update different mipmap levels of that texture, I need to re-attach the same texture several time per frame (thats up to 10 times for a 512x512 texture).
Depending on the excess of the updates, it takes between 0.x and 12ms. I want to speed that up but need some hints what to try first
I can think of several aspects, that may slow down this operation:
- The whole approach may be wrong
- The re-attachment of the different texture levels might cause an internal sync point. What about having a separate FBO for each level, then switch FBO instead of re-attaching the next texture level?
- The method of updating the VBO may be the wrong one (syncing again). Using glBufferData() or several VBOs may help?
- Scatter the updates in one level. Point drawing sometimes tends to slow down if many points get rendered nearby.
The program seems to spend alot of time in the kernel, which is mostly a sign for the driver doing much thread safety stuff.
I’d like to hear your opinion before I start to poke around