Blender  V3.3
Classes | Macros
gpu_py_framebuffer.c File Reference
#include <Python.h>
#include "GPU_context.h"
#include "GPU_framebuffer.h"
#include "GPU_init_exit.h"
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
#include "../mathutils/mathutils.h"
#include "gpu_py.h"
#include "gpu_py_buffer.h"
#include "gpu_py_framebuffer.h"
#include "gpu_py_texture.h"

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 (GPUFrameBuffer *fb, bool shared_reference)
 

GPUFrameBuffer 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 (GPUFrameBuffer *fb)
 
static void pygpu_framebuffer_free_safe (BPyGPUFrameBuffer *self)
 
static bool pygpu_framebuffer_stack_push_and_bind_or_error (GPUFrameBuffer *fb)
 
static bool pygpu_framebuffer_stack_pop_and_restore_or_error (GPUFrameBuffer *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 *UNUSED(args))
 
 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 struct 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 *UNUSED(self), PyObject *args, PyObject *kwds)
 
 PyDoc_STRVAR (pygpu_framebuffer_is_bound_doc, "Checks if this is the active framebuffer in the context.")
 
static PyObject * pygpu_framebuffer_is_bound (BPyGPUFrameBuffer *self, void *UNUSED(type))
 
 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: float sequence each representing ``(r, g, b, a)``.\n" " :type color: sequence of 3 or 4 floats\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" " :param x, y: lower left corner of the viewport_set rectangle, in pixels.\n" " :param xsize, ysize: width and height of the viewport_set.\n" " :type x, y, xsize, ysize: int\n")
 
static PyObject * pygpu_framebuffer_viewport_set (BPyGPUFrameBuffer *self, PyObject *args, void *UNUSED(type))
 
 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 *UNUSED(type))
 
 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" " :param x, y: Lower left corner of a rectangular block of pixels.\n" " :param xsize, ysize: Dimensions of the pixel rectangle.\n" " :type x, y, xsize, ysize: int\n" " :param channels: Number of components to read.\n" " :type channels: int\n" " :param slot: The framebuffer slot to read data from.\n" " :type slot: int\n" " :param format: The format that describes the content of a single channel.\n" " Possible values are `FLOAT`, `INT`, `UINT`, `UBYTE`, `UINT_24_8` and `10_11_11_REV`.\n" " :type type: 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" " :param x, y: Lower left corner of a rectangular block of pixels.\n" " :param xsize, ysize: Dimensions of the pixel rectangle.\n" " :type x, y, 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 functionallities.\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 or Nonetype\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: tuple or Nonetype\n")
 

Detailed Description

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

Definition in file gpu_py_framebuffer.c.

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

Definition at line 75 of file gpu_py_framebuffer.c.

◆ PYGPU_FRAMEBUFFER_CHECK_OBJ

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

Definition at line 41 of file gpu_py_framebuffer.c.

Function Documentation

◆ BPyGPUFrameBuffer__tp_dealloc()

static void BPyGPUFrameBuffer__tp_dealloc ( BPyGPUFrameBuffer self)
static

Definition at line 643 of file gpu_py_framebuffer.c.

References pygpu_framebuffer_free_safe().

◆ BPyGPUFrameBuffer_CreatePyObject()

PyObject* BPyGPUFrameBuffer_CreatePyObject ( GPUFrameBuffer fb,
bool  shared_reference 
)

◆ 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 functionallities.\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 or Nonetype\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:tuple or Nonetype\n"   
)

◆ 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 framebuffer 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" " :param  x,
y:Lower left corner of a rectangular block of pixels.\n" " :param  xsize,
ysize:Dimensions of the pixel rectangle.\n" " :type  x,
y  ,
xsize  ,
ysize:int\n" " :param channels:Number of components to read.\n" " :type channels:int\n" " :param slot:The framebuffer slot to read data from.\n" " :type slot:int\n" " :param format:The format that describes the content of a single channel.\n" " Possible values are `FLOAT ,
`INT`  ,
`UINT ,
`UBYTE`  ,
`UINT_24_8` and `10_11_11_REV`.\n" " :type type: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" " :param  x,
y:Lower left corner of a rectangular block of pixels.\n" " :param  xsize,
ysize:Dimensions of the pixel rectangle.\n" " :type  x,
y  ,
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" " :param  x,
y:lower left corner of the viewport_set  rectangle,
in pixels.\n" " :param  xsize,
ysize:width and height of the viewport_set.\n" " :type  x,
y  ,
xsize  ,
ysize:int\n"   
)

◆ pygpu_framebuffer__tp_new()

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

◆ pygpu_framebuffer_bind()

static PyObject* pygpu_framebuffer_bind ( BPyGPUFrameBuffer self)
static

Definition at line 186 of file gpu_py_framebuffer.c.

References FramebufferStackContext_Type, and ret.

◆ pygpu_framebuffer_clear()

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

