49 attachment.tex =
nullptr;
51 attachment.layer = -1;
58 if (attachment.tex !=
nullptr) {
59 reinterpret_cast<Texture *
>(attachment.tex)->detach_from(
this);
63#ifndef GPU_NO_USE_PY_REFERENCES
78 if (new_attachment.
mip == -1) {
84 "GPUFramebuffer: Error: Trying to attach texture to type %d but maximum slot is %d.\n",
90 if (new_attachment.
tex) {
91 if (new_attachment.
layer > 0) {
107 if (attachment.
tex == new_attachment.
tex && attachment.
layer == new_attachment.
layer &&
108 attachment.
mip == new_attachment.
mip)
114 if (attachment.
tex) {
115 reinterpret_cast<Texture *
>(attachment.
tex)->detach_from(
this);
119 if (new_attachment.
tex) {
120 reinterpret_cast<Texture *
>(new_attachment.
tex)->attach_to(
this, type);
126 attachment = new_attachment;
170 const GPULoadStore &depth_action = load_store_actions[0];
208 if (tex !=
nullptr) {
240 return fb->name_get();
247 const bool enable_srgb =
true;
249 fb->set_use_explicit_loadstore(
false);
250 fb->bind(enable_srgb);
257 const bool enable_srgb =
true;
259 fb->set_use_explicit_loadstore(
true);
260 fb->bind(enable_srgb);
263 fb->load_store_config_array(load_store_actions, actions_len);
270 fb->subpass_transition(attachment_states[0],
276 const bool enable_srgb =
false;
277 fb->bind(enable_srgb);
318 return gpu_fb->
check(err_out);
362 if (depth_attachment.
mip == -1) {
365 else if (depth_attachment.
tex ==
nullptr) {
374 fb->attachment_set(type, depth_attachment);
379 fb->attachment_set(type, attachment);
398 int viewport_rect[4] = {
x,
y, width, height};
429 "Lossy conversion when clearing integer attachment %d: "
430 "(%f, %f, %f, %f) > (%d, %d, %d, %d)",
440 "Lossy conversion when clearing unsigned integer attachment %d: "
441 "(%f, %f, %f, %f) > (%u, %u, %u, %u)",
456 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
457 "state via GPU_framebuffer_bind_ex is invalid.");
462 if (tex !=
nullptr) {
468 gpu_fb->
clear(buffers, clear_col, clear_depth, clear_stencil);
513 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
514 "state via GPU_framebuffer_bind_ex is invalid.");
519 if (tex !=
nullptr) {
525 fb->clear_multi(clear_colors);
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};
540 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
541 "state via GPU_framebuffer_bind_ex is invalid.");
548 int rect[4] = {
x,
y,
w, h};
562 int rect[4] = {
x,
y,
w, h};
569 int rect[4] = {
x,
y,
w, h};
591 read_tex = fb_read->
color_tex(read_slot);
592 write_tex = fb_write->
color_tex(write_slot);
599 TextureFormat::SFLOAT_32_DEPTH,
600 TextureFormat::SFLOAT_32_DEPTH_UINT_8) &&
602 TextureFormat::SFLOAT_32_DEPTH,
603 TextureFormat::SFLOAT_32_DEPTH_UINT_8)));
612 fb_read->
blit_to(blit_buffers, read_slot, fb_write, write_slot, 0, 0);
618#ifndef GPU_NO_USE_PY_REFERENCES
639#define FRAMEBUFFER_STACK_DEPTH 16
665#undef FRAMEBUFFER_STACK_DEPTH
697 if (framebuffer.fb ==
nullptr) {
698 framebuffer.ctx = ctx;
701 GPU_ATTACHMENT_TEXTURE(ofs->depth),
702 GPU_ATTACHMENT_TEXTURE(ofs->color),
706 if (framebuffer.ctx == ctx) {
707 return framebuffer.fb;
718 "Warning: GPUOffscreen used in more than 3 GPUContext. "
719 "This may create performance drop.\n");
723 framebuffer.fb =
nullptr;
731 bool with_depth_buffer,
741 height =
max_ii(1, height);
749 if (with_depth_buffer) {
756 gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8,
761 if ((with_depth_buffer && !ofs->
depth) || !ofs->
color) {
762 const char error[] =
"gpu::Texture: Texture allocation failed.";
767 fprintf(stderr,
"%s", error);
783 if (with_depth_buffer) {
798 if (framebuffer.fb) {
802 if (offscreen->
color) {
805 if (offscreen->
depth) {
809 MEM_delete(offscreen);
877 return offscreen->
color;
891 *r_color = offscreen->
color;
892 *r_depth = offscreen->
depth;
#define CLOG_WARN(clg_ref,...)
#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 BLI_assert_msg(a, msg)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
constexpr IndexRange()=default
constexpr int64_t size() const
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
uint get_bits_per_pixel()
void viewport_set(const int viewport[4])
void set_color_attachment_bit(GPUAttachmentType type, bool value)
virtual void bind(bool enabled_srgb)=0
char name_[DEBUG_NAME_LEN]
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
bool get_use_explicit_loadstore() const
gpu::Texture * depth_tex() const
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
int to_bytesize(const DataFormat format)
int to_component_len(TextureFormat format)
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()
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()
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
@ GPU_FB_DEPTH_STENCIL_ATTACHMENT
@ GPU_FB_DEPTH_ATTACHMENT
@ GPU_FB_COLOR_ATTACHMENT0
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 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]