Blender V5.0
gpu_py_framebuffer.cc File Reference
#include <Python.h>
#include "GPU_context.hh"
#include "GPU_framebuffer.hh"
#include "GPU_init_exit.hh"
#include "../generic/py_capi_utils.hh"
#include "../generic/python_compat.hh"
#include "../generic/python_utildefines.hh"
#include "../mathutils/mathutils.hh"
#include "gpu_py.hh"
#include "gpu_py_buffer.hh"
#include "gpu_py_framebuffer.hh"
#include "gpu_py_texture.hh"

Go to the source code of this file.

Classes

struct  PyFrameBufferStackContext

Macros

#define BPYGPU_FB_MAX_COLOR_ATTACHMENT   6

Functions

Public API
PyObject * BPyGPUFrameBuffer_CreatePyObject (blender::gpu::FrameBuffer *fb, bool shared_reference)

gpu::FrameBuffer Common Utilities

#define PYGPU_FRAMEBUFFER_CHECK_OBJ(bpygpu)
#define GPU_PY_FRAMEBUFFER_STACK_LEN   16
static int pygpu_framebuffer_valid_check (BPyGPUFrameBuffer *bpygpu_fb)
static void pygpu_framebuffer_free_if_possible (blender::gpu::FrameBuffer *fb)
static void pygpu_framebuffer_free_safe (BPyGPUFrameBuffer *self)
static bool pygpu_framebuffer_stack_push_and_bind_or_error (blender::gpu::FrameBuffer *fb)
static bool pygpu_framebuffer_stack_pop_and_restore_or_error (blender::gpu::FrameBuffer *fb)

Stack (Context Manager)

Safer alternative to ensure balanced push/pop calls.

static PyMethodDef pygpu_framebuffer_stack_context__tp_methods []
static PyTypeObject FramebufferStackContext_Type
static void pygpu_framebuffer_stack_context__tp_dealloc (PyFrameBufferStackContext *self)
static PyObject * pygpu_framebuffer_stack_context_enter (PyFrameBufferStackContext *self)
static PyObject * pygpu_framebuffer_stack_context_exit (PyFrameBufferStackContext *self, PyObject *)
 PyDoc_STRVAR (pygpu_framebuffer_bind_doc, ".. function:: bind()\n" "\n" " Context manager to ensure balanced bind calls, even in the case of an error.\n")
static PyObject * pygpu_framebuffer_bind (BPyGPUFrameBuffer *self)

GPUFramebuffer Type

