Commit: e5e1c3a360e0cb043802226be673d10245979433
Author: Dalai Felinto
Date:   Fri Oct 9 10:33:24 2015 -0300
Branches: framebuffer
https://developer.blender.org/rBe5e1c3a360e0cb043802226be673d10245979433

>From review: submodule refactor

===================================================================

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 c073785..54115d6 100644
--- a/source/blender/python/intern/gpu.c
+++ b/source/blender/python/intern/gpu.c
@@ -60,7 +60,7 @@
 #define PY_MODULE_ADD_CONSTANT(module, name) PyModule_AddIntConstant(module, # 
name, name)
 
 PyDoc_STRVAR(M_gpu_doc,
-"This module provides access to the GLSL shader."
+"This module provides access to the GLSL shader and Offscreen rendering 
functionalities."
 );
 static struct PyModuleDef gpumodule = {
        PyModuleDef_HEAD_INIT,
@@ -319,26 +319,19 @@ static PyMethodDef meth_export_shader[] = {
 PyObject *GPU_initPython(void)
 {
        PyObject *module;
-
-       /* Register the 'GPUOffscreen' class */
-       if (PyType_Ready(&PyGPUOffScreen_Type)) {
-               return NULL;
-       }
+       PyObject *submodule;
+       PyObject *sys_modules = PyThreadState_GET()->interp->modules;
 
        module = PyInit_gpu();
 
        PyModule_AddObject(module, "export_shader", (PyObject 
*)PyCFunction_New(meth_export_shader, NULL));
 
-       PyModule_AddObject(module, "OffScreenObject", (PyObject *) 
&PyGPUOffScreen_Type);
-
-       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));
+       /* gpu.offscreen */
+       PyModule_AddObject(module, "offscreen", (submodule = 
BPyInit_gpu_offscreen()));
+       PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), 
submodule);
+       Py_INCREF(submodule);
 
        PyDict_SetItemString(PyImport_GetModuleDict(), "gpu", module);
-
        return module;
 }
 
diff --git a/source/blender/python/intern/gpu.h 
b/source/blender/python/intern/gpu.h
index fb33b48..0da44a4 100644
--- a/source/blender/python/intern/gpu.h
+++ b/source/blender/python/intern/gpu.h
@@ -36,12 +36,6 @@
 
 PyObject *GPU_initPython(void);
 
-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[];
+PyObject *BPyInit_gpu_offscreen(void);
 
 #endif /* __GPU_H__ */
diff --git a/source/blender/python/intern/gpu_offscreen.c 
b/source/blender/python/intern/gpu_offscreen.c
index 5532532..d28b65b 100644
--- a/source/blender/python/intern/gpu_offscreen.c
+++ b/source/blender/python/intern/gpu_offscreen.c
@@ -69,37 +69,138 @@ typedef struct {
        GPUOffScreen *ofs;
 } PyGPUOffScreen;
 
-PyDoc_STRVAR(GPUOffScreen_width_doc, "Texture width.\n\n:type: GLsizei");
-static PyObject *GPUOffScreen_width_get(PyGPUOffScreen *self, void 
*UNUSED(type))
+PyDoc_STRVAR(pygpu_offscreen_width_doc, "Texture width.\n\n:type: GLsizei");
+static PyObject *pygpu_offscreen_width_get(PyGPUOffScreen *self, void 
*UNUSED(type))
 {
        return PyLong_FromLong(GPU_offscreen_width(self->ofs));
 }
 
-PyDoc_STRVAR(GPUOffScreen_height_doc, "Texture height.\n\n:type: GLsizei");
-static PyObject *GPUOffScreen_height_get(PyGPUOffScreen *self, void 
*UNUSED(type))
+PyDoc_STRVAR(pygpu_offscreen_height_doc, "Texture height.\n\n:type: GLsizei");
+static PyObject *pygpu_offscreen_height_get(PyGPUOffScreen *self, void 
*UNUSED(type))
 {
        return PyLong_FromLong(GPU_offscreen_height(self->ofs));
 }
 
