Fix #139565: PyGPU: Add builtin point shaders

This PR adds builtin shaders for drawing points. Using `FLAT_COLOR`,
`SMOOTH_COLOR`, `UNIFORM_COLOR` can lead to undesired behavior
on Metal and Vulkan backends. To ensure future compatibility this PR
adds `POINT_FLAT_COLOR` and `POINT_UNIFORM_COLOR`.

The point size can be set using `gpu.state.point_size_set`.

Pull Request: https://projects.blender.org/blender/blender/pulls/139583
This commit is contained in:
Jeroen Bakker
2025-05-29 14:36:32 +02:00
parent fd58d730b0
commit c56a855b9f
9 changed files with 119 additions and 2 deletions

View File

@@ -352,6 +352,33 @@ static PyObject *pygpu_batch_draw(BPyGPUBatch *self, PyObject *args)
}
}
/* Emit a warning when trying to draw points with a regular shader as it is too late to
* automatically switch to a point shader. */
if (py_shader && py_shader->is_builtin && self->batch->prim_type == GPU_PRIM_POINTS) {
GPUShader *shader = py_shader->shader;
if (shader == GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR)) {
PyErr_WarnEx(PyExc_DeprecationWarning,
"Calling GPUBatch.draw to draw points with "
"GPU_SHADER_3D_FLAT_COLOR is deprecated. "
"Use GPU_SHADER_3D_POINT_FLAT_COLOR instead.",
1);
}
else if (shader == GPU_shader_get_builtin_shader(GPU_SHADER_3D_SMOOTH_COLOR)) {
PyErr_WarnEx(PyExc_DeprecationWarning,
"Calling GPUBatch.draw to draw points with "
"GPU_SHADER_3D_SMOOTH_COLOR is deprecated. "
"Use GPU_SHADER_3D_POINT_FLAT_COLOR instead.",
1);
}
else if (shader == GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR)) {
PyErr_WarnEx(PyExc_DeprecationWarning,
"Calling GPUBatch.draw to draw points with "
"GPU_SHADER_3D_UNIFORM_COLOR is deprecated. "
"Use GPU_SHADER_3D_POINT_SMOOTH_COLOR instead.",
1);
}
}
if (const char *error = pygpu_shader_check_compatibility(self->batch)) {
PyErr_SetString(PyExc_RuntimeError, error);
return nullptr;