static PyGetSetDef pygpu_framebuffer__tp_getseters []
static PyMethodDef pygpu_framebuffer__tp_methods []
PyTypeObject BPyGPUFrameBuffer_Type
static bool pygpu_framebuffer_new_parse_arg (PyObject *o, GPUAttachment *r_attach)
static PyObject * pygpu_framebuffer__tp_new (PyTypeObject *, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR (pygpu_framebuffer_is_bound_doc, "Checks if this is the active frame-buffer in the context.")
static PyObject * pygpu_framebuffer_is_bound (BPyGPUFrameBuffer *self, void *)
 PyDoc_STRVAR (pygpu_framebuffer_clear_doc, ".. method:: clear(*, color=None, depth=None, stencil=None)\n" "\n" " Fill color, depth and stencil textures with specific value.\n" " Common values: color=(0.0, 0.0, 0.0, 1.0), depth=1.0, stencil=0.\n" "\n" " :arg color: Sequence of 3 or 4 floats representing ``(r, g, b, a)``.\n" " :type color: Sequence[float]\n" " :arg depth: depth value.\n" " :type depth: float\n" " :arg stencil: stencil value.\n" " :type stencil: int\n")
static PyObject * pygpu_framebuffer_clear (BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR (pygpu_framebuffer_viewport_set_doc, ".. function:: viewport_set(x, y, xsize, ysize)\n" "\n" " Set the viewport for this framebuffer object.\n" " Note: The viewport state is not saved upon framebuffer rebind.\n" "\n" " :arg x, y: lower left corner of the viewport_set rectangle, in pixels.\n" " :type x, y: int\n" " :arg xsize, ysize: width and height of the viewport_set.\n" " :type xsize, ysize: int\n")
static PyObject * pygpu_framebuffer_viewport_set (BPyGPUFrameBuffer *self, PyObject *args, void *)
 PyDoc_STRVAR (pygpu_framebuffer_viewport_get_doc, ".. function:: viewport_get()\n" "\n" " Returns position and dimension to current viewport.\n")
static PyObject * pygpu_framebuffer_viewport_get (BPyGPUFrameBuffer *self, void *)
 PyDoc_STRVAR (pygpu_framebuffer_read_color_doc, ".. function:: read_color(x, y, xsize, ysize, channels, slot, format, *, data=data)\n" "\n" " Read a block of pixels from the frame buffer.\n" "\n" " :arg x, y: Lower left corner of a rectangular block of pixels.\n" " :arg xsize, ysize: Dimensions of the pixel rectangle.\n" " :type x, y, xsize, ysize: int\n" " :arg channels: Number of components to read.\n" " :type channels: int\n" " :arg slot: The framebuffer slot to read data from.\n" " :type slot: int\n" " :arg format: The format that describes the content of a single channel.\n" " Possible values are ``FLOAT``, ``INT``, ``UINT``, ``UBYTE``, ``UINT_24_8`` & " "``10_11_11_REV``.\n" " ``UINT_24_8`` is deprecated, use ``FLOAT`` instead.\n" " :type format: str\n" " :arg data: Optional Buffer object to fill with the pixels values.\n" " :type data: :class:`gpu.types.Buffer`\n" " :return: The Buffer with the read pixels.\n" " :rtype: :class:`gpu.types.Buffer`\n")
static PyObject * pygpu_framebuffer_read_color (BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR (pygpu_framebuffer_read_depth_doc, ".. function:: read_depth(x, y, xsize, ysize, *, data=data)\n" "\n" " Read a pixel depth block from the frame buffer.\n" "\n" " :arg x, y: Lower left corner of a rectangular block of pixels.\n" " :type x, y: int\n" " :arg xsize, ysize: Dimensions of the pixel rectangle.\n" " :type xsize, ysize: int\n" " :arg data: Optional Buffer object to fill with the pixels values.\n" " :type data: :class:`gpu.types.Buffer`\n" " :return: The Buffer with the read pixels.\n" " :rtype: :class:`gpu.types.Buffer`\n")
static PyObject * pygpu_framebuffer_read_depth (BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)
static void BPyGPUFrameBuffer__tp_dealloc (BPyGPUFrameBuffer *self)
 PyDoc_STRVAR (pygpu_framebuffer__tp_doc, ".. class:: GPUFrameBuffer(*, depth_slot=None, color_slots=None)\n" "\n" " This object gives access to framebuffer functionalities.\n" " When a 'layer' is specified in a argument, a single layer of a 3D or array " "texture is attached to the frame-buffer.\n" " For cube map textures, layer is translated into a cube map face.\n" "\n" " :arg depth_slot: GPUTexture to attach or a ``dict`` containing keywords: " "'texture', 'layer' and 'mip'.\n" " :type depth_slot: :class:`gpu.types.GPUTexture` | dict[] | None\n" " :arg color_slots: Tuple where each item can be a GPUTexture or a ``dict`` " "containing keywords: 'texture', 'layer' and 'mip'.\n" " :type color_slots: :class:`gpu.types.GPUTexture` | " "dict[str, int | :class:`gpu.types.GPUTexture`] | " "Sequence[:class:`gpu.types.GPUTexture` | dict[str, int | " ":class:`gpu.types.GPUTexture`]] | " "None\n")

Detailed Description

This file defines the framebuffer 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_framebuffer.cc.

Macro Definition Documentation

◆ BPYGPU_FB_MAX_COLOR_ATTACHMENT

#define BPYGPU_FB_MAX_COLOR_ATTACHMENT   6

◆ GPU_PY_FRAMEBUFFER_STACK_LEN

#define GPU_PY_FRAMEBUFFER_STACK_LEN   16

◆ PYGPU_FRAMEBUFFER_CHECK_OBJ

#define PYGPU_FRAMEBUFFER_CHECK_OBJ ( bpygpu)
Value:
{ \
if (UNLIKELY(pygpu_framebuffer_valid_check(bpygpu) == -1)) { \
return nullptr; \
} \
} \
((void)0)
#define UNLIKELY(x)
static int pygpu_framebuffer_valid_check(BPyGPUFrameBuffer *bpygpu_fb)

Definition at line 45 of file gpu_py_framebuffer.cc.

Referenced by pygpu_framebuffer_clear(), pygpu_framebuffer_is_bound(), pygpu_framebuffer_read_color(), pygpu_framebuffer_read_depth(), pygpu_framebuffer_stack_context_enter(), pygpu_framebuffer_stack_context_exit(), and pygpu_framebuffer_viewport_get().

Function Documentation

◆ BPyGPUFrameBuffer__tp_dealloc()

void BPyGPUFrameBuffer__tp_dealloc ( BPyGPUFrameBuffer * self)
static

Definition at line 741 of file gpu_py_framebuffer.cc.

References pygpu_framebuffer_free_safe(), and self.

◆ BPyGPUFrameBuffer_CreatePyObject()

PyObject * BPyGPUFrameBuffer_CreatePyObject ( blender::gpu::FrameBuffer * fb,
bool shared_reference )
nodiscard

◆ PyDoc_STRVAR() [1/8]

PyDoc_STRVAR ( pygpu_framebuffer__tp_doc ,
".. class:: GPUFrameBuffer(*, depth_slot=None, color_slots=None)\n" "\n" " This object gives access to framebuffer functionalities.\n" " When a 'layer' is specified in a argument,
a single layer of a 3D or array " "texture is attached to the frame-buffer.\n" " For cube map textures,
layer is translated into a cube map face.\n" "\n" " :arg depth_slot:GPUTexture to attach or a ``dict`` containing keywords:" " 'texture' ,
'layer' and 'mip'.\n" " :type depth_slot::class:`gpu.types.GPUTexture`|dict|[]None\n" " :arg color_slots:Tuple where each item can be a GPUTexture or a ``dict`` " "containing keywords:'texture' ,
'layer' and 'mip'.\n" " :type color_slots::class:`gpu.types.GPUTexture`|" "dict|" "Sequence]|" "None\n" [str, int|:class:`gpu.types.GPUTexture`][:class:`gpu.types.GPUTexture`|dict[str, int|" ":class:`gpu.types.GPUTexture`] )

◆ PyDoc_STRVAR() [2/8]

PyDoc_STRVAR ( pygpu_framebuffer_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_framebuffer_clear_doc ,
".. method:: clear(*, color=None, depth=None, stencil=None)\n" "\n" " Fill color,
depth and stencil textures with specific value.\n" " Common values:color = (0.0, 0.0, 0.0, 1.0),
depth = 1.0 )

◆ PyDoc_STRVAR() [4/8]

PyDoc_STRVAR ( pygpu_framebuffer_is_bound_doc ,
"Checks if this is the active frame-buffer in the context."  )

◆ PyDoc_STRVAR() [5/8]

PyDoc_STRVAR ( pygpu_framebuffer_read_color_doc ,
".. function:: read_color(x, y, xsize, ysize, channels, slot, format, *, data=data)\n" "\n" " Read a block of pixels from the frame buffer.\n" "\n" " :arg x,
y:Lower left corner of a rectangular block of pixels.\n" " :arg xsize,
ysize:Dimensions of the pixel rectangle.\n" " :type x,
y ,
xsize ,
ysize:int\n" " :arg channels:Number of components to read.\n" " :type channels:int\n" " :arg slot:The framebuffer slot to read data from.\n" " :type slot:int\n" " :arg format:The format that describes the content of a single channel.\n" " Possible values are ``FLOAT`` ,
``INT`` ,
``UINT`` ,
``UBYTE`` ,
``UINT_24_8`` &" "``10_11_11_REV``.\n" " ``UINT_24_8`` is deprecated,
use ``FLOAT`` instead.\n" " :type format:str\n" " :arg data:Optional Buffer object to fill with the pixels values.\n" " :type data::class:`gpu.types.Buffer`\n" " :return:The Buffer with the read pixels.\n" " :rtype::class:`gpu.types.Buffer`\n"  )

◆ PyDoc_STRVAR() [6/8]

PyDoc_STRVAR ( pygpu_framebuffer_read_depth_doc ,
".. function:: read_depth(x, y, xsize, ysize, *, data=data)\n" "\n" " Read a pixel depth block from the frame buffer.\n" "\n" " :arg x,
y:Lower left corner of a rectangular block of pixels.\n" " :type x,
y:int\n" " :arg xsize,
ysize:Dimensions of the pixel rectangle.\n" " :type xsize,
ysize:int\n" " :arg data:Optional Buffer object to fill with the pixels values.\n" " :type data::class:`gpu.types.Buffer`\n" " :return:The Buffer with the read pixels.\n" " :rtype::class:`gpu.types.Buffer`\n"  )

◆ PyDoc_STRVAR() [7/8]

PyDoc_STRVAR ( pygpu_framebuffer_viewport_get_doc ,
".. function:: viewport_get()\n" "\n" " Returns position and dimension to current viewport.\n"  )

◆ PyDoc_STRVAR() [8/8]

PyDoc_STRVAR ( pygpu_framebuffer_viewport_set_doc ,
".. function:: viewport_set(x, y, xsize, ysize)\n" "\n" " Set the viewport for this framebuffer object.\n" " Note: The viewport state is not saved upon framebuffer rebind.\n" "\n" " :arg x,
y:lower left corner of the viewport_set rectangle,
in pixels.\n" " :type x,
y:int\n" " :arg xsize,
ysize:width and height of the viewport_set.\n" " :type xsize,
ysize:int\n"  )

◆ pygpu_framebuffer__tp_new()

◆ pygpu_framebuffer_bind()

PyObject * pygpu_framebuffer_bind ( BPyGPUFrameBuffer * self)
static

Definition at line 254 of file gpu_py_framebuffer.cc.

References FramebufferStackContext_Type, ret, and self.

◆ pygpu_framebuffer_clear()

PyObject * pygpu_framebuffer_clear ( BPyGPUFrameBuffer * self,
PyObject * args,
PyObject * kwds )
static

◆ pygpu_framebuffer_free_if_possible()

void pygpu_framebuffer_free_if_possible ( blender::gpu::FrameBuffer * fb)
static

Definition at line 53 of file gpu_py_framebuffer.cc.

References fb(), GPU_framebuffer_free(), GPU_is_init(), and printf.

Referenced by pygpu_framebuffer_free_safe().

◆ pygpu_framebuffer_free_safe()

void pygpu_framebuffer_free_safe ( BPyGPUFrameBuffer * self)
static

◆ pygpu_framebuffer_is_bound()

PyObject * pygpu_framebuffer_is_bound ( BPyGPUFrameBuffer * self,
void *  )
static

Definition at line 411 of file gpu_py_framebuffer.cc.

References GPU_framebuffer_bound(), PYGPU_FRAMEBUFFER_CHECK_OBJ, and self.

◆ pygpu_framebuffer_new_parse_arg()

bool pygpu_framebuffer_new_parse_arg ( PyObject * o,
GPUAttachment * r_attach )
static

◆ pygpu_framebuffer_read_color()

◆ pygpu_framebuffer_read_depth()

◆ pygpu_framebuffer_stack_context__tp_dealloc()

void pygpu_framebuffer_stack_context__tp_dealloc ( PyFrameBufferStackContext * self)
static

Definition at line 126 of file gpu_py_framebuffer.cc.

References Py_DECREF(), and self.

◆ pygpu_framebuffer_stack_context_enter()

PyObject * pygpu_framebuffer_stack_context_enter ( PyFrameBufferStackContext * self)
static

◆ pygpu_framebuffer_stack_context_exit()

PyObject * pygpu_framebuffer_stack_context_exit ( PyFrameBufferStackContext * self,
PyObject *  )
static

◆ pygpu_framebuffer_stack_pop_and_restore_or_error()

bool pygpu_framebuffer_stack_pop_and_restore_or_error ( blender::gpu::FrameBuffer * fb)
static

◆ pygpu_framebuffer_stack_push_and_bind_or_error()

◆ pygpu_framebuffer_valid_check()

int pygpu_framebuffer_valid_check ( BPyGPUFrameBuffer * bpygpu_fb)
static

Definition at line 36 of file gpu_py_framebuffer.cc.

References BPyGPUFrameBuffer::fb, and UNLIKELY.

◆ pygpu_framebuffer_viewport_get()

PyObject * pygpu_framebuffer_viewport_get ( BPyGPUFrameBuffer * self,
void *  )
static

◆ pygpu_framebuffer_viewport_set()

PyObject * pygpu_framebuffer_viewport_set ( BPyGPUFrameBuffer * self,
PyObject * args,
void *  )
static

Definition at line 503 of file gpu_py_framebuffer.cc.

References GPU_framebuffer_viewport_set(), self, x, and y.

Variable Documentation

◆ BPyGPUFrameBuffer_Type

PyTypeObject BPyGPUFrameBuffer_Type

Definition at line 824 of file gpu_py_framebuffer.cc.

Referenced by bpygpu_types_init(), and BPyGPUFrameBuffer_CreatePyObject().

◆ FramebufferStackContext_Type

PyTypeObject FramebufferStackContext_Type
static

Definition at line 196 of file gpu_py_framebuffer.cc.

Referenced by pygpu_framebuffer_bind().

◆ pygpu_framebuffer__tp_getseters

PyGetSetDef pygpu_framebuffer__tp_getseters[]
static
Initial value:
= {
{"is_bound",
(setter) nullptr,
pygpu_framebuffer_is_bound_doc,
nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr}
}
static PyObject * pygpu_framebuffer_is_bound(BPyGPUFrameBuffer *self, void *)

Definition at line 747 of file gpu_py_framebuffer.cc.

◆ pygpu_framebuffer__tp_methods

PyMethodDef pygpu_framebuffer__tp_methods[]
static
Initial value:
= {
{"bind", (PyCFunction)pygpu_framebuffer_bind, METH_NOARGS, pygpu_framebuffer_bind_doc},
{"clear",
METH_VARARGS | METH_KEYWORDS,
pygpu_framebuffer_clear_doc},
{"viewport_set",
METH_NOARGS,
pygpu_framebuffer_viewport_set_doc},
{"viewport_get",
METH_NOARGS,
pygpu_framebuffer_viewport_get_doc},
{"read_color",
METH_VARARGS | METH_KEYWORDS,
pygpu_framebuffer_read_color_doc},
{"read_depth",
METH_VARARGS | METH_KEYWORDS,
pygpu_framebuffer_read_depth_doc},
{nullptr, nullptr, 0, nullptr},
}
static PyObject * pygpu_framebuffer_viewport_get(BPyGPUFrameBuffer *self, void *)
static PyObject * pygpu_framebuffer_clear(BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)
static PyObject * pygpu_framebuffer_bind(BPyGPUFrameBuffer *self)
static PyObject * pygpu_framebuffer_viewport_set(BPyGPUFrameBuffer *self, PyObject *args, void *)
static PyObject * pygpu_framebuffer_read_color(BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)
static PyObject * pygpu_framebuffer_read_depth(BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)

Definition at line 766 of file gpu_py_framebuffer.cc.

◆ pygpu_framebuffer_stack_context__tp_methods

PyMethodDef pygpu_framebuffer_stack_context__tp_methods[]
static
Initial value:
= {
{"__enter__", (PyCFunction)pygpu_framebuffer_stack_context_enter, METH_NOARGS},
{"__exit__", (PyCFunction)pygpu_framebuffer_stack_context_exit, METH_VARARGS},
{nullptr},
}
static PyObject * pygpu_framebuffer_stack_context_enter(PyFrameBufferStackContext *self)
static PyObject * pygpu_framebuffer_stack_context_exit(PyFrameBufferStackContext *self, PyObject *)

Definition at line 182 of file gpu_py_framebuffer.cc.