Workbench: Option to use Object color
[blender.git] / source / blender / draw / engines / workbench / solid_flat_mode.c
1 /*
2  * Copyright 2016, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Institute
19  *
20  */
21
22 /** \file solid_flat_mode.c
23  *  \ingroup draw_engine
24  *
25  * Simple engine for drawing color and/or depth.
26  * When we only need simple flat shaders.
27  */
28
29 #include "DRW_render.h"
30
31 #include "GPU_shader.h"
32
33 #include "workbench_private.h"
34 /* Functions */
35
36 static void workbench_solid_flat_engine_init(void *UNUSED(vedata))
37 {
38         workbench_materials_engine_init();
39 }
40
41 static void workbench_solid_flat_cache_init(void *vedata)
42 {
43         WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
44         WORKBENCH_PassList *psl = data->psl;
45         WORKBENCH_StorageList *stl = data->stl;
46
47         if (!stl->g_data) {
48                 /* Alloc transient pointers */
49                 stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
50         }
51
52         /* Depth Pass */
53         {
54                 int state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
55                 psl->depth_pass = DRW_pass_create("Depth Pass", state);
56         }
57
58         /* Solid Pass */
59         {
60                 int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL;
61                 psl->solid_pass = DRW_pass_create("Solid Pass", state);
62         }
63
64         workbench_materials_cache_init(data);
65 }
66
67
68 static void workbench_solid_flat_cache_populate(void *vedata, Object *ob)
69 {
70         WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
71         workbench_materials_solid_cache_populate(data, ob, V3D_LIGHTING_FLAT);
72 }
73
74 static void workbench_solid_flat_cache_finish(void *vedata)
75 {
76         workbench_materials_cache_finish((WORKBENCH_Data *)vedata);
77 }
78
79 static void workbench_solid_flat_draw_scene(void *vedata)
80 {
81         WORKBENCH_Data *data = (WORKBENCH_Data *)vedata;
82         WORKBENCH_PassList *psl = data->psl;
83
84         DRW_draw_pass(psl->depth_pass);
85         DRW_draw_pass(psl->solid_pass);
86 }
87
88 static void workbench_solid_flat_engine_free(void)
89 {
90         workbench_materials_engine_finish();
91 }
92
93 static const DrawEngineDataSize workbench_data_size = DRW_VIEWPORT_DATA_SIZE(WORKBENCH_Data);
94
95 DrawEngineType draw_engine_workbench_solid_flat = {
96         NULL, NULL,
97         N_("Workbench"),
98         &workbench_data_size,
99         &workbench_solid_flat_engine_init,
100         &workbench_solid_flat_engine_free,
101         &workbench_solid_flat_cache_init,
102         &workbench_solid_flat_cache_populate,
103         &workbench_solid_flat_cache_finish,
104         NULL,
105         &workbench_solid_flat_draw_scene,
106         NULL,
107         NULL,
108         NULL,
109 };