From 06a60fe9f70061cd28af3ffcbf075273225d54b2 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Thu, 26 Aug 2021 13:02:52 -0300 Subject: PyAPI: GPU: expose clip distances Now you can get a shader that uses Clip Planes and set the number of Clip Distanes with `gpu.state.clip_distances_set(value)`. --- source/blender/python/gpu/gpu_py_state.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'source/blender/python/gpu/gpu_py_state.c') diff --git a/source/blender/python/gpu/gpu_py_state.c b/source/blender/python/gpu/gpu_py_state.c index 7b7a61cc338..757c787882b 100644 --- a/source/blender/python/gpu/gpu_py_state.c +++ b/source/blender/python/gpu/gpu_py_state.c @@ -123,6 +123,28 @@ static PyObject *pygpu_state_blend_get(PyObject *UNUSED(self)) return PyUnicode_FromString(PyC_StringEnum_FindIDFromValue(pygpu_state_blend_items, blend)); } +PyDoc_STRVAR(pygpu_state_clip_distances_set_doc, + ".. function:: clip_distances_set(distances_enabled)\n" + "\n" + " Sets number of `gl_ClipDistance`s that will be used for clip geometry.\n" + "\n" + " :param distances_enabled: Number of clip distances enabled.\n" + " :type distances_enabled: int\n"); +static PyObject *pygpu_state_clip_distances_set(PyObject *UNUSED(self), PyObject *value) +{ + int distances_enabled = (int)PyLong_AsUnsignedLong(value); + if (distances_enabled == -1) { + return NULL; + } + + if (distances_enabled > 6) { + PyErr_SetString(PyExc_ValueError, "too many distances enabled, max is 6"); + } + + GPU_clip_distances(distances_enabled); + Py_RETURN_NONE; +} + PyDoc_STRVAR(pygpu_state_depth_test_set_doc, ".. function:: depth_test_set(mode)\n" "\n" @@ -356,6 +378,10 @@ static struct PyMethodDef pygpu_state__tp_methods[] = { /* Manage Stack */ {"blend_set", (PyCFunction)pygpu_state_blend_set, METH_O, pygpu_state_blend_set_doc}, {"blend_get", (PyCFunction)pygpu_state_blend_get, METH_NOARGS, pygpu_state_blend_get_doc}, + {"clip_distances_set", + (PyCFunction)pygpu_state_clip_distances_set, + METH_O, + pygpu_state_clip_distances_set_doc}, {"depth_test_set", (PyCFunction)pygpu_state_depth_test_set, METH_O, -- cgit v1.2.3