Blender V5.3
wm_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2007 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstdlib>
12#include <cstring>
13
14#include "DNA_camera_types.h"
15#include "DNA_color_types.h"
16#include "DNA_listBase.h"
17#include "DNA_object_types.h"
18#include "DNA_screen_types.h"
19#include "DNA_space_types.h"
20#include "DNA_userdef_types.h"
21#include "DNA_view3d_types.h"
23
24#include "MEM_guardedalloc.h"
25
26#include "BLI_listbase.hh"
27#include "BLI_math_matrix_c.hh"
28#include "BLI_math_vector_c.hh"
30#include "BLI_rect.hh"
31#include "BLI_utildefines.hh"
32
33#include "BKE_context.hh"
34#include "BKE_image.hh"
35#include "BKE_layer.hh"
36#include "BKE_scene.hh"
37#include "BKE_screen.hh"
38
39#include "GHOST_ISystem.hh"
40#include "GHOST_IWindow.hh"
41#include "GHOST_Rect.hh"
42#include "GHOST_Types.hh"
43
44#include "ED_node.hh"
45#include "ED_screen.hh"
46#include "ED_view3d.hh"
47
48#include "GPU_batch_presets.hh"
49#include "GPU_capabilities.hh"
50#include "GPU_context.hh"
51#include "GPU_debug.hh"
52#include "GPU_framebuffer.hh"
53#include "GPU_immediate.hh"
54#include "GPU_matrix.hh"
55#include "GPU_state.hh"
56#include "GPU_texture.hh"
57#include "GPU_viewport.hh"
58
59#include "PRF_profile.hh"
60
61#include "RE_engine.h"
62
63#include "WM_api.hh"
64#include "WM_toolsystem.hh"
65#include "WM_types.hh"
66#include "wm.hh"
67#include "wm_draw.hh"
68#include "wm_event_system.hh"
69#include "wm_surface.hh"
70#include "wm_window.hh"
71#include "wm_window_private.hh"
72
73#include "UI_resources.hh"
74
76
77namespace blender {
78
79#ifdef WITH_OPENSUBDIV
80# include "BKE_subsurf.hh"
81#endif
82
83/* -------------------------------------------------------------------- */
86
91{
93 GHOST_TGrabCursorMode mode_dummy;
94 GHOST_TAxisFlag wrap_axis_dummy;
95 GHOST_Rect bounds = {0};
96 bool use_software_cursor_dummy = false;
97
98 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
99 ghost_window->getCursorGrabState(
100 mode_dummy, wrap_axis_dummy, bounds, use_software_cursor_dummy);
101
102 if (bounds.getWidth() != 0 || bounds.getHeight() != 0) {
103 return true;
104 }
105 }
106 return false;
107}
108
110
111/* -------------------------------------------------------------------- */
114
115static void wm_paintcursor_draw(bContext *C, ScrArea *area, ARegion *region)
116{
118 wmWindow *win = CTX_wm_window(C);
120
121 /* Don't draw paint cursors with locked interface. Painting is not possible
122 * then, and cursor drawing can use scene data that another thread may be
123 * modifying. */
124 if (wm->runtime->is_interface_locked) {
125 return;
126 }
127
128 if (!region->runtime->visible || region != screen->active_region) {
129 return;
130 }
131
132 for (wmPaintCursor &pc : wm->runtime->paintcursors.items_mutable()) {
133 if ((pc.space_type != SPACE_TYPE_ANY) && (area->spacetype != pc.space_type)) {
134 continue;
135 }
136
137 if (!ELEM(pc.region_type, RGN_TYPE_ANY, region->regiontype)) {
138 continue;
139 }
140
141 if (pc.poll == nullptr || pc.poll(C)) {
143
144 /* Prevent drawing outside region. */
145 GPU_scissor_test(true);
146 GPU_scissor(region->winrct.xmin,
147 region->winrct.ymin,
148 BLI_rcti_size_x(&region->winrct) + 1,
149 BLI_rcti_size_y(&region->winrct) + 1);
150 /* Reading the cursor location from the operating-system while the cursor is grabbed
151 * conflicts with grabbing logic that hides the cursor, then keeps it centered to accumulate
152 * deltas without it escaping from the window. In this case we never want to show the actual
153 * cursor coordinates so limit reading the cursor location to when the cursor is grabbed and
154 * wrapping in a region since this is the case when it would otherwise attempt to draw the
155 * cursor outside the view/window. See: #102792. */
156 const int *xy = win->runtime->eventstate->xy;
157 int xy_buf[2];
160 wm_cursor_position_get(win, &xy_buf[0], &xy_buf[1]))
161 {
162 xy = xy_buf;
163 }
164
165 pc.draw(C, xy, win->runtime->eventstate->tablet.tilt, pc.customdata);
166 GPU_scissor_test(false);
167 }
168 }
169}
170
172
173/* -------------------------------------------------------------------- */
179
183static struct {
185 int winid;
186 int xy[2];
188 /*enabled*/ -1,
189 /*winid*/ -1,
191
198
200{
201 if (g_software_cursor.enabled == -1) [[unlikely]] {
203 }
204 return g_software_cursor.enabled;
205}
206
207static bool wm_software_cursor_needed_for_window(const wmWindow *win, GrabState *grab_state)
208{
210
211 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
212 if (ghost_window->getCursorVisibility()) {
213 /* NOTE: The value in `win->grabcursor` can't be used as it
214 * doesn't always match GHOST's value in the case of tablet events. */
215 bool use_software_cursor;
216 ghost_window->getCursorGrabState(
217 grab_state->mode, grab_state->wrap_axis, grab_state->bounds, use_software_cursor);
218
219 if (use_software_cursor) {
220 return true;
221 }
222 }
223 return false;
224}
225
227{
228 return (g_software_cursor.winid != win->winid) ||
229 (g_software_cursor.xy[0] != win->runtime->eventstate->xy[0]) ||
230 (g_software_cursor.xy[1] != win->runtime->eventstate->xy[1]);
231}
232
234{
235
236 g_software_cursor.winid = win->winid;
237 g_software_cursor.xy[0] = win->runtime->eventstate->xy[0];
238 g_software_cursor.xy[1] = win->runtime->eventstate->xy[1];
239}
240
242{
243 g_software_cursor.winid = -1;
244 g_software_cursor.xy[0] = -1;
245 g_software_cursor.xy[1] = -1;
246}
247
249{
250 if (g_software_cursor.winid == win->winid) {
252 }
253}
254
255static void wm_software_cursor_draw_bitmap(const float system_scale,
256 const int event_xy[2],
257 const GHOST_CursorBitmapRef *bitmap)
258{
260
261 float gl_matrix[4][4];
263 gpu::Texture *texture = GPU_texture_create_2d("software_cursor",
264 bitmap->data_size[0],
265 bitmap->data_size[1],
266 1,
267 gpu::TextureFormat::UNORM_8_8_8_8,
268 usage,
269 nullptr);
272
274
275 /* With RGBA cursors, the cursor will have been generated at the correct size,
276 * there is no need to perform additional scaling.
277 *
278 * NOTE: *technically* if a window spans two output of different scales,
279 * we should scale to the output. This use case is currently not accounted for. */
281 1 :
282 std::max(1, round_fl_to_int(system_scale));
283
284 unit_m4(gl_matrix);
285
286 gl_matrix[3][0] = event_xy[0] - (bitmap->hot_spot[0] * scale);
287 gl_matrix[3][1] = event_xy[1] - ((bitmap->data_size[1] - bitmap->hot_spot[1]) * scale);
288
289 gl_matrix[0][0] = bitmap->data_size[0] * scale;
290 gl_matrix[1][1] = bitmap->data_size[1] * scale;
291
292 GPU_matrix_mul(gl_matrix);
293
294 GPUVertFormat *imm_format = immVertexFormat();
295 uint pos = GPU_vertformat_attr_add(imm_format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
296 uint texCoord = GPU_vertformat_attr_add(imm_format, "texCoord", gpu::VertAttrType::SFLOAT_32_32);
297
298 /* Use 3D image for correct display of planar tracked images. */
300
301 immBindTexture("image", texture);
302
304
305 immAttr2f(texCoord, 0.0f, 1.0f);
306 immVertex3f(pos, 0.0f, 0.0f, 0.0f);
307
308 immAttr2f(texCoord, 1.0f, 1.0f);
309 immVertex3f(pos, 1.0f, 0.0f, 0.0f);
310
311 immAttr2f(texCoord, 1.0f, 0.0f);
312 immVertex3f(pos, 1.0f, 1.0f, 0.0f);
313
314 immAttr2f(texCoord, 0.0f, 0.0f);
315 immVertex3f(pos, 0.0f, 1.0f, 0.0f);
316
317 immEnd();
318
320
324
326}
327
328static void wm_software_cursor_draw_crosshair(const float system_scale, const int event_xy[2])
329{
330 /* Draw a primitive cross-hair cursor.
331 * NOTE: the `win->cursor` could be used for drawing although it's complicated as some cursors
332 * are set by the operating-system, where the pixel information isn't easily available. */
333
334 /* The cursor scaled by the "default" size. */
335 const float cursor_scale = float(WM_cursor_preferred_logical_size(false)) /
337 const float unit = max_ff(system_scale * cursor_scale, 1.0f);
338 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
340
341 immUniformColor4f(1, 1, 1, 1);
342 {
343 const int ofs_line = (8 * unit);
344 const int ofs_size = (2 * unit);
345 immRectf(pos,
346 event_xy[0] - ofs_line,
347 event_xy[1] - ofs_size,
348 event_xy[0] + ofs_line,
349 event_xy[1] + ofs_size);
350 immRectf(pos,
351 event_xy[0] - ofs_size,
352 event_xy[1] - ofs_line,
353 event_xy[0] + ofs_size,
354 event_xy[1] + ofs_line);
355 }
356 immUniformColor4f(0, 0, 0, 1);
357 {
358 const int ofs_line = (7 * unit);
359 const int ofs_size = (1 * unit);
360 immRectf(pos,
361 event_xy[0] - ofs_line,
362 event_xy[1] - ofs_size,
363 event_xy[0] + ofs_line,
364 event_xy[1] + ofs_size);
365 immRectf(pos,
366 event_xy[0] - ofs_size,
367 event_xy[1] - ofs_line,
368 event_xy[0] + ofs_size,
369 event_xy[1] + ofs_line);
370 }
372}
373
374static void wm_software_cursor_draw(wmWindow *win, const GrabState *grab_state)
375{
376 int event_xy[2] = {UNPACK2(win->runtime->eventstate->xy)};
377
378 if (grab_state->wrap_axis & GHOST_kAxisX) {
379 const int min = grab_state->bounds.l_;
380 const int max = grab_state->bounds.r_;
381 if (min != max) {
382 event_xy[0] = mod_i(event_xy[0] - min, max - min) + min;
383 }
384 }
385 if (grab_state->wrap_axis & GHOST_kAxisY) {
386 const int height = WM_window_native_pixel_y(win);
387 const int min = height - grab_state->bounds.t_;
388 const int max = height - grab_state->bounds.b_;
389 if (min != max) {
390 event_xy[1] = mod_i(event_xy[1] - max, min - max) + max;
391 }
392 }
393
394 const float system_scale = WM_window_dpi_get_scale(win);
395
396 GHOST_CursorBitmapRef bitmap = {nullptr};
397 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
398 if (ghost_window->getCursorBitmap(&bitmap) == GHOST_kSuccess) {
399 wm_software_cursor_draw_bitmap(system_scale, event_xy, &bitmap);
400 }
401 else {
402 wm_software_cursor_draw_crosshair(system_scale, event_xy);
403 }
404}
405
407
408/* -------------------------------------------------------------------- */
411
412static void wm_region_draw_overlay(bContext *C, const ScrArea *area, ARegion *region)
413{
414 const wmWindow *win = CTX_wm_window(C);
415
416 wmViewport(&region->winrct);
418 region->runtime->type->draw_overlay(C, region);
419 wmWindowViewport(win);
420}
421
423
424/* -------------------------------------------------------------------- */
427
429 ScrArea *area,
430 ARegion *region,
431 eStereoViews sview)
432{
433 /* We could detect better when stereo is actually needed, by inspecting the
434 * image in the image editor and sequencer. */
436 return false;
437 }
438
439 switch (area->spacetype) {
440 case SPACE_IMAGE: {
441 if (region->regiontype == RGN_TYPE_WINDOW) {
442 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
443 sima->iuser.multiview_eye = sview;
444 return true;
445 }
446 break;
447 }
448 case SPACE_VIEW3D: {
449 if (region->regiontype == RGN_TYPE_WINDOW) {
450 View3D *v3d = area->spacedata.first_as<View3D>();
451 if (v3d->camera && v3d->camera->type == OB_CAMERA) {
452 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
453 RenderEngine *engine = rv3d->view_render ? RE_view_engine_get(rv3d->view_render) :
454 nullptr;
455 if (engine && !(engine->type->flag & RE_USE_STEREO_VIEWPORT)) {
456 return false;
457 }
458
459 Camera *cam = id_cast<Camera *>(v3d->camera->data);
460 CameraBGImage *bgpic = cam->bg_images.first();
461 v3d->multiview_eye = sview;
462 if (bgpic) {
463 bgpic->iuser.multiview_eye = sview;
464 }
465 return true;
466 }
467 }
468 break;
469 }
470 case SPACE_NODE: {
471 if (region->regiontype == RGN_TYPE_WINDOW) {
472 SpaceNode *snode = area->spacedata.first_as<SpaceNode>();
473 if ((snode->flag & SNODE_BACKDRAW) && ED_node_is_compositor(snode)) {
474 Image *ima = BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node");
475 ima->eye = sview;
476 return true;
477 }
478 }
479 break;
480 }
481 case SPACE_SEQ: {
482 SpaceSeq *sseq = area->spacedata.first_as<SpaceSeq>();
483 sseq->multiview_eye = sview;
484
485 if (region->regiontype == RGN_TYPE_PREVIEW) {
486 return true;
487 }
488 }
489 }
490
491 return false;
492}
493
495 ScrArea *area,
496 ARegion *region,
497 bool tag_redraw)
498{
499 if (region->runtime->gizmo_map == nullptr) {
500 return;
501 }
502
503 wmGizmoMap *gzmap = region->runtime->gizmo_map;
504 for (wmGizmoGroup &gzgroup : *WM_gizmomap_group_list(gzmap)) {
505 if (tag_redraw && (gzgroup.type->flag & WM_GIZMOGROUPTYPE_VR_REDRAWS)) {
506 ScrArea *ctx_area = CTX_wm_area(C);
507 ARegion *ctx_region = CTX_wm_region(C);
508
509 CTX_wm_area_set(C, area);
510 CTX_wm_region_set(C, region);
511
512 if (WM_gizmo_group_type_poll(C, gzgroup.type)) {
514 }
515
516 /* Reset. */
517 CTX_wm_area_set(C, ctx_area);
518 CTX_wm_region_set(C, ctx_region);
519 }
520
521 for (wmGizmo &gz : gzgroup.gizmos) {
522 if (gz.do_draw) {
523 if (tag_redraw) {
525 }
526 gz.do_draw = false;
527 }
528 }
529 }
530}
531
532static void wm_region_test_render_do_draw(const Scene *scene,
533 Depsgraph *depsgraph,
534 ScrArea *area,
535 ARegion *region)
536{
537 /* Tag region for redraw from render engine preview running inside of it. */
538 if (area->spacetype == SPACE_VIEW3D && region->regiontype == RGN_TYPE_WINDOW) {
539 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
540 RenderEngine *engine = rv3d->view_render ? RE_view_engine_get(rv3d->view_render) : nullptr;
541 GPUViewport *viewport = WM_draw_region_get_viewport(region);
542
543 if (engine && (engine->flag & RE_ENGINE_DO_DRAW)) {
544 View3D *v3d = area->spacedata.first_as<View3D>();
545 rcti border_rect;
546
547 /* Do partial redraw when possible. */
548 if (ED_view3d_calc_render_border(scene, depsgraph, v3d, region, &border_rect)) {
549 ED_region_tag_redraw_partial(region, &border_rect, false);
550 }
551 else {
553 }
554
555 engine->flag &= ~RE_ENGINE_DO_DRAW;
556 }
557 else if (viewport && GPU_viewport_do_update(viewport)) {
559 }
560 }
561}
562
563#ifdef WITH_XR_OPENXR
564static void wm_region_test_xr_do_draw(const wmWindowManager *wm,
565 const ScrArea *area,
566 ARegion *region)
567{
568 if ((area->spacetype == SPACE_VIEW3D) && (region->regiontype == RGN_TYPE_WINDOW)) {
569 if (ED_view3d_is_region_xr_mirror_active(
570 wm, static_cast<const View3D *>(area->spacedata.first_), region))
571 {
573 }
574 }
575}
576#endif
577
578static bool wm_region_use_viewport_by_type(short space_type, short region_type)
579{
580 return (ELEM(space_type, SPACE_VIEW3D, SPACE_IMAGE, SPACE_NODE) &&
581 region_type == RGN_TYPE_WINDOW) ||
582 ((space_type == SPACE_SEQ) && ELEM(region_type, RGN_TYPE_PREVIEW, RGN_TYPE_WINDOW));
583}
584
586{
588}
589
590static const char *wm_area_name(const ScrArea *area)
591{
592#define SPACE_NAME(space) \
593 case space: { \
594 return #space; \
595 }
596 switch (eSpace_Type(area->spacetype)) {
618 }
619#undef SPACE_NAME
620
621 return "Unknown Space";
622}
623
625
626/* -------------------------------------------------------------------- */
631
634
635 void (*draw)(const wmWindow *win, void *customdata);
637};
638
640 void (*draw)(const wmWindow *win, void *customdata),
641 void *customdata)
642{
643 WindowDrawCB *wdc = MEM_new_zeroed<WindowDrawCB>("WindowDrawCB");
644
645 BLI_addtail(&win->runtime->drawcalls, wdc);
646 wdc->draw = draw;
647 wdc->customdata = customdata;
648
649 return wdc;
650}
651
652void WM_draw_cb_exit(wmWindow *win, void *handle)
653{
654 for (WindowDrawCB &wdc : win->runtime->drawcalls) {
655 if (&wdc == static_cast<WindowDrawCB *>(handle)) {
656 BLI_remlink(&win->runtime->drawcalls, &wdc);
657 MEM_delete(&wdc);
658 return;
659 }
660 }
661}
662
664{
665 /* Allow callbacks to remove themselves. */
666 for (WindowDrawCB &wdc : win->runtime->drawcalls.items_mutable()) {
667 wdc.draw(win, wdc.customdata);
668 }
669}
670
672
673/* -------------------------------------------------------------------- */
681
683{
684 if (region->runtime->draw_buffer) {
685 if (region->runtime->draw_buffer->viewport) {
687 }
688 if (region->runtime->draw_buffer->offscreen) {
690 }
691
692 MEM_delete(region->runtime->draw_buffer);
693 region->runtime->draw_buffer = nullptr;
694 }
695}
696
698{
699 /* Setup offscreen color texture for drawing. */
701
702 /* No mipmaps or filtering. */
703 GPU_texture_mipmap_mode(texture, false, false);
704}
705
707{
708 bool use_float = false;
709
714 {
715 use_float = GPU_hdr_support();
716 }
717 gpu::TextureFormat desired_format = (use_float) ? gpu::TextureFormat::SFLOAT_16_16_16_16 :
718 gpu::TextureFormat::UNORM_8_8_8_8;
719 return desired_format;
720}
721
723 ARegion *region,
724 bool stereo,
725 bool use_viewport)
726{
727
728 /* Determine desired offscreen format depending on HDR availability. */
729 gpu::TextureFormat desired_format = get_hdr_framebuffer_format(scene);
730
731 if (region->runtime->draw_buffer) {
732 if (region->runtime->draw_buffer->stereo != stereo) {
733 /* Free draw buffer on stereo changes. */
735 }
736 else {
737 /* Free offscreen buffer on size changes. Viewport auto resizes. */
738 GPUOffScreen *offscreen = region->runtime->draw_buffer->offscreen;
739 if (offscreen && (GPU_offscreen_width(offscreen) != region->winx ||
740 GPU_offscreen_height(offscreen) != region->winy ||
741 GPU_offscreen_format(offscreen) != desired_format))
742 {
744 }
745 }
746 }
747
748 if (!region->runtime->draw_buffer) {
749 if (use_viewport) {
750 /* Allocate viewport which includes an off-screen buffer with depth multi-sample, etc. */
751 region->runtime->draw_buffer = MEM_new_zeroed<wmDrawBuffer>("wmDrawBuffer");
754 }
755 else {
756 /* Allocate off-screen buffer if it does not exist. This one has no
757 * depth or multi-sample buffers. 3D view creates its own buffers with
758 * the data it needs. */
759 GPUOffScreen *offscreen = GPU_offscreen_create(region->winx,
760 region->winy,
761 false,
762 desired_format,
764 true,
765 nullptr);
766 if (!offscreen) {
767 WM_global_report(RPT_ERROR, "Region could not be drawn!");
768 return;
769 }
770
772
773 region->runtime->draw_buffer = MEM_new_zeroed<wmDrawBuffer>("wmDrawBuffer");
774 region->runtime->draw_buffer->offscreen = offscreen;
775 }
776
777 region->runtime->draw_buffer->bound_view = -1;
778 region->runtime->draw_buffer->stereo = stereo;
779 }
780}
781
782static void wm_draw_region_bind(ARegion *region, int view)
783{
784 if (!region->runtime->draw_buffer) {
785 return;
786 }
787
788 if (region->runtime->draw_buffer->viewport) {
789 GPU_viewport_bind(region->runtime->draw_buffer->viewport, view, &region->winrct);
790 }
791 else {
793
794 /* For now scissor is expected by region drawing, we could disable it
795 * and do the enable/disable in the specific cases that setup scissor. */
796 GPU_scissor_test(true);
797 GPU_scissor(0, 0, region->winx, region->winy);
798 }
799
800 region->runtime->draw_buffer->bound_view = view;
801}
802
803static void wm_draw_region_unbind(ARegion *region)
804{
805 if (!region->runtime->draw_buffer) {
806 return;
807 }
808
809 region->runtime->draw_buffer->bound_view = -1;
810
811 if (region->runtime->draw_buffer->viewport) {
813 }
814 else {
815 GPU_scissor_test(false);
817 }
818}
819
820static void wm_draw_region_blit(ARegion *region, int view)
821{
822 if (!region->runtime->draw_buffer) {
823 return;
824 }
825
826 if (view == -1) {
827 /* Non-stereo drawing. */
828 view = 0;
829 }
830 else if (view > 0) {
831 if (region->runtime->draw_buffer->viewport == nullptr) {
832 /* Region does not need stereo or failed to allocate stereo buffers. */
833 view = 0;
834 }
835 }
836
837 /* Regions are copied in without blending, so without this, the region's own alpha would land in
838 * the window's frame-buffer. That matters for client-side-decorated windows for rounded corners:
839 * viewports are transparent where nothing was rendered, leading to un-wanted transparency.
840 *
841 * Everything else drawn into the window blends with #GPU_BLEND_ALPHA which leaves an opaque
842 * destination opaque, so masking here is enough to keep the window opaque for the whole frame,
843 * see #WM_window_csd_draw_corner_mask. */
844 GPU_color_mask(true, true, true, false);
845
846 if (region->runtime->draw_buffer->viewport) {
848 }
849 else {
851 region->runtime->draw_buffer->offscreen, region->winrct.xmin, region->winrct.ymin);
852 }
853
854 GPU_color_mask(true, true, true, true);
855}
856
858{
859 if (!region->runtime->draw_buffer) {
860 return nullptr;
861 }
862
863 GPUViewport *viewport = region->runtime->draw_buffer->viewport;
864 if (viewport) {
865 return GPU_viewport_color_texture(viewport, view);
866 }
868}
869
870void wm_draw_region_blend(ARegion *region, int view, bool blend)
871{
872 if (!region->runtime->draw_buffer) {
873 return;
874 }
875
876 /* Alpha is always 1, except when blend timer is running. */
877 float alpha = ED_region_blend_alpha(region);
878 if (alpha <= 0.0f) {
879 return;
880 }
881
882 if (!blend) {
883 alpha = 1.0f;
884 }
885
886 /* #wmOrtho for the screen has this same offset. */
887 const float halfx = GLA_PIXEL_OFS / (BLI_rcti_size_x(&region->winrct) + 1);
888 const float halfy = GLA_PIXEL_OFS / (BLI_rcti_size_y(&region->winrct) + 1);
889
890 rcti rect_geo = region->winrct;
891 if (blend) {
892 ED_region_blend_rect(region, &rect_geo);
893 }
894 rect_geo.xmax += 1;
895 rect_geo.ymax += 1;
896
897 rctf rect_tex;
898 rect_tex.xmin = halfx;
899 rect_tex.ymin = halfy;
900 rect_tex.xmax = 1.0f + halfx;
901 rect_tex.ymax = 1.0f + halfy;
902
904 rect_tex.xmax *= alpha;
905 }
907 rect_tex.xmin += 1.0f - alpha;
908 }
909 else if (RGN_ALIGN_ENUM_FROM_MASK(region->alignment) == RGN_ALIGN_TOP) {
910 rect_tex.ymax *= alpha;
911 }
913 rect_tex.ymin += 1.0f - alpha;
914 }
915
916 /* Not the same layout as #rctf/#rcti. */
917 const float rectt[4] = {rect_tex.xmin, rect_tex.ymin, rect_tex.xmax, rect_tex.ymax};
918 const float rectg[4] = {
919 float(rect_geo.xmin), float(rect_geo.ymin), float(rect_geo.xmax), float(rect_geo.ymax)};
920
921 if (blend) {
922 /* Regions drawn off-screen have pre-multiplied alpha. */
924 }
925
926 /* Setup actual texture. */
928
931
933 int rect_tex_loc = GPU_shader_get_uniform(shader, "rect_icon");
934 int rect_geo_loc = GPU_shader_get_uniform(shader, "rect_geom");
935 int texture_bind_loc = GPU_shader_get_sampler_binding(shader, "image");
936
937 GPU_texture_bind(texture, texture_bind_loc);
938
939 GPU_shader_uniform_float_ex(shader, rect_tex_loc, 4, 1, rectt);
940 GPU_shader_uniform_float_ex(shader, rect_geo_loc, 4, 1, rectg);
941 GPU_shader_uniform_float_ex(shader, color_loc, 4, 1, float4{alpha, alpha, alpha, alpha});
942
943 gpu::Batch *quad = GPU_batch_preset_quad();
945 GPU_batch_draw(quad);
946
948
949 if (blend) {
951 }
952}
953
955{
956 if (!region->runtime->draw_buffer) {
957 return nullptr;
958 }
959
960 GPUViewport *viewport = region->runtime->draw_buffer->viewport;
961 return viewport;
962}
963
965{
966 if (!region->runtime->draw_buffer || region->runtime->draw_buffer->bound_view == -1) {
967 return nullptr;
968 }
969
970 GPUViewport *viewport = region->runtime->draw_buffer->viewport;
971 return viewport;
972}
973
974static void wm_draw_area_offscreen(bContext *C, wmWindow *win, ScrArea *area, bool stereo)
975{
977 Main *bmain = CTX_data_main(C);
978
979 CTX_wm_area_set(C, area);
981
982 bool is_any_region_drawn = false;
983
984 /* Compute UI layouts for dynamically size regions. */
985 for (ARegion &region : area->regionbase) {
986 if (region.flag & RGN_FLAG_POLL_FAILED) {
987 continue;
988 }
989 /* Dynamic region may have been flagged as too small because their size on init is 0.
990 * ARegion.visible is false then, as expected. The layout should still be created then, so
991 * the region size can be updated (it may turn out to be not too small then). */
992 const bool ignore_visibility = (region.flag & RGN_FLAG_DYNAMIC_SIZE) &&
993 (region.flag & RGN_FLAG_TOO_SMALL) &&
994 !(region.flag & RGN_FLAG_HIDDEN);
995
996 if ((region.runtime->visible || ignore_visibility) && region.runtime->do_draw &&
997 region.runtime->type && region.runtime->type->layout)
998 {
999 /* Call space-level pre-draw callback if this is the first region to be laid out. */
1000 if (!is_any_region_drawn) {
1001 if (area->type->draw_pre) {
1002 area->type->draw_pre(C, area);
1003 }
1004 is_any_region_drawn = true;
1005 }
1006
1007 CTX_wm_region_set(C, &region);
1008 ED_region_do_layout(C, &region);
1009 CTX_wm_region_set(C, nullptr);
1010 }
1011 }
1012
1013 ED_area_update_region_sizes(wm, win, area);
1014
1015 if (area->flag & AREA_FLAG_ACTIVE_TOOL_UPDATE) {
1016 if ((1 << area->spacetype) & WM_TOOLSYSTEM_SPACE_MASK) {
1019 }
1021 }
1022
1023 /* Then do actual drawing of regions. */
1024 for (ARegion &region : area->regionbase) {
1025 if (!region.runtime->visible || !region.runtime->do_draw) {
1026 continue;
1027 }
1028
1029 /* Call space-level pre-draw callback if it wasn't called yet, which can happen when none of
1030 * the regions had a layout callback. */
1031 if (!is_any_region_drawn) {
1032 if (area->type->draw_pre) {
1033 area->type->draw_pre(C, area);
1034 }
1035 is_any_region_drawn = true;
1036 }
1037
1038 CTX_wm_region_set(C, &region);
1039 bool use_viewport = WM_region_use_viewport(area, &region);
1040
1041 GPU_debug_group_begin(use_viewport ? "Viewport" : "ARegion");
1042
1043 if (stereo && wm_draw_region_stereo_set(bmain, area, &region, STEREO_LEFT_ID)) {
1044 Scene *scene = WM_window_get_active_scene(win);
1045 wm_draw_region_buffer_create(scene, &region, true, use_viewport);
1046
1047 for (int view = 0; view < 2; view++) {
1048 eStereoViews sview;
1049 if (view == 0) {
1050 sview = STEREO_LEFT_ID;
1051 }
1052 else {
1053 sview = STEREO_RIGHT_ID;
1054 wm_draw_region_stereo_set(bmain, area, &region, sview);
1055 }
1056
1057 wm_draw_region_bind(&region, view);
1058 ED_region_do_draw(C, &region);
1059 wm_draw_region_unbind(&region);
1060 }
1061 if (use_viewport) {
1062 GPUViewport *viewport = region.runtime->draw_buffer->viewport;
1064 }
1065 }
1066 else {
1067 wm_draw_region_stereo_set(bmain, area, &region, STEREO_LEFT_ID);
1068 Scene *scene = WM_window_get_active_scene(win);
1069 wm_draw_region_buffer_create(scene, &region, false, use_viewport);
1070 wm_draw_region_bind(&region, 0);
1071 ED_region_do_draw(C, &region);
1072 wm_draw_region_unbind(&region);
1073 }
1074
1076
1077 region.runtime->do_draw = 0;
1078
1079 region.runtime->post_block_layout_fns.clear();
1080
1081 /* Clear temporary update flag. */
1083
1084 CTX_wm_region_set(C, nullptr);
1085 }
1086
1087 /* Call space-level post-draw callback, but only if there was at least one region drawn. */
1088 if (is_any_region_drawn && area->type->draw_post) {
1089 area->type->draw_post(C, area);
1090 }
1091
1092 CTX_wm_area_set(C, nullptr);
1093
1095}
1096
1097static void wm_draw_window_offscreen(bContext *C, wmWindow *win, bool stereo)
1098{
1099 bScreen *screen = WM_window_get_active_screen(win);
1100
1101 /* Draw screen areas into their own frame buffer. Status bar and spreadsheet is drawn
1102 * last, because mesh and memory usage statistics are affected by drawing of other
1103 * editors like the 3D viewport. */
1104 ED_screen_areas_iter (win, screen, area) {
1105 if (!ELEM(area->spacetype, SPACE_STATUSBAR, SPACE_SPREADSHEET)) {
1106 wm_draw_area_offscreen(C, win, area, stereo);
1107 }
1108 }
1109 ED_screen_areas_iter (win, screen, area) {
1110 if (ELEM(area->spacetype, SPACE_STATUSBAR, SPACE_SPREADSHEET)) {
1111 wm_draw_area_offscreen(C, win, area, stereo);
1112 }
1113 }
1114
1115 /* Draw menus into their own frame-buffer. */
1116 for (ARegion &region : screen->regionbase) {
1117 if (!region.runtime->visible) {
1118 continue;
1119 }
1120 CTX_wm_region_popup_set(C, &region);
1121
1122 GPU_debug_group_begin("Menu");
1123
1124 if (region.runtime->type && region.runtime->type->layout) {
1125 /* UI code reads the OpenGL state, but we have to refresh
1126 * the UI layout beforehand in case the menu size changes. */
1127 wmViewport(&region.winrct);
1128 region.runtime->type->layout(C, &region);
1129 }
1130
1131 Scene *scene = WM_window_get_active_scene(win);
1132 wm_draw_region_buffer_create(scene, &region, false, false);
1133 wm_draw_region_bind(&region, 0);
1134 GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f);
1135 ED_region_do_draw(C, &region);
1136 wm_draw_region_unbind(&region);
1137
1139
1140 region.runtime->do_draw = 0;
1141 CTX_wm_region_popup_set(C, nullptr);
1142 }
1143}
1144
1145static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
1146{
1148 bScreen *screen = WM_window_get_active_screen(win);
1149
1150 /* Restore screen context after drawing. Especially important for when this is called for drawing
1151 * to an offscreen buffer (see #WM_window_pixels_read_from_offscreen()) from operators or other
1152 * handlers. */
1153 ScrArea *restore_area = CTX_wm_area(C);
1154 ARegion *restore_region = CTX_wm_region(C);
1155 BLI_SCOPED_DEFER([&] {
1156 CTX_wm_area_set(C, restore_area);
1157 CTX_wm_region_set(C, restore_region);
1158 });
1159
1160 GPU_debug_group_begin("Window Redraw");
1161
1162 /* Draw into the window frame-buffer, in full window coordinates. */
1163 wmWindowViewport(win);
1164
1165/* We draw on all pixels of the windows so we don't need to clear them before.
1166 * Actually this is only a problem when resizing the window.
1167 * If it becomes a problem we should clear only when window size changes. */
1168#if 0
1169 GPU_clear_color(0, 0, 0, 0);
1170#endif
1171
1172 /* Blit non-overlapping area regions. */
1173 ED_screen_areas_iter (win, screen, area) {
1174 for (ARegion &region : area->regionbase) {
1175 if (!region.runtime->visible) {
1176 continue;
1177 }
1178
1179 if (region.overlap == false) {
1180 /* Blit from off-screen buffer. */
1181 wm_draw_region_blit(&region, view);
1182 }
1183 }
1184 }
1185
1186 /* Draw overlays and paint cursors. */
1187 ED_screen_areas_iter (win, screen, area) {
1188 for (ARegion &region : area->regionbase) {
1189 if (!region.runtime->visible) {
1190 continue;
1191 }
1192 const bool do_paint_cursor = (wm->runtime->paintcursors.first() &&
1193 &region == screen->active_region);
1194 const bool do_draw_overlay = (region.runtime->type && region.runtime->type->draw_overlay);
1195 if (!(do_paint_cursor || do_draw_overlay)) {
1196 continue;
1197 }
1198
1199 CTX_wm_area_set(C, area);
1200 CTX_wm_region_set(C, &region);
1201 if (do_draw_overlay) {
1202 wm_region_draw_overlay(C, area, &region);
1203 }
1204 if (do_paint_cursor) {
1205 wm_paintcursor_draw(C, area, &region);
1206 }
1207 CTX_wm_region_set(C, nullptr);
1208 CTX_wm_area_set(C, nullptr);
1209 }
1210 }
1211 wmWindowViewport(win);
1212
1213 /* Blend in overlapping area regions. */
1214 ED_screen_areas_iter (win, screen, area) {
1215 for (ARegion &region : area->regionbase) {
1216 if (!region.runtime->visible) {
1217 continue;
1218 }
1219 if (region.overlap) {
1220 wm_draw_region_blend(&region, 0, true);
1221 }
1222 }
1223 }
1224
1225 /* After area regions so we can do area 'overlay' drawing. */
1228
1229 /* Needs zero offset here or it looks blurry. #128112. */
1230 wmWindowViewport_ex(win, 0.0f);
1231
1232 wm_draw_callbacks(win);
1233 wmWindowViewport(win);
1234
1235 /* Always draw, not only when screen tagged. */
1236 if (win->runtime->gesture.first_) {
1237 wm_gesture_draw(win);
1238 wmWindowViewport(win);
1239 }
1240
1241 /* Blend in floating regions (menus). */
1242 for (ARegion &region : screen->regionbase) {
1243 if (!region.runtime->visible) {
1244 continue;
1245 }
1246 wm_draw_region_blend(&region, 0, true);
1247 }
1248
1249 /* Needs pixel coords in screen. */
1250 if (wm->runtime->drags.first_) {
1251 wm_drags_draw(C, win);
1252 wmWindowViewport(win);
1253 }
1254
1256 GrabState grab_state;
1257 if (wm_software_cursor_needed_for_window(win, &grab_state)) {
1258 wm_software_cursor_draw(win, &grab_state);
1260 }
1261 else {
1262 /* Checking the window is needed so one window doesn't clear the cursor state of another. */
1264 }
1265 }
1266
1268}
1269
1271{
1273 GPU_context_begin_frame(static_cast<GPUContext *>(win->runtime->gpuctx));
1274
1275 bScreen *screen = WM_window_get_active_screen(win);
1276 bool stereo = WM_stereo3d_enabled(win, false);
1277
1278#ifdef WITH_GHOST_CSD
1280 /* Title bar. */
1281 if (WM_window_is_csd(win)) {
1283 }
1284 else {
1285 /* Full-screen windows draw no decorations, so nothing above clears the frame-buffer.
1286 * Their alpha channel still has to be made opaque, see #WM_window_csd_clear_alpha. */
1288 }
1289 }
1290#endif
1291
1292 /* Draw area regions into their own frame-buffer. This way we can redraw
1293 * the areas that need it, and blit the rest from existing frame-buffers. */
1294 wm_draw_window_offscreen(C, win, stereo);
1295
1296 /* Now we draw into the window frame-buffer, in full window coordinates. */
1297 if (!stereo) {
1298 /* Regular mono drawing. */
1299 wm_draw_window_onscreen(C, win, -1);
1300 }
1302 /* For page-flip we simply draw to both back buffers. */
1304 wm_draw_window_onscreen(C, win, 1);
1305
1307 wm_draw_window_onscreen(C, win, 0);
1308 }
1310 /* For anaglyph and interlace, we draw individual regions with
1311 * stereo frame-buffers using different shaders. */
1312 wm_draw_window_onscreen(C, win, -1);
1313 }
1314 else {
1315 /* Determine desired offscreen format depending on HDR availability. */
1318
1319 /* For side-by-side and top-bottom, we need to render each view to an
1320 * an off-screen texture and then draw it. This used to happen for all
1321 * stereo methods, but it's less efficient than drawing directly. */
1322 const int2 win_size = WM_window_native_pixel_size(win);
1323 GPUOffScreen *offscreen = GPU_offscreen_create(win_size[0],
1324 win_size[1],
1325 false,
1326 desired_format,
1328 false,
1329 nullptr);
1330
1331 if (offscreen) {
1334
1335 for (int view = 0; view < 2; view++) {
1336 /* Draw view into offscreen buffer. */
1337 GPU_offscreen_bind(offscreen, false);
1338 wm_draw_window_onscreen(C, win, view);
1339 GPU_offscreen_unbind(offscreen, false);
1340
1341 /* Draw offscreen buffer to screen. */
1343
1344 wmWindowViewport(win);
1346 wm_stereo3d_draw_sidebyside(win, view);
1347 }
1348 else {
1349 wm_stereo3d_draw_topbottom(win, view);
1350 }
1351
1353 }
1354
1355 GPU_offscreen_free(offscreen);
1356 }
1357 else {
1358 /* Still draw something in case of allocation failure. */
1359 wm_draw_window_onscreen(C, win, 0);
1360 }
1361 }
1362
1363#ifdef WITH_GHOST_CSD
1364 /* Rounded corners, run last so the corners are cut away no matter what covered them
1365 * (the title bar at the top, editor areas & the status bar at the bottom). */
1366 if (WM_window_is_csd(win)) {
1368 }
1369#endif
1370
1371 screen->do_draw = false;
1372
1373 GPU_context_end_frame(static_cast<GPUContext *>(win->runtime->gpuctx));
1374}
1375
1379static void wm_draw_surface(bContext *C, wmSurface *surface)
1380{
1382 wm_surface_make_drawable(surface);
1383
1385
1386 surface->draw(C);
1387
1389
1390 /* Avoid interference with window drawable. */
1392}
1393
1395
1396/* -------------------------------------------------------------------- */
1401
1403 const wmWindow *win,
1404 int r_size[2])
1405{
1406 /* Don't assert as file-save uses this for a screenshot, where redrawing isn't an option
1407 * because of the side-effects of drawing a window on save.
1408 * In this case the thumbnail might not work and there are currently no better alternatives. */
1409 // BLI_assert(WM_capabilities_flag() & WM_CAPABILITY_GPU_FRONT_BUFFER_READ);
1410
1411 /* WARNING: Reading from the front-buffer immediately after drawing may fail,
1412 * for a slower but more reliable version of this function
1413 * #WM_window_pixels_read_from_offscreen should be preferred.
1414 * See it's comments for details on why it's needed, see also #98462. */
1415 bool setup_context = wm->runtime->windrawable != win;
1416
1417 if (setup_context) {
1418 static_cast<GHOST_IWindow *>(win->runtime->ghostwin)->activateDrawingContext();
1419 GPU_context_active_set(static_cast<GPUContext *>(win->runtime->gpuctx));
1420 }
1421
1422 const int2 win_size = WM_window_native_pixel_size(win);
1423 const uint rect_len = win_size[0] * win_size[1];
1424 uint8_t *rect = MEM_new_array_uninitialized<uint8_t>(4 * rect_len, __func__);
1425
1426 GPU_frontbuffer_read_color(0, 0, win_size[0], win_size[1], 4, GPU_DATA_UBYTE, rect);
1427
1428 if (setup_context) {
1429 if (wm->runtime->windrawable) {
1430 static_cast<GHOST_IWindow *>(wm->runtime->windrawable->runtime->ghostwin)
1431 ->activateDrawingContext();
1432 GPU_context_active_set(static_cast<GPUContext *>(wm->runtime->windrawable->runtime->gpuctx));
1433 }
1434 }
1435
1436 /* Clear alpha, it is not set to a meaningful value in OpenGL. */
1437 uchar *cp = static_cast<uchar *>(rect);
1438 uint i;
1439 for (i = 0, cp += 3; i < rect_len; i++, cp += 4) {
1440 *cp = 0xff;
1441 }
1442
1443 r_size[0] = win_size[0];
1444 r_size[1] = win_size[1];
1445 return rect;
1446}
1447
1449 const wmWindow *win,
1450 const int pos[2],
1451 float r_col[3])
1452{
1454 bool setup_context = wm->runtime->windrawable != win;
1455
1456 if (setup_context) {
1457 static_cast<GHOST_IWindow *>(win->runtime->ghostwin)->activateDrawingContext();
1458 GPU_context_active_set(static_cast<GPUContext *>(win->runtime->gpuctx));
1459 }
1460
1461 /* NOTE(@jbakker): Vulkan backend isn't able to read 3 channels from a 4 channel texture with
1462 * data data-conversions is needed. Data conversion happens inline for all channels. This is a
1463 * vulkan backend issue and should be solved. However the solution has a lot of branches that
1464 * requires testing so a quick fix has been added to the place where this was used. The solution
1465 * is to implement all the cases in 'VKFramebuffer::read'.
1466 */
1467 float4 color_with_alpha;
1468 GPU_frontbuffer_read_color(pos[0], pos[1], 1, 1, 4, GPU_DATA_FLOAT, color_with_alpha);
1469 copy_v3_v3(r_col, color_with_alpha.xyz());
1470
1471 if (setup_context) {
1472 if (wm->runtime->windrawable) {
1473 static_cast<GHOST_IWindow *>(wm->runtime->windrawable->runtime->ghostwin)
1474 ->activateDrawingContext();
1475 GPU_context_active_set(static_cast<GPUContext *>(wm->runtime->windrawable->runtime->gpuctx));
1476 }
1477 }
1478}
1479
1481{
1482 /* NOTE(@ideasman42): There is a problem reading the windows front-buffer after redrawing
1483 * the window in some cases (typically to clear UI elements such as menus or search popup).
1484 * With EGL `eglSurfaceAttrib(..)` may support setting the `EGL_SWAP_BEHAVIOR` attribute to
1485 * `EGL_BUFFER_PRESERVED` however not all implementations support this.
1486 * Requesting the ability with `EGL_SWAP_BEHAVIOR_PRESERVED_BIT` can even cause the EGL context
1487 * not to initialize at all.
1488 * Confusingly there are some cases where this *does* work, depending on the state of the window
1489 * and prior calls to swap-buffers, however ensuring the state exactly as needed to satisfy a
1490 * particular GPU back-end is fragile, see #98462.
1491 *
1492 * So provide an alternative to #WM_window_pixels_read that avoids using the front-buffer. */
1493
1494 /* Draw into an off-screen buffer and read its contents. */
1495 const int2 win_size = WM_window_native_pixel_size(win);
1496
1497 /* Determine desired offscreen format depending on HDR availability. */
1499
1500 GPUOffScreen *offscreen = GPU_offscreen_create(win_size[0],
1501 win_size[1],
1502 false,
1503 desired_format,
1505 false,
1506 nullptr);
1507 if (!offscreen) [[unlikely]] {
1508 return nullptr;
1509 }
1510
1511 const uint rect_len = win_size[0] * win_size[1];
1512 uint8_t *rect = MEM_new_array_uninitialized<uint8_t>(4 * rect_len, __func__);
1513 GPU_offscreen_bind(offscreen, false);
1514 wm_draw_window_onscreen(C, win, -1);
1515 GPU_offscreen_unbind(offscreen, false);
1516 GPU_offscreen_read_color(offscreen, GPU_DATA_UBYTE, rect);
1517 GPU_offscreen_free(offscreen);
1518
1519 r_size[0] = win_size[0];
1520 r_size[1] = win_size[1];
1521 return rect;
1522}
1523
1525 wmWindow *win,
1526 const int pos[2],
1527 float r_col[3])
1528{
1529 /* A version of #WM_window_pixels_read_from_offscreen that reads a single sample. */
1530 const int2 win_size = WM_window_native_pixel_size(win);
1531 zero_v3(r_col);
1532
1533 /* While this shouldn't happen, return in the case it does. */
1534 BLI_assert(uint(pos[0]) < uint(win_size[0]) && uint(pos[1]) < uint(win_size[1]));
1535 if (!(uint(pos[0]) < uint(win_size[0]) && uint(pos[1]) < uint(win_size[1]))) {
1536 return false;
1537 }
1538
1539 GPUOffScreen *offscreen = GPU_offscreen_create(win_size[0],
1540 win_size[1],
1541 false,
1542 gpu::TextureFormat::UNORM_8_8_8_8,
1544 false,
1545 nullptr);
1546 if (!offscreen) [[unlikely]] {
1547 return false;
1548 }
1549
1550 float rect_pixel[4];
1551 GPU_offscreen_bind(offscreen, false);
1552 wm_draw_window_onscreen(C, win, -1);
1553 GPU_offscreen_unbind(offscreen, false);
1554 GPU_offscreen_read_color_region(offscreen, GPU_DATA_FLOAT, pos[0], pos[1], 1, 1, rect_pixel);
1555 GPU_offscreen_free(offscreen);
1556 copy_v3_v3(r_col, rect_pixel);
1557 return true;
1558}
1559
1564{
1566 return false;
1567 }
1568 /* Not part of #WM_capabilities_flag as it depends on the GPU driver, not GHOST. */
1570 return false;
1571 }
1572 return true;
1573}
1574
1576{
1579 }
1580 return WM_window_pixels_read_from_offscreen(C, win, r_size);
1581}
1582
1583bool WM_window_pixels_read_sample(bContext *C, wmWindow *win, const int pos[2], float r_col[3])
1584{
1587 return true;
1588 }
1589 return WM_window_pixels_read_sample_from_offscreen(C, win, pos, r_col);
1590}
1591
1593{
1594 const GHOST_ISystem *ghost_system = GHOST_ISystem::getSystem();
1595 return ghost_system->getPixelAtCursor(r_col);
1596}
1597
1599
1600/* -------------------------------------------------------------------- */
1603
1604/* Quick test to prevent changing window drawable. */
1606{
1608 Scene *scene = WM_window_get_active_scene(win);
1609 ViewLayer *view_layer = WM_window_get_active_view_layer(win);
1610 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
1611 bScreen *screen = WM_window_get_active_screen(win);
1612 bool do_draw = false;
1613
1614 for (ARegion &region : screen->regionbase) {
1615 if (region.runtime->do_draw_paintcursor) {
1616 screen->do_draw_paintcursor = true;
1617 region.runtime->do_draw_paintcursor = false;
1618 }
1619 if (region.runtime->visible && region.runtime->do_draw) {
1620 do_draw = true;
1621 }
1622 }
1623
1624 ED_screen_areas_iter (win, screen, area) {
1625 for (ARegion &region : area->regionbase) {
1626 wm_region_test_gizmo_do_draw(C, area, &region, true);
1627 wm_region_test_render_do_draw(scene, depsgraph, area, &region);
1628#ifdef WITH_XR_OPENXR
1629 wm_region_test_xr_do_draw(wm, area, &region);
1630#endif
1631
1632 if (region.runtime->visible && region.runtime->do_draw) {
1633 do_draw = true;
1634 }
1635 }
1636 }
1637
1638 if (do_draw) {
1639 return true;
1640 }
1641
1642 if (screen->do_refresh) {
1643 return true;
1644 }
1645 if (screen->do_draw) {
1646 return true;
1647 }
1648 if (screen->do_draw_gesture) {
1649 return true;
1650 }
1651 if (screen->do_draw_paintcursor) {
1652 return true;
1653 }
1654 if (screen->do_draw_drag) {
1655 return true;
1656 }
1657
1659 GrabState grab_state;
1660 if (wm_software_cursor_needed_for_window(win, &grab_state)) {
1662 return true;
1663 }
1664 }
1665 else {
1666 /* Detect the edge case when the previous draw used the software cursor but this one doesn't,
1667 * it's important to redraw otherwise the software cursor will remain displayed. */
1668 if (g_software_cursor.winid == win->winid) {
1669 return true;
1670 }
1671 }
1672 }
1673
1674#ifndef WITH_XR_OPENXR
1675 UNUSED_VARS(wm);
1676#endif
1677
1678 return false;
1679}
1680
1681/* Clear drawing flags, after drawing is complete so any draw flags set during
1682 * drawing don't cause any additional redraws. */
1684{
1685 bScreen *screen = WM_window_get_active_screen(win);
1686
1687 ED_screen_areas_iter (win, screen, area) {
1688 for (ARegion &region : area->regionbase) {
1689 wm_region_test_gizmo_do_draw(C, area, &region, false);
1690 }
1691 }
1692
1693 screen->do_draw_gesture = false;
1694 screen->do_draw_paintcursor = false;
1695 screen->do_draw_drag = false;
1696}
1697
1699{
1700 if (win) {
1701 bScreen *screen = WM_window_get_active_screen(win);
1702 screen->do_draw_paintcursor = true;
1703 }
1704}
1705
1707{
1709
1710 Main *bmain = CTX_data_main(C);
1712 const bool rna_disallow_writes = true;
1713
1715
1717
1720
1721#ifdef WITH_METAL_BACKEND
1722 /* Reset drawable to ensure GPU context activation happens at least once per frame if only a
1723 * single context exists. This is required to ensure the default framebuffer is updated
1724 * to be the latest backbuffer. */
1726#endif
1727
1728 for (wmWindow &win : wm->windows) {
1729#ifdef WIN32
1730 const GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win.runtime->ghostwin);
1731 const GHOST_TWindowState state = ghost_window->getState();
1732
1734 /* Do not update minimized windows, gives issues on Intel (see #33223)
1735 * and AMD (see #50856). it seems logical to skip update for invisible window anyway. */
1736 continue;
1737 }
1738#endif
1739
1740 CTX_wm_window_set(C, &win);
1741
1742 if (wm_draw_update_test_window(bmain, C, &win)) {
1743 PRF_frame_mark_start("Window Drawing"_ustr);
1744 /* Sets context window+screen. */
1747
1748 /* Notifiers for screen redraw. */
1750
1751 wm_draw_window(C, &win);
1753
1755 PRF_frame_mark_end("Window Drawing"_ustr);
1756 }
1757 }
1758
1759 CTX_wm_window_set(C, nullptr);
1760
1761 /* Draw surfaces (non-windows, currently only used for XR). */
1763
1764 /* Restore GPU context to the last valid window if surface drawing cleared it, also restore DPI.
1765 * This is required for GPU rendering code called before the next window redraw. Such as by
1766 * events, handlers and notifiers (see #WM_main). */
1767 if (wm->runtime->windrawable == nullptr && GPU_context_active_get() == nullptr) {
1768 for (wmWindow &win : wm->windows.items_reversed()) {
1769 if (win.runtime->ghostwin) {
1771 break;
1772 }
1773 }
1774 }
1775
1778
1780}
1781
1782void wm_draw_region_clear(wmWindow *win, ARegion * /*region*/)
1783{
1784 bScreen *screen = WM_window_get_active_screen(win);
1785 screen->do_draw = true;
1786}
1787
1789{
1791}
1792
1794{
1795 /* Function for redraw timer benchmark. */
1796 bool use_viewport = WM_region_use_viewport(area, region);
1797 wmWindow *win = CTX_wm_window(C);
1798 Scene *scene = WM_window_get_active_scene(win);
1799 wm_draw_region_buffer_create(scene, region, false, use_viewport);
1800 wm_draw_region_bind(region, 0);
1801 ED_region_do_draw(C, region);
1802 wm_draw_region_unbind(region);
1803 region->runtime->do_draw = 0;
1804}
1805
1807{
1808 wmWindow *win_prev = CTX_wm_window(C);
1809 ScrArea *area_prev = CTX_wm_area(C);
1810 ARegion *region_prev = CTX_wm_region(C);
1811
1813
1814 CTX_wm_window_set(C, win_prev);
1815 CTX_wm_area_set(C, area_prev);
1816 CTX_wm_region_set(C, region_prev);
1817}
1818
1820
1821/* -------------------------------------------------------------------- */
1830
1831void WM_draw_region_viewport_ensure(Scene *scene, ARegion *region, short space_type)
1832{
1833 bool use_viewport = wm_region_use_viewport_by_type(space_type, region->regiontype);
1834 wm_draw_region_buffer_create(scene, region, false, use_viewport);
1835}
1836
1838{
1839 wm_draw_region_bind(region, 0);
1840}
1841
1843{
1844 wm_draw_region_unbind(region);
1845}
1846
1848
1849} // namespace blender
#define BLI_SCOPED_DEFER(function_to_defer)
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
#define RGN_ALIGN_ENUM_FROM_MASK(align)
#define RGN_TYPE_ANY
#define SPACE_TYPE_ANY
#define ED_screen_areas_iter(win, screen, area_name)
Definition ED_screen.hh:322
GHOST_TWindowState
@ GHOST_kWindowStateMinimized
GHOST_TAxisFlag
@ GHOST_kAxisX
@ GHOST_kAxisY
@ GHOST_kSuccess
GHOST_TGrabCursorMode
@ GHOST_kGrabWrap
@ GHOST_kGrabHide
#define GLA_PIXEL_OFS
Read Blender memory allocation and freeing.
#define PRF_frame_mark_start(name)
#define PRF_scope(category)
#define PRF_frame_mark_end(name)
#define C
Definition RandGen.cpp:29
#define WM_CURSOR_DEFAULT_LOGICAL_SIZE
Definition WM_api.hh:693
#define WM_TOOLSYSTEM_SPACE_MASK
#define UNPACK2(a)
#define UNUSED_VARS(...)
#define ELEM(...)
btScalar max
static GHOST_ISystem * getSystem()
virtual GHOST_TSuccess getPixelAtCursor(float r_color[3]) const =0
virtual GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap)=0
virtual void getCursorGrabState(GHOST_TGrabCursorMode &mode, GHOST_TAxisFlag &axis_flag, GHOST_Rect &bounds, bool &use_software_cursor)=0
virtual bool getCursorVisibility() const =0
virtual GHOST_TWindowState getState() const =0
int32_t t_
int32_t r_
int32_t b_
int32_t l_
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
float3x3 scale(float3x3 mat, float2 scale)
const int state
void theme_set(int spacetype, int regionid)
BMesh Iterators.
void GPU_viewport_stereo_composite(GPUViewport *viewport, Stereo3dFormat *stereo_format)
bool ED_node_is_compositor(const SpaceNode *snode)
Definition node_edit.cc:135
static void wm_paintcursor_draw(bContext *C, ScrArea *area, ARegion *region)
Definition wm_draw.cc:115
static void wm_draw_region_blit(ARegion *region, int view)
Definition wm_draw.cc:820
uint8_t * WM_window_pixels_read_from_offscreen(bContext *C, wmWindow *win, int r_size[2])
Definition wm_draw.cc:1480
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
gpu::Texture * GPU_viewport_color_texture(GPUViewport *viewport, int view)
int GPU_shader_get_sampler_binding(gpu::Shader *shader, const char *name)
void GPU_scissor_test(bool enable)
Definition gpu_state.cc:173
MINLINE int mod_i(int i, int n)
static bool wm_draw_region_stereo_set(Main *bmain, ScrArea *area, ARegion *region, eStereoViews sview)
Definition wm_draw.cc:428
ScrArea * CTX_wm_area(const bContext *C)
static void wm_software_cursor_motion_clear_with_window(const wmWindow *win)
Definition wm_draw.cc:248
void GPU_offscreen_free(GPUOffScreen *offscreen)
void ED_region_blend_rect(ARegion *region, rcti *r_rect)
void ED_screen_ensure_updated(bContext *C, wmWindowManager *wm, wmWindow *win)
void wmViewport(const rcti *winrct)
static void wm_draw_region_unbind(ARegion *region)
Definition wm_draw.cc:803
const ListBaseT< wmGizmoGroup > * WM_gizmomap_group_list(wmGizmoMap *gzmap)
void GPU_texture_update(gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
void wm_draw_region_test(bContext *C, ScrArea *area, ARegion *region)
Definition wm_draw.cc:1793
void immEnd()
bool IMB_colormanagement_display_is_hdr(const ColorManagedDisplaySettings *display_settings, const char *view_name)
void ED_area_update_region_sizes(wmWindowManager *wm, wmWindow *win, ScrArea *area)
Definition area.cc:2290
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void GPU_clear_color(float red, float green, float blue, float alpha)
WorkSpace * CTX_wm_workspace(const bContext *C)
MINLINE int round_fl_to_int(float a)
void wmWindowViewport(const wmWindow *win)
void ED_region_do_layout(bContext *C, ARegion *region)
Definition area.cc:495
int WM_window_native_pixel_y(const wmWindow *win)
void GPU_context_main_unlock()
static bool wm_software_cursor_needed_for_window(const wmWindow *win, GrabState *grab_state)
Definition wm_draw.cc:207
static bool wm_software_cursor_needed()
Definition wm_draw.cc:199
GPUVertFormat * immVertexFormat()
bool WM_region_use_viewport(ScrArea *area, ARegion *region)
Definition wm_draw.cc:585
bool IMB_colormanagement_display_is_wide_gamut(const ColorManagedDisplaySettings *display_settings, const char *view_name)
static void wm_region_test_render_do_draw(const Scene *scene, Depsgraph *depsgraph, ScrArea *area, ARegion *region)
Definition wm_draw.cc:532
void CTX_wm_window_set(bContext *C, wmWindow *win)
uint WM_cursor_preferred_logical_size(const bool hardware_cursor)
@ S3D_DISPLAY_SIDEBYSIDE
@ S3D_DISPLAY_INTERLACE
void GPU_context_end_frame(GPUContext *ctx)
@ RE_USE_STEREO_VIEWPORT
Definition RE_engine.h:51
void GPU_render_step(bool force_resource_release=false)
void immBegin(GPUPrimType, uint vertex_len)
float ED_region_blend_alpha(ARegion *region)
void WM_draw_region_free(ARegion *region)
Definition wm_draw.cc:1788
static void wm_region_test_gizmo_do_draw(bContext *C, ScrArea *area, ARegion *region, bool tag_redraw)
Definition wm_draw.cc:494
static void wm_draw_window(bContext *C, wmWindow *win)
Definition wm_draw.cc:1270
wmWindow * CTX_wm_window(const bContext *C)
bool WM_stereo3d_enabled(wmWindow *win, bool skip_stereo3d_check)
Definition wm_stereo.cc:141
uint8_t * WM_window_pixels_read(bContext *C, wmWindow *win, int r_size[2])
Definition wm_draw.cc:1575
void GPU_render_begin()
void GPU_batch_set_shader(gpu::Batch *batch, gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_context_active_set(GPUContext *)
bool WM_window_pixels_read_sample_from_offscreen(bContext *C, wmWindow *win, const int pos[2], float r_col[3])
Definition wm_draw.cc:1524
int GPU_offscreen_width(const GPUOffScreen *offscreen)
void ED_region_tag_redraw_editor_overlays(ARegion *region)
Definition area.cc:745
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
void wm_surface_clear_drawable()
Definition wm_surface.cc:70
void immAttr2f(uint attr_id, float x, float y)
void ED_region_do_draw(bContext *C, ARegion *region)
Definition area.cc:515
void immUnbindProgram()
static bool wm_draw_update_test_window(Main *bmain, bContext *C, wmWindow *win)
Definition wm_draw.cc:1605
ViewLayer * CTX_data_view_layer(const bContext *C)
void GPU_matrix_mul(const float m[4][4])
void GPU_context_begin_frame(GPUContext *ctx)
void WM_draw_region_viewport_bind(ARegion *region)
Definition wm_draw.cc:1837
static void wm_draw_area_offscreen(bContext *C, wmWindow *win, ScrArea *area, bool stereo)
Definition wm_draw.cc:974
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
@ GPU_BLEND_ALPHA_PREMULT
Definition GPU_state.hh:91
@ GPU_UNIFORM_COLOR
void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win)
VecBase< float, 4 > float4
static void wm_draw_surface(bContext *C, wmSurface *surface)
Definition wm_draw.cc:1379
void WM_draw_cb_exit(wmWindow *win, void *handle)
Definition wm_draw.cc:652
void GPU_offscreen_read_color_region(GPUOffScreen *offscreen, eGPUDataFormat data_format, int x, int y, int w, int h, void *r_data)
void GPU_viewport_unbind(GPUViewport *viewport)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
static void wm_draw_region_buffer_create(Scene *scene, ARegion *region, bool stereo, bool use_viewport)
Definition wm_draw.cc:722
void GPU_texture_mipmap_mode(gpu::Texture *texture, bool use_mipmap, bool use_filter)
static void wm_region_draw_overlay(bContext *C, const ScrArea *area, ARegion *region)
Definition wm_draw.cc:412
static bool rna_disallow_writes
Definition bpy_rna.cc:476
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void wm_draw_region_clear(wmWindow *win, ARegion *)
Definition wm_draw.cc:1782
bool wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y)
VecBase< int32_t, 2 > int2
Scene * WM_window_get_active_scene(const wmWindow *win)
int GPU_offscreen_height(const GPUOffScreen *offscreen)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void wm_stereo3d_draw_sidebyside(wmWindow *win, int view)
Definition wm_stereo.cc:44
unsigned char uchar
Definition BKE_text.h:58
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_GENERAL
void GPU_render_end()
static bool wm_window_pixels_read_use_frontbuffer()
Definition wm_draw.cc:1563
static void wm_draw_update_clear_window(bContext *C, wmWindow *win)
Definition wm_draw.cc:1683
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
bool WM_window_pixels_read_sample(bContext *C, wmWindow *win, const int pos[2], float r_col[3])
Definition wm_draw.cc:1583
void wm_draw_region_blend(ARegion *region, int view, bool blend)
Definition wm_draw.cc:870
void wm_window_swap_buffer_acquire(wmWindow *win)
Push rendered buffer to the screen.
bool WM_desktop_cursor_sample_read(float r_col[3])
Definition wm_draw.cc:1592
static void wm_software_cursor_draw_crosshair(const float system_scale, const int event_xy[2])
Definition wm_draw.cc:328
@ GPU_SHADER_2D_IMAGE_RECT_COLOR
static struct blender::@037277116025112217063260326170341263035346017163 g_software_cursor
wmWindowManager * CTX_wm_manager(const bContext *C)
void GPU_shader_uniform_float_ex(gpu::Shader *shader, int location, int length, int array_size, const float *value)
void wm_drags_draw(bContext *C, wmWindow *win)
static void wm_draw_region_bind(ARegion *region, int view)
Definition wm_draw.cc:782
bool ED_view3d_calc_render_border(const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, rcti *r_rect)
unsigned char uint8_t
Definition BKE_text.h:79
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
void GPU_color_mask(bool r, bool g, bool b, bool a)
Definition gpu_state.cc:95
static void wm_software_cursor_draw(wmWindow *win, const GrabState *grab_state)
Definition wm_draw.cc:374
void GPU_offscreen_draw_to_screen(GPUOffScreen *offscreen, int x, int y)
bool GPU_frontbuffer_read_workaround()
bool GPU_hdr_support()
static gpu::TextureFormat get_hdr_framebuffer_format(const Scene *scene)
Definition wm_draw.cc:706
void immUniformColor4f(float r, float g, float b, float a)
void wmWindowViewport_ex(const wmWindow *win, float offset)
void WM_redraw_windows(bContext *C)
Definition wm_draw.cc:1806
static void wm_draw_offscreen_texture_parameters(GPUOffScreen *offscreen)
Definition wm_draw.cc:697
void GPU_backbuffer_bind(GPUBackBuffer back_buffer_type)
static void wm_draw_region_buffer_free(ARegion *region)
Definition wm_draw.cc:682
void GPU_batch_draw(gpu::Batch *batch)
static void wm_software_cursor_motion_clear()
Definition wm_draw.cc:241
void unit_m4(float m[4][4])
void WM_window_csd_draw_corner_mask(const wmWindow *win)
void wm_window_clear_drawable(wmWindowManager *wm)
void immBindTexture(const char *name, gpu::Texture *tex)
void WM_global_report(eReportType type, const char *message)
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
bool WM_window_csd_is_active()
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
void GPU_viewport_bind(GPUViewport *viewport, int view, const rcti *rect)
void WM_toolsystem_update_from_context(bContext *C, WorkSpace *workspace, const Scene *scene, ViewLayer *view_layer, ScrArea *area)
void CTX_wm_region_popup_set(bContext *C, ARegion *region_popup)
void WM_draw_region_viewport_ensure(Scene *scene, ARegion *region, short space_type)
Definition wm_draw.cc:1831
void GPU_frontbuffer_read_color(int x, int y, int width, int height, int channels, eGPUDataFormat data_format, void *r_data)
MINLINE void zero_v3(float r[3])
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void WM_window_csd_draw_titlebar(const wmWindow *win)
static void wm_draw_window_offscreen(bContext *C, wmWindow *win, bool stereo)
Definition wm_draw.cc:1097
void GPU_debug_group_end()
Definition gpu_debug.cc:34
void CTX_rna_disallow_write_set_p(bContext *C, const bool *rna_disallow_writes)
int GPU_shader_get_uniform(gpu::Shader *shader, const char *name)
static const char * wm_area_name(const ScrArea *area)
Definition wm_draw.cc:590
@ WM_GIZMOGROUPTYPE_VR_REDRAWS
static bool wm_window_grab_warp_region_is_set(const wmWindow *win)
Definition wm_draw.cc:90
@ WM_CAPABILITY_CURSOR_RGBA
Definition WM_api.hh:247
@ WM_CAPABILITY_GPU_FRONT_BUFFER_READ
Definition WM_api.hh:233
@ WM_CAPABILITY_CURSOR_WARP
Definition WM_api.hh:208
void wm_window_swap_buffer_release(wmWindow *win)
gpu::Shader * GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
void GPU_scissor(int x, int y, int width, int height)
Definition gpu_state.cc:178
bool WM_window_is_csd(const wmWindow *win)
void GPU_viewport_free(GPUViewport *viewport)
gpu::Batch * GPU_batch_preset_quad()
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
gpu::Texture * GPU_offscreen_color_texture(const GPUOffScreen *offscreen)
int2 WM_window_native_pixel_size(const wmWindow *win)
void GPU_texture_bind(gpu::Texture *texture, int unit)
eWM_CapabilitiesFlag WM_capabilities_flag()
MINLINE float max_ff(float a, float b)
void GPU_texture_free(gpu::Texture *texture)
Image * BKE_image_ensure_viewer(Main *bmain, int type, const char *name)
static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
Definition wm_draw.cc:1145
gpu::TextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen)
uint8_t * WM_window_pixels_read_from_frontbuffer(const wmWindowManager *wm, const wmWindow *win, int r_size[2])
Definition wm_draw.cc:1402
void GPU_viewport_draw_to_screen(GPUViewport *viewport, int view, const rcti *rect)
void ED_screen_draw_edges(wmWindow *win)
bool WM_gizmo_group_type_poll(const bContext *C, const wmGizmoGroupType *gzgt)
void GPU_texture_unbind(gpu::Texture *texture)
RenderEngine * RE_view_engine_get(const ViewRender *view_render)
@ RE_ENGINE_DO_DRAW
Definition RE_engine.h:65
Scene * CTX_data_scene(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3644
void wm_stereo3d_draw_topbottom(wmWindow *win, int view)
Definition wm_stereo.cc:93
void immVertex3f(uint attr_id, float x, float y, float z)
void WM_window_pixels_read_sample_from_frontbuffer(const wmWindowManager *wm, const wmWindow *win, const int pos[2], float r_col[3])
Definition wm_draw.cc:1448
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, gpu::TextureFormat format, eGPUTextureUsage usage, bool clear, char err_out[256])
static void wm_draw_callbacks(wmWindow *win)
Definition wm_draw.cc:663
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
@ RGN_FLAG_SEARCH_FILTER_UPDATE
void wm_draw_update(bContext *C)
Definition wm_draw.cc:1706
void * WM_draw_cb_activate(wmWindow *win, void(*draw)(const wmWindow *win, void *customdata), void *customdata)
Definition wm_draw.cc:639
float WM_window_dpi_get_scale(const wmWindow *win)
Definition wm_window.cc:784
static bool wm_region_use_viewport_by_type(short space_type, short region_type)
Definition wm_draw.cc:578
GPUViewport * GPU_viewport_stereo_create()
int GPU_shader_get_builtin_uniform(gpu::Shader *shader, int builtin)
void GPU_context_main_lock()
void ED_region_tag_redraw_partial(ARegion *region, const rcti *rct, bool rebuild)
Definition area.cc:757
void GPU_matrix_pop()
GPUViewport * WM_draw_region_get_viewport(ARegion *region)
Definition wm_draw.cc:954
bScreen * WM_window_get_active_screen(const wmWindow *win)
gpu::Texture * wm_draw_region_texture(ARegion *region, int view)
Definition wm_draw.cc:857
void WM_window_csd_clear_alpha(const wmWindow *win)
void wm_surfaces_iter(bContext *C, void(*cb)(bContext *C, wmSurface *))
Definition wm_surface.cc:50
GPUViewport * WM_draw_region_get_bound_viewport(ARegion *region)
Definition wm_draw.cc:964
void wm_gesture_draw(wmWindow *win)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
ARegion * CTX_wm_region(const bContext *C)
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:727
static bool wm_software_cursor_motion_test(const wmWindow *win)
Definition wm_draw.cc:226
void WM_draw_region_viewport_unbind(ARegion *region)
Definition wm_draw.cc:1842
void WM_paint_cursor_tag_redraw(wmWindow *win, ARegion *)
Definition wm_draw.cc:1698
signed char int8_t
Definition BKE_text.h:76
static void wm_software_cursor_draw_bitmap(const float system_scale, const int event_xy[2], const GHOST_CursorBitmapRef *bitmap)
Definition wm_draw.cc:255
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
bool GPU_viewport_do_update(GPUViewport *viewport)
void GPU_matrix_push()
GPUContext * GPU_context_active_get()
@ AREA_FLAG_ACTIVE_TOOL_UPDATE
void GPU_debug_group_begin(const char *name)
Definition gpu_debug.cc:23
GPUViewport * GPU_viewport_create()
static void wm_software_cursor_motion_update(const wmWindow *win)
Definition wm_draw.cc:233
void CTX_wm_area_set(bContext *C, ScrArea *area)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)
void wm_surface_make_drawable(wmSurface *surface)
Definition wm_surface.cc:99
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
const uint8_t * data
void(*) draw_overlay(const bContext *C, ARegion *region)
void(*) layout(const bContext *C, ARegion *region)
bke::ARegionRuntime * runtime
eRegion_Alignment alignment
eRegion_Type regiontype
GHOST_TAxisFlag wrap_axis
Definition wm_draw.cc:195
GHOST_TGrabCursorMode mode
Definition wm_draw.cc:194
GHOST_Rect bounds
Definition wm_draw.cc:196
struct ViewRender * view_render
RenderEngineType * type
Definition RE_engine.h:141
ColorManagedViewSettings view_settings
ColorManagedDisplaySettings display_settings
ListBaseT< ARegion > regionbase
ListBaseT< SpaceLink > spacedata
struct SpaceType * type
struct ImageUser iuser
eSpaceNode_Flag flag
void(*) draw_pre(const bContext *C, ScrArea *area)
void(*) draw_post(const bContext *C, ScrArea *area)
eStereoDisplayMode display_mode
struct Object * camera
void(*) draw(const wmWindow *win, void *customdata)
Definition wm_draw.cc:635
WindowDrawCB * prev
Definition wm_draw.cc:633
WindowDrawCB * next
Definition wm_draw.cc:633
struct ARegion * active_region
ListBaseT< ARegion > regionbase
Vector< std::function< void(const bContext &C, ui::Block &Block)> > post_block_layout_fns
struct ARegionType * type
ListBaseT< wmGesture > gesture
ListBaseT< WindowDrawCB > drawcalls
GPUViewport * viewport
Definition wm_draw.hh:25
GPUOffScreen * offscreen
Definition wm_draw.hh:24
wmTabletData tablet
Definition WM_types.hh:846
GPUContext * blender_gpu_context
Definition wm_surface.hh:27
void(*) draw(bContext *)
Definition wm_surface.hh:31
bke::WindowRuntime * runtime
struct Stereo3dFormat * stereo3d_format
#define SPACE_NAME(space)