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:
@@ -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;
|
||||
|
||||
@@ -59,7 +59,13 @@
|
||||
" :Uniforms: vec2 viewportSize, float lineWidth\n" \
|
||||
"``POLYLINE_UNIFORM_COLOR``\n" \
|
||||
" :Attributes: vec3 pos\n" \
|
||||
" :Uniforms: vec2 viewportSize, float lineWidth\n"
|
||||
" :Uniforms: vec2 viewportSize, float lineWidth\n" \
|
||||
"``POINT_FLAT_COLOR``\n" \
|
||||
" :Attributes: vec3 pos, vec4 color\n" \
|
||||
" :Uniforms: float size\n" \
|
||||
"``POLYLINE_UNIFORM_COLOR``\n" \
|
||||
" :Attributes: vec3 pos\n" \
|
||||
" :Uniforms: vec4 color, float size\n"
|
||||
|
||||
static const PyC_StringEnumItems pygpu_shader_builtin_items[] = {
|
||||
{GPU_SHADER_3D_FLAT_COLOR, "FLAT_COLOR"},
|
||||
@@ -70,6 +76,8 @@ static const PyC_StringEnumItems pygpu_shader_builtin_items[] = {
|
||||
{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"},
|
||||
{GPU_SHADER_3D_POINT_FLAT_COLOR, "POINT_FLAT_COLOR"},
|
||||
{GPU_SHADER_3D_POINT_UNIFORM_COLOR, "POINT_UNIFORM_COLOR"},
|
||||
{0, nullptr},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user