Blender V4.3
gpu_py_offscreen.cc File Reference
#include <Python.h>
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BKE_global.hh"
#include "BKE_lib_id.hh"
#include "BKE_scene.hh"
#include "DNA_view3d_types.h"
#include "GPU_context.hh"
#include "GPU_framebuffer.hh"
#include "GPU_texture.hh"
#include "GPU_viewport.hh"
#include "ED_view3d_offscreen.hh"
#include "../mathutils/mathutils.hh"
#include "../generic/py_capi_utils.hh"
#include "../generic/python_compat.hh"
#include "gpu_py.hh"
#include "gpu_py_texture.hh"
#include "gpu_py_offscreen.hh"

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 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 *)
 
 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 PyMethodDef pygpu_offscreen__tp_methods []
 
PyTypeObject BPyGPUOffScreen_Type
 
static PyObject * pygpu_offscreen__tp_new (PyTypeObject *, 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 *)
 
 PyDoc_STRVAR (pygpu_offscreen_height_doc, "Height of the texture.\n" "\n" ":type: int")
 
static PyObject * pygpu_offscreen_height_get (BPyGPUOffScreen *self, void *)
 
 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 *)
 
 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 *)
 
 PyDoc_STRVAR (pygpu_offscreen_draw_view3d_doc, ".. method:: draw_view3d(scene, view_layer, view3d, region, view_matrix, projection_matrix, " "do_color_management=False, draw_background=True)\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" " :arg draw_background: Draw background.\n" " :type draw_background: 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.

  • Use bpygpu_ for local API.
  • Use BPyGPU for public API.

Definition in file gpu_py_offscreen.cc.

Macro Definition Documentation

◆ BPY_GPU_OFFSCREEN_CHECK_OBJ

#define BPY_GPU_OFFSCREEN_CHECK_OBJ ( bpygpu)

◆ BPYGPU_USE_GPUOBJ_FREE_METHOD

#define BPYGPU_USE_GPUOBJ_FREE_METHOD

Function Documentation

◆ BPyGPUOffScreen__tp_dealloc()

static void BPyGPUOffScreen__tp_dealloc ( BPyGPUOffScreen * self)
static

Definition at line 536 of file gpu_py_offscreen.cc.

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

◆ BPyGPUOffScreen_CreatePyObject()

PyObject * BPyGPUOffScreen_CreatePyObject ( GPUOffScreen * ofs)

Definition at line 672 of file gpu_py_offscreen.cc.

References BPyGPUOffScreen_Type, and self.

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, draw_background=True)\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" " :arg draw_background: Draw background.\n" " :type draw_background: 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()

◆ 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 *  )
static

◆ pygpu_offscreen_draw_view3d()

◆ pygpu_offscreen_free()

static PyObject * pygpu_offscreen_free ( BPyGPUOffScreen * self)
static

◆ pygpu_offscreen_height_get()

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

Definition at line 338 of file gpu_py_offscreen.cc.

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.cc.

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 *  )
static

◆ pygpu_offscreen_texture_color_get()

static PyObject * pygpu_offscreen_texture_color_get ( BPyGPUOffScreen * self,
void *  )
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.cc.

References BPYGPU_USE_GPUOBJ_FREE_METHOD, BPyGPUOffScreen::ofs, and UNLIKELY.

◆ pygpu_offscreen_width_get()

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

Definition at line 326 of file gpu_py_offscreen.cc.

References BPY_GPU_OFFSCREEN_CHECK_OBJ, GPU_offscreen_width(), and self.

Variable Documentation

◆ BPyGPUOffScreen_Type

PyTypeObject BPyGPUOffScreen_Type

Definition at line 614 of file gpu_py_offscreen.cc.

Referenced by bpygpu_types_init(), and BPyGPUOffScreen_CreatePyObject().

◆ pygpu_framebuffer_color_texture_formats

const PyC_StringEnumItems pygpu_framebuffer_color_texture_formats[]
static
Initial value:
= {
{GPU_RGBA8, "RGBA8"},
{GPU_RGBA16, "RGBA16"},
{GPU_RGBA16F, "RGBA16F"},
{GPU_RGBA32F, "RGBA32F"},
{0, nullptr},
}
@ GPU_RGBA16
additional_info("compositor_sum_float_shared") .push_constant(Type additional_info("compositor_sum_float_shared") .push_constant(Type GPU_RGBA32F
RAYTRACE_GROUP_SIZE additional_info("eevee_shared", "eevee_gbuffer_data", "eevee_global_ubo", "eevee_sampling_data", "eevee_utility_texture", "eevee_hiz_data", "draw_view") .specialization_constant(Type RAYTRACE_GROUP_SIZE in_sh_0_tx in_sh_2_tx screen_normal_tx GPU_RGBA8

Definition at line 50 of file gpu_py_offscreen.cc.

Referenced by pygpu_offscreen__tp_new().

◆ pygpu_offscreen__tp_getseters

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

Definition at line 547 of file gpu_py_offscreen.cc.

◆ pygpu_offscreen__tp_methods

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},
{nullptr, nullptr, 0, nullptr},
}
static PyObject * pygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
static PyObject * pygpu_offscreen_bind(BPyGPUOffScreen *self)
static PyObject * pygpu_offscreen_unbind(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
static PyObject * pygpu_offscreen_free(BPyGPUOffScreen *self)

Definition at line 576 of file gpu_py_offscreen.cc.

◆ 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},
{nullptr},
}
static PyObject * pygpu_offscreen_stack_context_enter(OffScreenStackContext *self)
static PyObject * pygpu_offscreen_stack_context_exit(OffScreenStackContext *self, PyObject *)

Definition at line 149 of file gpu_py_offscreen.cc.

◆ PyGPUOffscreenStackContext_Type

PyTypeObject PyGPUOffscreenStackContext_Type
static

Definition at line 159 of file gpu_py_offscreen.cc.

Referenced by pygpu_offscreen_bind().