[Bf-blender-cvs] [d3e81ae] experimental-build: Framebuffer test build
Dalai Felinto
noreply at git.blender.org
Fri Oct 9 05:36:03 CEST 2015
Commit: d3e81ae1621a09049b1086b03cba4358d272dad7
Author: Dalai Felinto
Date: Fri Oct 9 00:34:20 2015 -0300
Branches: experimental-build
https://developer.blender.org/rBd3e81ae1621a09049b1086b03cba4358d272dad7
Framebuffer test build
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/GPU_extensions.h
M source/blender/gpu/intern/gpu_extensions.c
M source/blender/python/intern/CMakeLists.txt
M source/blender/python/intern/gpu.c
M source/blender/python/intern/gpu.h
A source/blender/python/intern/gpu_offscreen.c
M source/blenderplayer/bad_level_call_stubs/stubs.c
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 328623f..3cde0db 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -28,6 +28,7 @@ set(INC
../blenkernel
../blenlib
../bmesh
+ ../editors/include
../imbuf
../makesdna
../makesrna
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 0e8d204..b4aad45 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -36,6 +36,7 @@
extern "C" {
#endif
+struct bContext;
struct Image;
struct ImageUser;
struct PreviewImage;
@@ -182,10 +183,13 @@ void GPU_framebuffer_blur(GPUFrameBuffer *fb, GPUTexture *tex, GPUFrameBuffer *b
GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256]);
void GPU_offscreen_free(GPUOffScreen *ofs);
void GPU_offscreen_bind(GPUOffScreen *ofs, bool save);
+void GPU_offscreen_draw(GPUOffScreen *ofs, struct bContext *C, float projection_matrix[4][4], float modelview_matrix[4][4]);
void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore);
void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels);
int GPU_offscreen_width(const GPUOffScreen *ofs);
int GPU_offscreen_height(const GPUOffScreen *ofs);
+int GPU_offscreen_fb_object(const GPUOffScreen *ofs);
+int GPU_offscreen_color_object(const GPUOffScreen *ofs);
/* Builtin/Non-generated shaders */
typedef enum GPUProgramType {
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index e30eeeb..a0b494c 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -42,6 +42,7 @@
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
+#include "BKE_context.h"
#include "BKE_global.h"
#include "GPU_glew.h"
@@ -53,6 +54,12 @@
#include "intern/gpu_private.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+
+#include "ED_view3d.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -1485,6 +1492,77 @@ int GPU_offscreen_height(const GPUOffScreen *ofs)
return ofs->color->h_orig;
}
+int GPU_offscreen_fb_object(const GPUOffScreen *ofs)
+{
+ return ofs->fb->object;
+}
+
+int GPU_offscreen_color_object(const GPUOffScreen *ofs)
+{
+ return ofs->color->bindcode;
+}
+
+
+/* GPUOffScreen Draw*/
+
+static void gpu_offscreen_draw_setup(GPUOffScreen *ofs)
+{
+ GPU_offscreen_bind(ofs, true);
+}
+
+static void gpu_offscreen_draw_reset(GPUOffScreen *ofs)
+{
+ GPU_offscreen_unbind(ofs, true);
+}
+
+static void gpu_offscreen_draw_doit(
+ GPUOffScreen *ofs,
+ bContext *C,
+ float modelviewmat[4][4],
+ float projmat[4][4])
+{
+ View3D *v3d = CTX_wm_view3d(C);
+ Scene *scene = CTX_data_scene(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ int width = GPU_offscreen_width(ofs);
+ int height = GPU_offscreen_height(ofs);
+ GPUFX *fx = GPU_fx_compositor_create();
+
+ /* full copy */
+ GPUFXSettings fx_settings = v3d->fx_settings;
+
+ ED_view3d_draw_offscreen_init(scene, v3d);
+
+ GPU_offscreen_bind(ofs, true); /* bind */
+
+ ED_view3d_draw_offscreen(
+ scene,
+ v3d,
+ ar,
+ width,
+ height,
+ projmat,
+ modelviewmat,
+ false,
+ true,
+ true,
+ ofs,
+ fx,
+ &fx_settings,
+ "");
+
+ GPU_fx_compositor_destroy(fx);
+ GPU_offscreen_unbind(ofs, true); /* unbind */
+}
+
+void GPU_offscreen_draw(GPUOffScreen *ofs, struct bContext *C, float projection_matrix[4][4], float modelview_matrix[4][4])
+{
+ gpu_offscreen_draw_setup(ofs);
+ gpu_offscreen_draw_doit(ofs, C, projection_matrix, modelview_matrix);
+ gpu_offscreen_draw_reset(ofs);
+}
+
/* GPUShader */
struct GPUShader {
diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt
index cd2a9fd..f04bca7 100644
--- a/source/blender/python/intern/CMakeLists.txt
+++ b/source/blender/python/intern/CMakeLists.txt
@@ -46,6 +46,7 @@ set(INC_SYS
set(SRC
gpu.c
+ gpu_offscreen.c
bpy.c
bpy_app.c
bpy_app_build_options.c
diff --git a/source/blender/python/intern/gpu.c b/source/blender/python/intern/gpu.c
index a7ece10..c073785 100644
--- a/source/blender/python/intern/gpu.c
+++ b/source/blender/python/intern/gpu.c
@@ -313,10 +313,30 @@ static PyMethodDef meth_export_shader[] = {
{"export_shader", (PyCFunction)GPU_export_shader, METH_VARARGS | METH_KEYWORDS, GPU_export_shader_doc}
};
+/* -------------------------------------------------------------------- */
+/* Initialize Module */
+
PyObject *GPU_initPython(void)
{
- PyObject *module = PyInit_gpu();
+ PyObject *module;
+
+ /* Register the 'GPUOffscreen' class */
+ if (PyType_Ready(&PyGPUOffScreen_Type)) {
+ return NULL;
+ }
+
+ 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));
+
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 8233886..fb33b48 100644
--- a/source/blender/python/intern/gpu.h
+++ b/source/blender/python/intern/gpu.h
@@ -36,4 +36,12 @@
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[];
+
#endif /* __GPU_H__ */
diff --git a/source/blender/python/intern/gpu_offscreen.c b/source/blender/python/intern/gpu_offscreen.c
new file mode 100644
index 0000000..5532532
--- /dev/null
+++ b/source/blender/python/intern/gpu_offscreen.c
@@ -0,0 +1,362 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2015 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/gpu_offscreen.c
+ * \ingroup pythonintern
+ *
+ * This file defines the offscreen functionalities of the 'gpu' module
+ * used for offline rendering
+ */
+
+/* python redefines */
+#ifdef _POSIX_C_SOURCE
+#undef _POSIX_C_SOURCE
+#endif
+
+#include <Python.h>
+
+#include "DNA_object_types.h"
+
+#include "BLI_utildefines.h"
+
+#include "BKE_context.h"
+
+#include "WM_types.h"
+
+#include "ED_screen.h"
+
+#include "GPU_extensions.h"
+#include "GPU_compositing.h"
+
+#include "../mathutils/mathutils.h"
+
+#include "bpy_util.h"
+
+#include "gpu.h"
+
+/* -------------------------------------------------------------------- */
+/* GPU Offscreen PyObject */
+
+/* annoying since arg parsing won't check overflow */
+#define UINT_IS_NEG(n) ((n) > INT_MAX)
+
+typedef struct {
+ PyObject_HEAD
+ GPUOffScreen *ofs;
+} PyGPUOffScreen;
+
+PyDoc_STRVAR(GPUOffScreen_width_doc, "Texture width.\n\n:type: GLsizei");
+static PyObject *GPUOffScreen_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))
+{
+ 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))
+{
+ 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))
+{
+ 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 */
+};
+
+static int PyGPUOffScreen__tp_init(PyGPUOffScreen *self, PyObject *args, PyObject *kwargs)
+{
+ unsigned int width, height;
+ const char *keywords[] = {"width", "height", NULL};
+ char err_out[256];
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list