Issues with bgl.Buffer() VAO,VBO and python wrapper #65208

Closed
opened 2019-05-28 00:47:01 +02:00 by Nikola Nevenov · 8 comments

System Information
Operating system: Windows-10-10.0.17763 64 Bits
Graphics card: GeForce GT 740M/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 419.35

Blender Version
Broken: version: 2.80 (sub 72), branch: blender2.7, commit date: 2019-05-26 22:34, hash: blender/blender@d525c76003
Worked: (optional)

Short description of error
Issue in https://devtalk.blender.org/t/bgl-simple-triangle-what-am-i-doing-wrong/6811

Exact steps for others to reproduce the error
I've contacted Clément Foucault about the issue. After his help, it appears that either the Buffer() is acting strange, or the VAO assignment is messed up.
he said : "I think the memory used by the BGL.Buffer gets released and reused by another thing before the draw callback.There is somethign strange with BGL.Buffer
or the VAO managment"
I went in and moved all my OpenGL code to the draw() function. This made it work as expected, but this means that on every draw call, OpenGL creates a VAO,VBO,Shaders and a program. Which I think won't be the best solution.
In the end Clément Foucault assumed that it's an issue with the python API or the python wrapper.

**System Information** Operating system: Windows-10-10.0.17763 64 Bits Graphics card: GeForce GT 740M/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 419.35 **Blender Version** Broken: version: 2.80 (sub 72), branch: blender2.7, commit date: 2019-05-26 22:34, hash: `blender/blender@d525c76003` Worked: (optional) **Short description of error** Issue in https://devtalk.blender.org/t/bgl-simple-triangle-what-am-i-doing-wrong/6811 **Exact steps for others to reproduce the error** I've contacted Clément Foucault about the issue. After his help, it appears that either the Buffer() is acting strange, or the VAO assignment is messed up. he said : "I think the memory used by the BGL.Buffer gets released and reused by another thing before the draw callback.There is somethign strange with BGL.Buffer or the VAO managment" I went in and moved all my OpenGL code to the `draw()` function. This made it work as expected, but this means that on every draw call, OpenGL creates a VAO,VBO,Shaders and a program. Which I think won't be the best solution. In the end Clément Foucault assumed that it's an issue with the python API or the python wrapper.
Author

Added subscriber: @okuma_10

Added subscriber: @okuma_10
Author

Added subscribers: @fclem, @JacquesLucke

Added subscribers: @fclem, @JacquesLucke
Author

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Added subscriber: @mano-wii

Added subscriber: @mano-wii

The problem with the code is that it disregards the fact that Blender works with more than one OpenGL context.
There is the OpenGL context offscreen and a context for each window.
The callback added to draw_handler_add runs in the offscreen context, but the rest of the code runs in the context of the window.
VBOs, Programs, Textures are shared between different contexts. But the VAO does not.
So a solution would be to create the VAO inside the callback with a lazy initialization.

The problem with the code is that it disregards the fact that Blender works with more than one OpenGL context. There is the OpenGL context offscreen and a context for each window. The callback added to `draw_handler_add` runs in the offscreen context, but the rest of the code runs in the context of the window. VBOs, Programs, Textures are shared between different contexts. But the VAO does not. So a solution would be to create the VAO inside the callback with a lazy initialization.
Author

Ah! I see...this explains why if I add all my code to the draw() function I see everything as it should be.Because the draw() function is what is getting the view3D OpenGL window context.
The problem is that I have no idea how to implement your suggested solution.

As I said ....when I added everything to the draw() function, every time the view was updated a VAO,VBO,Shaders and a Program was created. It was VAO id:2000+ in no time.

Maybe a solution is to have an option for the Buffer() ,that tells it which OpenGL context it should use.

Ah! I see...this explains why if I add all my code to the draw() function I see everything as it should be.Because the draw() function is what is getting the view3D OpenGL window context. The problem is that I have no idea how to implement your suggested solution. As I said ....when I added everything to the draw() function, every time the view was updated a VAO,VBO,Shaders and a Program was created. It was VAO id:2000+ in no time. Maybe a solution is to have an option for the Buffer() ,that tells it which OpenGL context it should use.

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Germano Cavalcante self-assigned this 2019-06-03 14:32:33 +02:00

Since it is not a bug (but a known limitation). Better close and continue on Devtalk .

Since it is not a bug (but a known limitation). Better close and continue on [Devtalk ](https://devtalk.blender.org/t/bgl-simple-triangle-what-am-i-doing-wrong/6811).
Sign in to join this conversation.
No Milestone
No project
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#65208
No description provided.