From 588087f88ecb490d08938de7358a4c522c86deb6 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Mon, 6 Jan 2025 16:05:50 +0100 Subject: [PATCH] Fix #131943: GPU: Vertex formats for polyline shaders PR #129315 refactored polylines. The shaders now attaches the vertex attributes as SSBOs. Adding a workaround for polyline shaders to extract the correct vertex formats when called via Python. Pull Request: https://projects.blender.org/blender/blender/pulls/132689 --- source/blender/python/gpu/gpu_py_shader.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/source/blender/python/gpu/gpu_py_shader.cc b/source/blender/python/gpu/gpu_py_shader.cc index 14f5ceff91d..69fd14edca5 100644 --- a/source/blender/python/gpu/gpu_py_shader.cc +++ b/source/blender/python/gpu/gpu_py_shader.cc @@ -13,6 +13,7 @@ #include "BLI_utildefines.h" +#include "GPU_capabilities.hh" #include "GPU_shader.hh" #include "GPU_texture.hh" #include "GPU_uniform_buffer.hh" @@ -685,7 +686,20 @@ PyDoc_STRVAR( static PyObject *pygpu_shader_format_calc(BPyGPUShader *self, PyObject * /*arg*/) { BPyGPUVertFormat *ret = (BPyGPUVertFormat *)BPyGPUVertFormat_CreatePyObject(nullptr); - GPU_vertformat_from_shader(&ret->fmt, self->shader); + if (bpygpu_shader_is_polyline(self->shader)) { + GPU_vertformat_clear(&ret->fmt); + + /* WORKAROUND: Special case for POLYLINE shader. */ + if (GPU_shader_get_ssbo_binding(self->shader, "pos") >= 0) { + GPU_vertformat_attr_add(&ret->fmt, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + } + if (GPU_shader_get_ssbo_binding(self->shader, "color") >= 0) { + GPU_vertformat_attr_add(&ret->fmt, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); + } + } + else { + GPU_vertformat_from_shader(&ret->fmt, self->shader); + } return (PyObject *)ret; }