Page MenuHome

BGL deprecation
Confirmed, NormalPublicTO DO


For 2.91 we refactored the whole GPU module to be ready for vulkan. In this process we added a state tracking mechanism which removes unneeded state changes by only pushing the state before drawing commands.

The issue is that BGL does not make use of this and directly use the GL API which can lead to unsafe states.

The current workaround is to push the state to the GL before the callbacks loop starts and just force reset all states after the loop (see rBfe5efccd8fb6ce2a7e5e858e3f8becf5f98bb087).

This is quite ugly since it does not prevent misusage of the BGL API with the pyGPU API (which is using our GPU module states).

So we have things to do here:

  • Polish the pyGPU API and force its usage everywhere: Impractical for 2.91 because there would be no transition period. But we do need to get started already since the API did change a little (see GPUOffscreen). A refactor is in the process here D8826. This is the long term plan. rB4430e8a00810
  • Make wrappers inside the BGL module to make the GPUState undefined if calling a function that modifies it: This would trigger a special path inside where the state would be ignored. This should fix some of the API mixing issues. rBf12b0373f322
  • But we also need to push the state for commands that need it (like glClear, glDrawArray, glReadPixels, ...). rBf12b0373f322
  • The last remaining issue is our resource binding check that needs to be disable because incompatible with the glUniform + glBindTexture idiom (we now use internal fixed binding points). rBf12b0373f322

We still have to figure how to mitigate:

  • Current framebuffer state: calling glBindFramebuffer(GL_FRAMEBUFFER, id) will break the state tracking. (Resolved with python's with statement forcing a context specific block. See rB4430e8a00810)
  • Current bound program state: calling glUseProgam(program) will break the state tracking.
  • ... (any other?)

Other issues with pyGPU:

  • There are still functions to get the raw GL handle for some object (Shader/Texture). Deprecate them.
  • GPUOffscreen / GPUFramebuffer now always store/resets their own Viewport/Scissor bounds. Document the API change.

Addons and scripts using the bgl module:

  • addons
    • archimesh
    • archipack
    • blenderkit
    • curve_tools
    • cycles
    • greasepencil_tools
    • io_mesh_uv_layout
    • io_scene_gltf2
    • magic_uv
    • measureit
    • mesh_snap_utilities_line
    • object_carver
    • object_collection_manager
    • object_scatter
    • power_sequencer
    • precision_drawing_tools
    • space_view3d_math_vis
    • sun_position
  • addons_contrib
    • exact_edit
    • np_station
  • modules
    • bl_ui_utils/
    • gpu_extras/
  • templates

Event Timeline

Clément Foucault (fclem) changed the task status from Needs Triage to Confirmed.Sep 12 2020, 6:08 PM
Clément Foucault (fclem) created this task.
Bastien Montagne (mont29) changed the subtype of this task from "Report" to "To Do".Sep 24 2020, 11:53 AM

So all the same abilities - (grab texture ID - replace with new Texture using py - will be abstracted now like the draw calls in order to be restored?)

Once D8826: Python: gpu module: add new submodules and types is committed, this task should be updated to reflect the current status.

Besides taking care of any remaining known API issues and documenting the new APIs, I think we should also involve the community. Once we are ready for it, I suggest to:

  • Create a task with the list of add-ons that needs to be updated, and get the community to help with this
  • Create a devtalk thread to gather feedback