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:
authorCampbell Barton <ideasman42@gmail.com>2018-10-31 04:02:22 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-10-31 04:02:22 +0300
commit1a865b4ff01c96fa365a1902c61b5d315bcffe11 (patch)
treef6b129627f3baeadc8fe75fbe05623926ddc3bfa /source/blender/python/gpu
parent756d1502e49c93984e5453f15b6384b119605695 (diff)
Cleanup: batch Python API
Add utility function to raise an error.
Diffstat (limited to 'source/blender/python/gpu')
-rw-r--r--source/blender/python/gpu/gpu_py_batch.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/source/blender/python/gpu/gpu_py_batch.c b/source/blender/python/gpu/gpu_py_batch.c
index ecf3bb6cb60..75db213a4e3 100644
--- a/source/blender/python/gpu/gpu_py_batch.c
+++ b/source/blender/python/gpu/gpu_py_batch.c
@@ -53,7 +53,24 @@
/* -------------------------------------------------------------------- */
+/** \name Utility Functions
+ * \{ */
+static bool bpygpu_batch_is_program_or_error(BPyGPUBatch *self)
+{
+ if (!glIsProgram(self->batch->program)) {
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "batch does not have any program assigned to it");
+ return false;
+ }
+ return true;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
/** \name VertBatch Type
* \{ */
@@ -180,20 +197,19 @@ static PyObject *bpygpu_VertBatch_draw(BPyGPUBatch *self, PyObject *args)
BPyGPUShader *py_program = NULL;
if (!PyArg_ParseTuple(
- args, "|O!:GPUShader.__exit__",
+ args, "|O!:GPUBatch.draw",
&BPyGPUShader_Type, &py_program))
{
return NULL;
}
else if (py_program == NULL) {
- if (!glIsProgram(self->batch->program)) {
- PyErr_SetString(PyExc_RuntimeError,
- "batch does not have any program assigned to it");
+ if (!bpygpu_batch_is_program_or_error(self)) {
return NULL;
}
}
else if (self->batch->program != GPU_shader_get_program(py_program->shader)) {
- GPU_batch_program_set(self->batch,
+ GPU_batch_program_set(
+ self->batch,
GPU_shader_get_program(py_program->shader),
GPU_shader_get_interface(py_program->shader));
}
@@ -204,9 +220,7 @@ static PyObject *bpygpu_VertBatch_draw(BPyGPUBatch *self, PyObject *args)
static PyObject *bpygpu_VertBatch_program_use_begin(BPyGPUBatch *self)
{
- if (!glIsProgram(self->batch->program)) {
- PyErr_SetString(PyExc_RuntimeError,
- "batch does not have any program assigned to it");
+ if (!bpygpu_batch_is_program_or_error(self)) {
return NULL;
}
GPU_batch_program_use_begin(self->batch);
@@ -215,9 +229,7 @@ static PyObject *bpygpu_VertBatch_program_use_begin(BPyGPUBatch *self)
static PyObject *bpygpu_VertBatch_program_use_end(BPyGPUBatch *self)
{
- if (!glIsProgram(self->batch->program)) {
- PyErr_SetString(PyExc_RuntimeError,
- "batch does not have any program assigned to it");
+ if (!bpygpu_batch_is_program_or_error(self)) {
return NULL;
}
GPU_batch_program_use_end(self->batch);
@@ -312,7 +324,6 @@ PyTypeObject BPyGPUBatch_Type = {
/* -------------------------------------------------------------------- */
-
/** \name Public API
* \{ */