46#define BPYGPU_USE_GPUOBJ_FREE_METHOD
53 {int(gpu::TextureFormat::UNORM_8_8_8_8),
"RGBA8"},
54 {int(gpu::TextureFormat::UNORM_16_16_16_16),
"RGBA16"},
55 {int(gpu::TextureFormat::SFLOAT_16_16_16_16),
"RGBA16F"},
56 {int(gpu::TextureFormat::SFLOAT_32_32_32_32),
"RGBA32F"},
62 if (py_ofs->
ofs ==
nullptr) [[unlikely]] {
63 PyErr_SetString(PyExc_ReferenceError,
65 "GPU offscreen was freed, no further access is valid"
67 "GPU offscreen: internal error"
75#define BPY_GPU_OFFSCREEN_CHECK_OBJ(bpygpu) \
77 if (pygpu_offscreen_valid_check(bpygpu) == -1) [[unlikely]] { \
112 if (self->
level != -1) {
113 PyErr_SetString(PyExc_RuntimeError,
"Already in use");
131 if (self->
level == -1) {
132 PyErr_SetString(PyExc_RuntimeError,
"Not yet in use\n");
137 if (level != self->
level) {
139 PyExc_RuntimeError,
"Level of bind mismatch, expected %d, got %d\n", self->
level, level);
148# pragma clang diagnostic push
149# pragma clang diagnostic ignored "-Wcast-function-type"
151# pragma GCC diagnostic push
152# pragma GCC diagnostic ignored "-Wcast-function-type"
164# pragma clang diagnostic pop
166# pragma GCC diagnostic pop
172 pygpu_offscreen_stack_context__tp_doc,
173 "Context manager for off-screen framebuffer binding.");
175 PyVarObject_HEAD_INIT(
nullptr, 0)
176 "OffScreenStackContext",
195 pygpu_offscreen_stack_context__tp_doc,
228 pygpu_offscreen_bind_doc,
229 ".. method:: bind()\n"
231 " Context manager to ensure balanced bind calls, even in the case of an error.\n"
233 " :return: A context manager for the off-screen binding.\n"
234 " :rtype: :class:`gpu.types.OffScreenStackContext`\n");
239 ret->py_offscreen = self;
241 ret->is_explicitly_bound =
false;
245 if (enter_ret ==
nullptr) [[unlikely]] {
249 Py_DECREF(enter_ret);
250 ret->is_explicitly_bound =
true;
252 return reinterpret_cast<PyObject *
>(
ret);
257 pygpu_offscreen_unbind_doc,
258 ".. method:: unbind(*, restore=True)\n"
260 " Unbind the offscreen object.\n"
262 " :param restore: Restore the OpenGL state, can only be used when the state has been "
264 " :type restore: bool\n");
271 static const char *_keywords[] = {
"restore",
nullptr};
272 static _PyArg_Parser _parser = {
279 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser,
PyC_ParseBool, &restore)) {
301 int(gpu::TextureFormat::UNORM_8_8_8_8)};
304 static const char *_keywords[] = {
"width",
"height",
"format",
nullptr};
305 static _PyArg_Parser _parser = {
310 ":GPUOffScreen.__new__",
314 if (!_PyArg_ParseTupleAndKeywordsFast(
333 if (ofs ==
nullptr) {
334 PyErr_Format(PyExc_RuntimeError,
335 "gpu.offscreen.new(...) failed with '%s'",
336 err_out[0] ? err_out :
"unknown error");
345 pygpu_offscreen_width_doc,
346 "Width of the texture.\n"
357 pygpu_offscreen_height_doc,
358 "Height of the texture.\n"
369 pygpu_offscreen_texture_color_doc,
370 "The color texture attached.\n"
372 ":type: :class:`gpu.types.GPUTexture`\n");
382 pygpu_offscreen_draw_view3d_doc,
383 ".. method:: draw_view3d(scene, view_layer, view3d, region, view_matrix, projection_matrix, "
384 "*, do_color_management=False, draw_background=True)\n"
386 " Draw the 3d viewport in the offscreen object.\n"
388 " :param scene: Scene to draw.\n"
389 " :type scene: :class:`bpy.types.Scene`\n"
390 " :param view_layer: View layer to draw.\n"
391 " :type view_layer: :class:`bpy.types.ViewLayer`\n"
392 " :param view3d: 3D View to get the drawing settings from.\n"
393 " :type view3d: :class:`bpy.types.SpaceView3D`\n"
394 " :param region: Region of the 3D View (required as temporary draw target).\n"
395 " :type region: :class:`bpy.types.Region`\n"
396 " :param view_matrix: View Matrix (e.g. ``camera.matrix_world.inverted()``).\n"
397 " :type view_matrix: :class:`mathutils.Matrix`\n"
398 " :param projection_matrix: Projection Matrix (e.g. ``camera.calc_matrix_camera(...)``).\n"
399 " :type projection_matrix: :class:`mathutils.Matrix`\n"
400 " :param do_color_management: Color manage the output.\n"
401 " :type do_color_management: bool\n"
402 " :param draw_background: Draw background.\n"
403 " :type draw_background: bool\n");
407 PyObject *py_scene, *py_view_layer, *py_region, *py_view3d;
409 Depsgraph *depsgraph;
415 bool do_color_management =
false;
416 bool draw_background =
true;
420 static const char *_keywords[] = {
427 "do_color_management",
431 static _PyArg_Parser _parser = {
445 if (!_PyArg_ParseTupleAndKeywordsFast(args,
457 &do_color_management,
471 PyErr_SetString(PyExc_RuntimeError,
"Nested off-screen drawing not supported");
498 reinterpret_cast<const float (*)[4]
>(py_mat_view->matrix),
499 reinterpret_cast<const float (*)[4]
>(py_mat_projection->matrix),
513#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
516 pygpu_offscreen_free_doc,
517 ".. method:: free()\n"
519 " Free the offscreen object.\n"
520 " The framebuffer, texture and render objects will no longer be accessible.\n");
544 Py_TYPE(self)->tp_free(
reinterpret_cast<PyObject *
>(self));
550 static_cast<setter
>(
nullptr),
551 pygpu_offscreen_texture_color_doc,
555 static_cast<setter
>(
nullptr),
556 pygpu_offscreen_width_doc,
560 static_cast<setter
>(
nullptr),
561 pygpu_offscreen_height_doc,
563 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
568# pragma clang diagnostic push
569# pragma clang diagnostic ignored "-Wcast-function-type"
571# pragma GCC diagnostic push
572# pragma GCC diagnostic ignored "-Wcast-function-type"
580 pygpu_offscreen_bind_doc},
583 METH_VARARGS | METH_KEYWORDS,
584 pygpu_offscreen_unbind_doc},
587 METH_VARARGS | METH_KEYWORDS,
588 pygpu_offscreen_draw_view3d_doc},
589#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
593 pygpu_offscreen_free_doc},
595 {
nullptr,
nullptr, 0,
nullptr},
600# pragma clang diagnostic pop
602# pragma GCC diagnostic pop
608 pygpu_offscreen__tp_doc,
609 ".. class:: GPUOffScreen\n"
611 " This object gives access to off screen buffers.\n"
613 " .. method:: __init__(width, height, *, format='RGBA8')\n"
615 " :param width: Horizontal dimension of the buffer.\n"
616 " :type width: int\n"
617 " :param height: Vertical dimension of the buffer.\n"
618 " :type height: int\n"
619 " :param format: Internal data format inside GPU memory for color attachment texture.\n"
620 " :type format: Literal['RGBA8', 'RGBA16', 'RGBA16F', 'RGBA32F']\n");
622 PyVarObject_HEAD_INIT(
nullptr, 0)
642 pygpu_offscreen__tp_doc,
687 return reinterpret_cast<PyObject *
>(self);
692#undef BPY_GPU_OFFSCREEN_CHECK_OBJ
#define STRNCPY_UTF8(dst, src)
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
#define BPY_GPU_OFFSCREEN_CHECK_OBJ(bpygpu)
#define BPYGPU_USE_GPUOBJ_FREE_METHOD
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool ED_view3d_draw_offscreen_check_nested()
void GPU_offscreen_free(GPUOffScreen *offscreen)
static PyGetSetDef pygpu_offscreen__tp_getseters[]
int PyC_ParseBool(PyObject *o, void *p)
void GPU_viewport_tag_update(GPUViewport *viewport)
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 PyObject * pygpu_offscreen_width_get(BPyGPUOffScreen *self, void *)
PyTypeObject PyGPUOffscreenStackContext_Type
int GPU_offscreen_width(const GPUOffScreen *offscreen)
static void BPyGPUOffScreen__tp_dealloc(BPyGPUOffScreen *self)
static PyObject * pygpu_offscreen__tp_new(PyTypeObject *, PyObject *args, PyObject *kwds)
static PyMethodDef pygpu_offscreen__tp_methods[]
static PyObject * pygpu_offscreen_bind(BPyGPUOffScreen *self)
static PyObject * pygpu_offscreen_free(BPyGPUOffScreen *self)
int GPU_offscreen_height(const GPUOffScreen *offscreen)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_HOST_READ
static PyObject * pygpu_offscreen_unbind(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
PyObject * BPyGPUOffScreen_CreatePyObject(GPUOffScreen *ofs)
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
static PyObject * pygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
uint GPU_framebuffer_stack_level_get()
void * PyC_RNA_AsPointer(PyObject *value, const char *type_name)
void GPU_viewport_free(GPUViewport *viewport)
static int pygpu_offscreen_valid_check(BPyGPUOffScreen *py_ofs)
gpu::Texture * GPU_offscreen_color_texture(const GPUOffScreen *offscreen)
static PyObject * pygpu_offscreen_height_get(BPyGPUOffScreen *self, void *)
int Matrix_Parse4x4(PyObject *o, void *p)
static PyObject * pygpu_offscreen_texture_color_get(BPyGPUOffScreen *self, void *)
static PyObject * pygpu_offscreen_stack_context_enter(OffScreenStackContext *self)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, gpu::TextureFormat format, eGPUTextureUsage usage, bool clear, char err_out[256])
int PyC_ParseStringEnum(PyObject *o, void *p)
static void pygpu_offscreen_stack_context__tp_dealloc(OffScreenStackContext *self)
static PyObject * pygpu_offscreen_stack_context_exit(OffScreenStackContext *self, PyObject *)
bool BKE_id_is_in_global_main(ID *id)
void ED_view3d_draw_offscreen(Depsgraph *depsgraph, const Scene *scene, eDrawType drawtype, View3D *v3d, ARegion *region, bContext *context, int winx, int winy, const float viewmat[4][4], const float winmat[4][4], bool is_image_render, bool draw_background, const char *viewname, bool do_color_management, bool restore_rv3d_mats, GPUOffScreen *ofs, GPUViewport *viewport)
GPUContext * GPU_context_active_get()
PyObject * BPyGPUTexture_CreatePyObject(gpu::Texture *tex, bool shared_reference)
GPUViewport * GPU_viewport_create()
static PyMethodDef pygpu_offscreen_stack_context__tp_methods[]
static const PyC_StringEnumItems pygpu_framebuffer_color_texture_formats[]
PyTypeObject BPyGPUOffScreen_Type
header-only compatibility defines.
PyObject_HEAD GPUOffScreen * ofs
PyObject_HEAD BPyGPUOffScreen * py_offscreen