From 1a865b4ff01c96fa365a1902c61b5d315bcffe11 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 31 Oct 2018 12:02:22 +1100 Subject: Cleanup: batch Python API Add utility function to raise an error. --- source/blender/python/gpu/gpu_py_batch.c | 35 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'source/blender/python/gpu') 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 * \{ */ -- cgit v1.2.3