GPUFrameBuffer *GPU_framebuffer_create(void) { GPUFrameBuffer *fb; if (!(GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object || (GLEW_EXT_framebuffer_object && GLEW_EXT_framebuffer_blit))) { return NULL; } fb = MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer"); glGenFramebuffersEXT(1, &fb->object); if (!fb->object) { fprintf(stderr, "GPUFFrameBuffer: framebuffer gen failed. %d\n", (int)glGetError()); GPU_framebuffer_free(fb); return NULL; } /* make sure no read buffer is enabled, so completeness check will not fail. We set those at binding time */ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object); glReadBuffer(GL_NONE); glDrawBuffer(GL_NONE); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); return fb; }
void GPU_offscreen_free(GPUOffScreen *ofs) { if (ofs->fb) GPU_framebuffer_free(ofs->fb); if (ofs->color) GPU_texture_free(ofs->color); if (ofs->depth) GPU_texture_free(ofs->depth); MEM_freeN(ofs); }
static void cleanup_fx_gl_data(GPUFX *fx, bool do_fbo) { if (fx->color_buffer) { GPU_framebuffer_texture_detach(fx->color_buffer); GPU_texture_free(fx->color_buffer); fx->color_buffer = NULL; } if (fx->color_buffer_sec) { GPU_framebuffer_texture_detach(fx->color_buffer_sec); GPU_texture_free(fx->color_buffer_sec); fx->color_buffer_sec = NULL; } if (fx->depth_buffer) { GPU_framebuffer_texture_detach(fx->depth_buffer); GPU_texture_free(fx->depth_buffer); fx->depth_buffer = NULL; } if (fx->depth_buffer_xray) { GPU_framebuffer_texture_detach(fx->depth_buffer_xray); GPU_texture_free(fx->depth_buffer_xray); fx->depth_buffer_xray = NULL; } cleanup_fx_dof_buffers(fx); if (fx->ssao_concentric_samples_tex) { GPU_texture_free(fx->ssao_concentric_samples_tex); fx->ssao_concentric_samples_tex = NULL; } if (fx->jitter_buffer && do_fbo) { GPU_texture_free(fx->jitter_buffer); fx->jitter_buffer = NULL; } if (fx->gbuffer && do_fbo) { GPU_framebuffer_free(fx->gbuffer); fx->gbuffer = NULL; } }
GPUFrameBuffer *GPU_framebuffer_create(void) { GPUFrameBuffer *fb; if (!GLEW_EXT_framebuffer_object) return NULL; fb= MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer"); glGenFramebuffersEXT(1, &fb->object); if (!fb->object) { fprintf(stderr, "GPUFFrameBuffer: framebuffer gen failed. %d\n", (int)glGetError()); GPU_framebuffer_free(fb); return NULL; } return fb; }
/* TODO: Creating, attaching texture, and destroying a framebuffer is quite slow. * Calling this function should be avoided during interactive drawing. */ static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data) { DefaultTextureList *dtxl = (DefaultTextureList *)GPU_viewport_texture_list_get(viewport); GPUFrameBuffer *tmp_fb = GPU_framebuffer_create(); GPU_framebuffer_texture_attach(tmp_fb, dtxl->depth, 0, 0); GPU_framebuffer_bind(tmp_fb); glReadPixels(rect->xmin, rect->ymin, BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), GL_DEPTH_COMPONENT, GL_FLOAT, data); GPU_framebuffer_restore(); GPU_framebuffer_free(tmp_fb); }