[Bf-blender-cvs] [6d04e48539c] blender2.8: Join the python modules `gpu` and `_gpu` into one.
mano-wii
noreply at git.blender.org
Thu Sep 6 02:17:37 CEST 2018
Commit: 6d04e48539ce50f0de9cc73a36e7733aee608773
Author: mano-wii
Date: Wed Sep 5 21:10:42 2018 -0300
Branches: blender2.8
https://developer.blender.org/rB6d04e48539ce50f0de9cc73a36e7733aee608773
Join the python modules `gpu` and `_gpu` into one.
Maybe it's still early to set the new drawing api for python.
But joining these two modules is an initial step.
```
>>> gpu.
matrix
select
types
```
```
>>> gpu.types.GPU
Batch(
OffScreen(
VertBuf(
VertFormat(
```
The creation of a new offscreen object is now done by the `GPUOffscreen.__new__` method.
Reviewers: campbellbarton, dfelinto
Reviewed By: campbellbarton, dfelinto
Tags: #bf_blender_2.8
Differential Revision: https://developer.blender.org/D3667
===================================================================
R097 doc/python_api/examples/gpu.offscreen.1.py doc/python_api/examples/gpu.types.GPUOffScreen.py
D doc/python_api/rst/gpu.rst
M doc/python_api/sphinx_doc_gen.py
M source/blender/python/gpu/CMakeLists.txt
M source/blender/python/gpu/gpu_py_api.c
M source/blender/python/gpu/gpu_py_api.h
A source/blender/python/gpu/gpu_py_batch.c
A source/blender/python/gpu/gpu_py_batch.h
R060 source/blender/python/intern/gpu_py_matrix.c source/blender/python/gpu/gpu_py_matrix.c
A source/blender/python/gpu/gpu_py_matrix.h
A source/blender/python/gpu/gpu_py_offscreen.c
A source/blender/python/gpu/gpu_py_offscreen.h
R073 source/blender/python/intern/gpu_py_select.c source/blender/python/gpu/gpu_py_select.c
R065 source/blender/python/intern/gpu.h source/blender/python/gpu/gpu_py_select.h
M source/blender/python/gpu/gpu_py_types.c
M source/blender/python/gpu/gpu_py_types.h
A source/blender/python/gpu/gpu_py_vertex_buffer.c
A source/blender/python/gpu/gpu_py_vertex_buffer.h
A source/blender/python/gpu/gpu_py_vertex_format.c
A source/blender/python/gpu/gpu_py_vertex_format.h
M source/blender/python/intern/CMakeLists.txt
M source/blender/python/intern/bpy_interface.c
===================================================================
diff --git a/doc/python_api/examples/gpu.offscreen.1.py b/doc/python_api/examples/gpu.types.GPUOffScreen.py
similarity index 97%
rename from doc/python_api/examples/gpu.offscreen.1.py
rename to doc/python_api/examples/gpu.types.GPUOffScreen.py
index bb34603bd23..a1b38837278 100644
--- a/doc/python_api/examples/gpu.offscreen.1.py
+++ b/doc/python_api/examples/gpu.types.GPUOffScreen.py
@@ -42,7 +42,7 @@ class OffScreenDraw(bpy.types.Operator):
aspect_ratio = scene.render.resolution_x / scene.render.resolution_y
try:
- offscreen = gpu.offscreen.new(512, int(512 / aspect_ratio))
+ offscreen = gpu.types.GPUOffScreen(512, int(512 / aspect_ratio))
except Exception as e:
print(e)
offscreen = None
@@ -52,7 +52,7 @@ class OffScreenDraw(bpy.types.Operator):
@staticmethod
def _update_offscreen(context, offscreen):
scene = context.scene
- render_layer = context.render_layer
+ view_layer = context.view_layer
render = scene.render
camera = scene.camera
diff --git a/doc/python_api/rst/gpu.rst b/doc/python_api/rst/gpu.rst
deleted file mode 100644
index d4860da4770..00000000000
--- a/doc/python_api/rst/gpu.rst
+++ /dev/null
@@ -1,20 +0,0 @@
-*******************
-GPU functions (gpu)
-*******************
-
-.. module:: gpu
-
-Functions for GPU offscreen rendering, matrix stacks and selection.
-
-Submodules:
-
-.. toctree::
- :maxdepth: 1
-
- gpu.offscreen.rst
-
-
-Intro
-=====
-
-Module to provide functions concerning the GPU implementation in Blender.
diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py
index 9b58f7b3888..edfa2c4a95b 100644
--- a/doc/python_api/sphinx_doc_gen.py
+++ b/doc/python_api/sphinx_doc_gen.py
@@ -235,7 +235,9 @@ else:
"bpy.utils.previews",
"bpy_extras",
"gpu",
- "gpu.offscreen",
+ "gpu.types",
+ "gpu.matrix",
+ "gpu.select",
"idprop.types",
"mathutils",
"mathutils.bvhtree",
@@ -1822,7 +1824,10 @@ def write_rst_importable_modules(basepath):
# C_modules
"aud": "Audio System",
"blf": "Font Drawing",
- "gpu.offscreen": "GPU Off-Screen Buffer",
+ "gpu": "GPU Shader Module",
+ "gpu.types": "GPU Types",
+ "gpu.matrix": "GPU Matrix",
+ "gpu.select": "GPU Select",
"bmesh": "BMesh Module",
"bmesh.types": "BMesh Types",
"bmesh.utils": "BMesh Utilities",
@@ -1865,7 +1870,6 @@ def copy_handwritten_rsts(basepath):
# TODO put this docs in Blender's code and use import as per modules above
handwritten_modules = [
"bgl", # "Blender OpenGl wrapper"
- "gpu", # "GPU Shader Module"
"bmesh.ops", # generated by rst_from_bmesh_opdefines.py
# includes...
diff --git a/source/blender/python/gpu/CMakeLists.txt b/source/blender/python/gpu/CMakeLists.txt
index 141a36bbcc2..bf317a4ebc5 100644
--- a/source/blender/python/gpu/CMakeLists.txt
+++ b/source/blender/python/gpu/CMakeLists.txt
@@ -35,10 +35,22 @@ set(INC_SYS
set(SRC
gpu_py_api.c
+ gpu_py_batch.c
+ gpu_py_matrix.c
+ gpu_py_offscreen.c
+ gpu_py_select.c
gpu_py_types.c
+ gpu_py_vertex_buffer.c
+ gpu_py_vertex_format.c
gpu_py_api.h
+ gpu_py_batch.h
+ gpu_py_matrix.h
+ gpu_py_offscreen.h
+ gpu_py_select.h
gpu_py_types.h
+ gpu_py_vertex_buffer.h
+ gpu_py_vertex_format.h
)
add_definitions(${GL_DEFINITIONS})
diff --git a/source/blender/python/gpu/gpu_py_api.c b/source/blender/python/gpu/gpu_py_api.c
index 53285b372d8..fc1e7390ffe 100644
--- a/source/blender/python/gpu/gpu_py_api.c
+++ b/source/blender/python/gpu/gpu_py_api.c
@@ -19,31 +19,44 @@
*/
/** \file blender/python/gpu/gpu_py_api.c
- * \ingroup pygpu
+ * \ingroup bpygpu
*
* Experimental Python API, not considered public yet (called '_gpu'),
* we may re-expose as public later.
+ *
+ * - Use ``bpygpu_`` for local API.
+ * - Use ``BPyGPU`` for public API.
*/
#include <Python.h>
-#include "GPU_batch.h"
-#include "GPU_vertex_format.h"
-
-#include "gpu_py_api.h"
-#include "gpu_py_types.h"
-
#include "BLI_utildefines.h"
#include "../generic/python_utildefines.h"
+#include "gpu_py_matrix.h"
+#include "gpu_py_select.h"
+#include "gpu_py_types.h"
+
+#include "gpu_py_api.h" /* own include */
+
PyDoc_STRVAR(GPU_doc,
-"This module provides access to gpu drawing functions."
+"This module to provide functions concerning the GPU implementation in Blender."
+"\n\n"
+"Submodules:\n"
+"\n"
+".. toctree::\n"
+" :maxdepth: 1\n"
+"\n"
+" gpu.types.rst\n"
+" gpu.matrix.rst\n"
+" gpu.select.rst\n"
+"\n"
);
static struct PyModuleDef GPU_module_def = {
PyModuleDef_HEAD_INIT,
- .m_name = "_gpu", /* m_name */
- .m_doc = GPU_doc, /* m_doc */
+ .m_name = "gpu",
+ .m_doc = GPU_doc,
};
PyObject *BPyInit_gpu(void)
@@ -54,10 +67,17 @@ PyObject *BPyInit_gpu(void)
mod = PyModule_Create(&GPU_module_def);
- /* _gpu.types */
PyModule_AddObject(mod, "types", (submodule = BPyInit_gpu_types()));
PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
Py_INCREF(submodule);
+ PyModule_AddObject(mod, "matrix", (submodule = BPyInit_gpu_matrix()));
+ PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+ Py_INCREF(submodule);
+
+ PyModule_AddObject(mod, "select", (submodule = BPyInit_gpu_select()));
+ PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+ Py_INCREF(submodule);
+
return mod;
}
diff --git a/source/blender/python/gpu/gpu_py_api.h b/source/blender/python/gpu/gpu_py_api.h
index 387bfcab950..20eafb3d140 100644
--- a/source/blender/python/gpu/gpu_py_api.h
+++ b/source/blender/python/gpu/gpu_py_api.h
@@ -18,13 +18,13 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#ifndef __GPU_PY_API_H__
-#define __GPU_PY_API_H__
-
/** \file blender/python/gpu/gpu_py_api.h
- * \ingroup pygpu
+ * \ingroup bpygpu
*/
+#ifndef __GPU_PY_API_H__
+#define __GPU_PY_API_H__
+
PyObject *BPyInit_gpu(void);
#endif /* __GPU_PY_API_H__ */
diff --git a/source/blender/python/gpu/gpu_py_batch.c b/source/blender/python/gpu/gpu_py_batch.c
new file mode 100644
index 00000000000..dfc95e2a996
--- /dev/null
+++ b/source/blender/python/gpu/gpu_py_batch.c
@@ -0,0 +1,414 @@
+/*
+ * ***** 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.
+ *
+ * Copyright 2015, Blender Foundation.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/gpu/gpu_py_batch.c
+ * \ingroup bpygpu
+ *
+ * This file defines the offscreen functionalities of the 'gpu' module
+ * used for off-screen OpenGL rendering.
+ *
+ * - Use ``bpygpu_`` for local API.
+ * - Use ``BPyGPU`` for public API.
+ */
+
+#include <Python.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+
+#include "BKE_global.h"
+#include "BKE_library.h"
+
+#include "GPU_batch.h"
+
+#include "../mathutils/mathutils.h"
+
+#include "../generic/py_capi_utils.h"
+
+#include "gpu_py_vertex_buffer.h"
+#include "gpu_py_batch.h" /* own include */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name VertBatch Type
+ * \{ */
+
+static int bpygpu_ParsePrimType(PyObject *o, void *p)
+{
+ Py_ssize_t mode_id_len;
+ const char *mode_id = _PyUnicode_AsStringAndSize(o, &mode_id_len);
+ if (mode_id == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "expected a string, got %s",
+ Py_TYPE(o)->tp_name);
+ return 0;
+ }
+#define MATCH_ID(id) \
+ if (mode_id_len == strlen(STRINGIFY(id))) { \
+ if (STREQ(mode_id, STRINGIFY(id))) { \
+ mode = GPU_PRIM_##id; \
+ goto success; \
+ } \
+ } ((void)0)
+
+ GPUPrimType mode;
+ MATCH_ID(POINTS);
+ MATCH_ID(LINES);
+ MATCH_ID(TRIS);
+ MATCH_ID(LINE_STRIP);
+ MATCH_ID(LINE_LOOP);
+ MATCH_ID(TRI_STRIP);
+ MATCH_ID(TRI_FAN);
+ MATCH_ID(LINE_STRIP_ADJ);
+
+#undef MATCH_ID
+ PyErr_Format(PyExc_ValueError,
+ "unknown type literal: '%s'",
+ mode_id);
+ return 0;
+
+success:
+ (*(GPUPrimType *)p) = mode;
+ return 1;
+}
+
+static PyObject *bpygpu_Batch_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
+{
+ const char * const keywords[] = {"type", "buf", NULL};
+
+ struct {
+ GPUPrimType type_id;
+ BPyGPUVertBuf *py_buf;
+ } params;
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwds,
+ "$O&O!:GPUBatch.__new__", (char **)keywords,
+ bpygpu_ParsePrimType, ¶ms.type_id,
+ &BPyGPUVertBuf_Type, ¶ms.py_buf))
+ {
+ return NULL;
+ }
+
+ GPUBatch *batch = GPU_batch_create(params.type_id, params.py_buf->buf, NULL);
+ BPyGPUBatch *ret = (BPyGPUBatch *)BPyGPUBatch_CreatePyObject(batch);
+
+#ifdef USE_GPU_PY_REFERENCES
+ ret->references = PyList_New(1);
+ PyList_SET_ITEM(ret->references, 0, (PyObject *)params.py_buf);
+ Py_INCREF(params.py_buf);
+ PyObject_GC_Track(ret);
+#endif
+
+ return (PyObject *)ret;
+}
+
+PyDoc_STRVAR(bpygpu_VertBatch_vertbuf_add_doc,
+"TODO"
+);
+static PyObject *bpygpu_VertBatch_vertbuf_add(BPyGPUBatch *self, BPyGPUVertBuf *py_buf)
+{
+ if (!BPyGPUVertBuf_Check(py_buf)) {
+ PyErr_Format(PyExc_TypeError,
+ "Expected a GPUVertBuf, got %s",
+ Py_TYPE(py_buf)->tp_name);
+ return NULL;
+ }
+
+ if (self->batch->verts[0]->vertex_len != py_buf->buf->vertex_len) {
+ PyErr_Format(PyExc_TypeError,
+ "Expected %d length, got %d",
+ self->batch->verts[0]->vertex_len, py_buf->buf->vertex_len);
+ return NULL;
+ }
+
+#ifdef US
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list