diff options
author | Germano Cavalcante <mano-wii> | 2022-04-13 00:28:27 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2022-04-13 00:50:56 +0300 |
commit | 9bc678969aaef5e2343d9362648e9a633d1b6e5e (patch) | |
tree | 6967bc7469d26d91925bddc618d4ad69432d12fc /source/blender/python/gpu/gpu_py_shader.c | |
parent | 359b6baf325a701328732598ecc04b68a9a335d9 (diff) |
pyGPU: Port 'StageInterfaceInfo' and 'ShaderCreateInfo' types
In order to allow GLSL Cross Compilation across platforms, expose in
Python the `GPUShaderCreateInfo` strategy as detailed in
https://wiki.blender.org/wiki/EEVEE_%26_Viewport/GPU_Module/GLSL_Cross_Compilation
The new features can be listed as follows:
```
>>> gpu.types.GPUShaderCreateInfo.
define(
fragment_out(
fragment_source(
push_constant(
sampler(
typedef_source(
uniform_buf(
vertex_in(
vertex_out(
vertex_source(
>>> gpu.types.GPUStageInterfaceInfo.
flat(
name
no_perspective(
smooth(
>>> gpu.shader.create_from_info(
```
Reviewed By: fclem, campbellbarton
Differential Revision: https://developer.blender.org/D14497
Diffstat (limited to 'source/blender/python/gpu/gpu_py_shader.c')
-rw-r--r-- | source/blender/python/gpu/gpu_py_shader.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index c74b3e173d1..cdcf22df7a1 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -831,6 +831,38 @@ static PyObject *pygpu_shader_code_from_builtin(BPyGPUShader *UNUSED(self), PyOb return r_dict; } +PyDoc_STRVAR(pygpu_shader_create_from_info_doc, + ".. function:: create_from_info(shader_info)\n" + "\n" + " Create shader from a GPUShaderCreateInfo.\n" + "\n" + " :param shader_info: GPUShaderCreateInfo\n" + " :type shader_info: :class:`bpy.types.GPUShaderCreateInfo`\n" + " :return: Shader object corresponding to the given name.\n" + " :rtype: :class:`bpy.types.GPUShader`\n"); +static PyObject *pygpu_shader_create_from_info(BPyGPUShader *UNUSED(self), + BPyGPUShaderCreateInfo *o) +{ + if (!BPyGPUShaderCreateInfo_Check(o)) { + PyErr_Format(PyExc_TypeError, "Expected a GPUShaderCreateInfo, got %s", Py_TYPE(o)->tp_name); + return NULL; + } + + char error[128]; + if (!GPU_shader_create_info_check_error(o->info, error)) { + PyErr_SetString(PyExc_Exception, error); + return NULL; + } + + GPUShader *shader = GPU_shader_create_from_info(o->info); + if (!shader) { + PyErr_SetString(PyExc_Exception, "Shader Compile Error, see console for more details"); + return NULL; + } + + return BPyGPUShader_CreatePyObject(shader, false); +} + static struct PyMethodDef pygpu_shader_module__tp_methods[] = { {"unbind", (PyCFunction)pygpu_shader_unbind, METH_NOARGS, pygpu_shader_unbind_doc}, {"from_builtin", @@ -841,6 +873,10 @@ static struct PyMethodDef pygpu_shader_module__tp_methods[] = { (PyCFunction)pygpu_shader_code_from_builtin, METH_O, pygpu_shader_code_from_builtin_doc}, + {"create_from_info", + (PyCFunction)pygpu_shader_create_from_info, + METH_O, + pygpu_shader_create_from_info_doc}, {NULL, NULL, 0, NULL}, }; |