◆ pygpu_framebuffer_free_if_possible()

static void pygpu_framebuffer_free_if_possible ( GPUFrameBuffer fb)
static

Definition at line 49 of file gpu_py_framebuffer.c.

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

Referenced by pygpu_framebuffer_free_safe().

◆ pygpu_framebuffer_free_safe()

static void pygpu_framebuffer_free_safe ( BPyGPUFrameBuffer self)
static

◆ pygpu_framebuffer_is_bound()

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

Definition at line 342 of file gpu_py_framebuffer.c.

References GPU_framebuffer_bound(), PYGPU_FRAMEBUFFER_CHECK_OBJ, and self.

◆ pygpu_framebuffer_new_parse_arg()

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

◆ pygpu_framebuffer_read_color()

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

◆ pygpu_framebuffer_read_depth()

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

◆ pygpu_framebuffer_stack_context__tp_dealloc()

static void pygpu_framebuffer_stack_context__tp_dealloc ( PyFrameBufferStackContext self)
static

Definition at line 122 of file gpu_py_framebuffer.c.

References self.

◆ pygpu_framebuffer_stack_context_enter()

static PyObject* pygpu_framebuffer_stack_context_enter ( PyFrameBufferStackContext self)
static

◆ pygpu_framebuffer_stack_context_exit()

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

◆ pygpu_framebuffer_stack_pop_and_restore_or_error()

static bool pygpu_framebuffer_stack_pop_and_restore_or_error ( GPUFrameBuffer fb)
static

◆ pygpu_framebuffer_stack_push_and_bind_or_error()

static bool pygpu_framebuffer_stack_push_and_bind_or_error ( GPUFrameBuffer fb)
static

◆ pygpu_framebuffer_valid_check()

static int pygpu_framebuffer_valid_check ( BPyGPUFrameBuffer bpygpu_fb)
static

Definition at line 32 of file gpu_py_framebuffer.c.

References BPyGPUFrameBuffer::fb, NULL, and UNLIKELY.

◆ pygpu_framebuffer_viewport_get()

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

◆ pygpu_framebuffer_viewport_set()

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

Definition at line 427 of file gpu_py_framebuffer.c.

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

Variable Documentation

◆ BPyGPUFrameBuffer_Type

PyTypeObject BPyGPUFrameBuffer_Type
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUFrameBuffer",
.tp_basicsize = sizeof(BPyGPUFrameBuffer),
.tp_dealloc = (destructor)BPyGPUFrameBuffer__tp_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_doc = pygpu_framebuffer__tp_doc,
}
static struct PyMethodDef pygpu_framebuffer__tp_methods[]
static PyGetSetDef pygpu_framebuffer__tp_getseters[]
static void BPyGPUFrameBuffer__tp_dealloc(BPyGPUFrameBuffer *self)
static PyObject * pygpu_framebuffer__tp_new(PyTypeObject *UNUSED(self), PyObject *args, PyObject *kwds)
struct BPyGPUFrameBuffer BPyGPUFrameBuffer

Definition at line 700 of file gpu_py_framebuffer.c.

Referenced by bpygpu_types_init(), and BPyGPUFrameBuffer_CreatePyObject().

◆ FramebufferStackContext_Type

PyTypeObject FramebufferStackContext_Type
static
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUFrameBufferStackContext",
.tp_basicsize = sizeof(PyFrameBufferStackContext),
.tp_flags = Py_TPFLAGS_DEFAULT,
}
static void pygpu_framebuffer_stack_context__tp_dealloc(PyFrameBufferStackContext *self)
static PyMethodDef pygpu_framebuffer_stack_context__tp_methods[]

Definition at line 174 of file gpu_py_framebuffer.c.

Referenced by pygpu_framebuffer_bind().

◆ pygpu_framebuffer__tp_getseters

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

Definition at line 649 of file gpu_py_framebuffer.c.

◆ pygpu_framebuffer__tp_methods

struct 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},
{NULL, NULL, 0, NULL},
}
static PyObject * pygpu_framebuffer_clear(BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)
static PyObject * pygpu_framebuffer_viewport_get(BPyGPUFrameBuffer *self, void *UNUSED(type))
static PyObject * pygpu_framebuffer_viewport_set(BPyGPUFrameBuffer *self, PyObject *args, void *UNUSED(type))
static PyObject * pygpu_framebuffer_bind(BPyGPUFrameBuffer *self)
static PyObject * pygpu_framebuffer_read_depth(BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)
static PyObject * pygpu_framebuffer_read_color(BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)

Definition at line 649 of file gpu_py_framebuffer.c.

◆ 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},
{NULL},
}
static PyObject * pygpu_framebuffer_stack_context_enter(PyFrameBufferStackContext *self)
static PyObject * pygpu_framebuffer_stack_context_exit(PyFrameBufferStackContext *self, PyObject *UNUSED(args))

Definition at line 168 of file gpu_py_framebuffer.c.