[Bf-blender-cvs] [cb67873ac52] blender2.8: PyAPI: Iniital gawain API for Python

Campbell Barton noreply at git.blender.org
Fri Aug 18 00:42:48 CEST 2017


Commit: cb67873ac5215e8331ceadf98d80e740eaed28be
Author: Campbell Barton
Date:   Thu Aug 17 20:32:42 2017 +1000
Branches: blender2.8
https://developer.blender.org/rBcb67873ac5215e8331ceadf98d80e740eaed28be

PyAPI: Iniital gawain API for Python

Wraps vertex-format, vertex-buffer and batch's (enough for drawing).

Doesn't yet expose index-buffers or shaders.

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

M	build_files/cmake/macros.cmake
M	intern/gawain/gawain/gwn_batch.h
M	intern/gawain/src/gwn_batch.c
M	source/blender/python/CMakeLists.txt
A	source/blender/python/gawain/CMakeLists.txt
A	source/blender/python/gawain/gwn_py_api.c
A	source/blender/python/gawain/gwn_py_api.h
A	source/blender/python/gawain/gwn_py_types.c
A	source/blender/python/gawain/gwn_py_types.h
M	source/blender/python/intern/bpy_interface.c

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

diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 836fd5f1a6b..10d9ed041ef 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -599,6 +599,7 @@ function(SETUP_BLENDER_SORTED_LIBS)
 		bf_python
 		bf_python_ext
 		bf_python_mathutils
+		bf_python_gawain
 		bf_python_bmesh
 		bf_freestyle
 		bf_ikplugin
diff --git a/intern/gawain/gawain/gwn_batch.h b/intern/gawain/gawain/gwn_batch.h
index 41e3f66637b..750463ca10f 100644
--- a/intern/gawain/gawain/gwn_batch.h
+++ b/intern/gawain/gawain/gwn_batch.h
@@ -77,6 +77,7 @@ void GWN_batch_uniform_1f(Gwn_Batch*, const char* name, float value);
 void GWN_batch_uniform_2f(Gwn_Batch*, const char* name, float x, float y);
 void GWN_batch_uniform_3f(Gwn_Batch*, const char* name, float x, float y, float z);
 void GWN_batch_uniform_4f(Gwn_Batch*, const char* name, float x, float y, float z, float w);
+void GWN_batch_uniform_2fv(Gwn_Batch*, const char* name, const float data[3]);
 void GWN_batch_uniform_3fv(Gwn_Batch*, const char* name, const float data[3]);
 void GWN_batch_uniform_4fv(Gwn_Batch*, const char* name, const float data[4]);
 
diff --git a/intern/gawain/src/gwn_batch.c b/intern/gawain/src/gwn_batch.c
index c95b67e39cf..359ca956495 100644
--- a/intern/gawain/src/gwn_batch.c
+++ b/intern/gawain/src/gwn_batch.c
@@ -227,6 +227,12 @@ void GWN_batch_uniform_1f(Gwn_Batch* batch, const char* name, float x)
 	glUniform1f(uniform->location, x);
 	}
 
