diff options
author | Jacques Lucke <jacques@blender.org> | 2021-05-20 15:41:07 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-05-20 15:41:07 +0300 |
commit | 1895205be3308ef7d0c2553519c1433e9117dc33 (patch) | |
tree | fe4146e10a6ded237e65dedba18a885cebb3c6f4 /doc | |
parent | 619b015a46786a4f4057b0dd4d20d27b61d13c0f (diff) | |
parent | 933999db752681ce881760e75befccd17e706f41 (diff) |
Merge branch 'master' into profiler-editorprofiler-editor
Diffstat (limited to 'doc')
-rw-r--r-- | doc/python_api/examples/bpy.types.RenderEngine.py | 72 | ||||
-rw-r--r-- | doc/python_api/examples/mathutils.Matrix.LocRotScale.py | 5 | ||||
-rw-r--r-- | doc/python_api/examples/mathutils.Matrix.py | 6 | ||||
-rw-r--r-- | doc/python_api/sphinx_doc_gen.py | 14 |
4 files changed, 33 insertions, 64 deletions
diff --git a/doc/python_api/examples/bpy.types.RenderEngine.py b/doc/python_api/examples/bpy.types.RenderEngine.py index 45910194244..0b8795340ad 100644 --- a/doc/python_api/examples/bpy.types.RenderEngine.py +++ b/doc/python_api/examples/bpy.types.RenderEngine.py @@ -4,7 +4,9 @@ Simple Render Engine """ import bpy -import bgl +import array +import gpu +from gpu_extras.presets import draw_texture_2d class CustomRenderEngine(bpy.types.RenderEngine): @@ -100,8 +102,7 @@ class CustomRenderEngine(bpy.types.RenderEngine): dimensions = region.width, region.height # Bind shader that converts from scene linear to display space, - bgl.glEnable(bgl.GL_BLEND) - bgl.glBlendFunc(bgl.GL_ONE, bgl.GL_ONE_MINUS_SRC_ALPHA) + gpu.state.blend_set('ALPHA_PREMULT') self.bind_display_space_shader(scene) if not self.draw_data or self.draw_data.dimensions != dimensions: @@ -110,7 +111,7 @@ class CustomRenderEngine(bpy.types.RenderEngine): self.draw_data.draw() self.unbind_display_space_shader() - bgl.glDisable(bgl.GL_BLEND) + gpu.state.blend_set('NONE') class CustomDrawData: @@ -119,68 +120,21 @@ class CustomDrawData: self.dimensions = dimensions width, height = dimensions - pixels = [0.1, 0.2, 0.1, 1.0] * width * height - pixels = bgl.Buffer(bgl.GL_FLOAT, width * height * 4, pixels) + pixels = width * height * array.array('f', [0.1, 0.2, 0.1, 1.0]) + pixels = gpu.types.Buffer('FLOAT', width * height * 4, pixels) # Generate texture - self.texture = bgl.Buffer(bgl.GL_INT, 1) - bgl.glGenTextures(1, self.texture) - bgl.glActiveTexture(bgl.GL_TEXTURE0) - bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.texture[0]) - bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA16F, width, height, 0, bgl.GL_RGBA, bgl.GL_FLOAT, pixels) - bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR) - bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR) - bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) + self.texture = gpu.types.GPUTexture((width, height), format='RGBA16F', data=pixels) - # Bind shader that converts from scene linear to display space, - # use the scene's color management settings. - shader_program = bgl.Buffer(bgl.GL_INT, 1) - bgl.glGetIntegerv(bgl.GL_CURRENT_PROGRAM, shader_program) - - # 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") - - 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] - position = bgl.Buffer(bgl.GL_FLOAT, len(position), position) - texcoord = [0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0] - 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) + # Note: This is just a didactic example. + # In this case it would be more convenient to fill the texture with: + # self.texture.clear('FLOAT', value=[0.1, 0.2, 0.1, 1.0]) def __del__(self): - bgl.glDeleteBuffers(2, self.vertex_buffer) - bgl.glDeleteVertexArrays(1, self.vertex_array) - bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) - bgl.glDeleteTextures(1, self.texture) + del self.texture def draw(self): - bgl.glActiveTexture(bgl.GL_TEXTURE0) - bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.texture[0]) - bgl.glBindVertexArray(self.vertex_array[0]) - bgl.glDrawArrays(bgl.GL_TRIANGLE_FAN, 0, 4) - bgl.glBindVertexArray(0) - bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) + draw_texture_2d(self.texture, (0, 0), self.texture.width, self.texture.height) # RenderEngines also need to tell UI Panels that they are compatible with. diff --git a/doc/python_api/examples/mathutils.Matrix.LocRotScale.py b/doc/python_api/examples/mathutils.Matrix.LocRotScale.py new file mode 100644 index 00000000000..016a5002e82 --- /dev/null +++ b/doc/python_api/examples/mathutils.Matrix.LocRotScale.py @@ -0,0 +1,5 @@ +# Compute local object transformation matrix: +if obj.rotation_mode == 'QUATERNION': + matrix = mathutils.Matrix.LocRotScale(obj.location, obj.rotation_quaternion, obj.scale) +else: + matrix = mathutils.Matrix.LocRotScale(obj.location, obj.rotation_euler, obj.scale) diff --git a/doc/python_api/examples/mathutils.Matrix.py b/doc/python_api/examples/mathutils.Matrix.py index 26c7ccba27c..84e09b97c15 100644 --- a/doc/python_api/examples/mathutils.Matrix.py +++ b/doc/python_api/examples/mathutils.Matrix.py @@ -14,10 +14,14 @@ mat_rot = mathutils.Matrix.Rotation(math.radians(45.0), 4, 'X') mat_out = mat_loc @ mat_rot @ mat_sca print(mat_out) -# extract components back out of the matrix +# extract components back out of the matrix as two vectors and a quaternion loc, rot, sca = mat_out.decompose() print(loc, rot, sca) +# recombine extracted components +mat_out2 = mathutils.Matrix.LocRotScale(loc, rot, sca) +print(mat_out2) + # it can also be useful to access components of a matrix directly mat = mathutils.Matrix() mat[0][0], mat[1][0], mat[2][0] = 0.0, 1.0, 2.0 diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py index 8be194a58a2..032f8a86bd5 100644 --- a/doc/python_api/sphinx_doc_gen.py +++ b/doc/python_api/sphinx_doc_gen.py @@ -545,6 +545,13 @@ def range_str(val): def example_extract_docstring(filepath): + ''' + Return (text, line_no, line_no_has_content) where: + - ``text`` is the doc-string text. + - ``line_no`` is the line the doc-string text ends. + - ``line_no_has_content`` when False, this file only contains a doc-string. + There is no need to include the remainder. + ''' file = open(filepath, "r", encoding="utf-8") line = file.readline() line_no = 0 @@ -553,7 +560,7 @@ def example_extract_docstring(filepath): line_no += 1 else: file.close() - return "", 0, False + return "", 0, True for line in file: line_no += 1 @@ -1029,7 +1036,6 @@ def pymodule2sphinx(basepath, module_name, module, title, module_all_extra): context_type_map = { # context_member: (RNA type, is_collection) "active_annotation_layer": ("GPencilLayer", False), - "active_base": ("ObjectBase", False), "active_bone": ("EditBone", False), "active_gpencil_frame": ("GreasePencilLayer", True), "active_gpencil_layer": ("GPencilLayer", True), @@ -1549,8 +1555,8 @@ def pyrna2sphinx(basepath): fw(".. hlist::\n") fw(" :columns: 2\n\n") - # context does its own thing - # "active_base": ("ObjectBase", False), + # Context does its own thing. + # "active_object": ("Object", False), for ref_attr, (ref_type, ref_is_seq) in sorted(context_type_map.items()): if ref_type == struct_id: fw(" * :mod:`bpy.context.%s`\n" % ref_attr) |