43 attachment.tex =
nullptr;
45 attachment.layer = -1;
52 if (attachment.tex !=
nullptr) {
53 reinterpret_cast<Texture *
>(attachment.tex)->detach_from(
this);
57#ifndef GPU_NO_USE_PY_REFERENCES
72 if (new_attachment.
mip == -1) {
78 "GPUFramebuffer: Error: Trying to attach texture to type %d but maximum slot is %d.\n",
84 if (new_attachment.
tex) {
85 if (new_attachment.
layer > 0) {
101 if (attachment.
tex == new_attachment.
tex && attachment.
layer == new_attachment.
layer &&
102 attachment.
mip == new_attachment.
mip)
108 if (attachment.
tex) {
109 reinterpret_cast<Texture *
>(attachment.
tex)->detach_from(
this);
113 if (new_attachment.
tex) {
114 reinterpret_cast<Texture *
>(new_attachment.
tex)->attach_to(
this, type);
120 attachment = new_attachment;
163 const GPULoadStore &depth_action = load_store_actions[0];
201 if (tex !=
nullptr) {
234 return fb->name_get();
241 const bool enable_srgb =
true;
243 fb->set_use_explicit_loadstore(
false);
244 fb->bind(enable_srgb);
251 const bool enable_srgb =
true;
253 fb->set_use_explicit_loadstore(
true);
254 fb->bind(enable_srgb);
257 fb->load_store_config_array(load_store_actions, actions_len);
264 fb->subpass_transition(attachment_states[0],
270 const bool enable_srgb =
false;
271 fb->bind(enable_srgb);
312 return gpu_fb->
check(err_out);
359 if (depth_attachment.
mip == -1) {
362 else if (depth_attachment.
tex ==
nullptr) {
371 fb->attachment_set(type, depth_attachment);
376 fb->attachment_set(type, attachment);
390 int viewport_rect[4] = {
x,
y, width, height};
414 const float clear_col[4],
419 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
420 "state via GPU_framebuffer_bind_ex is invalid.");
421 gpu_fb->
clear(
buffers, clear_col, clear_depth, clear_stencil);
435 const float clear_col[4],
454 const float clear_col[4],
465 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
466 "state via GPU_framebuffer_bind_ex is invalid.");
467 fb->clear_multi(clear_colors);
473 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
474 "state via GPU_framebuffer_bind_ex is invalid.");
475 float clear_col[4] = {red, green, blue, alpha};
482 "Using GPU_framebuffer_clear_* functions in conjunction with custom load-store "
483 "state via GPU_framebuffer_bind_ex is invalid.");
484 float clear_col[4] = {0};
491 int rect[4] = {
x,
y,
w, h};
505 int rect[4] = {
x,
y,
w, h};
512 int rect[4] = {
x,
y,
w, h};
534 read_tex = fb_read->
color_tex(read_slot);
535 write_tex = fb_write->
color_tex(write_slot);
549 fb_read->
blit_to(blit_buffers, read_slot, fb_write, write_slot, 0, 0);
555#ifndef GPU_NO_USE_PY_REFERENCES
576#define FRAMEBUFFER_STACK_DEPTH 16
602#undef FRAMEBUFFER_STACK_DEPTH
634 if (framebuffer.fb ==
nullptr) {
635 framebuffer.ctx = ctx;
638 GPU_ATTACHMENT_TEXTURE(ofs->depth),
639 GPU_ATTACHMENT_TEXTURE(ofs->color),
643 if (framebuffer.ctx == ctx) {
644 return framebuffer.fb;
655 "Warning: GPUOffscreen used in more than 3 GPUContext. "
656 "This may create performance drop.\n");
660 framebuffer.fb =
nullptr;
668 bool with_depth_buffer,
678 height =
max_ii(1, height);
686 if (with_depth_buffer) {
693 blender::gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8,
698 if ((with_depth_buffer && !ofs->
depth) || !ofs->
color) {
699 const char error[] =
"blender::gpu::Texture: Texture allocation failed.";
704 fprintf(stderr,
"%s",
error);
719 float const clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
720 float clear_depth = 0.0f;
722 if (with_depth_buffer) {
737 if (framebuffer.fb) {
741 if (offscreen->
color) {
744 if (offscreen->
depth) {
816 return offscreen->
color;
830 *r_color = offscreen->
color;
831 *r_depth = offscreen->
depth;
#define BLI_assert_msg(a, msg)
MINLINE int max_ii(int a, int b)
char * STRNCPY(char(&dst)[N], const char *src)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
@ GPU_LOADACTION_DONT_CARE
@ GPU_STOREACTION_DONT_CARE
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)
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()
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)
#define GPU_ATTACHMENT_NONE
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)
#define GPU_ATTACHMENT_TEXTURE_MIP(_texture, _mip)
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)
#define GPU_framebuffer_ensure_config(_fb,...)
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)
#define GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_texture, _layer, _mip)
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)
#define GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_texture, _face, _mip)
void GPU_framebuffer_viewport_get(blender::gpu::FrameBuffer *fb, int r_viewport[4])
blender::gpu::FrameBuffer * GPU_framebuffer_active_get()
int GPU_texture_height(const blender::gpu::Texture *texture)
bool GPU_texture_has_depth_format(const blender::gpu::Texture *texture)
blender::gpu::TextureFormat GPU_texture_format(const blender::gpu::Texture *texture)
bool GPU_texture_has_stencil_format(const blender::gpu::Texture *texture)
int GPU_texture_width(const blender::gpu::Texture *texture)
@ GPU_TEXTURE_USAGE_ATTACHMENT
@ GPU_TEXTURE_USAGE_FORMAT_VIEW
bool GPU_texture_is_cube(const blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(blender::gpu::Texture *texture)
bool GPU_texture_is_array(const blender::gpu::Texture *texture)
Read Guarded memory(de)allocation.
BMesh const char void * data
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
constexpr int64_t size() const
void attachment_remove(GPUAttachmentType type)
virtual void subpass_transition_impl(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states)=0
virtual void clear(GPUFrameBufferBits buffers, const float clear_col[4], 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)
blender::gpu::Texture * depth_tex() const
blender::gpu::Texture * color_tex(int slot) const
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
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
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)
static GPUBackend * get()
virtual FrameBuffer * framebuffer_alloc(const char *name)=0
GPUAttachmentType attachment_type(int slot) const
TextureFormat format_get() const
void detach_from(FrameBuffer *fb)
#define FRAMEBUFFER_STACK_DEPTH
static void gpu_framebuffer_texture_attach_ex(gpu::FrameBuffer *gpu_fb, GPUAttachment attachment, int slot)
gpu::FrameBuffer * framebuffers[FRAMEBUFFER_STACK_DEPTH]
static gpu::FrameBuffer * gpu_offscreen_fb_get(GPUOffScreen *ofs)
static struct @141033310223244255046200227055353175217006175233 FrameBufferStack
@ GPU_FB_DEPTH_STENCIL_ATTACHMENT
@ GPU_FB_COLOR_ATTACHMENT0
@ GPU_FB_DEPTH_ATTACHMENT
#define GPU_FB_MAX_COLOR_ATTACHMENT
BLI_INLINE float fb(float length, float L)
void * MEM_callocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
static void error(const char *str)
static void clear(Message &msg)
int to_bytesize(const DataFormat format)
int to_component_len(TextureFormat format)
blender::gpu::Texture * tex
static constexpr int MAX_CTX_FB_LEN
blender::gpu::Texture * color
struct GPUOffScreen::@167257126263316171025200246244026236355107071163 framebuffers[MAX_CTX_FB_LEN]
blender::gpu::Texture * depth