Blender V5.0
gpu_py_offscreen.cc File Reference
#include <Python.h>
#include "BLI_string_utf8.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_state.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\n")
static PyObject * pygpu_offscreen_width_get (BPyGPUOffScreen *self, void *)
 PyDoc_STRVAR (pygpu_offscreen_height_doc, "Height of the texture.\n" "\n" ":type: int\n")
static PyObject * pygpu_offscreen_height_get (BPyGPUOffScreen *self, void *)
 PyDoc_STRVAR (pygpu_offscreen_texture_color_doc, "The color texture attached.\n" "\n" ":type: :class:`gpu.types.GPUTexture`\n")
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()

void BPyGPUOffScreen__tp_dealloc ( BPyGPUOffScreen * self)
static

Definition at line 524 of file gpu_py_offscreen.cc.

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

◆ BPyGPUOffScreen_CreatePyObject()

PyObject * BPyGPUOffScreen_CreatePyObject ( GPUOffScreen * ofs)
nodiscard

Definition at line 664 of file gpu_py_offscreen.cc.

References BPyGPUOffScreen_Type, and self.

Referenced by pygpu_offscreen__tp_new().

◆ PyDoc_STRVAR() [1/8]

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/8]

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/8]

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() [4/8]

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() [5/8]

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

◆ PyDoc_STRVAR() [6/8]

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

◆ PyDoc_STRVAR() [7/8]

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() [8/8]

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

◆ pygpu_offscreen__tp_new()

◆ pygpu_offscreen_bind()

PyObject * pygpu_offscreen_bind ( BPyGPUOffScreen * self)
static

◆ pygpu_offscreen_draw_view3d()

◆ pygpu_offscreen_free()

PyObject * pygpu_offscreen_free ( BPyGPUOffScreen * self)
static

◆ pygpu_offscreen_height_get()

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

Definition at line 349 of file gpu_py_offscreen.cc.

References BPY_GPU_OFFSCREEN_CHECK_OBJ, GPU_offscreen_height(), and self.

◆ pygpu_offscreen_stack_context__tp_dealloc()

void pygpu_offscreen_stack_context__tp_dealloc ( OffScreenStackContext * self)
static

Definition at line 97 of file gpu_py_offscreen.cc.

References Py_DECREF(), and self.

◆ pygpu_offscreen_stack_context_enter()

PyObject * pygpu_offscreen_stack_context_enter ( OffScreenStackContext * self)
static

◆ pygpu_offscreen_stack_context_exit()

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

◆ pygpu_offscreen_texture_color_get()

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

◆ pygpu_offscreen_unbind()

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

◆ pygpu_offscreen_valid_check()

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()

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

Definition at line 337 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 606 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:
= {
{int(blender::gpu::TextureFormat::UNORM_8_8_8_8), "RGBA8"},
{int(blender::gpu::TextureFormat::UNORM_16_16_16_16), "RGBA16"},
{int(blender::gpu::TextureFormat::SFLOAT_16_16_16_16), "RGBA16F"},
{int(blender::gpu::TextureFormat::SFLOAT_32_32_32_32), "RGBA32F"},
{0, nullptr},
}

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:
= {
{"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_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 535 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 564 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 154 of file gpu_py_offscreen.cc.

◆ PyGPUOffscreenStackContext_Type

PyTypeObject PyGPUOffscreenStackContext_Type
static

Definition at line 168 of file gpu_py_offscreen.cc.

Referenced by pygpu_offscreen_bind().