+void GWN_batch_uniform_2fv(Gwn_Batch* batch, const char* name, const float data[2])
+	{
+	GET_UNIFORM
+	glUniform2fv(uniform->location, 1, data);
+	}
+
 void GWN_batch_uniform_3fv(Gwn_Batch* batch, const char* name, const float data[3])
 	{
 	GET_UNIFORM
diff --git a/source/blender/python/CMakeLists.txt b/source/blender/python/CMakeLists.txt
index e855f3a3756..8d26fee0abd 100644
--- a/source/blender/python/CMakeLists.txt
+++ b/source/blender/python/CMakeLists.txt
@@ -17,6 +17,7 @@
 # ***** END GPL LICENSE BLOCK *****
 
 add_subdirectory(intern)
+add_subdirectory(gawain)
 add_subdirectory(generic)
 add_subdirectory(mathutils)
 add_subdirectory(bmesh)
diff --git a/source/blender/python/CMakeLists.txt b/source/blender/python/gawain/CMakeLists.txt
similarity index 64%
copy from source/blender/python/CMakeLists.txt
copy to source/blender/python/gawain/CMakeLists.txt
index e855f3a3756..6b6c902f48a 100644
--- a/source/blender/python/CMakeLists.txt
+++ b/source/blender/python/gawain/CMakeLists.txt
@@ -14,9 +14,34 @@
 # along with this program; if not, write to the Free Software Foundation,
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
+# Contributor(s): Campbell Barton
+#
 # ***** END GPL LICENSE BLOCK *****
 
-add_subdirectory(intern)
-add_subdirectory(generic)
-add_subdirectory(mathutils)
-add_subdirectory(bmesh)
+set(INC 
+	.
+	../../blenkernel
+	../../blenlib
+	../../gpu
+	../../makesdna
+	../../../../intern/gawain
+	../../../../intern/guardedalloc
+	../../../../intern/glew-mx
+)
+
+set(INC_SYS
+	${GLEW_INCLUDE_PATH}
+	${PYTHON_INCLUDE_DIRS}
+)
+
+set(SRC
+	gwn_py_api.c
+	gwn_py_types.c
+
+	gwn_py_api.h
+	gwn_py_types.h
+)
+
+add_definitions(${GL_DEFINITIONS})
+
+blender_add_lib(bf_python_gawain "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/python/gawain/gwn_py_api.c b/source/blender/python/gawain/gwn_py_api.c
new file mode 100644
index 00000000000..d79ef070649
--- /dev/null
+++ b/source/blender/python/gawain/gwn_py_api.c
@@ -0,0 +1,63 @@
+/*
+ * ***** 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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/gawain/gwn_py_api.c
+ *  \ingroup pygawain
+ *
+ * Experimental Python API, not considered public yet (called '_gawain'),
+ * we may re-expose as public later.
+ */
+
+#include <Python.h>
+
+#include "gawain/gwn_batch.h"
+#include "gawain/gwn_vertex_format.h"
+
+#include "gwn_py_api.h"
+#include "gwn_py_types.h"
+
+#include "BLI_utildefines.h"
+
+#include "../generic/python_utildefines.h"
+
+PyDoc_STRVAR(GWN_doc,
+"This module provides access to gawain drawing functions."
+);
+static struct PyModuleDef GWN_module_def = {
+	PyModuleDef_HEAD_INIT,
+	.m_name = "_gawain",  /* m_name */
+	.m_doc = GWN_doc,  /* m_doc */
+};
+
+PyObject *BPyInit_gawain(void)
+{
+	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *submodule;
+	PyObject *mod;
+
+	mod = PyModule_Create(&GWN_module_def);
+
+	/* _gawain.types */
+	PyModule_AddObject(mod, "types", (submodule = BPyInit_gawain_types()));
+	PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+	Py_INCREF(submodule);
+
+	return mod;
+}
diff --git a/source/blender/python/gawain/gwn_py_api.h b/source/blender/python/gawain/gwn_py_api.h
new file mode 100644
index 00000000000..115ff6c5f24
--- /dev/null
+++ b/source/blender/python/gawain/gwn_py_api.h
@@ -0,0 +1,30 @@
+/*
+ * ***** 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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __GWN_PY_API__
+#define __GWN_PY_API__
+
+/** \file blender/python/gawain/gwn_py_api.h
+ *  \ingroup pygen
+ */
+
+PyObject *BPyInit_gawain(void);
+
+#endif  /* __GWN_PY_API__ */
diff --git a/source/blender/python/gawain/gwn_py_types.c b/source/blender/python/gawain/gwn_py_types.c
new file mode 100644
index 00000000000..903dce14e8e
--- /dev/null
+++ b/source/blender/python/gawain/gwn_py_types.c
@@ -0,0 +1,812 @@
+/*
+ * ***** 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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/gawain/gwn_py_types.c
+ *  \ingroup pygawain
+ */
+
+#include <Python.h>
+
+#include "gawain/gwn_batch.h"
+#include "gawain/gwn_vertex_format.h"
+
+#include "BLI_math.h"
+
+#include "GPU_batch.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "../generic/py_capi_utils.h"
+#include "../generic/python_utildefines.h"
+
+#include "gwn_py_types.h" /* own include */
+
+#ifdef __BIG_ENDIAN__
+   /* big endian */
+#  define MAKE_ID2(c, d)  ((c) << 8 | (d))
+#  define MAKE_ID3(a, b, c) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 )
+#  define MAKE_ID4(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) )
+#else
+   /* little endian  */
+#  define MAKE_ID2(c, d)  ((d) << 8 | (c))
+#  define MAKE_ID3(a, b, c) ( (int)(c) << 16 | (b) << 8 | (a) )
+#  define MAKE_ID4(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) )
+#endif
+
+/* -------------------------------------------------------------------- */
+
+/** \name Enum Conversion
+ *
+ * Use with PyArg_ParseTuple's "O&" formatting.
+ * \{ */
+
+static int BPy_Gwn_ParseVertCompType(PyObject *o, void *p)
+{
+	Py_ssize_t comp_type_id_len;
+	const char *comp_type_id = _PyUnicode_AsStringAndSize(o, &comp_type_id_len);
+	if (comp_type_id == NULL) {
+		PyErr_Format(PyExc_ValueError,
+		             "expected a string, got %s",
+		             Py_TYPE(o)->tp_name);
+		return 0;
+	}
+
+	Gwn_VertCompType comp_type;
+	if (comp_type_id_len == 2) {
+		switch (*((ushort *)comp_type_id)) {
+			case MAKE_ID2('I', '8'): { comp_type = GWN_COMP_I8; goto success; }
+			case MAKE_ID2('U', '8'): { comp_type = GWN_COMP_U8; goto success; }
+		}
+	}
+	else if (comp_type_id_len == 3) {
+		switch (*((uint *)comp_type_id)) {
+			case MAKE_ID3('I', '1', '6'): { comp_type = GWN_COMP_I16; goto success; }
+			case MAKE_ID3('U', '1', '6'): { comp_type = GWN_COMP_U16; goto success; }
+			case MAKE_ID3('I', '3', '2'): { comp_type = GWN_COMP_I32; goto success; }
+			case MAKE_ID3('U', '3', '2'): { comp_type = GWN_COMP_U32; goto success; }
+			case MAKE_ID3('F', '3', '2'): { comp_type = GWN_COMP_F32; goto success; }
+			case MAKE_ID3('I', '1', '0'): { comp_type = GWN_COMP_I10; goto success; }
+		}
+	}
+
+	PyErr_Format(PyExc_ValueError,
+	             "unknown type literal: '%s'",
+	             comp_type_id);
+	return 0;
+
+success:
+	*((Gwn_VertCompType *)p) = comp_type;
+	return 1;
+}
+
+static int BPy_Gwn_ParseVertFetchMode(PyObject *o, void *p)
+{
+	Py_ssize_t mode_id_len;
+	const char *mode_id = _PyUnicode_AsStringAndSize(o, &mode_id_len);
+	if (mode_id == NULL) {
+	

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list