Blender V4.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
25#pragma once
26
27#include "GPU_common_types.hh"
28#include "GPU_texture.hh"
29
30struct GPUTexture;
31
33 GPU_COLOR_BIT = (1 << 0),
34 GPU_DEPTH_BIT = (1 << 1),
35 GPU_STENCIL_BIT = (1 << 2),
36};
37
39
40/* Guaranteed by the spec and is never greater than 16 on any hardware or implementation. */
41#define GPU_MAX_VIEWPORTS 16
42
44 GPUTexture *tex;
45 int layer, mip;
46};
47
49struct GPUFrameBuffer;
50
51/* -------------------------------------------------------------------- */
59GPUFrameBuffer *GPU_framebuffer_create(const char *name);
60
65GPUFrameBuffer *GPU_framebuffer_active_get();
66
71GPUFrameBuffer *GPU_framebuffer_back_get();
72
75/* -------------------------------------------------------------------- */
83void GPU_framebuffer_free(GPUFrameBuffer *framebuffer);
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
95/* -------------------------------------------------------------------- */
105
110void GPU_backbuffer_bind(eGPUBackBuffer back_buffer_type);
111
115void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer);
116
120void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *framebuffer);
121
127
130/* -------------------------------------------------------------------- */
139
140/* Empty bind point. */
141#define NULL_ATTACHMENT_COLOR \
142 { \
143 0.0, 0.0, 0.0, 0.0 \
144 }
145#define NULL_LOAD_STORE \
146 { \
147 GPU_LOADACTION_DONT_CARE, GPU_STOREACTION_DONT_CARE, NULL_ATTACHMENT_COLOR \
148 }
149
177void GPU_framebuffer_bind_loadstore(GPUFrameBuffer *framebuffer,
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(GPUFrameBuffer *framebuffer,
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
220/* -------------------------------------------------------------------- */
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(GPUFrameBuffer *framebuffer,
259 const GPUAttachment *config,
260 int config_len);
261
263#define GPU_ATTACHMENT_NONE \
264 { \
265 nullptr, -1, 0, \
266 }
268#define GPU_ATTACHMENT_LEAVE \
269 { \
270 nullptr, -1, -1, \
271 }
273#define GPU_ATTACHMENT_TEXTURE(_texture) \
274 { \
275 _texture, -1, 0, \
276 }
278#define GPU_ATTACHMENT_TEXTURE_MIP(_texture, _mip) \
279 { \
280 _texture, -1, _mip, \
281 }
283#define GPU_ATTACHMENT_TEXTURE_LAYER(_texture, _layer) \
284 { \
285 _texture, _layer, 0, \
286 }
288#define GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_texture, _layer, _mip) \
289 { \
290 _texture, _layer, _mip, \
291 }
292
296#define GPU_ATTACHMENT_TEXTURE_CUBEFACE(_texture, _face) \
297 { \
298 _texture, _face, 0, \
299 }
301#define GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_texture, _face, _mip) \
302 { \
303 _texture, _face, _mip, \
304 }
305
314void GPU_framebuffer_texture_attach(GPUFrameBuffer *framebuffer,
315 GPUTexture *texture,
316 int slot,
317 int mip);
318
329 GPUFrameBuffer *framebuffer, GPUTexture *texture, int slot, int layer, int mip);
330
341 GPUFrameBuffer *framebuffer, GPUTexture *texture, int slot, int face, int mip);
342
349void GPU_framebuffer_texture_detach(GPUFrameBuffer *framebuffer, GPUTexture *texture);
350
358bool GPU_framebuffer_check_valid(GPUFrameBuffer *framebuffer, char err_out[256]);
359
362/* -------------------------------------------------------------------- */
374void GPU_framebuffer_default_size(GPUFrameBuffer *framebuffer, int width, int height);
375
378/* -------------------------------------------------------------------- */
392 GPUFrameBuffer *framebuffer, int x, int y, int width, int height);
393
402void GPU_framebuffer_multi_viewports_set(GPUFrameBuffer *gpu_fb,
403 const int viewport_rects[GPU_MAX_VIEWPORTS][4]);
404
409void GPU_framebuffer_viewport_get(GPUFrameBuffer *framebuffer, int r_viewport[4]);
410
415void GPU_framebuffer_viewport_reset(GPUFrameBuffer *framebuffer);
416
419/* -------------------------------------------------------------------- */
435void GPU_framebuffer_clear(GPUFrameBuffer *framebuffer,
437 const float clear_col[4],
438 float clear_depth,
439 unsigned int clear_stencil);
440
446void GPU_framebuffer_clear_color(GPUFrameBuffer *fb, const float clear_col[4]);
447
453void GPU_framebuffer_clear_depth(GPUFrameBuffer *fb, float clear_depth);
454
460void GPU_framebuffer_clear_stencil(GPUFrameBuffer *fb, uint clear_stencil);
461
468void GPU_framebuffer_clear_color_depth(GPUFrameBuffer *fb,
469 const float clear_col[4],
470 float clear_depth);
471
478void GPU_framebuffer_clear_depth_stencil(GPUFrameBuffer *fb,
479 float clear_depth,
480 uint clear_stencil);
488 const float clear_col[4],
489 float clear_depth,
490 uint clear_stencil);
491
498void GPU_framebuffer_multi_clear(GPUFrameBuffer *framebuffer, const float (*clear_colors)[4]);
499
507void GPU_clear_color(float red, float green, float blue, float alpha);
508
515void GPU_clear_depth(float depth);
516
519/* -------------------------------------------------------------------- */
523const char *GPU_framebuffer_get_name(GPUFrameBuffer *framebuffer);
524
527/* -------------------------------------------------------------------- */
538#ifndef GPU_NO_USE_PY_REFERENCES
539void **GPU_framebuffer_py_reference_get(GPUFrameBuffer *framebuffer);
540void GPU_framebuffer_py_reference_set(GPUFrameBuffer *framebuffer, void **py_ref);
541#endif
542
548/* TODO(fclem): This has nothing to do with the GPU module and should be move to the pyGPU module.
549 */
550void GPU_framebuffer_push(GPUFrameBuffer *framebuffer);
551GPUFrameBuffer *GPU_framebuffer_pop();
553
556/* -------------------------------------------------------------------- */
565bool GPU_framebuffer_bound(GPUFrameBuffer *framebuffer);
566
572void GPU_framebuffer_read_depth(GPUFrameBuffer *framebuffer,
573 int x,
574 int y,
575 int width,
576 int height,
577 eGPUDataFormat data_format,
578 void *r_data);
579
585void GPU_framebuffer_read_color(GPUFrameBuffer *framebuffer,
586 int x,
587 int y,
588 int width,
589 int height,
590 int channels,
591 int slot,
592 eGPUDataFormat data_format,
593 void *r_data);
594
603 int x, int y, int width, int height, int channels, eGPUDataFormat data_format, void *r_data);
604
613void GPU_framebuffer_blit(GPUFrameBuffer *fb_read,
614 int read_slot,
615 GPUFrameBuffer *fb_write,
616 int write_slot,
617 eGPUFrameBufferBits blit_buffers);
618
628void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *framebuffer,
629 int max_level,
630 void (*per_level_callback)(void *user_data, int level),
631 void *user_data);
632
635/* -------------------------------------------------------------------- */
643struct GPUOffScreen;
644
654 int height,
655 bool with_depth_buffer,
657 eGPUTextureUsage usage,
658 char err_out[256]);
659
663void GPU_offscreen_free(GPUOffScreen *offscreen);
664
669/* TODO(fclem): Remove the `save` parameter and always save/restore. */
670void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save);
671
677/* TODO(fclem): Remove the `save` parameter and always save/restore. */
678void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore);
679
686void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data);
691 GPUOffScreen *offscreen, eGPUDataFormat data_format, int x, int y, int w, int h, void *r_data);
692
696void GPU_offscreen_draw_to_screen(GPUOffScreen *offscreen, int x, int y);
697
701int GPU_offscreen_width(const GPUOffScreen *offscreen);
702
706int GPU_offscreen_height(const GPUOffScreen *offscreen);
707
712GPUTexture *GPU_offscreen_color_texture(const GPUOffScreen *offscreen);
713
718
724 GPUFrameBuffer **r_fb,
725 GPUTexture **r_color,
726 GPUTexture **r_depth);
727
unsigned int uint
#define ENUM_OPERATORS(_type, _max)
eGPUStoreOp
GPUAttachmentState
void GPU_framebuffer_multi_viewports_set(GPUFrameBuffer *gpu_fb, const int viewport_rects[GPU_MAX_VIEWPORTS][4])
bool GPU_framebuffer_check_valid(GPUFrameBuffer *framebuffer, char err_out[256])
void GPU_offscreen_draw_to_screen(GPUOffScreen *offscreen, int x, int y)
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, eGPUTextureFormat format, eGPUTextureUsage usage, char err_out[256])
GPUFrameBuffer * GPU_framebuffer_create(const char *name)
const char * GPU_framebuffer_get_name(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_push(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_default_size(GPUFrameBuffer *framebuffer, int width, int height)
void GPU_framebuffer_config_array(GPUFrameBuffer *framebuffer, const GPUAttachment *config, int config_len)
GPUFrameBuffer * GPU_framebuffer_active_get()
int GPU_offscreen_width(const GPUOffScreen *offscreen)
void GPU_framebuffer_viewport_get(GPUFrameBuffer *framebuffer, int r_viewport[4])
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
void GPU_offscreen_viewport_data_get(GPUOffScreen *offscreen, GPUFrameBuffer **r_fb, GPUTexture **r_color, GPUTexture **r_depth)
void GPU_framebuffer_texture_detach(GPUFrameBuffer *framebuffer, GPUTexture *texture)
void GPU_framebuffer_clear_color_depth_stencil(GPUFrameBuffer *fb, const float clear_col[4], float clear_depth, uint clear_stencil)
void GPU_framebuffer_texture_cubeface_attach(GPUFrameBuffer *framebuffer, GPUTexture *texture, int slot, int face, int mip)
void GPU_framebuffer_restore()
eGPUFrameBufferBits
@ GPU_DEPTH_BIT
@ GPU_STENCIL_BIT
@ GPU_COLOR_BIT
void GPU_framebuffer_clear_stencil(GPUFrameBuffer *fb, uint clear_stencil)
bool GPU_framebuffer_bound(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_clear_depth_stencil(GPUFrameBuffer *fb, float clear_depth, uint clear_stencil)
void GPU_framebuffer_py_reference_set(GPUFrameBuffer *framebuffer, void **py_ref)
void ** GPU_framebuffer_py_reference_get(GPUFrameBuffer *framebuffer)
void GPU_frontbuffer_read_color(int x, int y, int width, int height, int channels, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_read_depth(GPUFrameBuffer *framebuffer, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_viewport_reset(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_clear_color_depth(GPUFrameBuffer *fb, const float clear_col[4], float clear_depth)
uint GPU_framebuffer_stack_level_get()
void GPU_framebuffer_texture_layer_attach(GPUFrameBuffer *framebuffer, GPUTexture *texture, int slot, int layer, int mip)
int GPU_offscreen_height(const GPUOffScreen *offscreen)
void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *framebuffer, int max_level, void(*per_level_callback)(void *user_data, int level), void *user_data)
void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *framebuffer)
eGPUBackBuffer
@ GPU_BACKBUFFER_LEFT
@ GPU_BACKBUFFER_RIGHT
void GPU_framebuffer_clear(GPUFrameBuffer *framebuffer, eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, unsigned int clear_stencil)
GPUTexture * GPU_offscreen_color_texture(const GPUOffScreen *offscreen)
void GPU_clear_color(float red, float green, float blue, float alpha)
void GPU_framebuffer_multi_clear(GPUFrameBuffer *framebuffer, const float(*clear_colors)[4])
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_framebuffer_bind(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_subpass_transition_array(GPUFrameBuffer *framebuffer, const GPUAttachmentState *attachment_states, uint attachment_len)
void GPU_backbuffer_bind(eGPUBackBuffer back_buffer_type)
eGPUTextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen)
void GPU_clear_depth(float depth)
void GPU_framebuffer_read_color(GPUFrameBuffer *framebuffer, int x, int y, int width, int height, int channels, int slot, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_clear_color(GPUFrameBuffer *fb, const float clear_col[4])
void GPU_framebuffer_viewport_set(GPUFrameBuffer *framebuffer, int x, int y, int width, int height)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)
GPUFrameBuffer * GPU_framebuffer_pop()
#define GPU_MAX_VIEWPORTS
void GPU_framebuffer_clear_depth(GPUFrameBuffer *fb, float clear_depth)
void GPU_framebuffer_free(GPUFrameBuffer *framebuffer)
GPUFrameBuffer * GPU_framebuffer_back_get()
void GPU_framebuffer_texture_attach(GPUFrameBuffer *framebuffer, GPUTexture *texture, int slot, int mip)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
void GPU_framebuffer_blit(GPUFrameBuffer *fb_read, int read_slot, GPUFrameBuffer *fb_write, int write_slot, eGPUFrameBufferBits blit_buffers)
void GPU_framebuffer_bind_loadstore(GPUFrameBuffer *framebuffer, const GPULoadStore *load_store_actions, uint load_store_actions_len)
eGPUDataFormat
eGPUTextureUsage
eGPUTextureFormat
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its red
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
BLI_INLINE float fb(float length, float L)
format
GPUTexture * tex
eGPULoadOp load_action
eGPUStoreOp store_action
char * buffers[2]