2017-06-03 00:53:47 +02:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2019-01-23 11:29:18 +11:00
|
|
|
* Copyright 2016, Blender Foundation.
|
2017-06-03 00:53:47 +02:00
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup draw_engine
|
2017-11-20 14:11:45 +11:00
|
|
|
*
|
2017-11-22 10:52:39 -02:00
|
|
|
* All specific data handler for Objects, Lights, ViewLayers, ...
|
2017-06-03 00:53:47 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DRW_render.h"
|
|
|
|
|
|
|
|
#include "eevee_private.h"
|
2018-07-10 15:02:25 +02:00
|
|
|
#include "eevee_lightcache.h"
|
2017-06-03 00:53:47 +02:00
|
|
|
|
2018-07-27 17:33:53 +02:00
|
|
|
void EEVEE_view_layer_data_free(void *storage)
|
2017-06-03 00:53:47 +02:00
|
|
|
{
|
2017-11-22 10:52:39 -02:00
|
|
|
EEVEE_ViewLayerData *sldata = (EEVEE_ViewLayerData *)storage;
|
2017-06-03 00:53:47 +02:00
|
|
|
|
|
|
|
/* Lights */
|
2019-02-27 12:02:02 +11:00
|
|
|
MEM_SAFE_FREE(sldata->lights);
|
2017-06-03 00:53:47 +02:00
|
|
|
DRW_UBO_FREE_SAFE(sldata->light_ubo);
|
|
|
|
DRW_UBO_FREE_SAFE(sldata->shadow_ubo);
|
|
|
|
DRW_UBO_FREE_SAFE(sldata->shadow_render_ubo);
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cube_target_fb);
|
2018-05-04 14:39:05 +02:00
|
|
|
GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cube_store_fb);
|
2018-03-25 17:46:48 +02:00
|
|
|
GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cascade_target_fb);
|
2018-05-04 14:39:05 +02:00
|
|
|
GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cascade_store_fb);
|
2017-09-01 15:59:01 +02:00
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_target);
|
2017-09-08 20:21:57 +02:00
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_blur);
|
2018-05-04 14:39:05 +02:00
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_pool);
|
2017-09-01 15:59:01 +02:00
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_target);
|
2017-09-08 20:21:57 +02:00
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_blur);
|
2018-05-04 14:39:05 +02:00
|
|
|
DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_pool);
|
2018-01-11 14:08:21 +01:00
|
|
|
MEM_SAFE_FREE(sldata->shcasters_buffers[0].shadow_casters);
|
|
|
|
MEM_SAFE_FREE(sldata->shcasters_buffers[0].flags);
|
|
|
|
MEM_SAFE_FREE(sldata->shcasters_buffers[1].shadow_casters);
|
|
|
|
MEM_SAFE_FREE(sldata->shcasters_buffers[1].flags);
|
2017-06-03 00:53:47 +02:00
|
|
|
|
2018-07-10 15:02:25 +02:00
|
|
|
if (sldata->fallback_lightcache) {
|
|
|
|
EEVEE_lightcache_free(sldata->fallback_lightcache);
|
|
|
|
sldata->fallback_lightcache = NULL;
|
|
|
|
}
|
|
|
|
|
2017-06-03 00:53:47 +02:00
|
|
|
/* Probes */
|
|
|
|
MEM_SAFE_FREE(sldata->probes);
|
|
|
|
DRW_UBO_FREE_SAFE(sldata->probe_ubo);
|
2017-06-13 17:39:39 +02:00
|
|
|
DRW_UBO_FREE_SAFE(sldata->grid_ubo);
|
2017-06-17 00:08:03 +02:00
|
|
|
DRW_UBO_FREE_SAFE(sldata->planar_ubo);
|
2018-01-21 17:25:10 +01:00
|
|
|
DRW_UBO_FREE_SAFE(sldata->common_ubo);
|
2018-03-10 00:02:01 +01:00
|
|
|
DRW_UBO_FREE_SAFE(sldata->clip_ubo);
|
2017-06-03 00:53:47 +02:00
|
|
|
}
|
|
|
|
|
2017-11-29 11:00:50 +01:00
|
|
|
EEVEE_ViewLayerData *EEVEE_view_layer_data_get(void)
|
|
|
|
{
|
|
|
|
return (EEVEE_ViewLayerData *)DRW_view_layer_engine_data_get(
|
|
|
|
&draw_engine_eevee_type);
|
|
|
|
}
|
|
|
|
|
2018-07-10 15:02:25 +02:00
|
|
|
EEVEE_ViewLayerData *EEVEE_view_layer_data_ensure_ex(struct ViewLayer *view_layer)
|
|
|
|
{
|
|
|
|
EEVEE_ViewLayerData **sldata = (EEVEE_ViewLayerData **)DRW_view_layer_engine_data_ensure_ex(
|
2018-07-27 17:33:53 +02:00
|
|
|
view_layer, &draw_engine_eevee_type, &EEVEE_view_layer_data_free);
|
2018-07-10 15:02:25 +02:00
|
|
|
|
|
|
|
if (*sldata == NULL) {
|
|
|
|
*sldata = MEM_callocN(sizeof(**sldata), "EEVEE_ViewLayerData");
|
|
|
|
}
|
|
|
|
|
|
|
|
return *sldata;
|
|
|
|
}
|
|
|
|
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_ViewLayerData *EEVEE_view_layer_data_ensure(void)
|
2017-06-03 00:53:47 +02:00
|
|
|
{
|
2017-11-29 10:48:42 +01:00
|
|
|
EEVEE_ViewLayerData **sldata = (EEVEE_ViewLayerData **)DRW_view_layer_engine_data_ensure(
|
2018-07-27 17:33:53 +02:00
|
|
|
&draw_engine_eevee_type, &EEVEE_view_layer_data_free);
|
2017-06-03 00:53:47 +02:00
|
|
|
|
|
|
|
if (*sldata == NULL) {
|
2017-11-22 10:52:39 -02:00
|
|
|
*sldata = MEM_callocN(sizeof(**sldata), "EEVEE_ViewLayerData");
|
2017-06-03 00:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return *sldata;
|
|
|
|
}
|
|
|
|
|
2018-01-29 16:28:24 +01:00
|
|
|
/* Object data. */
|
|
|
|
|
2018-07-10 14:14:55 +02:00
|
|
|
static void eevee_object_data_init(DrawData *dd)
|
2018-01-29 16:28:24 +01:00
|
|
|
{
|
2018-07-10 14:14:55 +02:00
|
|
|
EEVEE_ObjectEngineData *eevee_data = (EEVEE_ObjectEngineData *)dd;
|
2018-01-29 16:28:24 +01:00
|
|
|
eevee_data->shadow_caster_id = -1;
|
|
|
|
}
|
|
|
|
|
2017-11-29 11:00:50 +01:00
|
|
|
EEVEE_ObjectEngineData *EEVEE_object_data_get(Object *ob)
|
|
|
|
{
|
2018-01-29 16:28:24 +01:00
|
|
|
if (ELEM(ob->type, OB_LIGHTPROBE, OB_LAMP)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-10 14:14:55 +02:00
|
|
|
return (EEVEE_ObjectEngineData *)DRW_drawdata_get(
|
|
|
|
&ob->id, &draw_engine_eevee_type);
|
2017-11-29 11:00:50 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_ObjectEngineData *EEVEE_object_data_ensure(Object *ob)
|
2017-06-03 00:53:47 +02:00
|
|
|
{
|
2018-01-29 16:28:24 +01:00
|
|
|
BLI_assert(!ELEM(ob->type, OB_LIGHTPROBE, OB_LAMP));
|
2018-07-10 14:14:55 +02:00
|
|
|
return (EEVEE_ObjectEngineData *)DRW_drawdata_ensure(
|
|
|
|
&ob->id,
|
2018-01-29 16:28:24 +01:00
|
|
|
&draw_engine_eevee_type,
|
|
|
|
sizeof(EEVEE_ObjectEngineData),
|
|
|
|
eevee_object_data_init,
|
|
|
|
NULL);
|
|
|
|
}
|
2017-06-03 00:53:47 +02:00
|
|
|
|
2018-01-29 16:28:24 +01:00
|
|
|
/* Light probe data. */
|
|
|
|
|
2018-07-10 14:14:55 +02:00
|
|
|
static void eevee_lightprobe_data_init(DrawData *dd)
|
2018-01-29 16:28:24 +01:00
|
|
|
{
|
2018-07-10 14:14:55 +02:00
|
|
|
EEVEE_LightProbeEngineData *ped = (EEVEE_LightProbeEngineData *)dd;
|
|
|
|
ped->need_update = false;
|
2017-06-03 00:53:47 +02:00
|
|
|
}
|
|
|
|
|
2017-11-29 11:00:50 +01:00
|
|
|
EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_get(Object *ob)
|
|
|
|
{
|
2018-01-29 16:28:24 +01:00
|
|
|
if (ob->type != OB_LIGHTPROBE) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-10 14:14:55 +02:00
|
|
|
return (EEVEE_LightProbeEngineData *)DRW_drawdata_get(
|
|
|
|
&ob->id, &draw_engine_eevee_type);
|
2017-11-29 11:00:50 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 10:36:58 +01:00
|
|
|
EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_ensure(Object *ob)
|
2017-06-08 21:48:50 +02:00
|
|
|
{
|
2018-01-29 16:28:24 +01:00
|
|
|
BLI_assert(ob->type == OB_LIGHTPROBE);
|
2018-07-10 14:14:55 +02:00
|
|
|
return (EEVEE_LightProbeEngineData *)DRW_drawdata_ensure(
|
|
|
|
&ob->id,
|
2018-01-29 16:28:24 +01:00
|
|
|
&draw_engine_eevee_type,
|
|
|
|
sizeof(EEVEE_LightProbeEngineData),
|
2018-01-30 13:14:17 +11:00
|
|
|
eevee_lightprobe_data_init,
|
2018-07-10 14:14:55 +02:00
|
|
|
NULL);
|
2018-01-29 16:28:24 +01:00
|
|
|
}
|
2017-06-08 21:48:50 +02:00
|
|
|
|
2019-02-27 10:46:48 +11:00
|
|
|
/* Light data. */
|
2017-06-08 21:48:50 +02:00
|
|
|
|
2019-02-27 12:02:02 +11:00
|
|
|
static void eevee_light_data_init(DrawData *dd)
|
2018-01-29 16:28:24 +01:00
|
|
|
{
|
2019-02-27 12:02:02 +11:00
|
|
|
EEVEE_LightEngineData *led = (EEVEE_LightEngineData *)dd;
|
2018-01-29 16:28:24 +01:00
|
|
|
led->need_update = true;
|
|
|
|
led->prev_cube_shadow_id = -1;
|
2017-06-08 21:48:50 +02:00
|
|
|
}
|
|
|
|
|
2019-02-27 12:02:02 +11:00
|
|
|
EEVEE_LightEngineData *EEVEE_light_data_get(Object *ob)
|
2017-11-29 11:00:50 +01:00
|
|
|
{
|
2018-01-29 16:28:24 +01:00
|
|
|
if (ob->type != OB_LAMP) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-02-27 12:02:02 +11:00
|
|
|
return (EEVEE_LightEngineData *)DRW_drawdata_get(
|
2018-07-10 14:14:55 +02:00
|
|
|
&ob->id, &draw_engine_eevee_type);
|
2017-11-29 11:00:50 +01:00
|
|
|
}
|
|
|
|
|
2019-02-27 12:02:02 +11:00
|
|
|
EEVEE_LightEngineData *EEVEE_light_data_ensure(Object *ob)
|
2017-06-03 00:53:47 +02:00
|
|
|
{
|
2018-01-29 16:28:24 +01:00
|
|
|
BLI_assert(ob->type == OB_LAMP);
|
2019-02-27 12:02:02 +11:00
|
|
|
return (EEVEE_LightEngineData *)DRW_drawdata_ensure(
|
2018-07-10 14:14:55 +02:00
|
|
|
&ob->id,
|
2018-01-29 16:28:24 +01:00
|
|
|
&draw_engine_eevee_type,
|
2019-02-27 12:02:02 +11:00
|
|
|
sizeof(EEVEE_LightEngineData),
|
|
|
|
eevee_light_data_init,
|
2018-01-29 16:28:24 +01:00
|
|
|
NULL);
|
2017-06-03 00:53:47 +02:00
|
|
|
}
|
2018-07-10 14:14:55 +02:00
|
|
|
|
|
|
|
/* World data. */
|
|
|
|
|
|
|
|
static void eevee_world_data_init(DrawData *dd)
|
|
|
|
{
|
|
|
|
EEVEE_WorldEngineData *wed = (EEVEE_WorldEngineData *)dd;
|
|
|
|
wed->dd.recalc |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EEVEE_WorldEngineData *EEVEE_world_data_get(World *wo)
|
|
|
|
{
|
|
|
|
return (EEVEE_WorldEngineData *)DRW_drawdata_get(
|
|
|
|
&wo->id, &draw_engine_eevee_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
EEVEE_WorldEngineData *EEVEE_world_data_ensure(World *wo)
|
|
|
|
{
|
|
|
|
return (EEVEE_WorldEngineData *)DRW_drawdata_ensure(
|
|
|
|
&wo->id,
|
|
|
|
&draw_engine_eevee_type,
|
|
|
|
sizeof(EEVEE_WorldEngineData),
|
|
|
|
eevee_world_data_init,
|
|
|
|
NULL);
|
|
|
|
}
|