-PyDoc_STRVAR(GPUOffScreen_framebuffer_object_doc, "Framebuffer 
object.\n\n:type: GLuint");
-static PyObject *GPUOffScreen_framebuffer_object_get(PyGPUOffScreen *self, 
void *UNUSED(type))
+PyDoc_STRVAR(pygpu_offscreen_framebuffer_object_doc, "Framebuffer 
object.\n\n:type: GLuint");
+static PyObject *pygpu_offscreen_framebuffer_object_get(PyGPUOffScreen *self, 
void *UNUSED(type))
 {
        return PyLong_FromLong(GPU_offscreen_fb_object(self->ofs));
 }
 
-PyDoc_STRVAR(GPUOffScreen_color_object_doc, "Color object.\n\n:type: GLuint");
-static PyObject *GPUOffScreen_color_object_get(PyGPUOffScreen *self, void 
*UNUSED(type))
+PyDoc_STRVAR(pygpu_offscreen_color_object_doc, "Color object.\n\n:type: 
GLuint");
+static PyObject *pygpu_offscreen_color_object_get(PyGPUOffScreen *self, void 
*UNUSED(type))
 {
        return PyLong_FromLong(GPU_offscreen_color_object(self->ofs));
 }
 
-static PyGetSetDef GPUOffScreen_getseters[] = {
-       {(char *)"color_object", (getter)GPUOffScreen_color_object_get, 
(setter)NULL, GPUOffScreen_color_object_doc, NULL},
-       {(char *)"framebuffer_object", 
(getter)GPUOffScreen_framebuffer_object_get, (setter)NULL, 
GPUOffScreen_framebuffer_object_doc, NULL},
-       {(char *)"width", (getter)GPUOffScreen_width_get, (setter)NULL, 
GPUOffScreen_width_doc, NULL},
-       {(char *)"height", (getter)GPUOffScreen_height_get, (setter)NULL, 
GPUOffScreen_height_doc, NULL},
-       {NULL, NULL, NULL, NULL, NULL}  /* Sentinel */
-};
+PyDoc_STRVAR(pygpu_offscreen_bind_doc,
+"bind(save)\n"
+"\n"
+"   Bind the offscreen object.\n"
+"\n"
+"   :param save: save OpenGL current states\n"
+"   :type save: bool"
+);
+static PyObject *pygpu_offscreen_bind(PyGPUOffScreen *self, PyObject *args, 
PyObject *kwds)
+{
+       int save;
+       static const char *kwlist[] = {"save", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:bind", (char 
**)(kwlist), &save))
+               return NULL;
+
+       GPU_offscreen_bind(self->ofs, save);
+       Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pygpu_offscreen_unbind_doc,
+"unbind(restore)\n"
+"\n"
+"   Unbind the offscreen object.\n"
+"\n"
+"   :param restore: restore OpenGL previous states\n"
+"   :type restore: bool"
+);
+static PyObject *pygpu_offscreen_unbind(PyGPUOffScreen *self, PyObject *args, 
PyObject *kwds)
+{
+       int restore;
+       static const char *kwlist[] = {"restore", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "i:unbind", (char 
**)(kwlist), &restore))
+               return NULL;
+
+       GPU_offscreen_unbind(self->ofs, restore);
+       Py_RETURN_NONE;
+}
+
+static bool pygpu_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(pygpu_offscreen_draw_doc,
+"draw(modelview_matrix, projection_matrix)\n"
+"\n"
+"   Draw the viewport in the offscreen object.\n"
+"\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 *pygpu_offscreen_draw(PyGPUOffScreen *self, PyObject *args, 
PyObject *kwds)
+{
+       MatrixObject *PyModelViewMatrix;
+       MatrixObject *PyProjectionMatrix;
+       bContext *C;
+
+       static const char *kwlist[] = {"projection_matrix", "modelview_matrix", 
NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:draw", (char 
**)(kwlist),
+                                        &PyProjectionMatrix, 
&PyModelViewMatrix))
+               return NULL;
+
+       if ((!pygpu_offscreen_check_matrix(PyProjectionMatrix, 
"projection_matrix")) ||
+           (!pygpu_offscreen_check_matrix(PyModelViewMatrix, 
"modelview_matrix")))
+       {
+               return NULL;
+       }
+
+       C = BPy_GetContext();
+       GPU_offscreen_draw(self->ofs, C, 
(float(*)[4])PyProjectionMatrix->matrix, 
(float(*)[4])PyModelViewMatrix->matrix);
+
+       Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pygpu_offscreen_free_doc,
+"free()\n"
+"\n"
+"   Free the offscreen object\n"
+"   The framebuffer, texture and render objects will no longer be accessible."
+);
+static PyObject *pygpu_offscreen_free(PyGPUOffScreen *self)
+{
+       GPU_offscreen_free(self->ofs);
+       self->ofs = NULL;
+       Py_RETURN_NONE;
+}
 
 static int PyGPUOffScreen__tp_init(PyGPUOffScreen *self, PyObject *args, 
PyObject *kwargs)
 {
@@ -132,12 +233,28 @@ static void PyGPUOffScreen__tp_dealloc(PyGPUOffScreen 
*self)
        Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
-PyDoc_STRVAR(py_GPUOffScreen_doc,
+static PyGetSetDef bpy_gpu_offscreen_getseters[] = {
+       {(char *)"color_object", (getter)pygpu_offscreen_color_object_get, 
(setter)NULL, pygpu_offscreen_color_object_doc, NULL},
+       {(char *)"framebuffer_object", 
(getter)pygpu_offscreen_framebuffer_object_get, (setter)NULL, 
pygpu_offscreen_framebuffer_object_doc, NULL},
+       {(char *)"width", (getter)pygpu_offscreen_width_get, (setter)NULL, 
pygpu_offscreen_width_doc, NULL},
+       {(char *)"height", (getter)pygpu_offscreen_height_get, (setter)NULL, 
pygpu_offscreen_height_doc, NULL},
+       {NULL, NULL, NULL, NULL, NULL}  /* Sentinel */
+};
+
+static struct PyMethodDef bpy_gpu_offscreen_methods[] = {
+       {"bind", (PyCFunction)pygpu_offscreen_bind, METH_VARARGS | 
METH_KEYWORDS,pygpu_offscreen_bind_doc},
+       {"unbind", (PyCFunction)pygpu_offscreen_unbind, METH_VARARGS | 
METH_KEYWORDS, pygpu_offscreen_unbind_doc},
+       {"draw", (PyCFunction)pygpu_offscreen_draw, METH_VARARGS | 
METH_KEYWORDS, pygpu_offscreen_draw_doc},
+       {"free", (PyCFunction)pygpu_offscreen_free, METH_NOARGS, 
pygpu_offscreen_free_doc},
+       {NULL, NULL, 0, NULL}
+};
+
+PyDoc_STRVAR(py_gpu_offscreen_doc,
 "GPUOffscreen(width, height) -> new GPU Offscreen object"
 "initialized to hold a framebuffer object of ``width`` x ``height``.\n"
 ""
 );
-PyTypeObject PyGPUOffScreen_Type = {
+static PyTypeObject PyGPUOffScreen_Type = {
        PyVarObject_HEAD_INIT(NULL, 0)
        "GPUOffScreen",                              /* tp_name */
        sizeof(PyGPUOffScreen),                      /* tp_basicsize */
@@ -159,16 +276,16 @@ PyTypeObject PyGPUOffScreen_Type = {
        NULL,                                        /* tp_setattro */
        NULL,                                        /* tp_as_buffer */
        Py_TPFLAGS_DEFAULT,                          /* tp_flags */
-       py_GPUOffScreen_doc,       

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to