2018-09-05 21:10:42 -03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bpygpu
|
2018-09-05 21:10:42 -03:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2019-09-09 14:49:05 +02:00
|
|
|
#include "BKE_global.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2018-09-05 21:10:42 -03:00
|
|
|
#include "BKE_scene.h"
|
|
|
|
|
2018-09-06 10:47:10 +10:00
|
|
|
#include "DNA_scene_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_screen_types.h"
|
2018-09-05 21:10:42 -03:00
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
|
2020-05-26 11:38:09 -03:00
|
|
|
#include "GPU_context.h"
|
2018-09-05 21:10:42 -03:00
|
|
|
#include "GPU_framebuffer.h"
|
|
|
|
#include "GPU_texture.h"
|
|
|
|
|
2020-03-06 12:08:03 +01:00
|
|
|
#include "ED_view3d.h"
|
|
|
|
#include "ED_view3d_offscreen.h"
|
2018-09-05 21:10:42 -03:00
|
|
|
|
|
|
|
#include "../mathutils/mathutils.h"
|
|
|
|
|
|
|
|
#include "../generic/py_capi_utils.h"
|
|
|
|
|
2019-01-03 00:55:07 +11:00
|
|
|
#include "gpu_py_api.h"
|
2018-09-05 21:10:42 -03:00
|
|
|
#include "gpu_py_offscreen.h" /* own include */
|
|
|
|
|
2019-03-19 15:17:46 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name GPUOffScreen Common Utilities
|
|
|
|
* \{ */
|
2018-11-19 10:16:27 -02:00
|
|
|
|
|
|
|
static int bpygpu_offscreen_valid_check(BPyGPUOffScreen *bpygpu_ofs)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (UNLIKELY(bpygpu_ofs->ofs == NULL)) {
|
|
|
|
PyErr_SetString(PyExc_ReferenceError, "GPU offscreen was freed, no further access is valid");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2018-11-19 10:16:27 -02:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
#define BPY_GPU_OFFSCREEN_CHECK_OBJ(bpygpu) \
|
|
|
|
{ \
|
|
|
|
if (UNLIKELY(bpygpu_offscreen_valid_check(bpygpu) == -1)) { \
|
|
|
|
return NULL; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
((void)0)
|
2018-11-19 10:16:27 -02:00
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
2018-09-05 21:10:42 -03:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name GPUOffscreen Type
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
static PyObject *bpygpu_offscreen_new(PyTypeObject *UNUSED(self), PyObject *args, PyObject *kwds)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BPYGPU_IS_INIT_OR_ERROR_OBJ;
|
|
|
|
|
2020-05-26 11:38:09 -03:00
|
|
|
GPUOffScreen *ofs = NULL;
|
2020-07-02 17:28:30 +02:00
|
|
|
int width, height;
|
2019-04-17 06:17:24 +02:00
|
|
|
char err_out[256];
|
|
|
|
|
2020-07-02 17:28:30 +02:00
|
|
|
static const char *_keywords[] = {"width", "height", NULL};
|
2019-04-17 06:17:24 +02:00
|
|
|
static _PyArg_Parser _parser = {"ii|i:GPUOffScreen.__new__", _keywords, 0};
|
2020-07-02 17:28:30 +02:00
|
|
|
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &width, &height)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-05-26 11:38:09 -03:00
|
|
|
if (GPU_context_active_get()) {
|
2020-07-02 17:28:30 +02:00
|
|
|
ofs = GPU_offscreen_create(width, height, true, false, err_out);
|
2020-05-26 11:38:09 -03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
strncpy(err_out, "No active GPU context found", 256);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (ofs == NULL) {
|
|
|
|
PyErr_Format(PyExc_RuntimeError,
|
|
|
|
"gpu.offscreen.new(...) failed with '%s'",
|
|
|
|
err_out[0] ? err_out : "unknown error");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return BPyGPUOffScreen_CreatePyObject(ofs);
|
2018-09-05 21:10:42 -03:00
|
|
|
}
|
|
|
|
|
2018-11-13 14:55:15 +01:00
|
|
|
PyDoc_STRVAR(bpygpu_offscreen_width_doc, "Width of the texture.\n\n:type: `int`");
|
2018-09-05 21:10:42 -03:00
|
|
|
static PyObject *bpygpu_offscreen_width_get(BPyGPUOffScreen *self, void *UNUSED(type))
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
|
|
|
|
return PyLong_FromLong(GPU_offscreen_width(self->ofs));
|
2018-09-05 21:10:42 -03:00
|
|
|
}
|
|
|
|
|
2018-11-13 14:55:15 +01:00
|
|
|
PyDoc_STRVAR(bpygpu_offscreen_height_doc, "Height of the texture.\n\n:type: `int`");
|
2018-09-05 21:10:42 -03:00
|
|
|
static PyObject *bpygpu_offscreen_height_get(BPyGPUOffScreen *self, void *UNUSED(type))
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
|
|
|
|
return PyLong_FromLong(GPU_offscreen_height(self->ofs));
|
2018-09-05 21:10:42 -03:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
PyDoc_STRVAR(bpygpu_offscreen_color_texture_doc,
|
|
|
|
"OpenGL bindcode for the color texture.\n\n:type: `int`");
|
2018-09-05 21:10:42 -03:00
|
|
|
static PyObject *bpygpu_offscreen_color_texture_get(BPyGPUOffScreen *self, void *UNUSED(type))
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
|
|
|
|
GPUTexture *texture = GPU_offscreen_color_texture(self->ofs);
|
|
|
|
return PyLong_FromLong(GPU_texture_opengl_bindcode(texture));
|
2018-09-05 21:10:42 -03:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
bpygpu_offscreen_bind_doc,
|
|
|
|
".. method:: bind(save=True)\n"
|
|
|
|
"\n"
|
|
|
|
" Bind the offscreen object.\n"
|
|
|
|
" To make sure that the offscreen gets unbind whether an exception occurs or not, pack it "
|
|
|
|
"into a `with` statement.\n"
|
|
|
|
"\n"
|
|
|
|
" :arg save: Save the current OpenGL state, so that it can be restored when unbinding.\n"
|
|
|
|
" :type save: `bool`\n");
|
2018-09-05 21:10:42 -03:00
|
|
|
static PyObject *bpygpu_offscreen_bind(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
|
|
|
|
bool save = true;
|
2018-09-05 21:10:42 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static const char *_keywords[] = {"save", NULL};
|
|
|
|
static _PyArg_Parser _parser = {"|O&:bind", _keywords, 0};
|
|
|
|
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, PyC_ParseBool, &save)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-09-05 21:10:42 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_offscreen_bind(self->ofs, save);
|
2018-11-19 10:16:27 -02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
self->is_saved = save;
|
|
|
|
Py_INCREF(self);
|
2018-11-19 10:16:27 -02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (PyObject *)self;
|
2018-09-05 21:10:42 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(bpygpu_offscreen_unbind_doc,
|
2019-04-17 06:17:24 +02:00
|
|
|
".. method:: unbind(restore=True)\n"
|
|
|
|
"\n"
|
|
|
|
" Unbind the offscreen object.\n"
|
|
|
|
"\n"
|
|
|
|
" :arg restore: Restore the OpenGL state, can only be used when the state has been "
|
|
|
|
"saved before.\n"
|
|
|
|
" :type restore: `bool`\n");
|
2018-09-05 21:10:42 -03:00
|
|
|
static PyObject *bpygpu_offscreen_unbind(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bool restore = true;
|
2018-09-05 21:10:42 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
|
2018-09-05 21:10:42 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static const char *_keywords[] = {"restore", NULL};
|
|
|
|
static _PyArg_Parser _parser = {"|O&:unbind", _keywords, 0};
|
|
|
|
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, PyC_ParseBool, &restore)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-09-05 21:10:42 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_offscreen_unbind(self->ofs, restore);
|
|
|
|
Py_RETURN_NONE;
|
2018-09-05 21:10:42 -03:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
bpygpu_offscreen_draw_view3d_doc,
|
2019-10-07 14:38:11 -03:00
|
|
|
".. method:: draw_view3d(scene, view_layer, view3d, region, view_matrix, projection_matrix)\n"
|
2019-04-17 06:17:24 +02:00
|
|
|
"\n"
|
|
|
|
" Draw the 3d viewport in the offscreen object.\n"
|
|
|
|
"\n"
|
|
|
|
" :arg scene: Scene to draw.\n"
|
|
|
|
" :type scene: :class:`bpy.types.Scene`\n"
|
|
|
|
" :arg view_layer: View layer to draw.\n"
|
|
|
|
" :type view_layer: :class:`bpy.types.ViewLayer`\n"
|
|
|
|
" :arg view3d: 3D View to get the drawing settings from.\n"
|
|
|
|
" :type view3d: :class:`bpy.types.SpaceView3D`\n"
|
|
|
|
" :arg region: Region of the 3D View (required as temporary draw target).\n"
|
|
|
|
" :type region: :class:`bpy.types.Region`\n"
|
|
|
|
" :arg view_matrix: View Matrix (e.g. ``camera.matrix_world.inverted()``).\n"
|
|
|
|
" :type view_matrix: :class:`mathutils.Matrix`\n"
|
|
|
|
" :arg projection_matrix: Projection Matrix (e.g. ``camera.calc_matrix_camera(...)``).\n"
|
|
|
|
" :type projection_matrix: :class:`mathutils.Matrix`\n");
|
|
|
|
static PyObject *bpygpu_offscreen_draw_view3d(BPyGPUOffScreen *self,
|
|
|
|
PyObject *args,
|
|
|
|
PyObject *kwds)
|
2018-09-05 21:10:42 -03:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MatrixObject *py_mat_view, *py_mat_projection;
|
|
|
|
PyObject *py_scene, *py_view_layer, *py_region, *py_view3d;
|
|
|
|
|
|
|
|
struct Depsgraph *depsgraph;
|
|
|
|
struct Scene *scene;
|
|
|
|
struct ViewLayer *view_layer;
|
|
|
|
View3D *v3d;
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region;
|
2019-04-17 06:17:24 +02:00
|
|
|
struct RV3DMatrixStore *rv3d_mats;
|
|
|
|
|
|
|
|
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
|
|
|
|
|
|
|
|
static const char *_keywords[] = {
|
|
|
|
"scene", "view_layer", "view3d", "region", "view_matrix", "projection_matrix", NULL};
|
|
|
|
|
|
|
|
static _PyArg_Parser _parser = {"OOOOO&O&:draw_view3d", _keywords, 0};
|
|
|
|
if (!_PyArg_ParseTupleAndKeywordsFast(args,
|
|
|
|
kwds,
|
|
|
|
&_parser,
|
|
|
|
&py_scene,
|
|
|
|
&py_view_layer,
|
|
|
|
&py_view3d,
|
|
|
|
&py_region,
|
|
|
|
Matrix_Parse4x4,
|
|
|
|
&py_mat_view,
|
|
|
|
Matrix_Parse4x4,
|
|
|
|
&py_mat_projection) ||
|
|
|
|
(!(scene = PyC_RNA_AsPointer(py_scene, "Scene")) ||
|
|
|
|
!(view_layer = PyC_RNA_AsPointer(py_view_layer, "ViewLayer")) ||
|
|
|
|
!(v3d = PyC_RNA_AsPointer(py_view3d, "SpaceView3D")) ||
|
2020-03-06 16:56:42 +01:00
|
|
|
!(region = PyC_RNA_AsPointer(py_region, "Region")))) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_assert(BKE_id_is_in_global_main(&scene->id));
|
|
|
|
|
2019-09-09 14:49:05 +02:00
|
|
|
depsgraph = BKE_scene_get_depsgraph(G_MAIN, scene, view_layer, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
rv3d_mats = ED_view3d_mats_rv3d_backup(region->regiondata);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
GPU_offscreen_bind(self->ofs, true);
|
|
|
|
|
|
|
|
ED_view3d_draw_offscreen(depsgraph,
|
|
|
|
scene,
|
|
|
|
v3d->shading.type,
|
|
|
|
v3d,
|
2020-03-06 16:56:42 +01:00
|
|
|
region,
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_offscreen_width(self->ofs),
|
|
|
|
GPU_offscreen_height(self->ofs),
|
|
|
|
(float(*)[4])py_mat_view->matrix,
|
|
|
|
(float(*)[4])py_mat_projection->matrix,
|
2019-06-06 08:37:43 +02:00
|
|
|
true,
|
2019-04-17 06:17:24 +02:00
|
|
|
true,
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
true,
|
2019-04-17 06:17:24 +02:00
|
|
|
"",
|
2020-03-02 09:24:06 +01:00
|
|
|
false,
|
2019-04-17 06:17:24 +02:00
|
|
|
self->ofs,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
GPU_offscreen_unbind(self->ofs, true);
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_view3d_mats_rv3d_restore(region->regiondata, rv3d_mats);
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(rv3d_mats);
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
2018-09-05 21:10:42 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(bpygpu_offscreen_free_doc,
|
2019-04-17 06:17:24 +02:00
|
|
|
".. method:: free()\n"
|
|
|
|
"\n"
|
|
|
|
" Free the offscreen object.\n"
|
|
|
|
" The framebuffer, texture and render objects will no longer be accessible.\n");
|
2018-09-05 21:10:42 -03:00
|
|
|
static PyObject *bpygpu_offscreen_free(BPyGPUOffScreen *self)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
|
2018-09-05 21:10:42 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_offscreen_free(self->ofs);
|
|
|
|
self->ofs = NULL;
|
|
|
|
Py_RETURN_NONE;
|
2018-09-05 21:10:42 -03:00
|
|
|
}
|
|
|
|
|
2018-11-20 08:53:00 +11:00
|
|
|
static PyObject *bpygpu_offscreen_bind_context_enter(BPyGPUOffScreen *UNUSED(self))
|
2018-11-19 10:16:27 -02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Py_RETURN_NONE;
|
2018-11-19 10:16:27 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *bpygpu_offscreen_bind_context_exit(BPyGPUOffScreen *self, PyObject *UNUSED(args))
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_offscreen_unbind(self->ofs, self->is_saved);
|
|
|
|
Py_RETURN_NONE;
|
2018-11-19 10:16:27 -02:00
|
|
|
}
|
|
|
|
|
2018-09-05 21:10:42 -03:00
|
|
|
static void BPyGPUOffScreen__tp_dealloc(BPyGPUOffScreen *self)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (self->ofs) {
|
|
|
|
GPU_offscreen_free(self->ofs);
|
|
|
|
}
|
|
|
|
Py_TYPE(self)->tp_free((PyObject *)self);
|
2018-09-05 21:10:42 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyGetSetDef bpygpu_offscreen_getseters[] = {
|
2019-12-20 10:42:57 +11:00
|
|
|
{"color_texture",
|
2019-04-17 06:17:24 +02:00
|
|
|
(getter)bpygpu_offscreen_color_texture_get,
|
|
|
|
(setter)NULL,
|
|
|
|
bpygpu_offscreen_color_texture_doc,
|
|
|
|
NULL},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"width", (getter)bpygpu_offscreen_width_get, (setter)NULL, bpygpu_offscreen_width_doc, NULL},
|
|
|
|
{"height",
|
2019-04-17 06:17:24 +02:00
|
|
|
(getter)bpygpu_offscreen_height_get,
|
|
|
|
(setter)NULL,
|
|
|
|
bpygpu_offscreen_height_doc,
|
|
|
|
NULL},
|
|
|
|
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
|
2018-09-05 21:10:42 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct PyMethodDef bpygpu_offscreen_methods[] = {
|
2019-04-17 06:17:24 +02:00
|
|
|
{"bind",
|
|
|
|
(PyCFunction)bpygpu_offscreen_bind,
|
|
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
|
|
bpygpu_offscreen_bind_doc},
|
|
|
|
{"unbind",
|
|
|
|
(PyCFunction)bpygpu_offscreen_unbind,
|
|
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
|
|
bpygpu_offscreen_unbind_doc},
|
|
|
|
{"draw_view3d",
|
|
|
|
(PyCFunction)bpygpu_offscreen_draw_view3d,
|
|
|
|
METH_VARARGS | METH_KEYWORDS,
|
|
|
|
bpygpu_offscreen_draw_view3d_doc},
|
|
|
|
{"free", (PyCFunction)bpygpu_offscreen_free, METH_NOARGS, bpygpu_offscreen_free_doc},
|
|
|
|
{"__enter__", (PyCFunction)bpygpu_offscreen_bind_context_enter, METH_NOARGS},
|
|
|
|
{"__exit__", (PyCFunction)bpygpu_offscreen_bind_context_exit, METH_VARARGS},
|
|
|
|
{NULL, NULL, 0, NULL},
|
2018-09-05 21:10:42 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
PyDoc_STRVAR(bpygpu_offscreen_doc,
|
2020-07-02 17:28:30 +02:00
|
|
|
".. class:: GPUOffScreen(width, height)\n"
|
2019-04-17 06:17:24 +02:00
|
|
|
"\n"
|
|
|
|
" This object gives access to off screen buffers.\n"
|
|
|
|
"\n"
|
|
|
|
" :arg width: Horizontal dimension of the buffer.\n"
|
|
|
|
" :type width: `int`\n"
|
|
|
|
" :arg height: Vertical dimension of the buffer.\n"
|
2020-07-02 17:28:30 +02:00
|
|
|
" :type height: `int`\n");
|
2018-09-05 21:10:42 -03:00
|
|
|
PyTypeObject BPyGPUOffScreen_Type = {
|
2019-04-17 06:17:24 +02:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUOffScreen",
|
|
|
|
.tp_basicsize = sizeof(BPyGPUOffScreen),
|
|
|
|
.tp_dealloc = (destructor)BPyGPUOffScreen__tp_dealloc,
|
|
|
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
|
|
|
.tp_doc = bpygpu_offscreen_doc,
|
|
|
|
.tp_methods = bpygpu_offscreen_methods,
|
|
|
|
.tp_getset = bpygpu_offscreen_getseters,
|
|
|
|
.tp_new = bpygpu_offscreen_new,
|
2018-09-05 21:10:42 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Public API
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
PyObject *BPyGPUOffScreen_CreatePyObject(GPUOffScreen *ofs)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BPyGPUOffScreen *self;
|
2018-09-05 21:10:42 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
self = PyObject_New(BPyGPUOffScreen, &BPyGPUOffScreen_Type);
|
|
|
|
self->ofs = ofs;
|
2018-09-05 21:10:42 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (PyObject *)self;
|
2018-09-05 21:10:42 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
#undef BPY_GPU_OFFSCREEN_CHECK_OBJ
|