[Bf-blender-cvs] [6a68b80] framebuffer: API: new gpu.offscreen_object_*() functions

Dalai Felinto noreply at git.blender.org
Tue Sep 29 00:05:04 CEST 2015


Commit: 6a68b80f212e2462b18c66dd87206772340d4901
Author: Dalai Felinto
Date:   Mon Sep 28 17:47:25 2015 -0300
Branches: framebuffer
https://developer.blender.org/rB6a68b80f212e2462b18c66dd87206772340d4901

API: new gpu.offscreen_object_*() functions

gpu.offscreen_object_bind()
gpu.offscreen_object_create()
gpu.offscreen_object_free()
gpu.offscreen_object_unbind()

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

M	source/blender/gpu/GPU_extensions.h
M	source/blender/gpu/intern/gpu_extensions.c
M	source/blender/python/intern/gpu.c
M	source/blender/python/intern/gpu.h

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

diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 0e8d204..35b576a 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -186,6 +186,8 @@ 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..762c6ea 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -1485,6 +1485,16 @@ 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;
+}
+
 /* GPUShader */
 
 struct GPUShader {
diff --git a/source/blender/python/intern/gpu.c b/source/blender/python/intern/gpu.c
index a7ece10..7485cd1 100644
--- a/source/blender/python/intern/gpu.c
+++ b/source/blender/python/intern/gpu.c
@@ -53,6 +53,7 @@
 
 #include "../generic/py_capi_utils.h"
 
+#include "GPU_extensions.h"
 #include "GPU_material.h"
 
 #include "gpu.h"
@@ -313,10 +314,268 @@ static PyMethodDef meth_export_shader[] = {
 	{"export_shader", (PyCFunction)GPU_export_shader, METH_VARARGS | METH_KEYWORDS, GPU_export_shader_doc}
 };
 
+/* -------------------------------------------------------------------- */
+/* 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:GPUOffscreen", (char **)keywords, &width, &height)) {
+		return -1;
+	}
+
+	if (UINT_IS_NEG(width)) {
+		PyErr_SetString(PyExc_ValueError, "negative 'width' given");
+		return -1;
+	}
+
+	if (UINT_IS_NEG(height)) {
+		PyErr_SetString(PyExc_ValueError, "negative 'height' given");
+		return -1;
+	}
+
+	self->ofs = GPU_offscreen_create(width, height, err_out);
+	return 0;
+}
+
+static void PyGPUOffscreen__tp_dealloc(PyGPUOffscreen *self)
+{
+	if (self->ofs)
+		GPU_offscreen_free(self->ofs);
+	Py_TYPE(self)->tp_free((PyObject *)self);
+}
+
+PyDoc_STRVAR(py_GPUOffscreen_doc,
+"GPUOffscreen(width, height) -> new GPU Offscreen object"
+"initialized to hold a framebuffer object of ``width`` x ``height``.\n"
+""
+);
+PyTypeObject PyGPUOffscreen_Type = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	"GPUOffscreen",                              /* tp_name */
+	sizeof(PyGPUOffscreen),                      /* tp_basicsize */
+	0,                                           /* tp_itemsize */
+	/* methods */
+	(destructor)PyGPUOffscreen__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_GPUOffscreen_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 */
+	GPUOffscreen_getseters,                      /* tp_getset */
+	NULL,                                        /* tp_base */
+	NULL,                                        /* tp_dict */
+	NULL,                                        /* tp_descr_get */
+	NULL,                                        /* tp_descr_set */
+	0,                                           /* tp_dictoffset */
+	(initproc)PyGPUOffscreen__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 */
+};
+
+/* -------------------------------------------------------------------- */
+/* GPU offscreen methods */
+
+PyDoc_STRVAR(GPU_offscreen_object_bind_doc,
+"offscreen_object_bind(offscreen_object, use_save)\n"
+"\n"
+"   Bind an offscreen object.\n"
+"\n"
+"   :param offscreen_object: offscreen object\n"
+"   :type offscreen_object: :class:`gpu.OffScreenObject`\n"
+"   :param use_save: \n"
+"   :type use_save: bool"
+);
+static PyObject *GPU_offscreen_object_bind(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
+{
+	PyGPUOffscreen *PyOfs;
+	int use_save;
+
+	static const char *kwlist[] = {"offscreen_object", "use_save", NULL};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oi:offscreen_object_bind", (char **)(kwlist), &PyOfs, &use_save))
+		return NULL;
+
+	GPU_offscreen_bind(PyOfs->ofs, use_save);
+	Py_RETURN_NONE;
+}
+
+static PyMethodDef meth_offscreen_object_bind[] = {
+	{"offscreen_object_bind", (PyCFunction)GPU_offscreen_object_bind, METH_VARARGS | METH_KEYWORDS, GPU_offscreen_object_bind_doc}
+};
+
+PyDoc_STRVAR(GPU_offscreen_object_create_doc,
+"offscreen_object_create(width, height)\n"
+"\n"
+"   Return a GPUOffScreen.\n"
+"\n"
+"   :return: struct with GPUFrameBuffer, GPUTexture, GPUTexture.\n"
+"   :rtype: :class:`gpu.OffScreenObject`"
+);
+static PyObject *GPU_offscreen_object_create(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
+{
+	int width;
+	int height;
+
+	static const char *kwlist[] = {"width", "height", NULL};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii:offscreen_object_create", (char **)(kwlist), &width, &height))
+		return NULL;
+
+	return PyObject_CallObject((PyObject *) &PyGPUOffscreen_Type, args);
+}
+
+static PyMethodDef meth_offscreen_object_create[] = {
+	{"offscreen_object_create", (PyCFunction)GPU_offscreen_object_create, METH_VARARGS | METH_KEYWORDS, GPU_offscreen_object_create_doc}
+};
+
+PyDoc_STRVAR(GPU_offscreen_object_free_doc,
+"offscreen_object_free(offscreen_object)\n"
+"\n"
+"   Free an offscreen object\n"
+"   The framebuffer, texture and render objects will no longer be accessible.\n"
+"\n"
+"   :param offscreen_object: offscreen object\n"
+"   :type offscreen_object: :class:`gpu.OffScreenObject`"
+);
+static PyObject *GPU_offscreen_object_free(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
+{
+	PyGPUOffscreen *PyOfs;
+
+	static const char *kwlist[] = {"offscreen_object", NULL};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:offscreen_object_unbind", (char **)(kwlist), &PyOfs))
+		return NULL;
+
+	GPU_offscreen_free(PyOfs->ofs);
+	Py_RETURN_NONE;
+}
+
+static PyMethodDef meth_offscreen_object_free[] = {
+	{"offscreen_object_free", (PyCFunction)GPU_offscreen_object_free, METH_VARARGS | METH_KEYWORDS, GPU_offscreen_object_free_doc}
+};
+
+PyDoc_STRVAR(GPU_off

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list