[Bf-blender-cvs] [76df3c1] framebuffer: gpu.offscreen_object_draw()
Dalai Felinto
noreply at git.blender.org
Tue Sep 29 19:56:36 CEST 2015
Commit: 76df3c1b07cc2e078d6dc92ea7f6106b74b20c3b
Author: Dalai Felinto
Date: Tue Sep 29 14:38:32 2015 -0300
Branches: framebuffer
https://developer.blender.org/rB76df3c1b07cc2e078d6dc92ea7f6106b74b20c3b
gpu.offscreen_object_draw()
I could not get the bContext from a PyObject, so I am instead using BPy_GetContext()
===================================================================
M source/blender/python/intern/gpu.c
M source/blender/python/intern/gpu.h
M source/blender/python/intern/gpu_offscreen.c
===================================================================
diff --git a/source/blender/python/intern/gpu.c b/source/blender/python/intern/gpu.c
index d7da160..c073785 100644
--- a/source/blender/python/intern/gpu.c
+++ b/source/blender/python/intern/gpu.c
@@ -333,6 +333,7 @@ PyObject *GPU_initPython(void)
PyModule_AddObject(module, "offscreen_object_bind", (PyObject *)PyCFunction_New(meth_offscreen_object_bind, NULL));
PyModule_AddObject(module, "offscreen_object_create", (PyObject *)PyCFunction_New(meth_offscreen_object_create, NULL));
+ PyModule_AddObject(module, "offscreen_object_draw", (PyObject *)PyCFunction_New(meth_offscreen_object_draw, NULL));
PyModule_AddObject(module, "offscreen_object_free", (PyObject *)PyCFunction_New(meth_offscreen_object_free, NULL));
PyModule_AddObject(module, "offscreen_object_unbind", (PyObject *)PyCFunction_New(meth_offscreen_object_unbind, NULL));
diff --git a/source/blender/python/intern/gpu.h b/source/blender/python/intern/gpu.h
index d354eb7..fb33b48 100644
--- a/source/blender/python/intern/gpu.h
+++ b/source/blender/python/intern/gpu.h
@@ -40,6 +40,7 @@ extern PyTypeObject PyGPUOffScreen_Type;
extern PyMethodDef meth_offscreen_object_bind[];
extern PyMethodDef meth_offscreen_object_create[];
+extern PyMethodDef meth_offscreen_object_draw[];
extern PyMethodDef meth_offscreen_object_free[];
extern PyMethodDef meth_offscreen_object_unbind[];
diff --git a/source/blender/python/intern/gpu_offscreen.c b/source/blender/python/intern/gpu_offscreen.c
index df8cd18..5532532 100644
--- a/source/blender/python/intern/gpu_offscreen.c
+++ b/source/blender/python/intern/gpu_offscreen.c
@@ -54,6 +54,8 @@
#include "../mathutils/mathutils.h"
+#include "bpy_util.h"
+
#include "gpu.h"
/* -------------------------------------------------------------------- */
@@ -295,3 +297,66 @@ static PyObject *GPU_offscreen_object_unbind(PyObject *UNUSED(self), PyObject *a
PyMethodDef meth_offscreen_object_unbind[] = {
{"offscreen_object_unbind", (PyCFunction)GPU_offscreen_object_unbind, METH_VARARGS | METH_KEYWORDS, GPU_offscreen_object_unbind_doc}
};
+
+static bool gpu_offscreen_check_matrix(MatrixObject *PyMat, const char *UNUSED(name))
+{
+ if (!MatrixObject_Check(PyMat)) {
+ PyErr_SetString(PyExc_TypeError, "matrix could not be converted to a matrix (sequence of sequences)");
+ return false;
+ }
+
+ if (BaseMath_ReadCallback(PyMat) == -1) {
+ PyErr_SetString(PyExc_TypeError, "matrix data could not be accessed");
+ return false;
+ }
+
+ if ((PyMat->num_col != 4) ||
+ (PyMat->num_row != 4))
+ {
+ PyErr_SetString(PyExc_TypeError, "matrix need to have 4 rows and 4 columns");
+ return false;
+ }
+
+ return true;
+}
+
+PyDoc_STRVAR(GPU_offscreen_object_draw_doc,
+"offscreen_object_unbind(offscreen_object, modelview_matrix, projection_matrix)\n"
+"\n"
+" Unbind an offscreen object.\n"
+"\n"
+" :param offscreen_object: offscreen object\n"
+" :type offscreen_object: :class:`gpu.OffScreenObject`\n"
+" :param modelview_matrix: ModelView Matrix\n"
+" :type modelview_matrix: :class:`bgl.Matrix`\n"
+" :param projection_matrix: Projection Matrix\n"
+" :type projection_matrix: :class:`bgl.Matrix`"
+);
+static PyObject *GPU_offscreen_object_draw(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
+{
+ PyGPUOffScreen *PyOfs;
+ MatrixObject *PyModelViewMatrix;
+ MatrixObject *PyProjectionMatrix;
+ bContext *C;
+
+ static const char *kwlist[] = {"offscreen_object", "projection_matrix", "modelview_matrix", NULL};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOO:offscreen_object_draw", (char **)(kwlist),
+ &PyOfs, &PyProjectionMatrix, &PyModelViewMatrix))
+ return NULL;
+
+ if ((!gpu_offscreen_check_matrix(PyProjectionMatrix, "projection_matrix")) ||
+ (!gpu_offscreen_check_matrix(PyModelViewMatrix, "modelview_matrix")))
+ {
+ return NULL;
+ }
+
+ C = BPy_GetContext();
+ GPU_offscreen_draw(PyOfs->ofs, C, (float(*)[4])PyProjectionMatrix->matrix, (float(*)[4])PyModelViewMatrix->matrix);
+
+ Py_RETURN_NONE;
+}
+
+PyMethodDef meth_offscreen_object_draw[] = {
+ {"offscreen_object_draw", (PyCFunction)GPU_offscreen_object_draw, METH_VARARGS | METH_KEYWORDS, GPU_offscreen_object_draw_doc}
+};
More information about the Bf-blender-cvs
mailing list