[Bf-blender-cvs] [c563849] decklink: BGE: new rasterizer method to create FBO for custom render in VideoTexture.

Benoit Bolsee noreply at git.blender.org
Tue Oct 6 15:08:44 CEST 2015


Commit: c56384944d070ef8f144d4814e2d6fe0eb8a600d
Author: Benoit Bolsee
Date:   Tue Oct 6 14:46:00 2015 +0200
Branches: decklink
https://developer.blender.org/rBc56384944d070ef8f144d4814e2d6fe0eb8a600d

BGE: new rasterizer method to create FBO for custom render in VideoTexture.

New raterizer method:

fbo = bge.render.offScreenCreate(width,height)
  width, height: size of the FBO, need not be power of two
  Returns a PyRASOffScreen object that encapsulates the FBO.
  It has just 2 attributes: width and height to return the size of the FBO.
  Currently, this object can only be used in the ImageRender constructor.

New optional argument on ImageRender constructor:

ir = bge.texture.ImageRender(scene, camera, fbo)
  If present, fbo is an object of type PyRASOffScreen.
  The returned ImageRender object holds a reference to it, which ensures
  that the FBO livespan is at least as long as the ImageRender object.
  One PyRASOffScreen object can be shared by multiple ImageRender objects.
  The FBO is automatically destroyed when all refences to the PyRASOffScreen
  object are released.
  Note: the whole and capSize attributes of the ImageRender object have no
        effect when an FBO is used: the render and the capture is automatically
        done on the full size of the FBO.

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

M	source/gameengine/Ketsji/KX_PythonInit.cpp
M	source/gameengine/Rasterizer/CMakeLists.txt
A	source/gameengine/Rasterizer/RAS_IOffScreen.h
M	source/gameengine/Rasterizer/RAS_IRasterizer.h
M	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt
A	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.cpp
A	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.h
M	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
M	source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
M	source/gameengine/VideoTexture/ImageRender.cpp
M	source/gameengine/VideoTexture/ImageRender.h
M	source/gameengine/VideoTexture/ImageViewport.cpp
M	source/gameengine/VideoTexture/ImageViewport.h

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

diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 2fef74c..b1824f6 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -108,6 +108,7 @@ extern "C" {
 #include "BL_ArmatureObject.h"
 #include "RAS_IRasterizer.h"
 #include "RAS_ICanvas.h"
+#include "RAS_IOffScreen.h"
 #include "RAS_BucketManager.h"
 #include "RAS_2DFilterManager.h"
 #include "MT_Vector3.h"
@@ -1448,6 +1449,137 @@ static PyObject *gPyGetDisplayDimensions(PyObject *)
 	return result;
 }
 
+
+/* python wrapper around RAS_IOffScreen
+ * Should eventually gets its own file
+ */
+
+static void PyRASOffScreen__tp_dealloc(PyRASOffScreen *self)
+{
+	if (self->ofs)
+		delete self->ofs;
+	Py_TYPE(self)->tp_free((PyObject *)self);
+}
+
+PyDoc_STRVAR(py_RASOffScreen_doc,
+"RASOffscreen(width, height) -> new GPU Offscreen object"
+"initialized to hold a framebuffer object of ``width`` x ``height``.\n"
+""
+);
+
+PyDoc_STRVAR(RASOffScreen_width_doc, "Offscreen buffer width.\n\n:type: integer");
+static PyObject *RASOffScreen_width_get(PyRASOffScreen *self, void *UNUSED(type))
+{
+	return PyLong_FromLong(self->ofs->GetWidth());
+}
+
+PyDoc_STRVAR(RASOffScreen_height_doc, "Offscreen buffer height.\n\n:type: GLsizei");
+static PyObject *RASOffScreen_height_get(PyRASOffScreen *self, void *UNUSED(type))
+{
+	return PyLong_FromLong(self->ofs->GetHeight());
+}
+
+static PyGetSetDef RASOffScreen_getseters[] = {
+	{(char *)"width", (getter)RASOffScreen_width_get, (setter)NULL, RASOffScreen_width_doc, NULL},
+	{(char *)"height", (getter)RASOffScreen_height_get, (setter)NULL, RASOffScreen_height_doc, NULL},
+	{NULL, NULL, NULL, NULL, NULL}  /* Sentinel */
+};
+
+static int PyRASOffScreen__tp_init(PyRASOffScreen *self, PyObject *args, PyObject *kwargs)
+{
+	int width, height;
+	const char *keywords[] = {"width", "height",  NULL};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:RASOffscreen", (char **)keywords, &width, &height)) {
+		return -1;
+	}
+
+	if (width <= 0) {
+		PyErr_SetString(PyExc_ValueError, "negative 'width' given");
+		return -1;
+	}
+
+	if (height <= 0) {
+		PyErr_SetString(PyExc_ValueError, "negative 'height' given");
+		return -1;
+	}
+
+	if (!gp_Rasterizer)
+	{
+		PyErr_SetString(PyExc_SystemError, "no rasterizer");
+		return -1;
+	}
+	self->ofs = gp_Rasterizer->CreateOffScreen(width, height);
+	if (!self->ofs) {
+		PyErr_SetString(PyExc_SystemError, "creation failed");
+		return -1;
+	}
+	return 0;
+}
+
+PyTypeObject PyRASOffScreen_Type = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	"RASOffScreen",                              /* tp_name */
+	sizeof(PyRASOffScreen),                      /* tp_basicsize */
+	0,                                           /* tp_itemsize */
+	/* methods */
+	(destructor)PyRASOffScreen__tp_dealloc,      /* tp_dealloc */
+	NULL,                                        /* tp_print */
+	NULL,                                        /* tp_getattr */
+	NULL,                                        /* tp_setattr */
+	NULL,                                        /* tp_compare */
+	NULL,                                        /* tp_repr */
+	NULL,                                        /* tp_as_number */
+	NULL,                                        /* tp_as_sequence */
+	NULL,                                        /* tp_as_mapping */
+	NULL,                                        /* tp_hash */
+	NULL,                                        /* tp_call */
+	NULL,                                        /* tp_str */
+	NULL,                                        /* tp_getattro */
+	NULL,                                        /* tp_setattro */
+	NULL,                                        /* tp_as_buffer */
+	Py_TPFLAGS_DEFAULT,                          /* tp_flags */
+	py_RASOffScreen_doc,                         /* Documentation string */
+	NULL,                                        /* tp_traverse */
+	NULL,                                        /* tp_clear */
+	NULL,                                        /* tp_richcompare */
+	0,                                           /* tp_weaklistoffset */
+	NULL,                                        /* tp_iter */
+	NULL,                                        /* tp_iternext */
+	NULL,                                        /* tp_methods */
+	NULL,                                        /* tp_members */
+	RASOffScreen_getseters,                      /* tp_getset */
+	NULL,                                        /* tp_base */
+	NULL,                                        /* tp_dict */
+	NULL,                                        /* tp_descr_get */
+	NULL,                                        /* tp_descr_set */
+	0,                                           /* tp_dictoffset */
+	(initproc)PyRASOffScreen__tp_init,           /* tp_init */
+	(allocfunc)PyType_GenericAlloc,              /* tp_alloc */
+	(newfunc)PyType_GenericNew,                  /* tp_new */
+	(freefunc)0,                                 /* tp_free */
+	NULL,                                        /* tp_is_gc */
+	NULL,                                        /* tp_bases */
+	NULL,                                        /* tp_mro */
+	NULL,                                        /* tp_cache */
+	NULL,                                        /* tp_subclasses */
+	NULL,                                        /* tp_weaklist */
+	(destructor) NULL                            /* tp_del */
+};
+
+
+static PyObject *gPyOffScreenCreate(PyObject *UNUSED(self), PyObject *args)
+{
+	int width;
+	int height;
+
+	if (!PyArg_ParseTuple(args, "ii:offscreen_create", &width, &height))
+		return NULL;
+
+	return PyObject_CallObject((PyObject *) &PyRASOffScreen_Type, args);
+}
+
+
 PyDoc_STRVAR(Rasterizer_module_documentation,
 "This is the Python API for the game engine of Rasterizer"
 );
