Py API Docs: use new bind context manager in gpu examples
authorJacques Lucke <mail@jlucke.com>
Mon, 19 Nov 2018 13:32:30 +0000 (14:32 +0100)
committerJacques Lucke <mail@jlucke.com>
Mon, 19 Nov 2018 13:32:51 +0000 (14:32 +0100)
doc/python_api/examples/gpu.8.py
doc/python_api/examples/gpu.9.py

index 7e41164fc7e41efea29383c959daa6451ead8e52..28964d2e6b227a8f511db51bc723adff7e955094 100644 (file)
@@ -19,8 +19,7 @@ from gpu_extras.presets import draw_circle_2d
 
 offscreen = gpu.types.GPUOffScreen(512, 512)
 
-offscreen.bind()
-try:
+with offscreen.bind():
     bgl.glClear(bgl.GL_COLOR_BUFFER_BIT)
     with gpu.matrix.push_pop():
         # reset matrices -> use normalized device coordinates [-1, 1]
@@ -31,8 +30,6 @@ try:
         for i in range(-amount, amount + 1):
             x_pos = i / amount
             draw_circle_2d((x_pos, 0.0), (1, 1, 1, 1), 0.5, 200)
-finally:
-    offscreen.unbind()
 
 
 # Drawing the generated texture in 3D space
index a281534765a69312819f55b5456c7378f6831482..84e279946da1f5ca8f7bb1f688af6c828377d449 100644 (file)
@@ -23,8 +23,7 @@ RING_AMOUNT = 10
 
 offscreen = gpu.types.GPUOffScreen(WIDTH, HEIGHT)
 
-offscreen.bind()
-try:
+with offscreen.bind():
     bgl.glClear(bgl.GL_COLOR_BUFFER_BIT)
     with gpu.matrix.push_pop():
         # reset matrices -> use normalized device coordinates [-1, 1]
@@ -40,9 +39,8 @@ try:
     buffer = bgl.Buffer(bgl.GL_BYTE, WIDTH * HEIGHT * 4)
     bgl.glReadBuffer(bgl.GL_BACK)
     bgl.glReadPixels(0, 0, WIDTH, HEIGHT, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer)
-finally:
-    offscreen.unbind()
-    offscreen.free()
+
+offscreen.free()
 
 
 if not IMAGE_NAME in bpy.data.images: