diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2022-09-02 15:33:29 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2022-09-02 15:39:09 +0300 |
commit | 8cfca8e1bd85a300732d92b30741d5c243797a31 (patch) | |
tree | 364b1932cf482cee01a510287d972fb042a5db3a /source/blender/python | |
parent | c8ac1280bb7e69bffadff4cf8c8f71f9c0ec6616 (diff) |
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).
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/gpu/gpu_py_shader.c | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index ce250df1589..02fccedd820 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -31,52 +31,36 @@ * \{ */ #define PYDOC_BUILTIN_SHADER_DESCRIPTION \ - "``2D_FLAT_COLOR``\n" \ - " :Attributes: vec2 pos, vec4 color\n" \ - " :Uniforms: none\n" \ - "``2D_IMAGE``\n" \ - " :Attributes: vec2 pos, vec2 texCoord\n" \ - " :Uniforms: sampler2D image\n" \ - "``2D_SMOOTH_COLOR``\n" \ - " :Attributes: vec2 pos, vec4 color\n" \ - " :Uniforms: none\n" \ - "``2D_UNIFORM_COLOR``\n" \ - " :Attributes: vec2 pos\n" \ - " :Uniforms: vec4 color\n" \ - "``3D_FLAT_COLOR``\n" \ + "``FLAT_COLOR``\n" \ " :Attributes: vec3 pos, vec4 color\n" \ " :Uniforms: none\n" \ - "``3D_IMAGE``\n" \ + "``IMAGE``\n" \ " :Attributes: vec3 pos, vec2 texCoord\n" \ " :Uniforms: sampler2D image\n" \ - "``3D_SMOOTH_COLOR``\n" \ + "``SMOOTH_COLOR``\n" \ " :Attributes: vec3 pos, vec4 color\n" \ " :Uniforms: none\n" \ - "``3D_UNIFORM_COLOR``\n" \ + "``UNIFORM_COLOR``\n" \ " :Attributes: vec3 pos\n" \ " :Uniforms: vec4 color\n" \ - "``3D_POLYLINE_FLAT_COLOR``\n" \ + "``POLYLINE_FLAT_COLOR``\n" \ " :Attributes: vec3 pos, vec4 color\n" \ " :Uniforms: vec2 viewportSize, float lineWidth\n" \ - "``3D_POLYLINE_SMOOTH_COLOR``\n" \ + "``POLYLINE_SMOOTH_COLOR``\n" \ " :Attributes: vec3 pos, vec4 color\n" \ " :Uniforms: vec2 viewportSize, float lineWidth\n" \ - "``3D_POLYLINE_UNIFORM_COLOR``\n" \ + "``POLYLINE_UNIFORM_COLOR``\n" \ " :Attributes: vec3 pos\n" \ " :Uniforms: vec2 viewportSize, float lineWidth\n" static const struct PyC_StringEnumItems pygpu_shader_builtin_items[] = { - {GPU_SHADER_2D_FLAT_COLOR, "2D_FLAT_COLOR"}, - {GPU_SHADER_2D_IMAGE, "2D_IMAGE"}, - {GPU_SHADER_2D_SMOOTH_COLOR, "2D_SMOOTH_COLOR"}, - {GPU_SHADER_2D_UNIFORM_COLOR, "2D_UNIFORM_COLOR"}, - {GPU_SHADER_3D_FLAT_COLOR, "3D_FLAT_COLOR"}, - {GPU_SHADER_3D_IMAGE, "3D_IMAGE"}, - {GPU_SHADER_3D_SMOOTH_COLOR, "3D_SMOOTH_COLOR"}, - {GPU_SHADER_3D_UNIFORM_COLOR, "3D_UNIFORM_COLOR"}, - {GPU_SHADER_3D_POLYLINE_FLAT_COLOR, "3D_POLYLINE_FLAT_COLOR"}, - {GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR, "3D_POLYLINE_SMOOTH_COLOR"}, - {GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR, "3D_POLYLINE_UNIFORM_COLOR"}, + {GPU_SHADER_3D_FLAT_COLOR, "FLAT_COLOR"}, + {GPU_SHADER_3D_IMAGE, "IMAGE"}, + {GPU_SHADER_3D_SMOOTH_COLOR, "SMOOTH_COLOR"}, + {GPU_SHADER_3D_UNIFORM_COLOR, "UNIFORM_COLOR"}, + {GPU_SHADER_3D_POLYLINE_FLAT_COLOR, "POLYLINE_FLAT_COLOR"}, + {GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR, "POLYLINE_SMOOTH_COLOR"}, + {GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR, "POLYLINE_UNIFORM_COLOR"}, {0, NULL}, }; @@ -784,6 +768,24 @@ PyTypeObject BPyGPUShader_Type = { /** \name gpu.shader Module API * \{ */ +static int pyc_parse_buitinshader_w_backward_compatibility(PyObject *o, void *p) +{ + struct PyC_StringEnum *e = p; + const char *value = PyUnicode_AsUTF8(o); + if (value && ELEM(value[0], u'2', u'3')) { + /* Deprecated enums that start with "3D_" or "2D_". */ + value += 3; + for (int i = 0; e->items[i].id; i++) { + if (STREQ(e->items[i].id, value)) { + e->value_found = e->items[i].value; + return 1; + } + } + } + + return PyC_ParseStringEnum(o, p); +} + PyDoc_STRVAR(pygpu_shader_unbind_doc, ".. function:: unbind()\n" "\n" @@ -834,7 +836,7 @@ static PyObject *pygpu_shader_from_builtin(PyObject *UNUSED(self), PyObject *arg if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, - PyC_ParseStringEnum, + pyc_parse_buitinshader_w_backward_compatibility, &pygpu_bultinshader, PyC_ParseStringEnum, &pygpu_config)) { |