Blender  V3.3
Classes | Macros
gpu_py_offscreen.c File Reference
#include <Python.h>
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BKE_global.h"
#include "BKE_lib_id.h"
#include "BKE_scene.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_view3d_types.h"
#include "GPU_context.h"
#include "GPU_framebuffer.h"
#include "GPU_texture.h"
#include "GPU_viewport.h"
#include "ED_view3d_offscreen.h"
#include "../mathutils/mathutils.h"
#include "../generic/py_capi_utils.h"
#include "gpu_py.h"
#include "gpu_py_texture.h"
#include "gpu_py_offscreen.h"

Go to the source code of this file.

Classes

struct  OffScreenStackContext
 

Macros

#define BPYGPU_USE_GPUOBJ_FREE_METHOD
 

Functions

Public API
PyObject * BPyGPUOffScreen_CreatePyObject (GPUOffScreen *ofs)
 

GPUOffScreen Common Utilities

#define BPY_GPU_OFFSCREEN_CHECK_OBJ(bpygpu)
 
static const struct PyC_StringEnumItems pygpu_framebuffer_color_texture_formats []
 
static int pygpu_offscreen_valid_check (BPyGPUOffScreen *py_ofs)
 

Stack (Context Manager)

Safer alternative to ensure balanced push/pop calls.

static PyMethodDef pygpu_offscreen_stack_context__tp_methods []
 
static PyTypeObject PyGPUOffscreenStackContext_Type
 
static void pygpu_offscreen_stack_context__tp_dealloc (OffScreenStackContext *self)
 
static PyObject * pygpu_offscreen_stack_context_enter (OffScreenStackContext *self)
 
static PyObject * pygpu_offscreen_stack_context_exit (OffScreenStackContext *self, PyObject *UNUSED(args))
 
 PyDoc_STRVAR (pygpu_offscreen_bind_doc, ".. function:: bind()\n" "\n" " Context manager to ensure balanced bind calls, even in the case of an error.\n")
 
static PyObject * pygpu_offscreen_bind (BPyGPUOffScreen *self)
 
 PyDoc_STRVAR (pygpu_offscreen_unbind_doc, ".. 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")
 
