Blender V5.3
gpu_framebuffer.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "BLI_math_base_c.hh"
12#include "BLI_string.hh"
13#include "BLI_utildefines.hh"
14
15#include "CLG_log.h"
16
17#include "GPU_capabilities.hh"
18#include "GPU_texture.hh"
19
20#include "gpu_backend.hh"
23
25
26namespace blender {
27
28namespace gpu {
29
30static CLG_LogRef LOG = {"gpu.framebuffer"};
31
32/* -------------------------------------------------------------------- */
35
36FrameBuffer::FrameBuffer(const char *name)
37{
38 if (name) {
39 STRNCPY(name_, name);
40 }
41 else {
42 name_[0] = '\0';
43 }
44 /* Force config on first use. */
45 dirty_attachments_ = true;
46 dirty_state_ = true;
47
48 for (GPUAttachment &attachment : attachments_) {
49 attachment.tex = nullptr;
50 attachment.mip = -1;
51 attachment.layer = -1;
52 }
53}
54
56{
57 for (GPUAttachment &attachment : attachments_) {
58 if (attachment.tex != nullptr) {
59 reinterpret_cast<Texture *>(attachment.tex)->detach_from(this);
60 }
61 }
62
63#ifndef GPU_NO_USE_PY_REFERENCES
64 if (this->py_ref) {
65 *this->py_ref = nullptr;
66 }
67#endif
68}
69
71
72/* -------------------------------------------------------------------- */
75
77{
78 if (new_attachment.mip == -1) {
79 return; /* GPU_ATTACHMENT_LEAVE */
80 }
81
82 if (type >= GPU_FB_MAX_ATTACHMENT) {
83 fprintf(stderr,
84 "GPUFramebuffer: Error: Trying to attach texture to type %d but maximum slot is %d.\n",
87 return;
88 }
89
90 if (new_attachment.tex) {
91 if (new_attachment.layer > 0) {
92 BLI_assert(GPU_texture_is_cube(new_attachment.tex) ||
93 GPU_texture_is_array(new_attachment.tex));
94 }
95 if (GPU_texture_has_stencil_format(new_attachment.tex)) {
97 }
98 else if (GPU_texture_has_depth_format(new_attachment.tex)) {
100 }
101 }
102
103 GPUAttachment &attachment = attachments_[type];
104
105 set_color_attachment_bit(type, new_attachment.tex != nullptr);
106
107 if (attachment.tex == new_attachment.tex && attachment.layer == new_attachment.layer &&
108 attachment.mip == new_attachment.mip)
109 {
110 return; /* Exact same texture already bound here. */
111 }
112 /* Unbind previous and bind new. */
113 /* TODO(fclem): cleanup the casts. */
114 if (attachment.tex) {
115 reinterpret_cast<Texture *>(attachment.tex)->detach_from(this);
116 }
117
118 /* Might be null if this is for unbinding. */
119 if (new_attachment.tex) {
120 reinterpret_cast<Texture *>(new_attachment.tex)->attach_to(this, type);
121 }
122 else {
123 /* GPU_ATTACHMENT_NONE */
124 }
125
126 attachment = new_attachment;
127 dirty_attachments_ = true;
128}
129
136
137void FrameBuffer::subpass_transition(const GPUAttachmentState depth_attachment_state,
138 Span<GPUAttachmentState> color_attachment_states)
139{
140 /* NOTE: Depth is not supported as input attachment because the Metal API doesn't support it and
141 * because depth is not compatible with the framebuffer fetch implementation. */
142 BLI_assert(depth_attachment_state != GPU_ATTACHMENT_READ);
143
146 {
147 BLI_assert(depth_attachment_state == GPU_ATTACHMENT_IGNORE);
148 }
149
150 BLI_assert(color_attachment_states.size() <= GPU_FB_MAX_COLOR_ATTACHMENT);
153 if (this->attachments_[type].tex) {
154 BLI_assert(i < color_attachment_states.size());
155 set_color_attachment_bit(type, color_attachment_states[i] == GPU_ATTACHMENT_WRITE);
156 }
157 else {
158 set_color_attachment_bit(type, false);
159 BLI_assert(i >= color_attachment_states.size() ||
160 color_attachment_states[i] != GPU_ATTACHMENT_READ);
161 }
162 }
163
164 subpass_transition_impl(depth_attachment_state, color_attachment_states);
165}
166
167void FrameBuffer::load_store_config_array(const GPULoadStore *load_store_actions, uint actions_len)
168{
169 /* Follows attachment structure of GPU_framebuffer_config_array/GPU_framebuffer_ensure_config */
170 const GPULoadStore &depth_action = load_store_actions[0];
171 Span<GPULoadStore> color_attachment_actions(load_store_actions + 1, actions_len - 1);
172 BLI_assert(color_attachment_actions.size() <= GPU_FB_MAX_COLOR_ATTACHMENT);
173
176 {
179 }
180
183 }
184
185 if (this->attachments_[GPU_FB_DEPTH_ATTACHMENT].tex) {
187 }
188
191 if (this->attachments_[type].tex) {
192 BLI_assert(i < color_attachment_actions.size());
193 this->attachment_set_loadstore_op(type, color_attachment_actions[i]);
194 }
195 else {
196 BLI_assert(i >= color_attachment_actions.size() ||
197 (color_attachment_actions[i].load_action == GPU_LOADACTION_DONT_CARE &&
198 color_attachment_actions[i].store_action == GPU_STOREACTION_DONT_CARE));
199 }
200 }
201}
202
204{
205 uint total_bits = 0;
206 for (GPUAttachment &attachment : attachments_) {
207 Texture *tex = reinterpret_cast<Texture *>(attachment.tex);
208 if (tex != nullptr) {
209 int bits = to_bytesize(tex->format_get()) * to_component_len(tex->format_get());
210 total_bits += bits;
211 }
212 }
213 return total_bits;
214}
215
217
218} // namespace gpu
219
220/* -------------------------------------------------------------------- */
223
224using namespace blender::gpu;
225
227{
228 /* We generate the FB object later at first use in order to
229 * create the frame-buffer in the right opengl context. */
230 return GPUBackend::get()->framebuffer_alloc(name);
231}
232
234{
235 delete fb;
236}
237
239{
240 return fb->name_get();
241}
242
243/* ---------- Binding ----------- */
244
246{
247 const bool enable_srgb = true;
248 /* Disable custom loadstore and bind. */
249 fb->set_use_explicit_loadstore(false);
250 fb->bind(enable_srgb);
251}
252
254 const GPULoadStore *load_store_actions,
255 uint actions_len)
256{
257 const bool enable_srgb = true;
258 /* Bind with explicit loadstore state */
259 fb->set_use_explicit_loadstore(true);
260 fb->bind(enable_srgb);
261
262 /* Update load store */
263 fb->load_store_config_array(load_store_actions, actions_len);
264}
265
267 const GPUAttachmentState *attachment_states,
268 uint attachment_len)
269{
270 fb->subpass_transition(attachment_states[0],
271 Span<GPUAttachmentState>(attachment_states + 1, attachment_len - 1));
272}
273
275{
276 const bool enable_srgb = false;
277 fb->bind(enable_srgb);
278}
279
280void GPU_backbuffer_bind(GPUBackBuffer back_buffer_type)
281{
282 Context *ctx = Context::get();
283
284 if (back_buffer_type == GPU_BACKBUFFER_LEFT) {
285 ctx->back_left->bind(false);
286 }
287 else {
288 ctx->back_right->bind(false);
289 }
290}
291
293{
294 Context::get()->back_left->bind(false);
295}
296
298{
299 Context *ctx = Context::get();
300 return ctx ? ctx->active_fb : nullptr;
301}
302
304{
305 Context *ctx = Context::get();
306 return ctx ? ctx->back_left : nullptr;
307}
308
310{
311 return (gpu_fb == GPU_framebuffer_active_get());
312}
313
314/* ---------- Attachment Management ----------- */
315
316bool GPU_framebuffer_check_valid(gpu::FrameBuffer *gpu_fb, char err_out[256])
317{
318 return gpu_fb->check(err_out);
319}
320
322 GPUAttachment attachment,
323 int slot)
324{
325 Texture *tex = reinterpret_cast<Texture *>(attachment.tex);
326 GPUAttachmentType type = tex->attachment_type(slot);
327 gpu_fb->attachment_set(type, attachment);
328}
329
331{
332 GPUAttachment attachment = GPU_ATTACHMENT_TEXTURE_MIP(tex, mip);
333 gpu_framebuffer_texture_attach_ex(fb, attachment, slot);
334}
335
337 gpu::FrameBuffer *fb, gpu::Texture *tex, int slot, int layer, int mip)
338{
340 gpu_framebuffer_texture_attach_ex(fb, attachment, slot);
341}
342
344 gpu::FrameBuffer *fb, gpu::Texture *tex, int slot, int face, int mip)
345{
346 GPUAttachment attachment = GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(tex, face, mip);
347 gpu_framebuffer_texture_attach_ex(fb, attachment, slot);
348}
349
354
356 const GPUAttachment *config,
357 int config_len)
358{
359 const GPUAttachment &depth_attachment = config[0];
360 Span<GPUAttachment> color_attachments(config + 1, config_len - 1);
361
362 if (depth_attachment.mip == -1) {
363 /* GPU_ATTACHMENT_LEAVE */
364 }
365 else if (depth_attachment.tex == nullptr) {
366 /* GPU_ATTACHMENT_NONE: Need to clear both targets. */
367 fb->attachment_set(GPU_FB_DEPTH_STENCIL_ATTACHMENT, depth_attachment);
368 fb->attachment_set(GPU_FB_DEPTH_ATTACHMENT, depth_attachment);
369 }
370 else {
371 GPUAttachmentType type = GPU_texture_has_stencil_format(depth_attachment.tex) ?
374 fb->attachment_set(type, depth_attachment);
375 }
376
378 for (const GPUAttachment &attachment : color_attachments) {
379 fb->attachment_set(type, attachment);
380 ++type;
381 }
382}
383
384void GPU_framebuffer_default_size(gpu::FrameBuffer *gpu_fb, int width, int height)
385{
386 gpu_fb->default_size_set(width, height);
387}
388
390{
391 return gpu_fb->size_get();
392}
393
394/* ---------- Viewport & Scissor Region ----------- */
395
396void GPU_framebuffer_viewport_set(gpu::FrameBuffer *gpu_fb, int x, int y, int width, int height)
397{
398 int viewport_rect[4] = {x, y, width, height};
399 gpu_fb->viewport_set(viewport_rect);
400}
401
403 const int viewport_rects[GPU_MAX_VIEWPORTS][4])
404{
405 gpu_fb->viewport_multi_set(viewport_rects);
406}
407
408void GPU_framebuffer_viewport_get(gpu::FrameBuffer *gpu_fb, int r_viewport[4])
409{
410 gpu_fb->viewport_get(r_viewport);
411}
412
417
418/* ---------- Frame-buffer Operations ----------- */
419
420/* Check for any loss of data when casting. */
421static void check_clear_color(const Texture *tex, double4 clear_value, int attachment)
422{
423 GPUTextureFormatFlag flag = tex->format_flag_get();
424
425 if ((flag & GPU_FORMAT_INTEGER) && (flag & GPU_FORMAT_SIGNED)) {
426 int4 data = int4(clear_value);
427 if (double4(data) != clear_value) {
428 CLOG_WARN(&LOG,
429 "Lossy conversion when clearing integer attachment %d: "
430 "(%f, %f, %f, %f) > (%d, %d, %d, %d)",
431 attachment,
432 UNPACK4(clear_value),
433 UNPACK4(data));
434 }
435 }
436 else if ((flag & GPU_FORMAT_INTEGER) && !(flag & GPU_FORMAT_SIGNED)) {
437 uint4 data = uint4(clear_value);
438 if (double4(data) != clear_value) {
439 CLOG_WARN(&LOG,
440 "Lossy conversion when clearing unsigned integer attachment %d: "
441 "(%f, %f, %f, %f) > (%u, %u, %u, %u)",
442 attachment,
443 UNPACK4(clear_value),
444 UNPACK4(data));
445 }
446 }
447}
448
450 GPUFrameBufferBits buffers,
451 const double4 clear_col,
452 float clear_depth,
453 uint clear_stencil)
454{
456 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
457 "state via GPU_framebuffer_bind_ex is invalid.");
458
459 if ((G.debug & G_DEBUG_GPU) && (buffers & GPU_COLOR_BIT)) {
460 for (int i = 0; i < GPU_FB_MAX_COLOR_ATTACHMENT; i++) {
461 Texture *tex = gpu_fb->color_tex(i);
462 if (tex != nullptr) {
463 check_clear_color(tex, clear_col, i);
464 }
465 }
466 }
467
468 gpu_fb->clear(buffers, clear_col, clear_depth, clear_stencil);
469}
470
472{
473 GPU_framebuffer_clear(fb, GPU_COLOR_BIT, clear_col, 0.0f, 0x00);
474}
475
477{
478 GPU_framebuffer_clear(fb, GPU_DEPTH_BIT, double4{}, clear_depth, 0x00);
479}
480
482 const double4 clear_col,
483 float clear_depth)
484{
485 GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT, clear_col, clear_depth, 0x00);
486}
487
489{
490 GPU_framebuffer_clear(fb, GPU_STENCIL_BIT, double4{}, 0.0f, clear_stencil);
491}
492
494 float clear_depth,
495 uint clear_stencil)
496{
498 fb, GPU_DEPTH_BIT | GPU_STENCIL_BIT, double4{}, clear_depth, clear_stencil);
499}
500
502 const double4 clear_col,
503 float clear_depth,
504 uint clear_stencil)
505{
507 fb, GPU_COLOR_BIT | GPU_DEPTH_BIT | GPU_STENCIL_BIT, clear_col, clear_depth, clear_stencil);
508}
509
511{
512 BLI_assert_msg(fb->get_use_explicit_loadstore() == false,
513 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
514 "state via GPU_framebuffer_bind_ex is invalid.");
515
516 if (G.debug & G_DEBUG_GPU) {
517 for (int i = 0; i < GPU_FB_MAX_COLOR_ATTACHMENT; i++) {
518 Texture *tex = fb->color_tex(i);
519 if (tex != nullptr) {
520 check_clear_color(tex, clear_colors[i], i);
521 }
522 }
523 }
524
525 fb->clear_multi(clear_colors);
526}
527
528void GPU_clear_color(float red, float green, float blue, float alpha)
529{
530 BLI_assert_msg(Context::get()->active_fb->get_use_explicit_loadstore() == false,
531 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
532 "state via GPU_framebuffer_bind_ex is invalid.");
533 double4 clear_col = {red, green, blue, alpha};
534 Context::get()->active_fb->clear(GPU_COLOR_BIT, clear_col, 0.0f, 0x0);
535}
536
537void GPU_clear_depth(float depth)
538{
539 BLI_assert_msg(Context::get()->active_fb->get_use_explicit_loadstore() == false,
540 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
541 "state via GPU_framebuffer_bind_ex is invalid.");
543}
544
546 gpu::FrameBuffer *fb, int x, int y, int w, int h, eGPUDataFormat format, void *data)
547{
548 int rect[4] = {x, y, w, h};
549 fb->read(GPU_DEPTH_BIT, format, rect, 1, 1, data);
550}
551
553 int x,
554 int y,
555 int w,
556 int h,
557 int channels,
558 int slot,
559 eGPUDataFormat format,
560 void *data)
561{
562 int rect[4] = {x, y, w, h};
563 fb->read(GPU_COLOR_BIT, format, rect, channels, slot, data);
564}
565
567 int x, int y, int w, int h, int channels, eGPUDataFormat format, void *data)
568{
569 int rect[4] = {x, y, w, h};
570 Context::get()->front_left->read(GPU_COLOR_BIT, format, rect, channels, 0, data);
571}
572
573/* TODO(fclem): port as texture operation. */
575 int read_slot,
576 gpu::FrameBuffer *fb_write,
577 int write_slot,
578 GPUFrameBufferBits blit_buffers)
579{
580 BLI_assert(blit_buffers != 0);
581
582 FrameBuffer *prev_fb = Context::get()->active_fb;
583
584#ifndef NDEBUG
585 gpu::Texture *read_tex, *write_tex;
586 if (blit_buffers & (GPU_DEPTH_BIT | GPU_STENCIL_BIT)) {
587 read_tex = fb_read->depth_tex();
588 write_tex = fb_write->depth_tex();
589 }
590 else {
591 read_tex = fb_read->color_tex(read_slot);
592 write_tex = fb_write->color_tex(write_slot);
593 }
594
595 if (blit_buffers & GPU_DEPTH_BIT) {
597 BLI_assert(GPU_texture_format(read_tex) == GPU_texture_format(write_tex) ||
598 (ELEM(GPU_texture_format(read_tex),
599 TextureFormat::SFLOAT_32_DEPTH,
600 TextureFormat::SFLOAT_32_DEPTH_UINT_8) &&
601 ELEM(GPU_texture_format(write_tex),
602 TextureFormat::SFLOAT_32_DEPTH,
603 TextureFormat::SFLOAT_32_DEPTH_UINT_8)));
604 }
605 if (blit_buffers & GPU_STENCIL_BIT) {
608 BLI_assert(GPU_texture_format(read_tex) == GPU_texture_format(write_tex));
609 }
610#endif
611
612 fb_read->blit_to(blit_buffers, read_slot, fb_write, write_slot, 0, 0);
613
614 /* FIXME(@fclem): sRGB is not saved. */
615 prev_fb->bind(true);
616}
617
618#ifndef GPU_NO_USE_PY_REFERENCES
620{
621 return fb->py_ref;
622}
623
625{
626 BLI_assert(py_ref == nullptr || fb->py_ref == nullptr);
627 fb->py_ref = py_ref;
628}
629#endif
630
632
633/* -------------------------------------------------------------------- */
638
639#define FRAMEBUFFER_STACK_DEPTH 16
640
645
652
659
664
665#undef FRAMEBUFFER_STACK_DEPTH
666
668
669/* -------------------------------------------------------------------- */
675
687
692{
693 Context *ctx = Context::get();
694 BLI_assert(ctx);
695
696 for (auto &framebuffer : ofs->framebuffers) {
697 if (framebuffer.fb == nullptr) {
698 framebuffer.ctx = ctx;
699 GPU_framebuffer_ensure_config(&framebuffer.fb,
700 {
701 GPU_ATTACHMENT_TEXTURE(ofs->depth),
702 GPU_ATTACHMENT_TEXTURE(ofs->color),
703 });
704 }
705
706 if (framebuffer.ctx == ctx) {
707 return framebuffer.fb;
708 }
709 }
710
711 /* List is full, this should never happen or
712 * it might just slow things down if it happens
713 * regularly. In this case we just empty the list
714 * and start over. This is most likely never going
715 * to happen under normal usage. */
716 BLI_assert(0);
717 printf(
718 "Warning: GPUOffscreen used in more than 3 GPUContext. "
719 "This may create performance drop.\n");
720
721 for (auto &framebuffer : ofs->framebuffers) {
722 GPU_framebuffer_free(framebuffer.fb);
723 framebuffer.fb = nullptr;
724 }
725
726 return gpu_offscreen_fb_get(ofs);
727}
728
730 int height,
731 bool with_depth_buffer,
732 gpu::TextureFormat format,
733 eGPUTextureUsage usage,
734 bool clear,
735 char err_out[256])
736{
738
739 /* Sometimes areas can have 0 height or width and this will
740 * create a 1D texture which we don't want. */
741 height = max_ii(1, height);
742 width = max_ii(1, width);
743
744 /* Always add GPU_TEXTURE_USAGE_ATTACHMENT for convenience. */
746
747 ofs->color = GPU_texture_create_2d("ofs_color", width, height, 1, format, usage, nullptr);
748
749 if (with_depth_buffer) {
750 /* Format view flag is needed by Workbench Volumes to read the stencil view. */
752 ofs->depth = GPU_texture_create_2d("ofs_depth",
753 width,
754 height,
755 1,
756 gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8,
757 depth_usage,
758 nullptr);
759 }
760
761 if ((with_depth_buffer && !ofs->depth) || !ofs->color) {
762 const char error[] = "gpu::Texture: Texture allocation failed.";
763 if (err_out) {
764 BLI_strncpy(err_out, error, 256);
765 }
766 else {
767 fprintf(stderr, "%s", error);
768 }
770 return nullptr;
771 }
772
774
775 /* check validity at the very end! */
776 if (!GPU_framebuffer_check_valid(fb, err_out)) {
778 return nullptr;
779 }
780
781 if (clear) {
783 if (with_depth_buffer) {
784 GPU_framebuffer_clear_color_depth(fb, {0.0, 0.0, 0.0, 0.0}, 0.0f);
785 }
786 else {
787 GPU_framebuffer_clear_color(fb, {0.0, 0.0, 0.0, 0.0});
788 }
789 }
790
792 return ofs;
793}
794
796{
797 for (auto &framebuffer : offscreen->framebuffers) {
798 if (framebuffer.fb) {
799 GPU_framebuffer_free(framebuffer.fb);
800 }
801 }
802 if (offscreen->color) {
803 GPU_texture_free(offscreen->color);
804 }
805 if (offscreen->depth) {
806 GPU_texture_free(offscreen->depth);
807 }
808
809 MEM_delete(offscreen);
810}
811
812void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
813{
814 if (save) {
817 }
818 gpu_offscreen_fb_get(offscreen)->bind(false);
819}
820
821void GPU_offscreen_unbind(GPUOffScreen * /*offscreen*/, bool restore)
822{
823 gpu::FrameBuffer *fb = nullptr;
824 if (restore) {
826 }
827
828 if (fb) {
830 }
831 else {
833 }
834}
835
837{
838 Context *ctx = Context::get();
839 FrameBuffer *ofs_fb = gpu_offscreen_fb_get(offscreen);
840 ofs_fb->blit_to(GPU_COLOR_BIT, 0, ctx->active_fb, 0, x, y);
841}
842
844 GPUOffScreen *offscreen, eGPUDataFormat format, int x, int y, int w, int h, void *r_data)
845{
847 BLI_assert(x >= 0 && y >= 0 && w > 0 && h > 0);
848 BLI_assert(x + w <= GPU_texture_width(offscreen->color));
849 BLI_assert(y + h <= GPU_texture_height(offscreen->color));
850
851 gpu::FrameBuffer *ofs_fb = gpu_offscreen_fb_get(offscreen);
852 GPU_framebuffer_read_color(ofs_fb, x, y, w, h, 4, 0, format, r_data);
853}
854
855void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat format, void *r_data)
856{
858
859 const int w = GPU_texture_width(offscreen->color);
860 const int h = GPU_texture_height(offscreen->color);
861
862 GPU_offscreen_read_color_region(offscreen, format, 0, 0, w, h, r_data);
863}
864
866{
867 return GPU_texture_width(offscreen->color);
868}
869
871{
872 return GPU_texture_height(offscreen->color);
873}
874
876{
877 return offscreen->color;
878}
879
881{
882 return GPU_texture_format(offscreen->color);
883}
884
886 gpu::FrameBuffer **r_fb,
887 gpu::Texture **r_color,
888 gpu::Texture **r_depth)
889{
890 *r_fb = gpu_offscreen_fb_get(offscreen);
891 *r_color = offscreen->color;
892 *r_depth = offscreen->depth;
893}
894
896
897} // namespace blender
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define GPU_ATTACHMENT_NONE
#define GPU_ATTACHMENT_TEXTURE_MIP(_texture, _mip)
#define GPU_framebuffer_ensure_config(_fb,...)
#define GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_texture, _layer, _mip)
#define GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_texture, _face, _mip)
Read Blender memory allocation and freeing.
#define UNPACK4(a)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
constexpr IndexRange()=default
constexpr int64_t size() const
Definition BLI_span.hh:256
static Context * get()
void attachment_remove(GPUAttachmentType type)
gpu::Texture * color_tex(int slot) const
virtual void subpass_transition_impl(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states)=0
virtual void clear(GPUFrameBufferBits buffers, const double4 clear_color, float clear_depth, uint clear_stencil)=0
virtual void read(GPUFrameBufferBits planes, eGPUDataFormat format, const int area[4], int channel_len, int slot, void *r_data)=0
virtual void attachment_set_loadstore_op(GPUAttachmentType type, GPULoadStore ls)=0
void viewport_set(const int viewport[4])
void set_color_attachment_bit(GPUAttachmentType type, bool value)
virtual void bind(bool enabled_srgb)=0
void default_size_set(int width, int height)
void subpass_transition(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states)
FrameBuffer(const char *name)
virtual bool check(char err_out[256])=0
int2 size_get() const
Get the size of the framebuffer.
virtual void blit_to(GPUFrameBufferBits planes, int src_slot, FrameBuffer *dst, int dst_slot, int dst_offset_x, int dst_offset_y)=0
void viewport_multi_set(const int viewports[GPU_MAX_VIEWPORTS][4])
void viewport_get(int r_viewport[4]) const
GPUAttachment attachments_[GPU_FB_MAX_ATTACHMENT]
void load_store_config_array(const GPULoadStore *load_store_actions, uint actions_len)
void attachment_set(GPUAttachmentType type, const GPUAttachment &new_attachment)
virtual FrameBuffer * framebuffer_alloc(const char *name)=0
static GPUBackend * get()
TextureFormat format_get() const
void detach_from(FrameBuffer *fb)
#define FRAMEBUFFER_STACK_DEPTH
#define GPU_FB_MAX_COLOR_ATTACHMENT
#define layer
static CLG_LogRef LOG
int to_bytesize(const DataFormat format)
int to_component_len(TextureFormat format)
BMesh Iterators.
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
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_texture_layer_attach(gpu::FrameBuffer *fb, gpu::Texture *texture, int slot, int layer, int mip)
void GPU_offscreen_free(GPUOffScreen *offscreen)
char * STRNCPY(char(&dst)[N], const char *src)
void GPU_framebuffer_clear(gpu::FrameBuffer *fb, GPUFrameBufferBits buffers, const double4 clear_col, float clear_depth, unsigned int clear_stencil)
gpu::TextureFormat GPU_texture_format(const gpu::Texture *texture)
VecBase< int32_t, 4 > int4
void GPU_framebuffer_restore()
unsigned int uint
Definition BKE_text.h:55
void GPU_framebuffer_py_reference_set(gpu::FrameBuffer *fb, void **py_ref)
const char * GPU_framebuffer_get_name(gpu::FrameBuffer *fb)
void GPU_clear_color(float red, float green, float blue, float alpha)
bool GPU_framebuffer_check_valid(gpu::FrameBuffer *fb, char err_out[256])
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)
int2 GPU_framebuffer_extent_get(gpu::FrameBuffer *fb)
Get the extent of the framebuffer.
void GPU_framebuffer_clear_depth_stencil(gpu::FrameBuffer *fb, float clear_depth, uint clear_stencil)
@ GPU_LOADACTION_DONT_CARE
VecBase< uint32_t, 4 > uint4
void GPU_clear_depth(float depth)
void GPU_framebuffer_push(gpu::FrameBuffer *fb)
void GPU_framebuffer_clear_color(gpu::FrameBuffer *fb, const double4 clear_col)
MINLINE int max_ii(int a, int b)
int GPU_offscreen_width(const GPUOffScreen *offscreen)
@ GPU_STOREACTION_DONT_CARE
gpu::FrameBuffer * GPU_framebuffer_pop()
Global G
Definition blender.cc:57
void GPU_offscreen_read_color_region(GPUOffScreen *offscreen, eGPUDataFormat data_format, int x, int y, int w, int h, void *r_data)
static struct blender::@167202142027231356234036257172206236002000331140 FrameBufferStack
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
VecBase< int32_t, 2 > int2
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 GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
@ GPU_TEXTURE_USAGE_FORMAT_VIEW
@ GPU_TEXTURE_USAGE_ATTACHMENT
static gpu::FrameBuffer * gpu_offscreen_fb_get(GPUOffScreen *ofs)
BMesh const char void * data
void GPU_offscreen_viewport_data_get(GPUOffScreen *offscreen, gpu::FrameBuffer **r_fb, gpu::Texture **r_color, gpu::Texture **r_depth)
gpu::FrameBuffer * GPU_framebuffer_back_get()
void GPU_offscreen_draw_to_screen(GPUOffScreen *offscreen, int x, int y)
int GPU_texture_width(const gpu::Texture *texture)
void GPU_framebuffer_viewport_reset(gpu::FrameBuffer *fb)
static constexpr int GPU_MAX_VIEWPORTS
void ** GPU_framebuffer_py_reference_get(gpu::FrameBuffer *fb)
bool GPU_texture_is_cube(const gpu::Texture *texture)
void GPU_framebuffer_config_array(gpu::FrameBuffer *fb, const GPUAttachment *config, int config_len)
void GPU_backbuffer_bind(GPUBackBuffer back_buffer_type)
void GPU_framebuffer_multi_viewports_set(gpu::FrameBuffer *gpu_fb, const int viewport_rects[GPU_MAX_VIEWPORTS][4])
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
void GPU_framebuffer_bind_no_srgb(gpu::FrameBuffer *fb)
void GPU_frontbuffer_read_color(int x, int y, int width, int height, int channels, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_blit(gpu::FrameBuffer *fb_read, int read_slot, gpu::FrameBuffer *fb_write, int write_slot, GPUFrameBufferBits blit_buffers)
bool GPU_texture_is_array(const gpu::Texture *texture)
gpu::FrameBuffer * GPU_framebuffer_create(const char *name)
void GPU_framebuffer_clear_depth(gpu::FrameBuffer *fb, float clear_depth)
void GPU_framebuffer_multi_clear(gpu::FrameBuffer *fb, Span< double4 > clear_colors)
void GPU_framebuffer_bind_loadstore(gpu::FrameBuffer *fb, const GPULoadStore *load_store_actions, uint load_store_actions_len)
uint GPU_framebuffer_stack_level_get()
void GPU_framebuffer_default_size(gpu::FrameBuffer *fb, int width, int height)
void GPU_framebuffer_texture_cubeface_attach(gpu::FrameBuffer *fb, gpu::Texture *texture, int slot, int face, int mip)
void GPU_framebuffer_texture_attach(gpu::FrameBuffer *fb, gpu::Texture *texture, int slot, int mip)
gpu::Texture * GPU_offscreen_color_texture(const GPUOffScreen *offscreen)
int GPU_texture_height(const gpu::Texture *texture)
void GPU_texture_free(gpu::Texture *texture)
gpu::TextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen)
static CLG_LogRef LOG
Definition logging.cpp:12
static void check_clear_color(const Texture *tex, double4 clear_value, int attachment)
void GPU_framebuffer_viewport_get(gpu::FrameBuffer *fb, int r_viewport[4])
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, gpu::TextureFormat format, eGPUTextureUsage usage, bool clear, char err_out[256])
void GPU_framebuffer_subpass_transition_array(gpu::FrameBuffer *fb, const GPUAttachmentState *attachment_states, uint attachment_len)
void GPU_framebuffer_read_depth(gpu::FrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
bool GPU_framebuffer_bound(gpu::FrameBuffer *fb)
void GPU_framebuffer_clear_color_depth(gpu::FrameBuffer *fb, const double4 clear_col, float clear_depth)
static void gpu_framebuffer_texture_attach_ex(gpu::FrameBuffer *gpu_fb, GPUAttachment attachment, int slot)
bool GPU_texture_has_stencil_format(const gpu::Texture *texture)
void GPU_framebuffer_clear_stencil(gpu::FrameBuffer *fb, uint clear_stencil)
VecBase< double, 4 > double4
void GPU_framebuffer_clear_color_depth_stencil(gpu::FrameBuffer *fb, const double4 clear_col, float clear_depth, uint clear_stencil)
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_framebuffer_texture_detach(gpu::FrameBuffer *fb, gpu::Texture *texture)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)
static constexpr int MAX_CTX_FB_LEN
struct blender::GPUOffScreen::@354056027274073302007354150117055316026025046135 framebuffers[MAX_CTX_FB_LEN]
gpu::FrameBuffer * framebuffers[FRAMEBUFFER_STACK_DEPTH]