Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/gpu/GPU_shader.h5
-rw-r--r--source/blender/gpu/intern/gpu_shader.cc19
-rw-r--r--source/blender/python/gpu/gpu_py_shader.c29
3 files changed, 44 insertions, 9 deletions
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index f834ee5b234..62b748b7edf 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -54,7 +54,8 @@ GPUShader *GPU_shader_create_from_python(const char *vertcode,
const char *fragcode,
const char *geomcode,
const char *libcode,
- const char *defines);
+ const char *defines,
+ const char *name);
GPUShader *GPU_shader_create_ex(const char *vertcode,
const char *fragcode,
const char *geomcode,
@@ -85,6 +86,8 @@ void GPU_shader_free(GPUShader *shader);
void GPU_shader_bind(GPUShader *shader);
void GPU_shader_unbind(void);
+const char *GPU_shader_get_name(GPUShader *shader);
+
/* Returns true if transform feedback was successfully enabled. */
bool GPU_shader_transform_feedback_enable(GPUShader *shader, struct GPUVertBuf *vertbuf);
void GPU_shader_transform_feedback_disable(GPUShader *shader);
diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc
index c754a649924..9340d311472 100644
--- a/source/blender/gpu/intern/gpu_shader.cc
+++ b/source/blender/gpu/intern/gpu_shader.cc
@@ -229,7 +229,8 @@ GPUShader *GPU_shader_create_from_python(const char *vertcode,
const char *fragcode,
const char *geomcode,
const char *libcode,
- const char *defines)
+ const char *defines,
+ const char *name)
{
char *libcodecat = nullptr;
@@ -240,6 +241,9 @@ GPUShader *GPU_shader_create_from_python(const char *vertcode,
libcode = libcodecat = BLI_strdupcat(libcode, datatoc_gpu_shader_colorspace_lib_glsl);
}
+ /* Use pyGPUShader as default name for shader. */
+ const char *shname = name != nullptr ? name : "pyGPUShader";
+
GPUShader *sh = GPU_shader_create_ex(vertcode,
fragcode,
geomcode,
@@ -249,7 +253,7 @@ GPUShader *GPU_shader_create_from_python(const char *vertcode,
GPU_SHADER_TFB_NONE,
nullptr,
0,
- "pyGPUShader");
+ shname);
MEM_SAFE_FREE(libcodecat);
return sh;
@@ -369,6 +373,17 @@ void GPU_shader_unbind(void)
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Shader name
+ * \{ */
+
+const char *GPU_shader_get_name(GPUShader *shader)
+{
+ return unwrap(shader)->name_get();
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Transform feedback
*
* TODO(fclem): Should be replaced by compute shaders.
diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c
index 95e505b1343..1bdf9766c1b 100644
--- a/source/blender/python/gpu/gpu_py_shader.c
+++ b/source/blender/python/gpu/gpu_py_shader.c
@@ -105,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,
@@ -118,12 +119,17 @@ static PyObject *pygpu_shader__tp_new(PyTypeObject *UNUSED(type), PyObject *args
&params.fragcode,
&params.geocode,
&params.libcode,
- &params.defines)) {
+ &params.defines,
+ &params.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");
@@ -639,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");
@@ -649,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 */
};
@@ -662,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"
@@ -688,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",