Page MenuHome

BGL deprecation
Confirmed, NormalPublicTO DO

Assigned To
None
Authored By
Clément Foucault (fclem)
Sep 12 2020, 6:08 PM
Tokens
"Love" token, awarded by jfmatheu."Like" token, awarded by massmaster."Love" token, awarded by MetinSeven."Like" token, awarded by Draise."Burninate" token, awarded by Maged_afra."Love" token, awarded by fkytt."Love" token, awarded by kenziemac130."Like" token, awarded by slumber."Love" token, awarded by Alaska.

Description

Situation:
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 gl_state.cc 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:

Related Objects

Mentioned In
rBAec558f2a9157: VR Scene Inspection: replace deprecated bgl module
rBAf3e1e980b619: Math Vis: replace deprecated bgl module
rBAc1cdc33579fe: Precision Drawing Tools: replace deprecated bgl module
rBAce8c5f8d1b18: Power Sequencer: replace deprecated bgl module
rBAc8109966ce74: Scatter Objects: replace deprecated bgl module
rBAa1424dc87f2c: MeasureIt: replace deprecated bgl module
rBA547adaa4edf8: Archimesh: replace deprecated bgl module
rBAb56a6acb9f4f: UV Layout: replace deprecated bgl module
rBA294e899bf73c: Grease Pencil Tools: replace deprecated bgl module
rBAf7c2fc63954c: Curve Assign Shape Keys: replace deprecated bgl module
rBAc383b027446f: Curve Tools: replace deprecated bgl module
rBAaf9462746056: Sun position: replace deprecated bgl module by gpu T80730
rBb11499939c77: Python GPU: Replace part of the code that uses 'bgl' with 'gpu'
rB48fa029dd11b: Python GPU: New 'platform' module
rB3f4f10964605: Python GPU: New 'capabilities' module
D11129: Python GPU: Replace a few calls to the bgl module
T85675: Blender 3.0 (Python API deprecation, updates)
T84577: Photogrammetry Importer Addon Proposal
T82843: inverted GL_DEPTH_TEST behavior depending on object selection or presence of non-geo object
T82647: Python bgl.GL_DEPTH_TEST Bug
T81784: 2D Gizmo glitch when using glEnable/glDisable (Blender 2.91)
rBf12b0373f322: BGL: Workaround broken bgl usage caused by GPU refactor
T81003: First image drawn with the Python gpu module may be black
T81334: viewport drawing with gpu module
T81289: Python gpu bgl image drawing alpha problem
Mentioned Here
rBA547adaa4edf8: Archimesh: replace deprecated bgl module
rBAa1424dc87f2c: MeasureIt: replace deprecated bgl module
rBAc8109966ce74: Scatter Objects: replace deprecated bgl module
rBAce8c5f8d1b18: Power Sequencer: replace deprecated bgl module
rBAc1cdc33579fe: Precision Drawing Tools: replace deprecated bgl module
rBAf3e1e980b619: Math Vis: replace deprecated bgl module
rBAec558f2a9157: VR Scene Inspection: replace deprecated bgl module
rBAf7c2fc63954c: Curve Assign Shape Keys: replace deprecated bgl module
rBAc383b027446f: Curve Tools: replace deprecated bgl module
rBA294e899bf73c: Grease Pencil Tools: replace deprecated bgl module
rBAb56a6acb9f4f: UV Layout: replace deprecated bgl module
rBAaf9462746056: Sun position: replace deprecated bgl module by gpu T80730
rB4430e8a00810: Python: gpu module: add new submodules and types
rBf12b0373f322: BGL: Workaround broken bgl usage caused by GPU refactor
rBfe5efccd8fb6: GPUOffscreen: Push the GL state before and after binding
D8826: Python: gpu module: add new submodules and types

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Clément Foucault (fclem) changed the task status from Needs Triage to Confirmed.Sep 12 2020, 6:08 PM
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