diff options
Diffstat (limited to 'source/blender/python/gpu/gpu_py_shader.c')
-rw-r--r-- | source/blender/python/gpu/gpu_py_shader.c | 88 |
1 files changed, 31 insertions, 57 deletions
diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index d2167f2f102..1bdf9766c1b 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -76,21 +76,6 @@ static const struct PyC_StringEnumItems pygpu_shader_config_items[] = { {0, NULL}, }; -static const struct PyC_FlagSet pygpu_texture_samplerstate_items[] = { - {GPU_SAMPLER_DEFAULT, "DEFAULT"}, - {GPU_SAMPLER_FILTER, "FILTER"}, - {GPU_SAMPLER_MIPMAP, "MIPMAP"}, - {GPU_SAMPLER_REPEAT_S, "REPEAT_S"}, - {GPU_SAMPLER_REPEAT_T, "REPEAT_T"}, - {GPU_SAMPLER_REPEAT_R, "REPEAT_R"}, - {GPU_SAMPLER_CLAMP_BORDER, "CLAMP_BORDER"}, - {GPU_SAMPLER_COMPARE, "COMPARE"}, - {GPU_SAMPLER_ANISO, "ANISO"}, - {GPU_SAMPLER_ICON, "ICON"}, - {GPU_SAMPLER_REPEAT, "REPEAT"}, - {0, NULL}, -}; - static int pygpu_shader_uniform_location_get(GPUShader *shader, const char *name, const char *error_prefix) @@ -120,12 +105,13 @@ static PyObject *pygpu_shader__tp_new(PyTypeObject *UNUSED(type), PyObject *args const char *geocode; const char *libcode; const char *defines; + const char *name; } params = {0}; static const char *_keywords[] = { - "vertexcode", "fragcode", "geocode", "libcode", "defines", NULL}; + "vertexcode", "fragcode", "geocode", "libcode", "defines", "name", NULL}; - static _PyArg_Parser _parser = {"ss|$sss:GPUShader.__new__", _keywords, 0}; + static _PyArg_Parser _parser = {"ss|$ssss:GPUShader.__new__", _keywords, 0}; if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, @@ -133,12 +119,17 @@ static PyObject *pygpu_shader__tp_new(PyTypeObject *UNUSED(type), PyObject *args ¶ms.fragcode, ¶ms.geocode, ¶ms.libcode, - ¶ms.defines)) { + ¶ms.defines, + ¶ms.name)) { return NULL; } - GPUShader *shader = GPU_shader_create_from_python( - params.vertexcode, params.fragcode, params.geocode, params.libcode, params.defines); + GPUShader *shader = GPU_shader_create_from_python(params.vertexcode, + params.fragcode, + params.geocode, + params.libcode, + params.defines, + params.name); if (shader == NULL) { PyErr_SetString(PyExc_Exception, "Shader Compile Error, see console for more details"); @@ -507,53 +498,25 @@ static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args) } PyDoc_STRVAR(pygpu_shader_uniform_sampler_doc, - ".. method:: uniform_sampler(name, texture, state={'DEFAULT'})\n" + ".. method:: uniform_sampler(name, texture)\n" "\n" - " Specify the texture and state for an uniform sampler in the current GPUShader.\n" + " Specify the value of a texture uniform variable for the current GPUShader.\n" "\n" " :param name: name of the uniform variable whose texture is to be specified.\n" " :type name: str\n" " :param texture: Texture to attach.\n" - " :type texture: :class:`gpu.types.GPUTexture`\n" - " :param state: set of values in:\n" - "\n" - " - ``DEFAULT``\n" - " - ``FILTER``\n" - " - ``MIPMAP``\n" - " - ``REPEAT_S``\n" - " - ``REPEAT_T``\n" - " - ``REPEAT_R``\n" - " - ``CLAMP_BORDER``\n" - " - ``COMPARE``\n" - " - ``ANISO``\n" - " - ``ICON``\n" - " - ``REPEAT``\n" - " :type state: set\n"); -static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args, PyObject *kwds) + " :type texture: :class:`gpu.types.GPUTexture`\n"); +static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args) { const char *name; BPyGPUTexture *py_texture; - PyObject *py_samplerstate = NULL; - - static const char *_keywords[] = {"name", "texture", "state", NULL}; - static _PyArg_Parser _parser = {"sO!|$O:uniform_sampler", _keywords, 0}; - if (!_PyArg_ParseTupleAndKeywordsFast( - args, kwds, &_parser, &name, &BPyGPUTexture_Type, &py_texture, &py_samplerstate)) { + if (!PyArg_ParseTuple( + args, "sO!:GPUShader.uniform_sampler", &name, &BPyGPUTexture_Type, &py_texture)) { return NULL; } - int sampler_state = GPU_SAMPLER_DEFAULT; - if (py_samplerstate) { - if (PyC_FlagSet_ToBitfield(pygpu_texture_samplerstate_items, - py_samplerstate, - &sampler_state, - "shader.uniform_sampler") == -1) { - return NULL; - } - } - int slot = GPU_shader_get_texture_binding(self->shader, name); - GPU_texture_bind_ex(py_texture->tex, (eGPUSamplerState)sampler_state, slot, false); + GPU_texture_bind(py_texture->tex, slot); GPU_shader_uniform_1i(self->shader, name, slot); Py_RETURN_NONE; @@ -665,7 +628,7 @@ static struct PyMethodDef pygpu_shader__tp_methods[] = { pygpu_shader_uniform_int_doc}, {"uniform_sampler", (PyCFunction)pygpu_shader_uniform_sampler, - METH_VARARGS | METH_KEYWORDS, + METH_VARARGS, pygpu_shader_uniform_sampler_doc}, {"uniform_block", (PyCFunction)pygpu_shader_uniform_block, @@ -682,6 +645,13 @@ static struct PyMethodDef pygpu_shader__tp_methods[] = { {NULL, NULL, 0, NULL}, }; +PyDoc_STRVAR(pygpu_shader_name_doc, + "The name of the shader object for debugging purposes (read-only).\n\n:type: str"); +static PyObject *pygpu_shader_name(BPyGPUShader *self) +{ + return PyUnicode_FromString(GPU_shader_get_name(self->shader)); +} + PyDoc_STRVAR( pygpu_shader_program_doc, "The name of the program object for use by the OpenGL API (read-only).\n\n:type: int"); @@ -692,6 +662,7 @@ static PyObject *pygpu_shader_program_get(BPyGPUShader *self, void *UNUSED(closu static PyGetSetDef pygpu_shader__tp_getseters[] = { {"program", (getter)pygpu_shader_program_get, (setter)NULL, pygpu_shader_program_doc, NULL}, + {"name", (getter)pygpu_shader_name, (setter)NULL, pygpu_shader_name_doc, NULL}, {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; @@ -705,7 +676,8 @@ static void pygpu_shader__tp_dealloc(BPyGPUShader *self) PyDoc_STRVAR( pygpu_shader__tp_doc, - ".. class:: GPUShader(vertexcode, fragcode, geocode=None, libcode=None, defines=None)\n" + ".. class:: GPUShader(vertexcode, fragcode, geocode=None, libcode=None, defines=None, " + "name='pyGPUShader')\n" "\n" " GPUShader combines multiple GLSL shaders into a program used for drawing.\n" " It must contain at least a vertex and fragment shaders.\n" @@ -731,6 +703,8 @@ PyDoc_STRVAR( " :param libcode: Code with functions and presets to be shared between shaders.\n" " :type value: str\n" " :param defines: Preprocessor directives.\n" + " :type value: str\n" + " :param name: Name of shader code, for debugging purposes.\n" " :type value: str\n"); PyTypeObject BPyGPUShader_Type = { PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUShader", |