You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to suggest a new feature for GLES3+ applications. Transform feedback allows updating VBOs on the GPU only and writing the results back to a sepereate feedback buffer. So sending data from the CPU to the GPU isn't necessary anymore. That data can then be used fro all the following drawing operations.
This type of updating VBOs benefits most if used with particle systems, since the movement of particles is controlled by a few forces and a lot of attributes. Those attributes can all be pushed into a VBO and then be transformed by a vertex shader. This updating process benefits of the huge parallelism possible on modern GPUs, instead of serialized or less parallel/concurrent updating on the CPU.
Compared to a normal batch, which sends updated data every frame via glBufferSubData, transform feedback can boost performance, in terms of updating vertex data, immensly. A IntelHD 4600 could update up to 400.000 vertices per frame and still draw the untextured scene with a good framerate of about 50fps.
Since there are already feature implemented with GL30 only access, like TextureArrays, I thought it might be a good feature to introduce to allow more complex scenes, with better performance on newer hardware.
What would be needed is a VeretxData class which is capable of doing transform feedback and a fitting Mesh class. There has to be a new Shader class since transform feedback shaders consist only of a vertex shader and optionally a geometry shader and output varyings have to be specified before linking the program.
Below is an example code of how to use the transform feedback. Please let me know if this feature is worth implementing it.
Reproduction steps/code
//begin setup
val floatsBuffer = BufferUtils.newFloatBuffer(100_000 * 8)
/*fill buffer with data*/
val srcBuffer = gl20.glGenBuffer()
gl20.glBindBuffer(GL_ARRAY_BUFFER, srcBuffer)
gl20.glBufferData(GL_ARRAY_BUFFER, floatsBuffer.limit() * 4, floatsBuffer, GL20.GL_DYNAMIC_DRAW)
val swapBuffer = gl20.glGenBuffer()
gl20.glBindBuffer(GL_ARRAY_BUFFER, swapBuffer)
gl20.glBufferData(GL_ARRAY_BUFFER, floatsBuffer.limit() * 4, null, GL20.GL_DYNAMIC_DRAW)
val intsBuffer = BufferUtils.newIntBuffer(100_000 * 6)
/*fill buffer with indices*/
val ebo = gl20.glGenBuffer()
gl20.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, ebo)
gl20.glBufferData(GL20.GL_ELEMENT_ARRAY_BUFFER, intsBuffer.limit() * 4, intsBuffer, GL20.GL_STATIC_DRAW)
val tfShader = TFShaderProgram(" . . . ") //mod of Shaderprogram with only vertex shader
//end setup
//...
//begin render
gl20.glBindBuffer(GL_ARRAY_BUFFER, srcBuffer)
gl20.glEnableVertexAttribArray(0)
gl20.glVertexAttribPointer(0, 2, GL_FLOAT, false, 2 * 4, 0)
gl30?.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, swapBuffer)
tfShader.begin()
gl20.glEnable(GL_RASTERIZER_DISCARD) //disable drawing to screen
gl30?.glBeginTransformFeedback(GL_POINTS)
gl20.glDrawArrays(GL_POINTS, 0, 4 * 100_000) //transform data according to bound shader
gl30?.glEndTransformFeedback()
gl20.glDisable(GL_RASTERIZER_DISCARD)
tfShader.end()
vbo = tbo.also { tbo = vbo } //swap srcBuffer and swapBuffer pointers
gl20.glBindBuffer(GL_ARRAY_BUFFER, srcBuffer) //binding the transformed srcBuffer data
gl20.glEnableVertexAttribArray(0)
gl20.glVertexAttribPointer(0, 2, GL_FLOAT, false, 2 * 4, 0)
gl20.glDrawElements(GL_TRIANGLES, 6 * 100_000, GL_UNSIGNED_INT, 0) //drawing transformed data
//end render
Version of LibGDX and/or relevant dependencies
(Dependency) OpenGL 3+ / OpenGLES 3+ / WebGL 2
Please select the affected platforms
Android
iOS (robovm)
iOS (MOE)
HTML/GWT
Windows
Linux
MacOS
The text was updated successfully, but these errors were encountered:
It would be great to have this feature !
FYI i have a pending PR allowing any combinaition of shaders including the "vertex shader only case" : https://github.com/libgdx/libgdx/pull/4963/files
I wanted to suggest a new feature for GLES3+ applications. Transform feedback allows updating VBOs on the GPU only and writing the results back to a sepereate feedback buffer. So sending data from the CPU to the GPU isn't necessary anymore. That data can then be used fro all the following drawing operations.
This type of updating VBOs benefits most if used with particle systems, since the movement of particles is controlled by a few forces and a lot of attributes. Those attributes can all be pushed into a VBO and then be transformed by a vertex shader. This updating process benefits of the huge parallelism possible on modern GPUs, instead of serialized or less parallel/concurrent updating on the CPU.
Compared to a normal batch, which sends updated data every frame via glBufferSubData, transform feedback can boost performance, in terms of updating vertex data, immensly. A IntelHD 4600 could update up to 400.000 vertices per frame and still draw the untextured scene with a good framerate of about 50fps.
Since there are already feature implemented with GL30 only access, like TextureArrays, I thought it might be a good feature to introduce to allow more complex scenes, with better performance on newer hardware.
What would be needed is a VeretxData class which is capable of doing transform feedback and a fitting Mesh class. There has to be a new Shader class since transform feedback shaders consist only of a vertex shader and optionally a geometry shader and output varyings have to be specified before linking the program.
Below is an example code of how to use the transform feedback. Please let me know if this feature is worth implementing it.
Reproduction steps/code
Version of LibGDX and/or relevant dependencies
Please select the affected platforms
The text was updated successfully, but these errors were encountered: