Industry Compat keymap: Fix inconsistencies and conflicts with color swatches and...
[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 void workbench_aa_create_pass(WORKBENCH_Data *vedata, GPUTexture **tx)
28 {
29   WORKBENCH_StorageList *stl = vedata->stl;
30   WORKBENCH_PrivateData *wpd = stl->g_data;
31   WORKBENCH_PassList *psl = vedata->psl;
32   WORKBENCH_EffectInfo *effect_info = stl->effects;
33   const DRWContextState *draw_ctx = DRW_context_state_get();
34
35   if (draw_ctx->evil_C != NULL) {
36     struct wmWindowManager *wm = CTX_wm_manager(draw_ctx->evil_C);
37     wpd->is_playback = ED_screen_animation_playing(wm) != NULL;
38   }
39   else {
40     wpd->is_playback = false;
41   }
42
43   if (workbench_is_taa_enabled(wpd)) {
44     psl->effect_aa_pass = workbench_taa_create_pass(vedata, tx);
45   }
46   else if (workbench_is_fxaa_enabled(wpd)) {
47     psl->effect_aa_pass = workbench_fxaa_create_pass(tx);
48     effect_info->jitter_index = 0;
49   }
50   else {
51     psl->effect_aa_pass = NULL;
52     effect_info->jitter_index = 0;
53   }
54 }
55
56 static void workspace_aa_draw_transform(GPUTexture *tx, WORKBENCH_PrivateData *wpd)
57 {
58   if (DRW_state_do_color_management()) {
59     /* Display space result for viewport. */
60     DRW_transform_to_display(tx, wpd->use_color_render_settings, wpd->use_color_render_settings);
61   }
62   else {
63     /* Linear result for render. */
64     DRW_transform_none(tx);
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 (workbench_is_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 (workbench_is_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 }