@@ -1502,11 +1634,10 @@ static struct PyMethodDef rasterizer_methods[] = {
 	{"showProperties",(PyCFunction) gPyShowProperties, METH_VARARGS, "show or hide the debug properties"},
 	{"autoDebugList",(PyCFunction) gPyAutoDebugList, METH_VARARGS, "enable or disable auto adding debug properties to the debug  list"},
 	{"clearDebugList",(PyCFunction) gPyClearDebugList, METH_NOARGS, "clears the debug property list"},
+	{"offScreenCreate", (PyCFunction) gPyOffScreenCreate, METH_VARARGS, "create an offscreen buffer object, arguments are width and height in pixels"},
 	{ NULL, (PyCFunction) NULL, 0, NULL }
 };
 
-
-
 PyDoc_STRVAR(GameLogic_module_documentation,
 "This is the Python API for the game engine of bge.logic"
 );
@@ -2304,6 +2435,8 @@ PyMODINIT_FUNC initRasterizerPythonBinding()
 	PyObject *m;
 	PyObject *d;
 
+	PyType_Ready(&PyRASOffScreen_Type);
+
 	m = PyModule_Create(&Rasterizer_module_def);
 	PyDict_SetItemString(PySys_GetObject("modules"), Rasterizer_module_def.m_name, m);
 
diff --git a/source/gameengine/Rasterizer/CMakeLists.txt b/source/gameengine/Rasterizer/CMakeLists.txt
index 5bc3f22..23e677b 100644
--- a/source/gameengine/Rasterizer/CMakeLists.txt
+++ b/source/gameengine/Rasterizer/CMakeLists.txt
@@ -63,6 +63,7 @@ set(SRC
 	RAS_IPolygonMaterial.h
 	RAS_IRasterizer.h
 	RAS_ILightObject.h
+	RAS_IOffScreen.h
 	RAS_MaterialBucket.h
 	RAS_MeshObject.h
 	RAS_ObjectColor.h
diff --git a/source/gameengine/Rasterizer/RAS_IOffScreen.h b/source/gameengine/Rasterizer/RAS_IOffScreen.h
new file mode 100644
index 0000000..d1caf14
--- /dev/null
+++ b/source/gameengine/Rasterizer/RAS_IOffScreen.h
@@ -0,0 +1,72 @@
+/*
+ * ***** 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) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Benoit Bolsee
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file RAS_IOffScreen.h
+ *  \ingroup bgerast
+ */
+
+#ifndef __RAS_OFFSCREEN_H__
+#define __RAS_OFFSCREEN_H__
+
+#include "EXP_Python.h"
+
+class RAS_ICanvas;
+
+class KX_Camera;
+class KX_Scene;
+
+class MT_Transform;
+
+struct Image;
+
+class RAS_IOffScreen
+{
+public:
+	int		m_width;
+	int     m_height;
+
+	virtual ~RAS_IOffScreen() {}
+
+	virtual bool Create(int width, int height) = 0;
+	virtual void Destroy() = 0;
+	virtual void Bind() = 0;
+	virtual void Unbind() = 0;
+
+	virtual int GetWidth() { return m_width; }
+	virtual int GetHeight() { return m_height; }
+};
+
+#ifdef WITH_PYTHON
+typedef struct {
+	PyObject_HEAD
+	RAS_IOffScreen *ofs;
+} PyRASOffScreen;
+
+extern PyTypeObject PyRASOffScreen_Type;
+#endif
+
+#endif  /* __RAS_OFFSCREEN_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h
index 7fbaf07..8f4a7ff 100644
--- a/source/gameengine/Rasterizer/RAS_IRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h
@@ -55,6 +55,7 @@ class RAS_IPolyMaterial;
 class RAS_MeshSlot;
 class RAS_ILightObject;
 class SCA_IScene;
+class RAS_IOffScreen;
 
 typedef vector<unsigned short> KX_IndexArray;
 typedef vector<RAS_TexVert> KX_VertexArray;
@@ -258,6 +259,12 @@ public:
 	virtual float GetFocalLength() = 0;
 
 	/**
+	 * Create an offscreen render buffer that can be used as target for render.
+	 * For the time being, it is only used in VideoTexture for custom render.
+	 */
+	virtual RAS_IOffScreen *CreateOffScreen(int width, int height) = 0;
+
+	/**
 	 * SwapBuffers swaps the back buffer with the front buffer.
 	 */
 	virtual void SwapBuffers() = 0;
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRaster

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list