Blender V5.0
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
30namespace blender::gpu {
31class Texture;
32class FrameBuffer;
33} // namespace blender::gpu
34
36 GPU_COLOR_BIT = (1 << 0),
37 GPU_DEPTH_BIT = (1 << 1),
38 GPU_STENCIL_BIT = (1 << 2),
39};
40
42
43/* Guaranteed by the spec and is never greater than 16 on any hardware or implementation. */
44constexpr static int GPU_MAX_VIEWPORTS = 16;
45
50
51/* -------------------------------------------------------------------- */
54
60
66
72
74
75/* -------------------------------------------------------------------- */
78
84
85#define GPU_FRAMEBUFFER_FREE_SAFE(fb) \
86 do { \
87 if (fb != nullptr) { \
88 GPU_framebuffer_free(fb); \
89 fb = nullptr; \
90 } \
91 } while (0)
92
94
95/* -------------------------------------------------------------------- */
98
105
110void GPU_backbuffer_bind(GPUBackBuffer back_buffer_type);
111
116
121
127
129
130/* -------------------------------------------------------------------- */
133
139
140/* Empty bind point. */
141#define NULL_ATTACHMENT_COLOR {0.0, 0.0, 0.0, 0.0}
142#define NULL_LOAD_STORE \
143 {GPU_LOADACTION_DONT_CARE, GPU_STOREACTION_DONT_CARE, NULL_ATTACHMENT_COLOR}
144
173 const GPULoadStore *load_store_actions,
174 uint load_store_actions_len);
175#define GPU_framebuffer_bind_ex(_fb, ...) \
176 { \
177 GPULoadStore actions[] = __VA_ARGS__; \
178 GPU_framebuffer_bind_loadstore(_fb, actions, (sizeof(actions) / sizeof(GPULoadStore))); \
179 }
180
203 const GPUAttachmentState *attachment_states,
204 uint attachment_len);
205
206#define GPU_framebuffer_subpass_transition(_fb, ...) \
207 { \
208 GPUAttachmentState actions[] = __VA_ARGS__; \
209 GPU_framebuffer_subpass_transition_array( \
210 _fb, actions, (sizeof(actions) / sizeof(GPUAttachmentState))); \
211 }
212
214
215/* -------------------------------------------------------------------- */
218
238#define GPU_framebuffer_ensure_config(_fb, ...) \
239 do { \
240 if (*(_fb) == nullptr) { \
241 *(_fb) = GPU_framebuffer_create(#_fb); \
242 } \
243 GPUAttachment config[] = __VA_ARGS__; \
244 GPU_framebuffer_config_array(*(_fb), config, (sizeof(config) / sizeof(GPUAttachment))); \
245 } while (0)
246
254 const GPUAttachment *config,
255 int config_len);
256
258#define GPU_ATTACHMENT_NONE \
259 { \
260 nullptr, \
261 -1, \
262 0, \
263 }
264
265#define GPU_ATTACHMENT_LEAVE \
266 { \
267 nullptr, \
268 -1, \
269 -1, \
270 }
271
272#define GPU_ATTACHMENT_TEXTURE(_texture) \
273 { \
274 _texture, \
275 -1, \
276 0, \
277 }
278
279#define GPU_ATTACHMENT_TEXTURE_MIP(_texture, _mip) \
280 { \
281 _texture, \
282 -1, \
283 _mip, \
284 }
285
286#define GPU_ATTACHMENT_TEXTURE_LAYER(_texture, _layer) \
287 { \
288 _texture, \
289 _layer, \
290 0, \
291 }
292
293#define GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_texture, _layer, _mip) \
294 { \
295 _texture, \
296 _layer, \
297 _mip, \
298 }
299
301
303#define GPU_ATTACHMENT_TEXTURE_CUBEFACE(_texture, _face) \
304 { \
305 _texture, \
306 _face, \
307 0, \
308 }
309
310#define GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_texture, _face, _mip) \
311 { \
312 _texture, \
313 _face, \
314 _mip, \
315 }
316
327 int slot,
328 int mip);
329
340 blender::gpu::FrameBuffer *fb, blender::gpu::Texture *texture, int slot, int layer, int mip);
341
352 blender::gpu::FrameBuffer *fb, blender::gpu::Texture *texture, int slot, int face, int mip);
353
361
370
372
373/* -------------------------------------------------------------------- */
380
385void GPU_framebuffer_default_size(blender::gpu::FrameBuffer *fb, int width, int height);
386
388
389/* -------------------------------------------------------------------- */
392
403 blender::gpu::FrameBuffer *fb, int x, int y, int width, int height);
404
414 const int viewport_rects[GPU_MAX_VIEWPORTS][4]);
415
421
427
429
430/* -------------------------------------------------------------------- */
433
448 const float clear_col[4],
449 float clear_depth,
450 unsigned int clear_stencil);
451
457void GPU_framebuffer_clear_color(blender::gpu::FrameBuffer *fb, const float clear_col[4]);
458
465
472
480 const float clear_col[4],
481 float clear_depth);
482
490 float clear_depth,
491 uint clear_stencil);
499 const float clear_col[4],
500 float clear_depth,
501 uint clear_stencil);
502
509void GPU_framebuffer_multi_clear(blender::gpu::FrameBuffer *fb, const float (*clear_colors)[4]);
510
518void GPU_clear_color(float red, float green, float blue, float alpha);
519
526void GPU_clear_depth(float depth);
527
529
530/* -------------------------------------------------------------------- */
533
535
537
538/* -------------------------------------------------------------------- */
544
549#ifndef GPU_NO_USE_PY_REFERENCES
552#endif
553
559/* TODO(fclem): This has nothing to do with the GPU module and should be move to the pyGPU module.
560 */
564
566
567/* -------------------------------------------------------------------- */
570
577
584 int x,
585 int y,
586 int width,
587 int height,
588 eGPUDataFormat data_format,
589 void *r_data);
590
597 int x,
598 int y,
599 int width,
600 int height,
601 int channels,
602 int slot,
603 eGPUDataFormat data_format,
604 void *r_data);
605
614 int x, int y, int width, int height, int channels, eGPUDataFormat data_format, void *r_data);
615
625 int read_slot,
627 int write_slot,
628 GPUFrameBufferBits blit_buffers);
629
631
632/* -------------------------------------------------------------------- */
639
640struct GPUOffScreen;
641
652 int height,
653 bool with_depth_buffer,
655 eGPUTextureUsage usage,
656 bool clear,
657 char err_out[256]);
658
662void GPU_offscreen_free(GPUOffScreen *offscreen);
663
668/* TODO(fclem): Remove the `save` parameter and always save/restore. */
669void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save);
670
676/* TODO(fclem): Remove the `save` parameter and always save/restore. */
677void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore);
678
685void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data);
690 GPUOffScreen *offscreen, eGPUDataFormat data_format, int x, int y, int w, int h, void *r_data);
691
695void GPU_offscreen_draw_to_screen(GPUOffScreen *offscreen, int x, int y);
696
700int GPU_offscreen_width(const GPUOffScreen *offscreen);
701
705int GPU_offscreen_height(const GPUOffScreen *offscreen);
706
712
717
724 blender::gpu::Texture **r_color,
725 blender::gpu::Texture **r_depth);
726
unsigned int uint
#define ENUM_OPERATORS(_type, _max)
GPUAttachmentState
blender::gpu::FrameBuffer * GPU_framebuffer_create(const char *name)
void GPU_framebuffer_subpass_transition_array(blender::gpu::FrameBuffer *fb, const GPUAttachmentState *attachment_states, uint attachment_len)
blender::gpu::Texture * GPU_offscreen_color_texture(const GPUOffScreen *offscreen)
void GPU_framebuffer_default_size(blender::gpu::FrameBuffer *fb, int width, int height)
void GPU_framebuffer_texture_detach(blender::gpu::FrameBuffer *fb, blender::gpu::Texture *texture)
void GPU_offscreen_draw_to_screen(GPUOffScreen *offscreen, int x, int y)
GPUFrameBufferBits
@ GPU_DEPTH_BIT
@ GPU_STENCIL_BIT
@ GPU_COLOR_BIT
void GPU_framebuffer_viewport_reset(blender::gpu::FrameBuffer *fb)
void GPU_framebuffer_clear_stencil(blender::gpu::FrameBuffer *fb, uint clear_stencil)
int GPU_offscreen_width(const GPUOffScreen *offscreen)
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
void GPU_framebuffer_restore()
GPUBackBuffer
@ GPU_BACKBUFFER_LEFT
@ GPU_BACKBUFFER_RIGHT
void GPU_backbuffer_bind(GPUBackBuffer back_buffer_type)
void GPU_framebuffer_bind_loadstore(blender::gpu::FrameBuffer *fb, const GPULoadStore *load_store_actions, uint load_store_actions_len)
void GPU_framebuffer_clear_depth_stencil(blender::gpu::FrameBuffer *fb, float clear_depth, uint clear_stencil)
blender::gpu::FrameBuffer * GPU_framebuffer_back_get()
void GPU_framebuffer_read_color(blender::gpu::FrameBuffer *fb, int x, int y, int width, int height, int channels, int slot, eGPUDataFormat data_format, void *r_data)
blender::gpu::TextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen)
void GPU_framebuffer_multi_clear(blender::gpu::FrameBuffer *fb, const float(*clear_colors)[4])
static constexpr int GPU_MAX_VIEWPORTS
void ** GPU_framebuffer_py_reference_get(blender::gpu::FrameBuffer *fb)
void GPU_framebuffer_py_reference_set(blender::gpu::FrameBuffer *fb, void **py_ref)
void GPU_frontbuffer_read_color(int x, int y, int width, int height, int channels, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_free(blender::gpu::FrameBuffer *fb)
uint GPU_framebuffer_stack_level_get()
void GPU_framebuffer_texture_layer_attach(blender::gpu::FrameBuffer *fb, blender::gpu::Texture *texture, int slot, int layer, int mip)
void GPU_framebuffer_texture_attach(blender::gpu::FrameBuffer *fb, blender::gpu::Texture *texture, int slot, int mip)
void GPU_framebuffer_viewport_set(blender::gpu::FrameBuffer *fb, int x, int y, int width, int height)
int GPU_offscreen_height(const GPUOffScreen *offscreen)
blender::gpu::FrameBuffer * GPU_framebuffer_pop()
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, blender::gpu::TextureFormat format, eGPUTextureUsage usage, bool clear, char err_out[256])
void GPU_clear_color(float red, float green, float blue, float alpha)
bool GPU_framebuffer_check_valid(blender::gpu::FrameBuffer *fb, char err_out[256])
void GPU_framebuffer_blit(blender::gpu::FrameBuffer *fb_read, int read_slot, blender::gpu::FrameBuffer *fb_write, int write_slot, GPUFrameBufferBits blit_buffers)
void GPU_offscreen_read_color_region(GPUOffScreen *offscreen, eGPUDataFormat data_format, int x, int y, int w, int h, void *r_data)
void GPU_offscreen_free(GPUOffScreen *offscreen)
void GPU_offscreen_viewport_data_get(GPUOffScreen *offscreen, blender::gpu::FrameBuffer **r_fb, blender::gpu::Texture **r_color, blender::gpu::Texture **r_depth)
const char * GPU_framebuffer_get_name(blender::gpu::FrameBuffer *fb)
void GPU_framebuffer_bind_no_srgb(blender::gpu::FrameBuffer *fb)
void GPU_framebuffer_clear_depth(blender::gpu::FrameBuffer *fb, float clear_depth)
void GPU_framebuffer_clear_color_depth_stencil(blender::gpu::FrameBuffer *fb, const float clear_col[4], float clear_depth, uint clear_stencil)
void GPU_clear_depth(float depth)
bool GPU_framebuffer_bound(blender::gpu::FrameBuffer *fb)
void GPU_framebuffer_clear_color(blender::gpu::FrameBuffer *fb, const float clear_col[4])
void GPU_framebuffer_read_depth(blender::gpu::FrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_push(blender::gpu::FrameBuffer *fb)
void GPU_framebuffer_config_array(blender::gpu::FrameBuffer *fb, const GPUAttachment *config, int config_len)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_multi_viewports_set(blender::gpu::FrameBuffer *gpu_fb, const int viewport_rects[GPU_MAX_VIEWPORTS][4])
void GPU_framebuffer_texture_cubeface_attach(blender::gpu::FrameBuffer *fb, blender::gpu::Texture *texture, int slot, int face, int mip)
void GPU_framebuffer_clear_color_depth(blender::gpu::FrameBuffer *fb, const float clear_col[4], float clear_depth)
void GPU_framebuffer_clear(blender::gpu::FrameBuffer *fb, GPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, unsigned int clear_stencil)
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
void GPU_framebuffer_viewport_get(blender::gpu::FrameBuffer *fb, int r_viewport[4])
blender::gpu::FrameBuffer * GPU_framebuffer_active_get()
eGPUDataFormat
eGPUTextureUsage
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
BLI_INLINE float fb(float length, float L)
format
static void clear(Message &msg)
Definition msgfmt.cc:213
const char * name
blender::gpu::Texture * tex
GPUStoreOp store_action
GPULoadOp load_action
char * buffers[2]