(no more) BGL in 2.8

Sounds like a state issue. Some draw functions force a state (blend mode, scissors, constants etc.) and might not necessarily clean up after themselves. It’s generally good practice to be explicit with states, like enabling alpha when you need it, and disable when you’re done. Some go as far as storing the previous state, set their own, draw stuff, and then restore back to the previous state. There aren’t concrete guidelines here, but generally if something must be turned on, or modified, it’s considered a state change which may affect drawing further down the gl pipeline.

Right. When doing a localized transform, it’s common to push a new matrix, make your transforms, draw stuff, then pop the matrix, restoring it back to before it was transformed. Blender offers a context manager which does the boilerplate code for you:

def draw():

    # Draw inside a new matrix layer
    with gpu.matrix.push_pop():

        gpu.matrix.translate(x, y)
        # (draw something)

    # Leaving the with-block reverts the matrix back
    # (draw something else)

3 Likes

aaah, ok. I can try that out, thanks!

Yeah, seems like that’s the case. Gotta cleanup or maybeis my fault, i might need to be doing more of that up the chain/in my code.

I have a question when it comes to registering a handler. Let’s say a user runs into an error and the drawn handler is frozen. How do I go about removing the handlers and clearing up the viewport?

Not sure if this is possible, especially if the draw handler is part of the operator.