31 const char *name,
GLContext *ctx, GLenum target, GLuint fbo,
int w,
int h)
38 gl_attachments_[0] = target;
57 if (context_ ==
nullptr) {
63 glDeleteFramebuffers(1, &fbo_id_);
77 void GLFrameBuffer::init()
81 glGenFramebuffers(1, &fbo_id_);
84 glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_);
99 GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
101 #define FORMAT_STATUS(X) \
117 case GL_FRAMEBUFFER_COMPLETE:
126 const char *
format =
"GPUFrameBuffer: %s status %s\n";
138 void GLFrameBuffer::update_attachments()
153 first_attachment = (attach.
tex) ?
type : first_attachment;
157 first_attachment = (attach.
tex) ?
type : first_attachment;
160 if (attach.
tex ==
nullptr) {
161 glFramebufferTexture(GL_FRAMEBUFFER, gl_attachment, 0, 0);
168 GLenum gl_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + attach.
layer;
169 glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attachment, gl_target, gl_tex, attach.
mip);
171 else if (attach.
layer > -1) {
172 glFramebufferTextureLayer(GL_FRAMEBUFFER, gl_attachment, gl_tex, attach.
mip, attach.
layer);
176 glFramebufferTexture(GL_FRAMEBUFFER, gl_attachment, gl_tex, attach.
mip);
189 for (
int i =
ARRAY_SIZE(gl_attachments_) - 1; i >= 0; --i) {
192 if (attach.
tex !=
nullptr) {
195 else if (gl_tex != 0) {
197 gl_attachments_[i] = gl_attachment;
198 glFramebufferTexture(GL_FRAMEBUFFER, gl_attachment, gl_tex, 0);
213 glDrawBuffers(
ARRAY_SIZE(gl_attachments_), gl_attachments_);
247 if (!immutable_ && fbo_id_ == 0) {
252 BLI_assert_msg(0,
"Trying to use the same frame-buffer in multiple context");
257 glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_);
259 if (immutable_ && fbo_id_ == 0) {
260 glDrawBuffer(gl_attachments_[0]);
265 this->update_attachments();
270 if (context_->
active_fb !=
this || enabled_srgb_ != enabled_srgb) {
271 enabled_srgb_ = enabled_srgb;
272 if (enabled_srgb && srgb_) {
295 const float clear_col[4],
309 glClearColor(clear_col[0], clear_col[1], clear_col[2], clear_col[3]);
313 glClearDepth(clear_depth);
318 glClearStencil(clear_stencil);
337 const void *clear_value)
350 float depth = ((*(
uint32_t *)clear_value) & 0x00FFFFFFu) / (
float)0x00FFFFFFu;
351 int stencil = ((*(
uint32_t *)clear_value) >> 24);
352 glClearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
356 glClearBufferfv(GL_DEPTH, 0, (GLfloat *)clear_value);
359 float depth = *(
uint32_t *)clear_value / (
float)0xFFFFFFFFu;
360 glClearBufferfv(GL_DEPTH, 0, &depth);
368 switch (data_format) {
370 glClearBufferfv(GL_COLOR, slot, (GLfloat *)clear_value);
373 glClearBufferuiv(GL_COLOR, slot, (GLuint *)clear_value);
376 glClearBufferiv(GL_COLOR, slot, (GLint *)clear_value);
408 mode = gl_attachments_[slot];
413 format = GL_DEPTH_COMPONENT;
417 "GPUFramebuffer: Error: Trying to read depth without a depth buffer attached.");
422 "GPUFramebuffer: Error: Trying to read a color slot without valid attachment.");
425 if (
format == GL_RED &&
type == GL_UNSIGNED_INT) {
430 fprintf(stderr,
"GPUFramebuffer: Error: Trying to read stencil bit. Unsupported.");
433 fprintf(stderr,
"GPUFramebuffer: Error: Trying to read more than one frame-buffer plane.");
437 glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_id_);
449 if (
src->dirty_attachments_) {
456 glBindFramebuffer(GL_READ_FRAMEBUFFER,
src->fbo_id_);
457 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst->fbo_id_);
461 BLI_assert(dst->immutable_ ==
false || dst_slot == 0);
463 BLI_assert(dst->gl_attachments_[dst_slot] != GL_NONE);
464 glReadBuffer(
src->gl_attachments_[src_slot]);
465 glDrawBuffer(dst->gl_attachments_[dst_slot]);
471 int h =
src->height_;
473 glBlitFramebuffer(0, 0,
w, h,
x,
y,
x +
w,
y + h,
mask, GL_NEAREST);
475 if (!dst->immutable_) {
477 glDrawBuffers(
ARRAY_SIZE(dst->gl_attachments_), dst->gl_attachments_);
#define BLI_assert_msg(a, msg)
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
void GPU_framebuffer_restore(void)
_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 type
void GPU_shader_set_framebuffer_srgb_target(int use_srgb_to_linear)
void GPU_write_mask(eGPUWriteMask mask)
uint GPU_stencil_mask_get(void)
void GPU_depth_mask(bool depth)
void GPU_stencil_test(eGPUStencilTest test)
void GPU_stencil_write_mask_set(uint write_mask)
void GPU_color_mask(bool r, bool g, bool b, bool a)
eGPUWriteMask GPU_write_mask_get(void)
eGPUStencilTest GPU_stencil_test_get(void)
bool GPU_texture_cube(const GPUTexture *tex)
bool GPU_texture_array(const GPUTexture *tex)
void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *size)
eGPUTextureFormat GPU_texture_format(const GPUTexture *tex)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
StateManager * state_manager
void size_set(int width, int height)
char name_[DEBUG_NAME_LEN]
GPUAttachment attachments_[GPU_FB_MAX_ATTACHMENT]
static bool unused_fb_slot_workaround
void fbo_free(GLuint fbo_id)
void clear(eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, uint clear_stencil) override
bool check(char err_out[256]) override
void read(eGPUFrameBufferBits planes, eGPUDataFormat format, const int area[4], int channel_len, int slot, void *r_data) override
void clear_multi(const float(*clear_cols)[4]) override
GLFrameBuffer(const char *name)
void bind(bool enabled_srgb) override
void clear_attachment(GPUAttachmentType type, eGPUDataFormat data_format, const void *clear_value) override
void blit_to(eGPUFrameBufferBits planes, int src_slot, FrameBuffer *dst, int dst_slot, int dst_offset_x, int dst_offset_y) override
GLFrameBuffer * active_fb
virtual void apply_state()=0
SyclQueue void void * src
@ GPU_FB_DEPTH_STENCIL_ATTACHMENT
@ GPU_FB_COLOR_ATTACHMENT0
@ GPU_FB_DEPTH_ATTACHMENT
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
static void area(int d1, int d2, int e1, int e2, float weights[2])
void object_label(GLenum type, GLuint object, const char *name)
static Context * unwrap(GPUContext *ctx)
GLenum channel_len_to_gl(int channel_len)
static GLenum to_gl(const GPUAttachmentType type)