61 attachment.tex =
nullptr;
63 attachment.layer = -1;
70 if (attachment.tex !=
nullptr) {
71 reinterpret_cast<Texture *
>(attachment.tex)->detach_from(
this);
84 if (new_attachment.
mip == -1) {
90 "GPUFramebuffer: Error: Trying to attach texture to type %d but maximum slot is %d.\n",
96 if (new_attachment.
tex) {
97 if (new_attachment.
layer > 0) {
110 if (attachment.
tex == new_attachment.
tex && attachment.
layer == new_attachment.
layer &&
111 attachment.
mip == new_attachment.
mip) {
116 if (attachment.
tex) {
117 reinterpret_cast<Texture *
>(attachment.
tex)->detach_from(
this);
120 attachment = new_attachment;
123 if (attachment.
tex) {
124 reinterpret_cast<Texture *
>(attachment.
tex)->attach_to(
this,
type);
140 void (*
callback)(
void *userData,
int level),
149 for (
int mip_lvl = 1; mip_lvl <= max_lvl; mip_lvl++) {
153 if (
tex !=
nullptr) {
159 tex->mip_range_set(mip_lvl - 1, mip_max);
161 attachment.mip = mip_lvl;
172 if (attachment.tex !=
nullptr) {
174 reinterpret_cast<Texture *
>(attachment.tex)->mip_range_set(0, max_lvl);
209 const bool enable_srgb =
true;
210 unwrap(gpu_fb)->bind(enable_srgb);
218 const bool enable_srgb =
false;
219 unwrap(gpu_fb)->bind(enable_srgb);
264 return unwrap(gpu_fb)->check(err_out);
271 unwrap(gpu_fb)->attachment_set(
type, attachment);
283 GPUAttachment attachment = GPU_ATTACHMENT_TEXTURE_LAYER_MIP(
tex, layer, mip);
290 GPUAttachment attachment = GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(
tex, face, mip);
314 if (depth_attachment.
mip == -1) {
317 else if (depth_attachment.
tex ==
nullptr) {
326 fb->attachment_set(
type, depth_attachment);
331 fb->attachment_set(
type, attachment);
346 unwrap(gpu_fb)->viewport_set(viewport_rect);
351 unwrap(gpu_fb)->viewport_get(r_viewport);
359 unwrap(gpu_fb)->viewport_reset();
366 const float clear_col[4],
370 unwrap(gpu_fb)->clear(buffers, clear_col, clear_depth, clear_stencil);
378 unwrap(gpu_fb)->clear_multi(clear_cols);
389 float clear_col[4] = {0};
396 int rect[4] = {
x,
y,
w, h};
410 int rect[4] = {
x,
y,
w, h};
418 int rect[4] = {
x,
y,
w, h};
443 read_tex = fb_read->
color_tex(read_slot);
444 write_tex = fb_write->
color_tex(write_slot);
457 fb_read->
blit_to(blit_buffers, read_slot, fb_write, write_slot, 0, 0);
470 void (*
callback)(
void *userData,
int level),
473 unwrap(gpu_fb)->recursive_downsample(max_lvl,
callback, userData);
484 #define FRAMEBUFFER_STACK_DEPTH 16
510 #undef FRAMEBUFFER_STACK_DEPTH
521 #define MAX_CTX_FB_LEN 3
542 if (framebuffer.fb ==
nullptr) {
543 framebuffer.ctx = ctx;
544 GPU_framebuffer_ensure_config(&framebuffer.fb,
546 GPU_ATTACHMENT_TEXTURE(ofs->depth),
547 GPU_ATTACHMENT_TEXTURE(ofs->color),
551 if (framebuffer.ctx == ctx) {
552 return framebuffer.fb;
563 "Warning: GPUOffscreen used in more than 3 GPUContext. "
564 "This may create performance drop.\n");
568 framebuffer.fb =
nullptr;
575 int width,
int height,
bool depth,
bool high_bitdepth,
char err_out[256])
593 BLI_snprintf(err_out, 256,
"GPUTexture: Texture allocation failed.");
612 if (framebuffer.fb) {
692 *r_color = ofs->
color;
693 *r_depth = ofs->
depth;
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
bool GPU_mip_render_workaround(void)
struct GPUFrameBuffer GPUFrameBuffer
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte blue
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble green
bool GPU_texture_cube(const GPUTexture *tex)
int GPU_texture_height(const GPUTexture *tex)
struct GPUTexture GPUTexture
int GPU_texture_width(const GPUTexture *tex)
bool GPU_texture_array(const GPUTexture *tex)
void GPU_texture_free(GPUTexture *tex)
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
bool GPU_texture_stencil(const GPUTexture *tex)
eGPUTextureFormat GPU_texture_format(const GPUTexture *tex)
bool GPU_texture_depth(const GPUTexture *tex)
Read Guarded memory(de)allocation.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
static Context * get(void)
void attachment_remove(GPUAttachmentType type)
GPUTexture * depth_tex(void) const
virtual void read(eGPUFrameBufferBits planes, eGPUDataFormat format, const int area[4], int channel_len, int slot, void *r_data)=0
virtual void bind(bool enabled_srgb)=0
char name_[DEBUG_NAME_LEN]
FrameBuffer(const char *name)
GPUTexture * color_tex(int slot) const
virtual void clear(eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, uint clear_stencil)=0
void recursive_downsample(int max_lvl, void(*callback)(void *userData, int level), void *userData)
GPUAttachment attachments_[GPU_FB_MAX_ATTACHMENT]
virtual void blit_to(eGPUFrameBufferBits planes, int src_slot, FrameBuffer *dst, int dst_slot, int dst_offset_x, int dst_offset_y)=0
void attachment_set(GPUAttachmentType type, const GPUAttachment &new_attachment)
static GPUBackend * get(void)
DEGForeachIDComponentCallback callback
static CCL_NAMESPACE_BEGIN const double alpha
#define FRAMEBUFFER_STACK_DEPTH
GPUFrameBuffer * GPU_framebuffer_back_get(void)
void GPU_framebuffer_clear(GPUFrameBuffer *gpu_fb, eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, uint clear_stencil)
static GPUFrameBuffer * gpu_offscreen_fb_get(GPUOffScreen *ofs)
void GPU_framebuffer_bind(GPUFrameBuffer *gpu_fb)
void GPU_framebuffer_texture_attach_ex(GPUFrameBuffer *gpu_fb, GPUAttachment attachment, int slot)
uint GPU_framebuffer_stack_level_get(void)
void GPU_framebuffer_texture_layer_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip)
void GPU_framebuffer_config_array(GPUFrameBuffer *gpu_fb, const GPUAttachment *config, int config_len)
void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *gpu_fb)
void GPU_framebuffer_multi_clear(GPUFrameBuffer *gpu_fb, const float(*clear_cols)[4])
void GPU_framebuffer_texture_cubeface_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int face, int mip)
void GPU_framebuffer_restore(void)
void GPU_framebuffer_free(GPUFrameBuffer *gpu_fb)
void GPU_offscreen_free(GPUOffScreen *ofs)
static struct @619 FrameBufferStack
GPUFrameBuffer * GPU_framebuffer_pop(void)
void GPU_framebuffer_read_color(GPUFrameBuffer *gpu_fb, int x, int y, int w, int h, int channels, int slot, eGPUDataFormat format, void *data)
void GPU_offscreen_unbind(GPUOffScreen *UNUSED(ofs), bool restore)
GPUFrameBuffer * GPU_framebuffer_active_get(void)
GPUFrameBuffer * framebuffers[FRAMEBUFFER_STACK_DEPTH]
void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip)
void GPU_offscreen_read_pixels(GPUOffScreen *ofs, eGPUDataFormat format, void *pixels)
bool GPU_framebuffer_bound(GPUFrameBuffer *gpu_fb)
void GPU_framebuffer_viewport_get(GPUFrameBuffer *gpu_fb, int r_viewport[4])
void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *gpu_fb, int max_lvl, void(*callback)(void *userData, int level), void *userData)
void GPU_backbuffer_bind(eGPUBackBuffer buffer)
void GPU_clear_color(float red, float green, float blue, float alpha)
GPUOffScreen * GPU_offscreen_create(int width, int height, bool depth, bool high_bitdepth, char err_out[256])
bool GPU_framebuffer_check_valid(GPUFrameBuffer *gpu_fb, char err_out[256])
void GPU_offscreen_viewport_data_get(GPUOffScreen *ofs, GPUFrameBuffer **r_fb, GPUTexture **r_color, GPUTexture **r_depth)
void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex)
void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y)
void GPU_frontbuffer_read_pixels(int x, int y, int w, int h, int channels, eGPUDataFormat format, void *data)
void GPU_framebuffer_push(GPUFrameBuffer *fb)
int GPU_offscreen_width(const GPUOffScreen *ofs)
void GPU_framebuffer_viewport_reset(GPUFrameBuffer *gpu_fb)
void GPU_framebuffer_blit(GPUFrameBuffer *gpufb_read, int read_slot, GPUFrameBuffer *gpufb_write, int write_slot, eGPUFrameBufferBits blit_buffers)
void GPU_clear_depth(float depth)
void GPU_offscreen_bind(GPUOffScreen *ofs, bool save)
GPUTexture * GPU_offscreen_color_texture(const GPUOffScreen *ofs)
void GPU_framebuffer_viewport_set(GPUFrameBuffer *gpu_fb, int x, int y, int width, int height)
int GPU_offscreen_height(const GPUOffScreen *ofs)
void GPU_framebuffer_read_depth(GPUFrameBuffer *gpu_fb, int x, int y, int w, int h, eGPUDataFormat format, void *data)
GPUFrameBuffer * GPU_framebuffer_create(const char *name)
@ 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)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
int save(ostream &out, const Vec3r &v)
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
struct GPUOffScreen::@620 framebuffers[MAX_CTX_FB_LEN]
ccl_device_inline float2 floor(const float2 &a)