Blender V5.3
GPU_framebuffer.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
24
25#pragma once
26
27#include "GPU_common_types.hh"
28#include "GPU_texture.hh"
29
30#include "BLI_enum_flags.hh"
32
33namespace blender {
34
35namespace gpu {
36class Texture;
37class FrameBuffer;
38} // namespace gpu
39
41 GPU_COLOR_BIT = (1 << 0),
42 GPU_DEPTH_BIT = (1 << 1),
43 GPU_STENCIL_BIT = (1 << 2),
44};
45
47
48/* Guaranteed by the spec and is never greater than 16 on any hardware or implementation. */
49constexpr static int GPU_MAX_VIEWPORTS = 16;
50
55
56/* -------------------------------------------------------------------- */
59
65
71
77
79
80/* -------------------------------------------------------------------- */
83
89
90#define GPU_FRAMEBUFFER_FREE_SAFE(fb) \
91 do { \
92 if (fb != nullptr) { \
93 GPU_framebuffer_free(fb); \
94 fb = nullptr; \
95 } \
96 } while (0)
97
99
100/* -------------------------------------------------------------------- */
103
110
115void GPU_backbuffer_bind(GPUBackBuffer back_buffer_type);
116
120void GPU_framebuffer_bind(gpu::FrameBuffer *fb);
121
125void GPU_framebuffer_bind_no_srgb(gpu::FrameBuffer *fb);
126
132
134
135/* -------------------------------------------------------------------- */
138
144
145/* Empty bind point. */
146#define NULL_ATTACHMENT_COLOR {0.0, 0.0, 0.0, 0.0}
147#define NULL_LOAD_STORE \
148 {GPU_LOADACTION_DONT_CARE, GPU_STOREACTION_DONT_CARE, NULL_ATTACHMENT_COLOR}
149
177void GPU_framebuffer_bind_loadstore(gpu::FrameBuffer *fb,
178 const GPULoadStore *load_store_actions,
179 uint load_store_actions_len);
180#define GPU_framebuffer_bind_ex(_fb, ...) \
181 { \
182 GPULoadStore actions[] = __VA_ARGS__; \
183 GPU_framebuffer_bind_loadstore(_fb, actions, (sizeof(actions) / sizeof(GPULoadStore))); \
184 }
185
207void GPU_framebuffer_subpass_transition_array(gpu::FrameBuffer *fb,
208 const GPUAttachmentState *attachment_states,
209 uint attachment_len);
210
211#define GPU_framebuffer_subpass_transition(_fb, ...) \
212 { \
213 GPUAttachmentState actions[] = __VA_ARGS__; \
214 GPU_framebuffer_subpass_transition_array( \
215 _fb, actions, (sizeof(actions) / sizeof(GPUAttachmentState))); \
216 }
217
219
220/* -------------------------------------------------------------------- */
223
243#define GPU_framebuffer_ensure_config(_fb, ...) \
244 do { \
245 if (*(_fb) == nullptr) { \
246 *(_fb) = GPU_framebuffer_create(#_fb); \
247 } \
248 GPUAttachment config[] = __VA_ARGS__; \
249 GPU_framebuffer_config_array(*(_fb), config, (sizeof(config) / sizeof(GPUAttachment))); \
250 } while (0)
251
258void GPU_framebuffer_config_array(gpu::FrameBuffer *fb,
259 const GPUAttachment *config,
260 int config_len);
261
263#define GPU_ATTACHMENT_NONE \
264 GPUAttachment \
265 { \
266 nullptr, -1, 0, \
267 }
268
269#define GPU_ATTACHMENT_LEAVE \
270 GPUAttachment \
271 { \
272 nullptr, -1, -1, \
273 }
274
275#define GPU_ATTACHMENT_TEXTURE(_texture) \
276 GPUAttachment \
277 { \
278 _texture, -1, 0, \
279 }
280
281#define GPU_ATTACHMENT_TEXTURE_MIP(_texture, _mip) \
282 GPUAttachment \
283 { \
284 _texture, -1, _mip, \
285 }
286
287#define GPU_ATTACHMENT_TEXTURE_LAYER(_texture, _layer) \
288 GPUAttachment \
289 { \
290 _texture, _layer, 0, \
291 }
292
293#define GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_texture, _layer, _mip) \
294 GPUAttachment \
295 { \
296 _texture, _layer, _mip, \
297 }
298
300
302#define GPU_ATTACHMENT_TEXTURE_CUBEFACE(_texture, _face) \
303 GPUAttachment \
304 { \
305 _texture, _face, 0, \
306 }
307
308#define GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_texture, _face, _mip) \
309 GPUAttachment \
310 { \
311 _texture, _face, _mip, \
312 }
313
322void GPU_framebuffer_texture_attach(gpu::FrameBuffer *fb,
323 gpu::Texture *texture,
324 int slot,
325 int mip);
326
337 gpu::FrameBuffer *fb, gpu::Texture *texture, int slot, int layer, int mip);
338
349 gpu::FrameBuffer *fb, gpu::Texture *texture, int slot, int face, int mip);
350
357void GPU_framebuffer_texture_detach(gpu::FrameBuffer *fb, gpu::Texture *texture);
358
366bool GPU_framebuffer_check_valid(gpu::FrameBuffer *fb, char err_out[256]);
367
369
370/* -------------------------------------------------------------------- */
377
382void GPU_framebuffer_default_size(gpu::FrameBuffer *fb, int width, int height);
383
385
386/* -------------------------------------------------------------------- */
389
393int2 GPU_framebuffer_extent_get(gpu::FrameBuffer *fb);
394
404void GPU_framebuffer_viewport_set(gpu::FrameBuffer *fb, int x, int y, int width, int height);
405
414void GPU_framebuffer_multi_viewports_set(gpu::FrameBuffer *gpu_fb,
415 const int viewport_rects[GPU_MAX_VIEWPORTS][4]);
416
421void GPU_framebuffer_viewport_get(gpu::FrameBuffer *fb, int r_viewport[4]);
422
427void GPU_framebuffer_viewport_reset(gpu::FrameBuffer *fb);
428
430
431/* -------------------------------------------------------------------- */
434
447void GPU_framebuffer_clear(gpu::FrameBuffer *fb,
448 GPUFrameBufferBits buffers,
449 const double4 clear_col,
450 float clear_depth,
451 unsigned int clear_stencil);
452
458void GPU_framebuffer_clear_color(gpu::FrameBuffer *fb, const double4 clear_col);
459
465void GPU_framebuffer_clear_depth(gpu::FrameBuffer *fb, float clear_depth);
466
472void GPU_framebuffer_clear_stencil(gpu::FrameBuffer *fb, uint clear_stencil);
473
480void GPU_framebuffer_clear_color_depth(gpu::FrameBuffer *fb,
481 const double4 clear_col,
482 float clear_depth);
483
490void GPU_framebuffer_clear_depth_stencil(gpu::FrameBuffer *fb,
491 float clear_depth,
492 uint clear_stencil);
499void GPU_framebuffer_clear_color_depth_stencil(gpu::FrameBuffer *fb,
500 const double4 clear_col,
501 float clear_depth,
502 uint clear_stencil);
503
510void GPU_framebuffer_multi_clear(gpu::FrameBuffer *fb, Span<double4> clear_colors);
511
519void GPU_clear_color(float red, float green, float blue, float alpha);
520
527void GPU_clear_depth(float depth);
528
530
531/* -------------------------------------------------------------------- */
534
535const char *GPU_framebuffer_get_name(gpu::FrameBuffer *fb);
536
538
539/* -------------------------------------------------------------------- */
545
550#ifndef GPU_NO_USE_PY_REFERENCES
551void **GPU_framebuffer_py_reference_get(gpu::FrameBuffer *fb);
552void GPU_framebuffer_py_reference_set(gpu::FrameBuffer *fb, void **py_ref);
553#endif
554
560/* TODO(fclem): This has nothing to do with the GPU module and should be move to the pyGPU module.
561 */
562void GPU_framebuffer_push(gpu::FrameBuffer *fb);
563gpu::FrameBuffer *GPU_framebuffer_pop();
565
567
568/* -------------------------------------------------------------------- */
571
578bool GPU_framebuffer_bound(gpu::FrameBuffer *fb);
579
585void GPU_framebuffer_read_depth(gpu::FrameBuffer *fb,
586 int x,
587 int y,
588 int width,
589 int height,
590 eGPUDataFormat data_format,
591 void *r_data);
592
598void GPU_framebuffer_read_color(gpu::FrameBuffer *fb,
599 int x,
600 int y,
601 int width,
602 int height,
603 int channels,
604 int slot,
605 eGPUDataFormat data_format,
606 void *r_data);
607
616 int x, int y, int width, int height, int channels, eGPUDataFormat data_format, void *r_data);
617
626void GPU_framebuffer_blit(gpu::FrameBuffer *fb_read,
627 int read_slot,
628 gpu::FrameBuffer *fb_write,
629 int write_slot,
630 GPUFrameBufferBits blit_buffers);
631
633
634/* -------------------------------------------------------------------- */
641
642struct GPUOffScreen;
643
653GPUOffScreen *GPU_offscreen_create(int width,
654 int height,
655 bool with_depth_buffer,
656 gpu::TextureFormat format,
657 eGPUTextureUsage usage,
658 bool clear,
659 char err_out[256]);
660
664void GPU_offscreen_free(GPUOffScreen *offscreen);
665
670/* TODO(fclem): Remove the `save` parameter and always save/restore. */
671void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save);
672
678/* TODO(fclem): Remove the `save` parameter and always save/restore. */
679void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore);
680
687void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data);
692 GPUOffScreen *offscreen, eGPUDataFormat data_format, int x, int y, int w, int h, void *r_data);
693
697void GPU_offscreen_draw_to_screen(GPUOffScreen *offscreen, int x, int y);
698
702int GPU_offscreen_width(const GPUOffScreen *offscreen);
703
707int GPU_offscreen_height(const GPUOffScreen *offscreen);
708
713gpu::Texture *GPU_offscreen_color_texture(const GPUOffScreen *offscreen);
714
718gpu::TextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen);
719
724void GPU_offscreen_viewport_data_get(GPUOffScreen *offscreen,
725 gpu::FrameBuffer **r_fb,
726 gpu::Texture **r_color,
727 gpu::Texture **r_depth);
728
730
731} // namespace blender
#define ENUM_OPERATORS(_enum_type)
static void clear(T &value)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
#define layer
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
BMesh Iterators.
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
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)
void GPU_framebuffer_clear(gpu::FrameBuffer *fb, GPUFrameBufferBits buffers, const double4 clear_col, float clear_depth, unsigned int clear_stencil)
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)
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)
int GPU_offscreen_width(const GPUOffScreen *offscreen)
gpu::FrameBuffer * GPU_framebuffer_pop()
void GPU_offscreen_read_color_region(GPUOffScreen *offscreen, eGPUDataFormat data_format, int x, int y, int w, int h, void *r_data)
int GPU_offscreen_height(const GPUOffScreen *offscreen)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
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)
void GPU_framebuffer_viewport_reset(gpu::FrameBuffer *fb)
static constexpr int GPU_MAX_VIEWPORTS
void ** GPU_framebuffer_py_reference_get(gpu::FrameBuffer *fb)
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)
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)
gpu::TextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen)
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)
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)
void GPU_framebuffer_texture_detach(gpu::FrameBuffer *fb, gpu::Texture *texture)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)