doxygen: add newline after \file
[blender.git] / source / blender / draw / engines / workbench / workbench_effect_aa.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2016, Blender Foundation.
17  */
18
19 /** \file
20  * \ingroup draw_engine
21  */
22
23 #include "ED_screen.h"
24
25 #include "workbench_private.h"
26
27
28 void workbench_aa_create_pass(WORKBENCH_Data *vedata, GPUTexture **tx)
29 {
30         WORKBENCH_StorageList *stl = vedata->stl;
31         WORKBENCH_PrivateData *wpd = stl->g_data;
32         WORKBENCH_PassList *psl = vedata->psl;
33         WORKBENCH_EffectInfo *effect_info = stl->effects;
34         const DRWContextState *draw_ctx = DRW_context_state_get();
35
36         if (draw_ctx->evil_C != NULL) {
37                 struct wmWindowManager *wm = CTX_wm_manager(draw_ctx->evil_C);
38                 wpd->is_playback = ED_screen_animation_playing(wm) != NULL;
39         }
40         else {
41                 wpd->is_playback = false;
42         }
43
44         if (TAA_ENABLED(wpd)) {
45                 psl->effect_aa_pass = workbench_taa_create_pass(vedata, tx);
46         }
47         else if (FXAA_ENABLED(wpd)) {
48                 psl->effect_aa_pass = workbench_fxaa_create_pass(tx);
49                 effect_info->jitter_index = 0;
50         }
51         else {
52                 psl->effect_aa_pass = NULL;
53         }
54 }
55
56 static void workspace_aa_draw_transform(GPUTexture *tx, WORKBENCH_PrivateData *wpd)
57 {
58         if (DRW_state_is_image_render()) {
59                 /* Linear result for render. */
60                 DRW_transform_none(tx);
61         }
62         else {
63                 /* Display space result for viewport. */
64                 DRW_transform_to_display(tx, wpd->use_color_render_settings, wpd->use_color_render_settings);
65         }
66 }
67
68 void workbench_aa_draw_pass(WORKBENCH_Data *vedata, GPUTexture *tx)
69 {
70         WORKBENCH_StorageList *stl = vedata->stl;
71         WORKBENCH_PrivateData *wpd = stl->g_data;
72         WORKBENCH_FramebufferList *fbl = vedata->fbl;
73         WORKBENCH_PassList *psl = vedata->psl;
74         WORKBENCH_EffectInfo *effect_info = stl->effects;
75
76         DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
77         if (FXAA_ENABLED(wpd)) {
78                 GPU_framebuffer_bind(fbl->effect_fb);
79                 workspace_aa_draw_transform(tx, wpd);
80                 GPU_framebuffer_bind(dfbl->color_only_fb);
81                 DRW_draw_pass(psl->effect_aa_pass);
82         }
83         else if (TAA_ENABLED(wpd)) {
84                 /*
85                  * when drawing the first TAA frame, we transform directly to the
86                  * color_only_fb as the TAA shader is just performing a direct copy.
87                  * the workbench_taa_draw_screen_end will fill the history buffer
88                  * for the other iterations.
89                  */
90                 if (effect_info->jitter_index == 1) {
91                         GPU_framebuffer_bind(dfbl->color_only_fb);
92                         workspace_aa_draw_transform(tx, wpd);
93                 }
94                 else {
95                         GPU_framebuffer_bind(fbl->effect_fb);
96                         workspace_aa_draw_transform(tx, wpd);
97                         GPU_framebuffer_bind(dfbl->color_only_fb);
98                         DRW_draw_pass(psl->effect_aa_pass);
99                 }
100                 workbench_taa_draw_scene_end(vedata);
101         }
102         else {
103                 GPU_framebuffer_bind(dfbl->color_only_fb);
104                 workspace_aa_draw_transform(tx, wpd);
105         }
106 }