[Bf-blender-cvs] [99c98aa3067] master: Python API: tweak RenderEngine example to be a bit more efficient.

Brecht Van Lommel noreply at git.blender.org
Wed Mar 27 16:27:01 CET 2019


Commit: 99c98aa306783d03403c7c16e59a488e5b21996e
Author: Brecht Van Lommel
Date:   Wed Mar 27 16:25:19 2019 +0100
Branches: master
https://developer.blender.org/rB99c98aa306783d03403c7c16e59a488e5b21996e

Python API: tweak RenderEngine example to be a bit more efficient.

Suggested by Germano Cavalcante.

===================================================================

M	doc/python_api/examples/bpy.types.RenderEngine.py

===================================================================

diff --git a/doc/python_api/examples/bpy.types.RenderEngine.py b/doc/python_api/examples/bpy.types.RenderEngine.py
index 1195204bdeb..6014b4f1d53 100644
--- a/doc/python_api/examples/bpy.types.RenderEngine.py
+++ b/doc/python_api/examples/bpy.types.RenderEngine.py
@@ -142,9 +142,13 @@ class CustomDrawData:
         # Generate vertex array
         self.vertex_array = bgl.Buffer(bgl.GL_INT, 1)
         bgl.glGenVertexArrays(1, self.vertex_array)
+        bgl.glBindVertexArray(self.vertex_array[0])
+
+        texturecoord_location = bgl.glGetAttribLocation(shader_program[0], "texCoord");
+        position_location = bgl.glGetAttribLocation(shader_program[0], "pos");
 
-        self.texturecoord_location = bgl.glGetAttribLocation(shader_program[0], "texCoord");
-        self.position_location = bgl.glGetAttribLocation(shader_program[0], "pos");
+        bgl.glEnableVertexAttribArray(texturecoord_location);
+        bgl.glEnableVertexAttribArray(position_location);
 
         # Generate geometry buffers for drawing textured quad
         position = [0.0, 0.0, width, 0.0, width, height, 0.0, height]
@@ -153,12 +157,18 @@ class CustomDrawData:
         texcoord = bgl.Buffer(bgl.GL_FLOAT, len(texcoord), texcoord)
 
         self.vertex_buffer = bgl.Buffer(bgl.GL_INT, 2)
+
         bgl.glGenBuffers(2, self.vertex_buffer)
         bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vertex_buffer[0])
         bgl.glBufferData(bgl.GL_ARRAY_BUFFER, 32, position, bgl.GL_STATIC_DRAW)
+        bgl.glVertexAttribPointer(position_location, 2, bgl.GL_FLOAT, bgl.GL_FALSE, 0, None)
+
         bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vertex_buffer[1])
         bgl.glBufferData(bgl.GL_ARRAY_BUFFER, 32, texcoord, bgl.GL_STATIC_DRAW)
+        bgl.glVertexAttribPointer(texturecoord_location, 2, bgl.GL_FLOAT, bgl.GL_FALSE, 0, None)
+
         bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, 0)
+        bgl.glBindVertexArray(0)
 
     def __del__(self):
         bgl.glDeleteBuffers(2, self.vertex_buffer)
@@ -169,19 +179,8 @@ class CustomDrawData:
     def draw(self):
         bgl.glActiveTexture(bgl.GL_TEXTURE0)
         bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.texture[0])
-
         bgl.glBindVertexArray(self.vertex_array[0])
-        bgl.glEnableVertexAttribArray(self.texturecoord_location);
-        bgl.glEnableVertexAttribArray(self.position_location);
-
-        bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vertex_buffer[0])
-        bgl.glVertexAttribPointer(self.position_location, 2, bgl.GL_FLOAT, bgl.GL_FALSE, 0, None)
-        bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vertex_buffer[1])
-        bgl.glVertexAttribPointer(self.texturecoord_location, 2, bgl.GL_FLOAT, bgl.GL_FALSE, 0, None)
-        bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, 0)
-
         bgl.glDrawArrays(bgl.GL_TRIANGLE_FAN, 0, 4);
-
         bgl.glBindVertexArray(0)
         bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)



More information about the Bf-blender-cvs mailing list