Cleanup: remove redundant doxygen \file argument
[blender.git] / source / blender / draw / engines / eevee / eevee_data.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 \ingroup draw_engine
20  *
21  * All specific data handler for Objects, Lights, ViewLayers, ...
22  */
23
24 #include "DRW_render.h"
25
26 #include "eevee_private.h"
27 #include "eevee_lightcache.h"
28
29 void EEVEE_view_layer_data_free(void *storage)
30 {
31         EEVEE_ViewLayerData *sldata = (EEVEE_ViewLayerData *)storage;
32
33         /* Lights */
34         MEM_SAFE_FREE(sldata->lamps);
35         DRW_UBO_FREE_SAFE(sldata->light_ubo);
36         DRW_UBO_FREE_SAFE(sldata->shadow_ubo);
37         DRW_UBO_FREE_SAFE(sldata->shadow_render_ubo);
38         GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cube_target_fb);
39         GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cube_store_fb);
40         GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cascade_target_fb);
41         GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cascade_store_fb);
42         DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_target);
43         DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_blur);
44         DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_pool);
45         DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_target);
46         DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_blur);
47         DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_pool);
48         MEM_SAFE_FREE(sldata->shcasters_buffers[0].shadow_casters);
49         MEM_SAFE_FREE(sldata->shcasters_buffers[0].flags);
50         MEM_SAFE_FREE(sldata->shcasters_buffers[1].shadow_casters);
51         MEM_SAFE_FREE(sldata->shcasters_buffers[1].flags);
52
53         if (sldata->fallback_lightcache) {
54                 EEVEE_lightcache_free(sldata->fallback_lightcache);
55                 sldata->fallback_lightcache = NULL;
56         }
57
58         /* Probes */
59         MEM_SAFE_FREE(sldata->probes);
60         DRW_UBO_FREE_SAFE(sldata->probe_ubo);
61         DRW_UBO_FREE_SAFE(sldata->grid_ubo);
62         DRW_UBO_FREE_SAFE(sldata->planar_ubo);
63         DRW_UBO_FREE_SAFE(sldata->common_ubo);
64         DRW_UBO_FREE_SAFE(sldata->clip_ubo);
65 }
66
67 EEVEE_ViewLayerData *EEVEE_view_layer_data_get(void)
68 {
69         return (EEVEE_ViewLayerData *)DRW_view_layer_engine_data_get(
70                 &draw_engine_eevee_type);
71 }
72
73 EEVEE_ViewLayerData *EEVEE_view_layer_data_ensure_ex(struct ViewLayer *view_layer)
74 {
75         EEVEE_ViewLayerData **sldata = (EEVEE_ViewLayerData **)DRW_view_layer_engine_data_ensure_ex(
76                 view_layer, &draw_engine_eevee_type, &EEVEE_view_layer_data_free);
77
78         if (*sldata == NULL) {
79                 *sldata = MEM_callocN(sizeof(**sldata), "EEVEE_ViewLayerData");
80         }
81
82         return *sldata;
83 }
84
85 EEVEE_ViewLayerData *EEVEE_view_layer_data_ensure(void)
86 {
87         EEVEE_ViewLayerData **sldata = (EEVEE_ViewLayerData **)DRW_view_layer_engine_data_ensure(
88                 &draw_engine_eevee_type, &EEVEE_view_layer_data_free);
89
90         if (*sldata == NULL) {
91                 *sldata = MEM_callocN(sizeof(**sldata), "EEVEE_ViewLayerData");
92         }
93
94         return *sldata;
95 }
96
97 /* Object data. */
98
99 static void eevee_object_data_init(DrawData *dd)
100 {
101         EEVEE_ObjectEngineData *eevee_data = (EEVEE_ObjectEngineData *)dd;
102         eevee_data->shadow_caster_id = -1;
103 }
104
105 EEVEE_ObjectEngineData *EEVEE_object_data_get(Object *ob)
106 {
107         if (ELEM(ob->type, OB_LIGHTPROBE, OB_LAMP)) {
108                 return NULL;
109         }
110         return (EEVEE_ObjectEngineData *)DRW_drawdata_get(
111                 &ob->id, &draw_engine_eevee_type);
112 }
113
114 EEVEE_ObjectEngineData *EEVEE_object_data_ensure(Object *ob)
115 {
116         BLI_assert(!ELEM(ob->type, OB_LIGHTPROBE, OB_LAMP));
117         return (EEVEE_ObjectEngineData *)DRW_drawdata_ensure(
118                 &ob->id,
119                 &draw_engine_eevee_type,
120                 sizeof(EEVEE_ObjectEngineData),
121                 eevee_object_data_init,
122                 NULL);
123 }
124
125 /* Light probe data. */
126
127 static void eevee_lightprobe_data_init(DrawData *dd)
128 {
129         EEVEE_LightProbeEngineData *ped = (EEVEE_LightProbeEngineData *)dd;
130         ped->need_update = false;
131 }
132
133 EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_get(Object *ob)
134 {
135         if (ob->type != OB_LIGHTPROBE) {
136                 return NULL;
137         }
138         return (EEVEE_LightProbeEngineData *)DRW_drawdata_get(
139                 &ob->id, &draw_engine_eevee_type);
140 }
141
142 EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_ensure(Object *ob)
143 {
144         BLI_assert(ob->type == OB_LIGHTPROBE);
145         return (EEVEE_LightProbeEngineData *)DRW_drawdata_ensure(
146                 &ob->id,
147                 &draw_engine_eevee_type,
148                 sizeof(EEVEE_LightProbeEngineData),
149                 eevee_lightprobe_data_init,
150                 NULL);
151 }
152
153 /* Lamp data. */
154
155 static void eevee_lamp_data_init(DrawData *dd)
156 {
157         EEVEE_LampEngineData *led = (EEVEE_LampEngineData *)dd;
158         led->need_update = true;
159         led->prev_cube_shadow_id = -1;
160 }
161
162 EEVEE_LampEngineData *EEVEE_lamp_data_get(Object *ob)
163 {
164         if (ob->type != OB_LAMP) {
165                 return NULL;
166         }
167         return (EEVEE_LampEngineData *)DRW_drawdata_get(
168                 &ob->id, &draw_engine_eevee_type);
169 }
170
171 EEVEE_LampEngineData *EEVEE_lamp_data_ensure(Object *ob)
172 {
173         BLI_assert(ob->type == OB_LAMP);
174         return (EEVEE_LampEngineData *)DRW_drawdata_ensure(
175                 &ob->id,
176                 &draw_engine_eevee_type,
177                 sizeof(EEVEE_LampEngineData),
178                 eevee_lamp_data_init,
179                 NULL);
180 }
181
182 /* World data. */
183
184 static void eevee_world_data_init(DrawData *dd)
185 {
186         EEVEE_WorldEngineData *wed = (EEVEE_WorldEngineData *)dd;
187         wed->dd.recalc |= 1;
188 }
189
190 EEVEE_WorldEngineData *EEVEE_world_data_get(World *wo)
191 {
192         return (EEVEE_WorldEngineData *)DRW_drawdata_get(
193                 &wo->id, &draw_engine_eevee_type);
194 }
195
196 EEVEE_WorldEngineData *EEVEE_world_data_ensure(World *wo)
197 {
198         return (EEVEE_WorldEngineData *)DRW_drawdata_ensure(
199                 &wo->id,
200                 &draw_engine_eevee_type,
201                 sizeof(EEVEE_WorldEngineData),
202                 eevee_world_data_init,
203                 NULL);
204 }