static PyObject * pygpu_offscreen_unbind (BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
 

GPUOffscreen Type

static PyGetSetDef pygpu_offscreen__tp_getseters []
 
static struct PyMethodDef pygpu_offscreen__tp_methods []
 
PyTypeObject BPyGPUOffScreen_Type
 
static PyObject * pygpu_offscreen__tp_new (PyTypeObject *UNUSED(self), PyObject *args, PyObject *kwds)
 
 PyDoc_STRVAR (pygpu_offscreen_width_doc, "Width of the texture.\n\n:type: `int`")
 
static PyObject * pygpu_offscreen_width_get (BPyGPUOffScreen *self, void *UNUSED(type))
 
 PyDoc_STRVAR (pygpu_offscreen_height_doc, "Height of the texture.\n\n:type: `int`")
 
static PyObject * pygpu_offscreen_height_get (BPyGPUOffScreen *self, void *UNUSED(type))
 
 PyDoc_STRVAR (pygpu_offscreen_color_texture_doc, "OpenGL bindcode for the color texture.\n\n:type: `int`")
 
static PyObject * pygpu_offscreen_color_texture_get (BPyGPUOffScreen *self, void *UNUSED(type))
 
 PyDoc_STRVAR (pygpu_offscreen_texture_color_doc, "The color texture attached.\n" "\n" ":type: :class:`gpu.types.GPUTexture`")
 
static PyObject * pygpu_offscreen_texture_color_get (BPyGPUOffScreen *self, void *UNUSED(type))
 
 PyDoc_STRVAR (pygpu_offscreen_draw_view3d_doc, ".. method:: draw_view3d(scene, view_layer, view3d, region, view_matrix, projection_matrix, " "do_color_management=False)\n" "\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" " :arg do_color_management: Color manage the output.\n" " :type do_color_management: bool\n")
 
static PyObject * pygpu_offscreen_draw_view3d (BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
 
 PyDoc_STRVAR (pygpu_offscreen_free_doc, ".. method:: free()\n" "\n" " Free the offscreen object.\n" " The framebuffer, texture and render objects will no longer be accessible.\n")
 
static PyObject * pygpu_offscreen_free (BPyGPUOffScreen *self)
 
static void BPyGPUOffScreen__tp_dealloc (BPyGPUOffScreen *self)
 
 PyDoc_STRVAR (pygpu_offscreen__tp_doc, ".. class:: GPUOffScreen(width, height, *, format='RGBA8')\n" "\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" " :type height: int\n" " :arg format: Internal data format inside GPU memory for color attachment " "texture. Possible values are:\n" " `RGBA8`,\n" " `RGBA16`,\n" " `RGBA16F`,\n" " `RGBA32F`,\n" " :type format: str\n")
 

Detailed Description

This file defines the offscreen functionalities of the 'gpu' module used for off-screen OpenGL rendering.

Definition in file gpu_py_offscreen.c.

Macro Definition Documentation

◆ BPY_GPU_OFFSCREEN_CHECK_OBJ

#define BPY_GPU_OFFSCREEN_CHECK_OBJ (   bpygpu)
Value:
{ \
if (UNLIKELY(pygpu_offscreen_valid_check(bpygpu) == -1)) { \
return NULL; \
} \
} \
((void)0)
#define UNLIKELY(x)
SyclQueue void void size_t num_bytes void
static int pygpu_offscreen_valid_check(BPyGPUOffScreen *py_ofs)

Definition at line 73 of file gpu_py_offscreen.c.

◆ BPYGPU_USE_GPUOBJ_FREE_METHOD

#define BPYGPU_USE_GPUOBJ_FREE_METHOD

Definition at line 44 of file gpu_py_offscreen.c.

Function Documentation

◆ BPyGPUOffScreen__tp_dealloc()

static void BPyGPUOffScreen__tp_dealloc ( BPyGPUOffScreen self)
static

Definition at line 434 of file gpu_py_offscreen.c.

References GPU_offscreen_free(), GPU_viewport_free(), and self.

◆ BPyGPUOffScreen_CreatePyObject()

PyObject* BPyGPUOffScreen_CreatePyObject ( GPUOffScreen ofs)

Definition at line 510 of file gpu_py_offscreen.c.

References BPyGPUOffScreen_Type, and NULL.

Referenced by pygpu_offscreen__tp_new().

◆ PyDoc_STRVAR() [1/9]

PyDoc_STRVAR ( pygpu_offscreen__tp_doc  ,
".. class:: GPUOffScreen(width, height, *, format='RGBA8')\n" "\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" " :type height: int\n" " :arg format: Internal data format inside GPU memory for color attachment " "texture. Possible values are:\n" " `RGBA8`  ,
\n" " `RGBA16`  ,
\n" " `RGBA16F`  ,
\n" " `RGBA32F`  ,
\n" " :type format:str\n"   
)

◆ PyDoc_STRVAR() [2/9]

PyDoc_STRVAR ( pygpu_offscreen_bind_doc  ,
".. function:: bind()\n" "\n" " Context manager to ensure balanced bind  calls,
even in the case of an error.\n"   
)

◆ PyDoc_STRVAR() [3/9]

PyDoc_STRVAR ( pygpu_offscreen_color_texture_doc  ,
"OpenGL bindcode for the color texture.\n\n:type: `int`"   
)

◆ PyDoc_STRVAR() [4/9]

PyDoc_STRVAR ( pygpu_offscreen_draw_view3d_doc  ,
".. method:: draw_view3d(scene, view_layer, view3d, region, view_matrix, projection_matrix, " "do_color_management=False)\n" "\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" " :arg do_color_management: Color manage the output.\n" " :type do_color_management: bool\n"   
)

◆ PyDoc_STRVAR() [5/9]

PyDoc_STRVAR ( pygpu_offscreen_free_doc  ,
".. method:: free()\n" "\n" " Free the offscreen object.\n" " The  framebuffer,
texture and render objects will no longer be accessible.\n"   
)

◆ PyDoc_STRVAR() [6/9]

PyDoc_STRVAR ( pygpu_offscreen_height_doc  ,
"Height of the texture.\n\n:type: `int`"   
)

◆ PyDoc_STRVAR() [7/9]

PyDoc_STRVAR ( pygpu_offscreen_texture_color_doc  ,
"The color texture attached.\n" "\n" ":type: :class:`gpu.types.GPUTexture`"   
)

◆ PyDoc_STRVAR() [8/9]

PyDoc_STRVAR ( pygpu_offscreen_unbind_doc  ,
".. 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"   
)

◆ PyDoc_STRVAR() [9/9]

PyDoc_STRVAR ( pygpu_offscreen_width_doc  ,
"Width of the texture.\n\n:type: `int`"   
)

◆ pygpu_offscreen__tp_new()

static PyObject* pygpu_offscreen__tp_new ( PyTypeObject *  UNUSEDself,
PyObject *  args,
PyObject *  kwds 
)
static

◆ pygpu_offscreen_bind()

static PyObject* pygpu_offscreen_bind ( BPyGPUOffScreen self)
static

◆ pygpu_offscreen_color_texture_get()

static PyObject* pygpu_offscreen_color_texture_get ( BPyGPUOffScreen self,
void UNUSEDtype 
)
static

◆ pygpu_offscreen_draw_view3d()

static PyObject* pygpu_offscreen_draw_view3d ( BPyGPUOffScreen self,
PyObject *  args,
PyObject *  kwds 
)
static

◆ pygpu_offscreen_free()

static PyObject* pygpu_offscreen_free ( BPyGPUOffScreen self)
static

◆ pygpu_offscreen_height_get()

static PyObject* pygpu_offscreen_height_get ( BPyGPUOffScreen self,
void UNUSEDtype 
)
static

Definition at line 261 of file gpu_py_offscreen.c.

References BPY_GPU_OFFSCREEN_CHECK_OBJ, GPU_offscreen_height(), and self.

◆ pygpu_offscreen_stack_context__tp_dealloc()

static void pygpu_offscreen_stack_context__tp_dealloc ( OffScreenStackContext self)
static

Definition at line 97 of file gpu_py_offscreen.c.

References self.

◆ pygpu_offscreen_stack_context_enter()

static PyObject* pygpu_offscreen_stack_context_enter ( OffScreenStackContext self)
static

◆ pygpu_offscreen_stack_context_exit()

static PyObject* pygpu_offscreen_stack_context_exit ( OffScreenStackContext self,
PyObject *  UNUSEDargs 
)
static

◆ pygpu_offscreen_texture_color_get()

static PyObject* pygpu_offscreen_texture_color_get ( BPyGPUOffScreen self,
void UNUSEDtype 
)
static

◆ pygpu_offscreen_unbind()

static PyObject* pygpu_offscreen_unbind ( BPyGPUOffScreen self,
PyObject *  args,
PyObject *  kwds 
)
static

◆ pygpu_offscreen_valid_check()

static int pygpu_offscreen_valid_check ( BPyGPUOffScreen py_ofs)
static

Definition at line 58 of file gpu_py_offscreen.c.

References BPYGPU_USE_GPUOBJ_FREE_METHOD, NULL, BPyGPUOffScreen::ofs, and UNLIKELY.

◆ pygpu_offscreen_width_get()

static PyObject* pygpu_offscreen_width_get ( BPyGPUOffScreen self,
void UNUSEDtype 
)
static

Definition at line 254 of file gpu_py_offscreen.c.

References BPY_GPU_OFFSCREEN_CHECK_OBJ, GPU_offscreen_width(), and self.

Variable Documentation

◆ BPyGPUOffScreen_Type

PyTypeObject BPyGPUOffScreen_Type
Initial value:
= {
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 = pygpu_offscreen__tp_doc,
}
static PyObject * pygpu_offscreen__tp_new(PyTypeObject *UNUSED(self), PyObject *args, PyObject *kwds)
static struct PyMethodDef pygpu_offscreen__tp_methods[]
static void BPyGPUOffScreen__tp_dealloc(BPyGPUOffScreen *self)
static PyGetSetDef pygpu_offscreen__tp_getseters[]
struct BPyGPUOffScreen BPyGPUOffScreen

Definition at line 493 of file gpu_py_offscreen.c.

Referenced by bpygpu_types_init(), and BPyGPUOffScreen_CreatePyObject().

◆ pygpu_framebuffer_color_texture_formats

const struct PyC_StringEnumItems pygpu_framebuffer_color_texture_formats[]
static
Initial value:
= {
{GPU_RGBA8, "RGBA8"},
{GPU_RGBA16, "RGBA16"},
{GPU_RGBA16F, "RGBA16F"},
{GPU_RGBA32F, "RGBA32F"},
{0, NULL},
}
@ GPU_RGBA32F
Definition: GPU_texture.h:90
@ GPU_RGBA16
Definition: GPU_texture.h:94
@ GPU_RGBA8
Definition: GPU_texture.h:87
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img GPU_RGBA16F

Definition at line 1 of file gpu_py_offscreen.c.

Referenced by pygpu_offscreen__tp_new().

◆ pygpu_offscreen__tp_getseters

PyGetSetDef pygpu_offscreen__tp_getseters[]
static
Initial value:
= {
{"color_texture",
(setter)NULL,
pygpu_offscreen_color_texture_doc,
NULL},
{"texture_color",
(setter)NULL,
pygpu_offscreen_texture_color_doc,
NULL},
{"width", (getter)pygpu_offscreen_width_get, (setter)NULL, pygpu_offscreen_width_doc, NULL},
{"height", (getter)pygpu_offscreen_height_get, (setter)NULL, pygpu_offscreen_height_doc, NULL},
}
static PyObject * pygpu_offscreen_width_get(BPyGPUOffScreen *self, void *UNUSED(type))
static PyObject * pygpu_offscreen_texture_color_get(BPyGPUOffScreen *self, void *UNUSED(type))
static PyObject * pygpu_offscreen_height_get(BPyGPUOffScreen *self, void *UNUSED(type))
static PyObject * pygpu_offscreen_color_texture_get(BPyGPUOffScreen *self, void *UNUSED(type))

Definition at line 445 of file gpu_py_offscreen.c.

◆ pygpu_offscreen__tp_methods

struct PyMethodDef pygpu_offscreen__tp_methods[]
static
Initial value:
= {
{"bind", (PyCFunction)pygpu_offscreen_bind, METH_NOARGS, pygpu_offscreen_bind_doc},
{"unbind",
(PyCFunction)pygpu_offscreen_unbind,
METH_VARARGS | METH_KEYWORDS,
pygpu_offscreen_unbind_doc},
{"draw_view3d",
METH_VARARGS | METH_KEYWORDS,
pygpu_offscreen_draw_view3d_doc},
{"free", (PyCFunction)pygpu_offscreen_free, METH_NOARGS, pygpu_offscreen_free_doc},
{NULL, NULL, 0, NULL},
}
static PyObject * pygpu_offscreen_unbind(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
static PyObject * pygpu_offscreen_bind(BPyGPUOffScreen *self)
static PyObject * pygpu_offscreen_free(BPyGPUOffScreen *self)
static PyObject * pygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)

Definition at line 445 of file gpu_py_offscreen.c.

◆ pygpu_offscreen_stack_context__tp_methods

PyMethodDef pygpu_offscreen_stack_context__tp_methods[]
static
Initial value:
= {
{"__enter__", (PyCFunction)pygpu_offscreen_stack_context_enter, METH_NOARGS},
{"__exit__", (PyCFunction)pygpu_offscreen_stack_context_exit, METH_VARARGS},
{NULL},
}
static PyObject * pygpu_offscreen_stack_context_exit(OffScreenStackContext *self, PyObject *UNUSED(args))
static PyObject * pygpu_offscreen_stack_context_enter(OffScreenStackContext *self)

Definition at line 140 of file gpu_py_offscreen.c.

◆ PyGPUOffscreenStackContext_Type

PyTypeObject PyGPUOffscreenStackContext_Type
static
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUFrameBufferStackContext",
.tp_basicsize = sizeof(OffScreenStackContext),
.tp_dealloc = (destructor)pygpu_offscreen_stack_context__tp_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
}
static PyMethodDef pygpu_offscreen_stack_context__tp_methods[]
static void pygpu_offscreen_stack_context__tp_dealloc(OffScreenStackContext *self)

Definition at line 146 of file gpu_py_offscreen.c.

Referenced by pygpu_offscreen_bind().