Rename any instance of scene layer or render layer in code with view layer
[blender.git] / source / blender / draw / engines / eevee / eevee_data.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 eevee_data.c
23  *  \ingroup draw_engine
24  *
25  * All specific data handler for Objects, Lights, ViewLayers, ...
26  */
27
28 #include "DRW_render.h"
29
30 #include "eevee_private.h"
31
32 static void eevee_view_layer_data_free(void *storage)
33 {
34         EEVEE_ViewLayerData *sldata = (EEVEE_ViewLayerData *)storage;
35
36         /* Lights */
37         MEM_SAFE_FREE(sldata->lamps);
38         DRW_UBO_FREE_SAFE(sldata->light_ubo);
39         DRW_UBO_FREE_SAFE(sldata->shadow_ubo);
40         DRW_UBO_FREE_SAFE(sldata->shadow_render_ubo);
41         DRW_FRAMEBUFFER_FREE_SAFE(sldata->shadow_target_fb);
42         DRW_FRAMEBUFFER_FREE_SAFE(sldata->shadow_store_fb);
43         DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_target);
44         DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_blur);
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_pool);
48         BLI_freelistN(&sldata->shadow_casters);
49
50         /* Probes */
51         MEM_SAFE_FREE(sldata->probes);
52         DRW_UBO_FREE_SAFE(sldata->probe_ubo);
53         DRW_UBO_FREE_SAFE(sldata->grid_ubo);
54         DRW_UBO_FREE_SAFE(sldata->planar_ubo);
55         DRW_FRAMEBUFFER_FREE_SAFE(sldata->probe_fb);
56         DRW_FRAMEBUFFER_FREE_SAFE(sldata->probe_filter_fb);
57         DRW_TEXTURE_FREE_SAFE(sldata->probe_rt);
58         DRW_TEXTURE_FREE_SAFE(sldata->probe_pool);
59         DRW_TEXTURE_FREE_SAFE(sldata->irradiance_pool);
60         DRW_TEXTURE_FREE_SAFE(sldata->irradiance_rt);
61
62         /* Volumetrics */
63         MEM_SAFE_FREE(sldata->volumetrics);
64 }
65
66 static void eevee_lamp_data_free(void *storage)
67 {
68         EEVEE_LampEngineData *led = (EEVEE_LampEngineData *)storage;
69
70         MEM_SAFE_FREE(led->storage);
71         BLI_freelistN(&led->shadow_caster_list);
72 }
73
74 static void eevee_lightprobe_data_free(void *storage)
75 {
76         EEVEE_LightProbeEngineData *ped = (EEVEE_LightProbeEngineData *)storage;
77
78         BLI_freelistN(&ped->captured_object_list);
79 }
80
81 EEVEE_ViewLayerData *EEVEE_view_layer_data_get(void)
82 {
83         EEVEE_ViewLayerData **sldata = (EEVEE_ViewLayerData **)DRW_view_layer_engine_data_get(
84                 &draw_engine_eevee_type, &eevee_view_layer_data_free);
85
86         if (*sldata == NULL) {
87                 *sldata = MEM_callocN(sizeof(**sldata), "EEVEE_ViewLayerData");
88         }
89
90         return *sldata;
91 }
92
93 EEVEE_ObjectEngineData *EEVEE_object_data_get(Object *ob)
94 {
95         EEVEE_ObjectEngineData **oedata = (EEVEE_ObjectEngineData **)DRW_object_engine_data_get(
96                 ob, &draw_engine_eevee_type, NULL);
97
98         if (*oedata == NULL) {
99                 *oedata = MEM_callocN(sizeof(**oedata), "EEVEE_ObjectEngineData");
100         }
101
102         return *oedata;
103 }
104
105 EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_get(Object *ob)
106 {
107         EEVEE_LightProbeEngineData **pedata = (EEVEE_LightProbeEngineData **)DRW_object_engine_data_get(
108                 ob, &draw_engine_eevee_type, &eevee_lightprobe_data_free);
109
110         if (*pedata == NULL) {
111                 *pedata = MEM_callocN(sizeof(**pedata), "EEVEE_LightProbeEngineData");
112                 (*pedata)->need_update = true;
113         }
114
115         return *pedata;
116 }
117
118 EEVEE_LampEngineData *EEVEE_lamp_data_get(Object *ob)
119 {
120         EEVEE_LampEngineData **ledata = (EEVEE_LampEngineData **)DRW_object_engine_data_get(
121                 ob, &draw_engine_eevee_type, &eevee_lamp_data_free);
122
123         if (*ledata == NULL) {
124                 *ledata = MEM_callocN(sizeof(**ledata), "EEVEE_LampEngineData");
125                 (*ledata)->need_update = true;
126         }
127
128         return *ledata;
129 }