40 if (bpygpu_fb->
fb ==
nullptr) [[unlikely]] {
41 PyErr_SetString(PyExc_ReferenceError,
"GPU framebuffer was freed, no further access is valid");
47#define PYGPU_FRAMEBUFFER_CHECK_OBJ(bpygpu) \
49 if (pygpu_framebuffer_valid_check(bpygpu) == -1) [[unlikely]] { \
61 printf(
"PyFramebuffer freed after the context has been destroyed.\n");
68#ifndef GPU_NO_USE_PY_REFERENCES
81#define GPU_PY_FRAMEBUFFER_STACK_LEN 16
99 PyErr_SetString(PyExc_RuntimeError,
"Minimum framebuffer stack depth reached");
104 PyErr_SetString(PyExc_RuntimeError,
"Framebuffer is not bound");
130 Py_DECREF(self->
py_fb);
139 if (self->
level != -1) {
140 PyErr_SetString(PyExc_RuntimeError,
"Already in use");
158 if (self->
level == -1) {
159 fprintf(stderr,
"Not yet in use\n");
164 if (level != self->
level) {
165 fprintf(stderr,
"Level of bind mismatch, expected %d, got %d\n", self->
level, level);
176# pragma clang diagnostic push
177# pragma clang diagnostic ignored "-Wcast-function-type"
179# pragma GCC diagnostic push
180# pragma GCC diagnostic ignored "-Wcast-function-type"
196# pragma clang diagnostic pop
198# pragma GCC diagnostic pop
203 PyVarObject_HEAD_INIT(
nullptr, 0)
204 "GPUFrameBufferStackContext",
256 pygpu_framebuffer_bind_doc,
257 ".. method:: bind()\n"
259 " Context manager to ensure balanced bind calls, even in the case of an error.\n");
267 return reinterpret_cast<PyObject *
>(
ret);
284 if (!o || o == Py_None) {
293 const char *c_texture =
"texture";
294 const char *c_layer =
"layer";
295 const char *c_mip =
"mip";
296 PyObject *key, *value;
298 while (PyDict_Next(o, &pos, &key, &value)) {
299 if (!PyUnicode_Check(key)) {
300 PyErr_SetString(PyExc_TypeError,
"keywords must be strings");
304 if (c_texture && PyUnicode_CompareWithASCIIString(key, c_texture) == 0) {
311 else if (c_layer && PyUnicode_CompareWithASCIIString(key, c_layer) == 0) {
314 tmp_attach.
layer = PyLong_AsLong(value);
315 if (tmp_attach.
layer == -1 && PyErr_Occurred()) {
319 else if (c_mip && PyUnicode_CompareWithASCIIString(key, c_mip) == 0) {
322 tmp_attach.
mip = PyLong_AsLong(value);
323 if (tmp_attach.
mip == -1 && PyErr_Occurred()) {
329 PyExc_TypeError,
"'%U' is an invalid keyword argument for this attribute", key);
335 *r_attach = tmp_attach;
344 PyErr_SetString(PyExc_RuntimeError,
"No active GPU context found");
348 PyObject *depth_attachment =
nullptr;
349 PyObject *color_attachements =
nullptr;
350 static const char *_keywords[] = {
"depth_slot",
"color_slots",
nullptr};
351 static _PyArg_Parser _parser = {
355 ":GPUFrameBuffer.__new__",
359 if (!_PyArg_ParseTupleAndKeywordsFast(
360 args, kwds, &_parser, &depth_attachment, &color_attachements))
367#define BPYGPU_FB_MAX_COLOR_ATTACHMENT 6
375 PyErr_SetString(PyExc_ValueError,
"Depth texture with incompatible format");
379 int color_attachements_len = 0;
380 if (color_attachements && color_attachements != Py_None) {
381 if (PySequence_Check(color_attachements)) {
382 color_attachements_len = PySequence_Size(color_attachements);
384 PyErr_SetString(PyExc_AttributeError,
389 for (
int i = 0; i < color_attachements_len; i++) {
390 PyObject *o = PySequence_GetItem(color_attachements, i);
402 color_attachements_len = 1;
414 pygpu_framebuffer_is_bound_doc,
415 "Checks if this is the active frame-buffer in the context.\n"
426 pygpu_framebuffer_clear_doc,
427 ".. method:: clear(*, color=None, depth=None, stencil=None)\n"
429 " Fill color, depth and stencil textures with specific value.\n"
430 " Common values: color=(0.0, 0.0, 0.0, 1.0), depth=1.0, stencil=0.\n"
432 " :param color: Sequence of 3 or 4 floats representing ``(r, g, b, a)``.\n"
433 " :type color: Sequence[float] | None\n"
434 " :param depth: depth value.\n"
435 " :type depth: float | None\n"
436 " :param stencil: stencil value.\n"
437 " :type stencil: int | None\n");
446 PyObject *py_col =
nullptr;
447 PyObject *py_depth =
nullptr;
448 PyObject *py_stencil =
nullptr;
450 static const char *_keywords[] = {
"color",
"depth",
"stencil",
nullptr};
451 static _PyArg_Parser _parser = {
460 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &py_col, &py_depth, &py_stencil)) {
465 float col[4] = {0.0f, 0.0f, 0.0f, 1.0f};
469 if (py_col && py_col != Py_None) {
471 col, 3, 4, py_col,
"gpu::FrameBuffer.clear(), invalid 'color' arg") == -1)
478 if (py_depth && py_depth != Py_None) {
479 depth = PyFloat_AsDouble(py_depth);
480 if (PyErr_Occurred()) {
486 if (py_stencil && py_stencil != Py_None) {
499 pygpu_framebuffer_viewport_set_doc,
500 ".. method:: viewport_set(x, y, xsize, ysize)\n"
502 " Set the viewport for this framebuffer object.\n"
503 " Note: The viewport state is not saved upon framebuffer rebind.\n"
505 " :param x: Lower left corner x of the viewport rectangle, in pixels.\n"
507 " :param y: Lower left corner y of the viewport rectangle, in pixels.\n"
509 " :param xsize: Width of the viewport.\n"
510 " :type xsize: int\n"
511 " :param ysize: Height of the viewport.\n"
512 " :type ysize: int\n");
515 int x,
y, xsize, ysize;
516 if (!PyArg_ParseTuple(args,
536 pygpu_framebuffer_viewport_get_doc,
537 ".. method:: viewport_get()\n"
539 " Returns position and dimension to current viewport.\n"
541 " :return: The viewport as ``(x, y, width, height)``.\n"
542 " :rtype: tuple[int, int, int, int]\n");
549 PyObject *
ret = PyTuple_New(4);
551 PyLong_FromLong(viewport[0]),
552 PyLong_FromLong(viewport[1]),
553 PyLong_FromLong(viewport[2]),
554 PyLong_FromLong(viewport[3]));
560 pygpu_framebuffer_read_color_doc,
561 ".. method:: read_color(x, y, xsize, ysize, channels, slot, format, *, data=None)\n"
563 " Read a block of pixels from the frame buffer.\n"
565 " :param x: Lower left corner x of a rectangular block of pixels.\n"
567 " :param y: Lower left corner y of a rectangular block of pixels.\n"
569 " :param xsize: Width of the pixel rectangle.\n"
570 " :type xsize: int\n"
571 " :param ysize: Height of the pixel rectangle.\n"
572 " :type ysize: int\n"
573 " :param channels: Number of components to read.\n"
574 " :type channels: int\n"
575 " :param slot: The framebuffer slot to read data from.\n"
577 " :param format: The format that describes the content of a single channel.\n"
578 " ``UINT_24_8`` is deprecated, use ``FLOAT`` instead.\n"
581 " :param data: Optional Buffer object to fill with the pixels values.\n"
582 " :type data: :class:`gpu.types.Buffer` | None\n"
583 " :return: The Buffer with the read pixels.\n"
584 " :rtype: :class:`gpu.types.Buffer`\n");
590 int x,
y,
w, h, channels;
593 int(gpu::TextureFormat::UNORM_8_8_8_8)};
597 static const char *_keywords[] = {
598 "x",
"y",
"xsize",
"ysize",
"channels",
"slot",
"format",
"data",
nullptr};
599 static _PyArg_Parser _parser = {
613 if (!_PyArg_ParseTupleAndKeywordsFast(args,
631 PyErr_WarnEx(PyExc_DeprecationWarning,
"`UINT_24_8` is deprecated, use `FLOAT` instead", 1);
635 PyErr_SetString(PyExc_AttributeError,
"Color channels must be 1, 2, 3 or 4");
640 PyErr_SetString(PyExc_ValueError,
"slot overflow");
646 PyErr_SetString(PyExc_ValueError,
647 "Trying to read color outside the extent of the framebuffer");
653 PyErr_SetString(PyExc_AttributeError,
654 "the format of the buffer is different from that specified");
659 size_t size_expected =
w * h * channels *
662 if (size_curr < size_expected) {
663 PyErr_SetString(PyExc_BufferError,
"the buffer size is smaller than expected");
666 Py_INCREF(py_buffer);
669 const Py_ssize_t shape[3] = {h,
w, channels};
672 size_t(
w) *
size_t(h) *
size_t(channels) *
684 py_buffer->
buf.as_void);
686 return reinterpret_cast<PyObject *
>(py_buffer);
691 pygpu_framebuffer_read_depth_doc,
692 ".. method:: read_depth(x, y, xsize, ysize, *, data=None)\n"
694 " Read a pixel depth block from the frame buffer.\n"
696 " :param x: Lower left corner x of a rectangular block of pixels.\n"
698 " :param y: Lower left corner y of a rectangular block of pixels.\n"
700 " :param xsize: Width of the pixel rectangle.\n"
701 " :type xsize: int\n"
702 " :param ysize: Height of the pixel rectangle.\n"
703 " :type ysize: int\n"
704 " :param data: Optional Buffer object to fill with the pixels values.\n"
705 " :type data: :class:`gpu.types.Buffer` | None\n"
706 " :return: The Buffer with the read pixels.\n"
707 " :rtype: :class:`gpu.types.Buffer`\n");
717 static const char *_keywords[] = {
"x",
"y",
"xsize",
"ysize",
"data",
nullptr};
718 static _PyArg_Parser _parser = {
729 if (!_PyArg_ParseTupleAndKeywordsFast(
737 PyErr_SetString(PyExc_ValueError,
738 "Trying to read depth outside the extent of the framebuffer");
744 PyErr_SetString(PyExc_AttributeError,
"the format of the buffer must be 'GPU_DATA_FLOAT'");
750 if (size_curr < size_expected) {
751 PyErr_SetString(PyExc_BufferError,
"the buffer size is smaller than expected");
754 Py_INCREF(py_buffer);
757 const Py_ssize_t shape[2] = {h,
w};
765 return reinterpret_cast<PyObject *
>(py_buffer);
768#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
771 pygpu_framebuffer_free_doc,
772 ".. method:: free()\n"
774 " Free the framebuffer object.\n"
775 " The framebuffer will no longer be accessible.\n");
776static PyObject *pygpu_framebuffer_free(BPyGPUFrameBuffer *self)
787 Py_TYPE(self)->tp_free(
reinterpret_cast<PyObject *
>(self));
793 static_cast<setter
>(
nullptr),
794 pygpu_framebuffer_is_bound_doc,
796 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
801# pragma clang diagnostic push
802# pragma clang diagnostic ignored "-Wcast-function-type"
804# pragma GCC diagnostic push
805# pragma GCC diagnostic ignored "-Wcast-function-type"
813 pygpu_framebuffer_bind_doc},
816 METH_VARARGS | METH_KEYWORDS,
817 pygpu_framebuffer_clear_doc},
821 pygpu_framebuffer_viewport_set_doc},
825 pygpu_framebuffer_viewport_get_doc},
828 METH_VARARGS | METH_KEYWORDS,
829 pygpu_framebuffer_read_color_doc},
832 METH_VARARGS | METH_KEYWORDS,
833 pygpu_framebuffer_read_depth_doc},
834#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
835 {
"free", (PyCFunction)pygpu_framebuffer_free, METH_NOARGS, pygpu_framebuffer_free_doc},
837 {
nullptr,
nullptr, 0,
nullptr},
842# pragma clang diagnostic pop
844# pragma GCC diagnostic pop
852 pygpu_framebuffer__tp_doc,
853 ".. class:: GPUFrameBuffer\n"
855 " This object gives access to framebuffer functionalities.\n"
856 " When a 'layer' is specified in a argument, a single layer of a 3D or array "
857 "texture is attached to the frame-buffer.\n"
858 " For cube map textures, layer is translated into a cube map face.\n"
860 " .. method:: __init__(*, depth_slot=None, color_slots=None)\n"
862 " :param depth_slot: GPUTexture to attach or a ``dict`` containing keywords: "
863 "'texture', 'layer' and 'mip'.\n"
864 " :type depth_slot: :class:`gpu.types.GPUTexture` | dict[str, int | "
865 ":class:`gpu.types.GPUTexture`] | None\n"
866 " :param color_slots: Tuple where each item can be a GPUTexture or a ``dict`` "
867 "containing keywords: 'texture', 'layer' and 'mip'.\n"
868 " :type color_slots: :class:`gpu.types.GPUTexture` | "
869 "dict[str, int | :class:`gpu.types.GPUTexture`] | "
870 "Sequence[:class:`gpu.types.GPUTexture` | dict[str, int | "
871 ":class:`gpu.types.GPUTexture`]] | "
874 PyVarObject_HEAD_INIT(
nullptr, 0)
894 pygpu_framebuffer__tp_doc,
935#ifndef GPU_NO_USE_PY_REFERENCES
936 if (shared_reference) {
944 return reinterpret_cast<PyObject *
>(self);
954#ifndef GPU_NO_USE_PY_REFERENCES
961 return reinterpret_cast<PyObject *
>(self);
966#undef PYGPU_FRAMEBUFFER_CHECK_OBJ
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
#define GPU_ATTACHMENT_NONE
#define POINTER_OFFSET(v, ofs)
#define IN_RANGE_INCL(a, b, c)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
#define PYDOC_DATAFORMAT_LITERAL
#define PYGPU_FRAMEBUFFER_CHECK_OBJ(bpygpu)
#define BPYGPU_FB_MAX_COLOR_ATTACHMENT
#define GPU_PY_FRAMEBUFFER_STACK_LEN
#define BPyGPUTexture_Check(v)
PyTypeObject BPyGPU_BufferType
PyC_StringEnumItems bpygpu_dataformat_items[]
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
static PyMethodDef pygpu_framebuffer__tp_methods[]
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static PyObject * pygpu_framebuffer_read_depth(BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)
bool GPU_texture_has_depth_format(const gpu::Texture *texture)
gpu::FrameBuffer * GPU_framebuffer_active_get()
void GPU_framebuffer_read_color(gpu::FrameBuffer *fb, int x, int y, int width, int height, int channels, int slot, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_clear(gpu::FrameBuffer *fb, GPUFrameBufferBits buffers, const double4 clear_col, float clear_depth, unsigned int clear_stencil)
static PyGetSetDef pygpu_framebuffer__tp_getseters[]
void GPU_framebuffer_py_reference_set(gpu::FrameBuffer *fb, void **py_ref)
void GPU_framebuffer_free(gpu::FrameBuffer *fb)
void GPU_framebuffer_viewport_set(gpu::FrameBuffer *fb, int x, int y, int width, int height)
BLI_INLINE float fb(float length, float L)
int bpygpu_ParseTexture(PyObject *o, void *p)
static void BPyGPUFrameBuffer__tp_dealloc(BPyGPUFrameBuffer *self)
int2 GPU_framebuffer_extent_get(gpu::FrameBuffer *fb)
Get the extent of the framebuffer.
@ GPU_DATA_UINT_24_8_DEPRECATED
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static PyMethodDef pygpu_framebuffer_stack_context__tp_methods[]
void GPU_framebuffer_push(gpu::FrameBuffer *fb)
static PyObject * pygpu_framebuffer_viewport_get(BPyGPUFrameBuffer *self)
static void pygpu_framebuffer_free_if_possible(gpu::FrameBuffer *fb)
static PyTypeObject FramebufferStackContext_Type
PyObject * BPyGPUFrameBuffer_CreatePyObject(gpu::FrameBuffer *fb, bool shared_reference)
static bool pygpu_framebuffer_stack_pop_and_restore_or_error(gpu::FrameBuffer *fb)
static int pygpu_framebuffer_valid_check(BPyGPUFrameBuffer *bpygpu_fb)
gpu::FrameBuffer * GPU_framebuffer_pop()
static PyObject * pygpu_framebuffer_bind(BPyGPUFrameBuffer *self)
static void pygpu_framebuffer_stack_context__tp_dealloc(PyFrameBufferStackContext *self)
static bool pygpu_framebuffer_stack_push_and_bind_or_error(gpu::FrameBuffer *fb)
size_t bpygpu_Buffer_size(BPyGPUBuffer *buffer)
static void pygpu_framebuffer_free_safe(BPyGPUFrameBuffer *self)
VecBase< int32_t, 2 > int2
size_t GPU_texture_dataformat_size(eGPUDataFormat data_format)
static PyObject * pygpu_framebuffer_is_bound(BPyGPUFrameBuffer *self, void *)
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
void ** GPU_framebuffer_py_reference_get(gpu::FrameBuffer *fb)
void GPU_framebuffer_config_array(gpu::FrameBuffer *fb, const GPUAttachment *config, int config_len)
static bool pygpu_framebuffer_new_parse_arg(PyObject *o, GPUAttachment *r_attach)
gpu::FrameBuffer * GPU_framebuffer_create(const char *name)
uint GPU_framebuffer_stack_level_get()
uint32_t PyC_Long_AsU32(PyObject *value)
static PyObject * pygpu_framebuffer_stack_context_enter(PyFrameBufferStackContext *self)
static PyObject * pygpu_framebuffer_read_color(BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)
BPyGPUBuffer * BPyGPU_Buffer_CreatePyObject(const int format, const Py_ssize_t *shape, const int shape_len, void *buffer)
static PyObject * pygpu_framebuffer_clear(BPyGPUFrameBuffer *self, PyObject *args, PyObject *kwds)
PyTypeObject BPyGPUFrameBuffer_Type
static PyObject * pygpu_framebuffer_stack_context_exit(PyFrameBufferStackContext *self, PyObject *)
void GPU_framebuffer_viewport_get(gpu::FrameBuffer *fb, int r_viewport[4])
int PyC_ParseStringEnum(PyObject *o, void *p)
void GPU_framebuffer_read_depth(gpu::FrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
static PyObject * pygpu_framebuffer_viewport_set(BPyGPUFrameBuffer *self, PyObject *args)
bool GPU_framebuffer_bound(gpu::FrameBuffer *fb)
int PyC_ParseTypeOrNone(PyObject *o, void *p)
VecBase< double, 4 > double4
GPUContext * GPU_context_active_get()
static PyObject * pygpu_framebuffer__tp_new(PyTypeObject *, PyObject *args, PyObject *kwds)
#define PyC_TYPE_OR_NONE_INIT(py_type, value_p)
header-only compatibility defines.
#define PyTuple_SET_ITEMS(op_arg,...)
union blender::BPyGPUBuffer::@121160014351146313222050217274041240110051113162 buf
PyObject_HEAD gpu::FrameBuffer * fb
PyObject_HEAD BPyGPUFrameBuffer * py_fb