44#define BPYGPU_USE_GPUOBJ_FREE_METHOD
61 PyErr_SetString(PyExc_ReferenceError,
63 "GPU offscreen was freed, no further access is valid"
65 "GPU offscreen: internal error"
73#define BPY_GPU_OFFSCREEN_CHECK_OBJ(bpygpu) \
75 if (UNLIKELY(pygpu_offscreen_valid_check(bpygpu) == -1)) { \
99 Py_DECREF(
self->py_offscreen);
109 if (!
self->is_explicitly_bound) {
110 if (
self->level != -1) {
111 PyErr_SetString(PyExc_RuntimeError,
"Already in use");
129 if (
self->level == -1) {
130 PyErr_SetString(PyExc_RuntimeError,
"Not yet in use\n");
135 if (level !=
self->level) {
137 PyExc_RuntimeError,
"Level of bind mismatch, expected %d, got %d\n",
self->level, level);
144#if (defined(__GNUC__) && !defined(__clang__))
145# pragma GCC diagnostic push
146# pragma GCC diagnostic ignored "-Wcast-function-type"
155#if (defined(__GNUC__) && !defined(__clang__))
156# pragma GCC diagnostic pop
160 PyVarObject_HEAD_INIT(
nullptr, 0)
161 "GPUFrameBufferStackContext",
213 pygpu_offscreen_bind_doc,
214 ".. function:: bind()\n"
216 " Context manager to ensure balanced bind calls, even in the case of an error.\n");
223 ret->is_explicitly_bound =
false;
227 ret->is_explicitly_bound =
true;
229 return (PyObject *)
ret;
234 pygpu_offscreen_unbind_doc,
235 ".. method:: unbind(restore=True)\n"
237 " Unbind the offscreen object.\n"
239 " :arg restore: Restore the OpenGL state, can only be used when the state has been "
241 " :type restore: bool\n");
248 static const char *_keywords[] = {
"restore",
nullptr};
249 static _PyArg_Parser _parser = {
257 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser,
PyC_ParseBool, &restore)) {
281 static const char *_keywords[] = {
"width",
"height",
"format",
nullptr};
282 static _PyArg_Parser _parser = {
288 ":GPUOffScreen.__new__",
292 if (!_PyArg_ParseTupleAndKeywordsFast(
307 STRNCPY(err_out,
"No active GPU context found");
310 if (ofs ==
nullptr) {
311 PyErr_Format(PyExc_RuntimeError,
312 "gpu.offscreen.new(...) failed with '%s'",
313 err_out[0] ? err_out :
"unknown error");
322 pygpu_offscreen_width_doc,
323 "Width of the texture.\n"
334 pygpu_offscreen_height_doc,
335 "Height of the texture.\n"
346 pygpu_offscreen_color_texture_doc,
347 "OpenGL bindcode for the color texture.\n"
359 pygpu_offscreen_texture_color_doc,
360 "The color texture attached.\n"
362 ":type: :class:`gpu.types.GPUTexture`");
372 pygpu_offscreen_draw_view3d_doc,
373 ".. method:: draw_view3d(scene, view_layer, view3d, region, view_matrix, projection_matrix, "
374 "do_color_management=False, draw_background=True)\n"
376 " Draw the 3d viewport in the offscreen object.\n"
378 " :arg scene: Scene to draw.\n"
379 " :type scene: :class:`bpy.types.Scene`\n"
380 " :arg view_layer: View layer to draw.\n"
381 " :type view_layer: :class:`bpy.types.ViewLayer`\n"
382 " :arg view3d: 3D View to get the drawing settings from.\n"
383 " :type view3d: :class:`bpy.types.SpaceView3D`\n"
384 " :arg region: Region of the 3D View (required as temporary draw target).\n"
385 " :type region: :class:`bpy.types.Region`\n"
386 " :arg view_matrix: View Matrix (e.g. ``camera.matrix_world.inverted()``).\n"
387 " :type view_matrix: :class:`mathutils.Matrix`\n"
388 " :arg projection_matrix: Projection Matrix (e.g. ``camera.calc_matrix_camera(...)``).\n"
389 " :type projection_matrix: :class:`mathutils.Matrix`\n"
390 " :arg do_color_management: Color manage the output.\n"
391 " :type do_color_management: bool\n"
392 " :arg draw_background: Draw background.\n"
393 " :type draw_background: bool\n");
397 PyObject *py_scene, *py_view_layer, *py_region, *py_view3d;
405 bool do_color_management =
false;
410 static const char *_keywords[] = {
417 "do_color_management",
421 static _PyArg_Parser _parser = {
436 if (!_PyArg_ParseTupleAndKeywordsFast(args,
448 &do_color_management,
462 PyErr_SetString(PyExc_RuntimeError,
"Nested off-screen drawing not supported");
480 if (!
self->viewport) {
494 (
const float(*)[4])py_mat_view->matrix,
495 (
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");
525 if (
self->viewport) {
527 self->viewport =
nullptr;
538 if (
self->viewport) {
544 Py_TYPE(
self)->tp_free((PyObject *)
self);
551 pygpu_offscreen_color_texture_doc,
556 pygpu_offscreen_texture_color_doc,
561 pygpu_offscreen_width_doc,
566 pygpu_offscreen_height_doc,
568 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
571#if (defined(__GNUC__) && !defined(__clang__))
572# pragma GCC diagnostic push
573# pragma GCC diagnostic ignored "-Wcast-function-type"
580 METH_VARARGS | METH_KEYWORDS,
581 pygpu_offscreen_unbind_doc},
584 METH_VARARGS | METH_KEYWORDS,
585 pygpu_offscreen_draw_view3d_doc},
586#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
589 {
nullptr,
nullptr, 0,
nullptr},
592#if (defined(__GNUC__) && !defined(__clang__))
593# pragma GCC diagnostic pop
598 pygpu_offscreen__tp_doc,
599 ".. class:: GPUOffScreen(width, height, *, format='RGBA8')\n"
601 " This object gives access to off screen buffers.\n"
603 " :arg width: Horizontal dimension of the buffer.\n"
604 " :type width: int\n"
605 " :arg height: Vertical dimension of the buffer.\n"
606 " :type height: int\n"
607 " :arg format: Internal data format inside GPU memory for color attachment "
608 "texture. Possible values are:\n"
613 " :type format: str\n");
615 PyVarObject_HEAD_INIT(
nullptr, 0)
635 pygpu_offscreen__tp_doc,
678 self->viewport =
nullptr;
680 return (PyObject *)
self;
685#undef BPY_GPU_OFFSCREEN_CHECK_OBJ
bool BKE_id_is_in_global_main(ID *id)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
#define STRNCPY(dst, src)
bool ED_view3d_draw_offscreen_check_nested()
void ED_view3d_draw_offscreen(Depsgraph *depsgraph, const Scene *scene, eDrawType drawtype, View3D *v3d, ARegion *region, 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()
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, eGPUTextureFormat format, eGPUTextureUsage usage, char err_out[256])
int GPU_offscreen_width(const GPUOffScreen *offscreen)
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
uint GPU_framebuffer_stack_level_get()
int GPU_offscreen_height(const GPUOffScreen *offscreen)
GPUTexture * GPU_offscreen_color_texture(const GPUOffScreen *offscreen)
void GPU_offscreen_free(GPUOffScreen *offscreen)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
int GPU_texture_opengl_bindcode(const GPUTexture *texture)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_HOST_READ
GPUViewport * GPU_viewport_create()
void GPU_viewport_free(GPUViewport *viewport)
void GPU_viewport_tag_update(GPUViewport *viewport)
additional_info("compositor_sum_float_shared") .push_constant(Type additional_info("compositor_sum_float_shared") .push_constant(Type GPU_RGBA32F
const Depsgraph * depsgraph
RAYTRACE_GROUP_SIZE additional_info("eevee_shared", "eevee_gbuffer_data", "eevee_global_ubo", "eevee_sampling_data", "eevee_utility_texture", "eevee_hiz_data", "draw_view") .specialization_constant(Type RAYTRACE_GROUP_SIZE in_sh_0_tx in_sh_2_tx screen_normal_tx GPU_RGBA8
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
static PyMethodDef pygpu_offscreen_stack_context__tp_methods[]
static PyObject * pygpu_offscreen_color_texture_get(BPyGPUOffScreen *self, void *)
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")
PyObject * BPyGPUOffScreen_CreatePyObject(GPUOffScreen *ofs)
#define BPY_GPU_OFFSCREEN_CHECK_OBJ(bpygpu)
static PyMethodDef pygpu_offscreen__tp_methods[]
#define BPYGPU_USE_GPUOBJ_FREE_METHOD
static int pygpu_offscreen_valid_check(BPyGPUOffScreen *py_ofs)
static void BPyGPUOffScreen__tp_dealloc(BPyGPUOffScreen *self)
static PyObject * pygpu_offscreen_texture_color_get(BPyGPUOffScreen *self, void *)
PyTypeObject BPyGPUOffScreen_Type
static PyObject * pygpu_offscreen_width_get(BPyGPUOffScreen *self, void *)
static PyObject * pygpu_offscreen__tp_new(PyTypeObject *, PyObject *args, PyObject *kwds)
static PyObject * pygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
static PyObject * pygpu_offscreen_bind(BPyGPUOffScreen *self)
static PyTypeObject PyGPUOffscreenStackContext_Type
static void pygpu_offscreen_stack_context__tp_dealloc(OffScreenStackContext *self)
static PyObject * pygpu_offscreen_unbind(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds)
static PyObject * pygpu_offscreen_free(BPyGPUOffScreen *self)
static PyObject * pygpu_offscreen_height_get(BPyGPUOffScreen *self, void *)
static PyGetSetDef pygpu_offscreen__tp_getseters[]
static const PyC_StringEnumItems pygpu_framebuffer_color_texture_formats[]
static PyObject * pygpu_offscreen_stack_context_enter(OffScreenStackContext *self)
static PyObject * pygpu_offscreen_stack_context_exit(OffScreenStackContext *self, PyObject *)
PyObject * BPyGPUTexture_CreatePyObject(GPUTexture *tex, bool shared_reference)
int Matrix_Parse4x4(PyObject *o, void *p)
void * PyC_RNA_AsPointer(PyObject *value, const char *type_name)
int PyC_ParseStringEnum(PyObject *o, void *p)
int PyC_ParseBool(PyObject *o, void *p)
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()
static void draw_background()
PyObject_HEAD GPUOffScreen * ofs
PyObject_HEAD BPyGPUOffScreen * py_offscreen