49 const char *name,
GLContext *ctx, GLenum target, GLuint fbo,
int w,
int h)
56 gl_attachments_[0] = target;
75 if (context_ ==
nullptr) {
81 glDeleteFramebuffers(1, &fbo_id_);
95 void GLFrameBuffer::init()
99 glGenFramebuffers(1, &fbo_id_);
102 glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_);
118 GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
120 #define FORMAT_STATUS(X) \
136 case GL_FRAMEBUFFER_COMPLETE:
145 const char *
format =
"GPUFrameBuffer: %s status %s\n";
157 void GLFrameBuffer::update_attachments()
172 first_attachment = (attach.
tex) ?
type : first_attachment;
176 first_attachment = (attach.
tex) ?
type : first_attachment;
179 if (attach.
tex ==
nullptr) {
180 glFramebufferTexture(GL_FRAMEBUFFER, gl_attachment, 0, 0);
187 GLenum gl_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + attach.
layer;
188 glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attachment, gl_target, gl_tex, attach.
mip);
190 else if (attach.
layer > -1) {
191 glFramebufferTextureLayer(GL_FRAMEBUFFER, gl_attachment, gl_tex, attach.
mip, attach.
layer);
195 glFramebufferTexture(GL_FRAMEBUFFER, gl_attachment, gl_tex, attach.
mip);
208 for (
int i =
ARRAY_SIZE(gl_attachments_) - 1; i >= 0; --i) {
211 if (attach.
tex !=
nullptr) {
214 else if (gl_tex != 0) {
216 gl_attachments_[i] = gl_attachment;
217 glFramebufferTexture(GL_FRAMEBUFFER, gl_attachment, gl_tex, 0);
232 glDrawBuffers(
ARRAY_SIZE(gl_attachments_), gl_attachments_);
266 if (!immutable_ && fbo_id_ == 0) {
271 BLI_assert(!
"Trying to use the same frame-buffer in multiple context");
276 glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_);
278 if (immutable_ && fbo_id_ == 0) {
279 glDrawBuffer(gl_attachments_[0]);
284 this->update_attachments();
289 if (context_->
active_fb !=
this || enabled_srgb_ != enabled_srgb) {
290 enabled_srgb_ = enabled_srgb;
291 if (enabled_srgb && srgb_) {
314 const float clear_col[4],
328 glClearColor(clear_col[0], clear_col[1], clear_col[2], clear_col[3]);
332 glClearDepth(clear_depth);
337 glClearStencil(clear_stencil);
356 const void *clear_value)
369 float depth = ((*(
uint32_t *)clear_value) & 0x00FFFFFFu) / (
float)0x00FFFFFFu;
370 int stencil = ((*(
uint32_t *)clear_value) >> 24);
371 glClearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
375 glClearBufferfv(GL_DEPTH, 0, (GLfloat *)clear_value);
378 float depth = *(
uint32_t *)clear_value / (
float)0xFFFFFFFFu;
379 glClearBufferfv(GL_DEPTH, 0, &depth);
387 switch (data_format) {
389 glClearBufferfv(GL_COLOR, slot, (GLfloat *)clear_value);
392 glClearBufferuiv(GL_COLOR, slot, (GLuint *)clear_value);
395 glClearBufferiv(GL_COLOR, slot, (GLint *)clear_value);
427 mode = gl_attachments_[slot];
432 format = GL_DEPTH_COMPONENT;
437 if (
format == GL_RED &&
type == GL_UNSIGNED_INT) {
442 fprintf(stderr,
"GPUFramebuffer: Error: Trying to read stencil bit. Unsupported.");
445 fprintf(stderr,
"GPUFramebuffer: Error: Trying to read more than one frame-buffer plane.");
449 glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_id_);
471 glBindFramebuffer(GL_READ_FRAMEBUFFER, src->fbo_id_);
472 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst->fbo_id_);
475 BLI_assert(src->immutable_ ==
false || src_slot == 0);
476 BLI_assert(dst->immutable_ ==
false || dst_slot == 0);
477 BLI_assert(src->gl_attachments_[src_slot] != GL_NONE);
478 BLI_assert(dst->gl_attachments_[dst_slot] != GL_NONE);
479 glReadBuffer(src->gl_attachments_[src_slot]);
480 glDrawBuffer(dst->gl_attachments_[dst_slot]);
488 glBlitFramebuffer(0, 0,
w, h,
x,
y,
x +
w,
y + h,
mask, GL_NEAREST);
490 if (!dst->immutable_) {
492 glDrawBuffers(
ARRAY_SIZE(dst->gl_attachments_), dst->gl_attachments_);
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 type
_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
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
static Context * get(void)
void size_set(int width, int height)
char name_[DEBUG_NAME_LEN]
void viewport_reset(void)
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(void)=0
@ GPU_FB_DEPTH_STENCIL_ATTACHMENT
@ GPU_FB_COLOR_ATTACHMENT0
@ GPU_FB_DEPTH_ATTACHMENT
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)
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)