Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-03-25 18:46:48 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-03-25 21:06:12 +0300
commitbc15ec0896c2deba2e2a45581fd0f408d4906df4 (patch)
tree97f7f0a32a92fc441226c89fc09b80dbdc5e343f /source/blender/draw/engines/eevee/eevee_depth_of_field.c
parentf937123116abd4ba34ff858fa03415362d6c07cf (diff)
GPUFramebuffer: Refactor (Part 2)
This refactor modernise the use of framebuffers. It also touches a lot of files so breaking down changes we have: - GPUTexture: Allow textures to be attached to more than one GPUFrameBuffer. This allows to create and configure more FBO without the need to attach and detach texture at drawing time. - GPUFrameBuffer: The wrapper starts to mimic opengl a bit closer. This allows to configure the framebuffer inside a context other than the one that will be rendering the framebuffer. We do the actual configuration when binding the FBO. We also Keep track of config validity and save drawbuffers state in the FBO. We remove the different bind/unbind functions. These make little sense now that we have separate contexts. - DRWFrameBuffer: We replace DRW_framebuffer functions by GPU_framebuffer ones to avoid another layer of abstraction. We move the DRW convenience functions to GPUFramebuffer instead and even add new ones. The MACRO GPU_framebuffer_ensure_config is pretty much all you need to create and config a GPUFramebuffer. - DRWTexture: Due to the removal of DRWFrameBuffer, we needed to create functions to create textures for thoses framebuffers. Pool textures are now using default texture parameters for the texture type asked. - DRWManager: Make sure no framebuffer object is bound when doing cache filling. - GPUViewport: Add new color_only_fb and depth_only_fb along with FB API usage update. This let draw engines render to color/depth only target and without the need to attach/detach textures. - WM_window: Assert when a framebuffer is bound when changing context. This balance the fact we are not track ogl context inside GPUFramebuffer. - Eevee, Clay, Mode engines: Update to new API. This comes with a lot of code simplification. This also come with some cleanups in some engine codes.
Diffstat (limited to 'source/blender/draw/engines/eevee/eevee_depth_of_field.c')
-rw-r--r--source/blender/draw/engines/eevee/eevee_depth_of_field.c92
1 files changed, 38 insertions, 54 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_depth_of_field.c b/source/blender/draw/engines/eevee/eevee_depth_of_field.c
index dcd45e27337..c137aa8da24 100644
--- a/source/blender/draw/engines/eevee/eevee_depth_of_field.c
+++ b/source/blender/draw/engines/eevee/eevee_depth_of_field.c
@@ -79,7 +79,6 @@ int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *v
{
EEVEE_StorageList *stl = vedata->stl;
EEVEE_FramebufferList *fbl = vedata->fbl;
- EEVEE_TextureList *txl = vedata->txl;
EEVEE_EffectsInfo *effects = stl->effects;
const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -104,39 +103,36 @@ int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *v
int buffer_size[2] = {(int)viewport_size[0] / 2, (int)viewport_size[1] / 2};
- /* Reuse buffer from Bloom if available */
- /* WATCH IT : must have the same size */
- struct GPUTexture **dof_down_near;
-
- if ((effects->enabled_effects & EFFECT_BLOOM) != 0) {
- dof_down_near = &txl->bloom_downsample[0];
- }
- else {
- dof_down_near = &txl->dof_down_near;
- }
+ effects->dof_down_near = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGB_11_11_10,
+ &draw_engine_eevee_type);
+ effects->dof_down_far = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RGB_11_11_10,
+ &draw_engine_eevee_type);
+ effects->dof_coc = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], DRW_TEX_RG_16,
+ &draw_engine_eevee_type);
- /* Setup buffers */
- DRWFboTexture tex_down[3] = {
- {dof_down_near, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER}, /* filter to not interfeer with bloom */
- {&txl->dof_down_far, DRW_TEX_RGB_11_11_10, 0},
- {&txl->dof_coc, DRW_TEX_RG_16, 0},
- };
- DRW_framebuffer_init(
- &fbl->dof_down_fb, &draw_engine_eevee_type,
- buffer_size[0], buffer_size[1], tex_down, 3);
+ GPU_framebuffer_ensure_config(&fbl->dof_down_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->dof_down_near),
+ GPU_ATTACHMENT_TEXTURE(effects->dof_down_far),
+ GPU_ATTACHMENT_TEXTURE(effects->dof_coc)
+ });
/* Go full 32bits for rendering and reduce the color artifacts. */
DRWTextureFormat fb_format = DRW_state_is_image_render() ? DRW_TEX_RGBA_32 : DRW_TEX_RGBA_16;
- DRWFboTexture tex_scatter_far = {&txl->dof_far_blur, fb_format, DRW_TEX_FILTER};
- DRW_framebuffer_init(
- &fbl->dof_scatter_far_fb, &draw_engine_eevee_type,
- buffer_size[0], buffer_size[1], &tex_scatter_far, 1);
+ effects->dof_far_blur = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], fb_format,
+ &draw_engine_eevee_type);
+ GPU_framebuffer_ensure_config(&fbl->dof_scatter_far_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->dof_far_blur),
+ });
- DRWFboTexture tex_scatter_near = {&txl->dof_near_blur, fb_format, DRW_TEX_FILTER};
- DRW_framebuffer_init(
- &fbl->dof_scatter_near_fb, &draw_engine_eevee_type,
- buffer_size[0], buffer_size[1], &tex_scatter_near, 1);
+ effects->dof_near_blur = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], fb_format,
+ &draw_engine_eevee_type);
+ GPU_framebuffer_ensure_config(&fbl->dof_scatter_near_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->dof_near_blur),
+ });
/* Parameters */
/* TODO UI Options */
@@ -178,14 +174,9 @@ int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *v
}
/* Cleanup to release memory */
- DRW_TEXTURE_FREE_SAFE(txl->dof_down_near);
- DRW_TEXTURE_FREE_SAFE(txl->dof_down_far);
- DRW_TEXTURE_FREE_SAFE(txl->dof_coc);
- DRW_TEXTURE_FREE_SAFE(txl->dof_far_blur);
- DRW_TEXTURE_FREE_SAFE(txl->dof_near_blur);
- DRW_FRAMEBUFFER_FREE_SAFE(fbl->dof_down_fb);
- DRW_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_far_fb);
- DRW_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_near_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->dof_down_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_far_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_near_fb);
return 0;
}
@@ -194,7 +185,6 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_
{
EEVEE_PassList *psl = vedata->psl;
EEVEE_StorageList *stl = vedata->stl;
- EEVEE_TextureList *txl = vedata->txl;
EEVEE_EffectsInfo *effects = stl->effects;
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
@@ -229,7 +219,7 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_
grp = DRW_shgroup_empty_tri_batch_create(e_data.dof_scatter_sh, psl->dof_scatter, sprite_ct);
DRW_shgroup_uniform_buffer(grp, "colorBuffer", &effects->unf_source_buffer);
- DRW_shgroup_uniform_buffer(grp, "cocBuffer", &txl->dof_coc);
+ DRW_shgroup_uniform_buffer(grp, "cocBuffer", &effects->dof_coc);
DRW_shgroup_uniform_vec2(grp, "layerSelection", effects->dof_layer_select, 1);
DRW_shgroup_uniform_vec4(grp, "bokehParams", effects->dof_bokeh, 1);
@@ -237,8 +227,8 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_
grp = DRW_shgroup_create(e_data.dof_resolve_sh, psl->dof_resolve);
DRW_shgroup_uniform_buffer(grp, "colorBuffer", &effects->source_buffer);
- DRW_shgroup_uniform_buffer(grp, "nearBuffer", &txl->dof_near_blur);
- DRW_shgroup_uniform_buffer(grp, "farBuffer", &txl->dof_far_blur);
+ DRW_shgroup_uniform_buffer(grp, "nearBuffer", &effects->dof_near_blur);
+ DRW_shgroup_uniform_buffer(grp, "farBuffer", &effects->dof_far_blur);
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &dtxl->depth);
DRW_shgroup_uniform_vec2(grp, "nearFar", effects->dof_near_far, 1);
DRW_shgroup_uniform_vec3(grp, "dofParams", effects->dof_params, 1);
@@ -259,31 +249,25 @@ void EEVEE_depth_of_field_draw(EEVEE_Data *vedata)
float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
/* Downsample */
- DRW_framebuffer_bind(fbl->dof_down_fb);
+ GPU_framebuffer_bind(fbl->dof_down_fb);
DRW_draw_pass(psl->dof_down);
/* Scatter Far */
- effects->unf_source_buffer = txl->dof_down_far;
+ effects->unf_source_buffer = effects->dof_down_far;
copy_v2_fl2(effects->dof_layer_select, 0.0f, 1.0f);
- DRW_framebuffer_bind(fbl->dof_scatter_far_fb);
- DRW_framebuffer_clear(true, false, false, clear_col, 0.0f);
+ GPU_framebuffer_bind(fbl->dof_scatter_far_fb);
+ GPU_framebuffer_clear_color(fbl->dof_scatter_far_fb, clear_col);
DRW_draw_pass(psl->dof_scatter);
/* Scatter Near */
- if ((effects->enabled_effects & EFFECT_BLOOM) != 0) {
- /* Reuse bloom half res buffer */
- effects->unf_source_buffer = txl->bloom_downsample[0];
- }
- else {
- effects->unf_source_buffer = txl->dof_down_near;
- }
+ effects->unf_source_buffer = effects->dof_down_near;
copy_v2_fl2(effects->dof_layer_select, 1.0f, 0.0f);
- DRW_framebuffer_bind(fbl->dof_scatter_near_fb);
- DRW_framebuffer_clear(true, false, false, clear_col, 0.0f);
+ GPU_framebuffer_bind(fbl->dof_scatter_near_fb);
+ GPU_framebuffer_clear_color(fbl->dof_scatter_near_fb, clear_col);
DRW_draw_pass(psl->dof_scatter);
/* Resolve */
- DRW_framebuffer_bind(effects->target_buffer);
+ GPU_framebuffer_bind(effects->target_buffer);
DRW_draw_pass(psl->dof_resolve);
SWAP_BUFFERS();
}