Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/gpu/gpu_py_shader.c
| Show First 20 Lines • Show All 588 Lines • ▼ Show 20 Lines | |||||
| ); | ); | ||||
| static PyObject *bpygpu_shader_calc_format(BPyGPUShader *self, PyObject *UNUSED(arg)) | static PyObject *bpygpu_shader_calc_format(BPyGPUShader *self, PyObject *UNUSED(arg)) | ||||
| { | { | ||||
| BPyGPUVertFormat *ret = (BPyGPUVertFormat *)BPyGPUVertFormat_CreatePyObject(NULL); | BPyGPUVertFormat *ret = (BPyGPUVertFormat *)BPyGPUVertFormat_CreatePyObject(NULL); | ||||
| GPU_vertformat_from_interface(&ret->fmt, GPU_shader_get_interface(self->shader)); | GPU_vertformat_from_interface(&ret->fmt, GPU_shader_get_interface(self->shader)); | ||||
| return (PyObject *)ret; | return (PyObject *)ret; | ||||
| } | } | ||||
| static PyObject *get_external_function(const char *module_name, const char *function_name) | |||||
| { | |||||
| PyObject *module = PyImport_ImportModule(module_name); | |||||
| PyObject *globals = PyModule_GetDict(module); | |||||
| PyObject *function = PyDict_GetItemString(globals, function_name); | |||||
| Py_DecRef(module); | |||||
| return function; | |||||
| } | |||||
| static PyObject *call_external_method( | |||||
| const char *module_name, | |||||
| const char *function_name, | |||||
| PyObject *self, PyObject *args, PyObject *kwds) | |||||
| { | |||||
| PyObject *function = get_external_function(module_name, function_name); | |||||
| int args_length = PyTuple_Size(args); | |||||
| PyObject *new_args = PyTuple_New(1 + args_length); | |||||
| Py_IncRef(self); | |||||
| PyTuple_SET_ITEM(new_args, 0, self); | |||||
| for (int i = 0; i < args_length; i++) { | |||||
| PyObject *value = PyTuple_GetItem(args, i); | |||||
| Py_IncRef(value); | |||||
| PyTuple_SET_ITEM(new_args, i + 1, value); | |||||
| } | |||||
| PyObject *ret = PyEval_CallObjectWithKeywords(function, new_args, kwds); | |||||
| Py_DecRef(new_args); | |||||
| return ret; | |||||
| } | |||||
| PyDoc_STRVAR(bpygpu_shader_new_batch_doc, | |||||
| ".. method:: new_batch(type, content, indices=None)\n" | |||||
| "\n" | |||||
| " Build a new GPUBatch for this shader.\n" | |||||
| "\n" | |||||
| " :return: a new batch that can be drawn using the shader\n" | |||||
| " :rtype: GPUBatch\n" | |||||
| ); | |||||
| static PyObject *bpygpu_shader_new_batch(BPyGPUShader *self, PyObject *args, PyObject *kwds) | |||||
| { | |||||
| return call_external_method("_gpu_utils.shader", "new_batch", (PyObject *)self, args, kwds); | |||||
| } | |||||
| static struct PyMethodDef bpygpu_shader_methods[] = { | static struct PyMethodDef bpygpu_shader_methods[] = { | ||||
| {"bind", (PyCFunction)bpygpu_shader_bind, | {"bind", (PyCFunction)bpygpu_shader_bind, | ||||
| METH_NOARGS, bpygpu_shader_bind_doc}, | METH_NOARGS, bpygpu_shader_bind_doc}, | ||||
| {"transform_feedback_enable", | {"transform_feedback_enable", | ||||
| (PyCFunction)bpygpu_shader_transform_feedback_enable, | (PyCFunction)bpygpu_shader_transform_feedback_enable, | ||||
| METH_O, bpygpu_shader_transform_feedback_enable_doc}, | METH_O, bpygpu_shader_transform_feedback_enable_doc}, | ||||
| {"transform_feedback_disable", | {"transform_feedback_disable", | ||||
| (PyCFunction)bpygpu_transform_feedback_disable, | (PyCFunction)bpygpu_transform_feedback_disable, | ||||
| Show All 20 Lines | static struct PyMethodDef bpygpu_shader_methods[] = { | ||||
| (PyCFunction)bpygpu_shader_uniform_int, | (PyCFunction)bpygpu_shader_uniform_int, | ||||
| METH_VARARGS, bpygpu_shader_uniform_int_doc}, | METH_VARARGS, bpygpu_shader_uniform_int_doc}, | ||||
| {"attr_from_name", | {"attr_from_name", | ||||
| (PyCFunction)bpygpu_shader_attr_from_name, | (PyCFunction)bpygpu_shader_attr_from_name, | ||||
| METH_O, bpygpu_shader_attr_from_name_doc}, | METH_O, bpygpu_shader_attr_from_name_doc}, | ||||
| {"format_calc", | {"format_calc", | ||||
| (PyCFunction)bpygpu_shader_calc_format, | (PyCFunction)bpygpu_shader_calc_format, | ||||
| METH_NOARGS, bpygpu_shader_calc_format_doc}, | METH_NOARGS, bpygpu_shader_calc_format_doc}, | ||||
| {"new_batch", | |||||
| (PyCFunction)bpygpu_shader_new_batch, | |||||
| METH_VARARGS | METH_KEYWORDS, bpygpu_shader_new_batch_doc}, | |||||
| {NULL, NULL, 0, NULL} | {NULL, NULL, 0, NULL} | ||||
| }; | }; | ||||
| PyDoc_STRVAR(bpygpu_shader_program_doc, | PyDoc_STRVAR(bpygpu_shader_program_doc, | ||||
| "The name of the program object for use by the OpenGL API (read-only).\n\n:type: int" | "The name of the program object for use by the OpenGL API (read-only).\n\n:type: int" | ||||
| ); | ); | ||||
| static PyObject *bpygpu_shader_program_get(BPyGPUShader *self, void *UNUSED(closure)) | static PyObject *bpygpu_shader_program_get(BPyGPUShader *self, void *UNUSED(closure)) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 216 Lines • Show Last 20 Lines | |||||