From 8cfca8e1bd85a300732d92b30741d5c243797a31 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Fri, 2 Sep 2022 09:33:29 -0300 Subject: PyGPU: only use 3D shaders and rename string enums Since rB6269d66da, creating formats no longer depends solely on the shader, but now depends on the dimensions used to fill the VBOs. This allows 3D shaders to work flawlessly when assigned dimensions are 2D. So there's no real benefit to us having shaders that are limited to 2D use anymore. This limitation makes it difficult to implement other builtin shaders as they indirectly require a 2D version. So this commit removes the 2D versions of the builtin sahders used in Python , renames the string enums but keeps the old enums working for backward compatibility. (This brings parts of the changes reviewed in D15836). --- release/scripts/modules/bpy_types.py | 2 +- release/scripts/modules/gpu_extras/presets.py | 6 +++--- release/scripts/templates_py/operator_modal_draw.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'release') diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index 87b32eb1f40..b2f4d71ed92 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -793,7 +793,7 @@ class Gizmo(StructRNA): vbo = GPUVertBuf(len=len(verts), format=fmt) vbo.attr_fill(id=pos_id, data=verts) batch = GPUBatch(type=type, buf=vbo) - shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR' if dims == 3 else '2D_UNIFORM_COLOR') + shader = gpu.shader.from_builtin('UNIFORM_COLOR') batch.program_set(shader) return (batch, shader) diff --git a/release/scripts/modules/gpu_extras/presets.py b/release/scripts/modules/gpu_extras/presets.py index eba8d6c161d..f68824d76c8 100644 --- a/release/scripts/modules/gpu_extras/presets.py +++ b/release/scripts/modules/gpu_extras/presets.py @@ -42,7 +42,7 @@ def draw_circle_2d(position, color, radius, *, segments=None): vbo = GPUVertBuf(len=len(verts), format=fmt) vbo.attr_fill(id=pos_id, data=verts) batch = GPUBatch(type='LINE_STRIP', buf=vbo) - shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR') + shader = gpu.shader.from_builtin('UNIFORM_COLOR') batch.program_set(shader) shader.uniform_float("color", color) batch.draw() @@ -67,7 +67,7 @@ def draw_texture_2d(texture, position, width, height): coords = ((0, 0), (1, 0), (1, 1), (0, 1)) - shader = gpu.shader.from_builtin('2D_IMAGE') + shader = gpu.shader.from_builtin('IMAGE') batch = batch_for_shader( shader, 'TRI_FAN', {"pos": coords, "texCoord": coords}, @@ -77,7 +77,7 @@ def draw_texture_2d(texture, position, width, height): gpu.matrix.translate(position) gpu.matrix.scale((width, height)) - shader = gpu.shader.from_builtin('2D_IMAGE') + shader = gpu.shader.from_builtin('IMAGE') shader.bind() if isinstance(texture, int): diff --git a/release/scripts/templates_py/operator_modal_draw.py b/release/scripts/templates_py/operator_modal_draw.py index 20e888ad5f3..78edf874791 100644 --- a/release/scripts/templates_py/operator_modal_draw.py +++ b/release/scripts/templates_py/operator_modal_draw.py @@ -15,7 +15,7 @@ def draw_callback_px(self, context): blf.draw(font_id, "Hello Word " + str(len(self.mouse_path))) # 50% alpha, 2 pixel width line - shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR') + shader = gpu.shader.from_builtin('UNIFORM_COLOR') gpu.state.blend_set('ALPHA') gpu.state.line_width_set(2.0) batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": self.mouse_path}) -- cgit v1.2.3