Refactor: move LightCache .blend I/O to eevee_lightcache.c
Ref T76372.
This commit is contained in:
@@ -3894,47 +3894,6 @@ static void lib_link_sequence_modifiers(BlendLibReader *reader, Scene *scene, Li
|
||||
}
|
||||
}
|
||||
|
||||
static void direct_link_lightcache_texture(BlendDataReader *reader, LightCacheTexture *lctex)
|
||||
{
|
||||
lctex->tex = NULL;
|
||||
|
||||
if (lctex->data) {
|
||||
BLO_read_data_address(reader, &lctex->data);
|
||||
if (lctex->data && BLO_read_requires_endian_switch(reader)) {
|
||||
int data_size = lctex->components * lctex->tex_size[0] * lctex->tex_size[1] *
|
||||
lctex->tex_size[2];
|
||||
|
||||
if (lctex->data_type == LIGHTCACHETEX_FLOAT) {
|
||||
BLI_endian_switch_float_array((float *)lctex->data, data_size * sizeof(float));
|
||||
}
|
||||
else if (lctex->data_type == LIGHTCACHETEX_UINT) {
|
||||
BLI_endian_switch_uint32_array((uint *)lctex->data, data_size * sizeof(uint));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lctex->data == NULL) {
|
||||
zero_v3_int(lctex->tex_size);
|
||||
}
|
||||
}
|
||||
|
||||
static void direct_link_lightcache(BlendDataReader *reader, LightCache *cache)
|
||||
{
|
||||
cache->flag &= ~LIGHTCACHE_NOT_USABLE;
|
||||
direct_link_lightcache_texture(reader, &cache->cube_tx);
|
||||
direct_link_lightcache_texture(reader, &cache->grid_tx);
|
||||
|
||||
if (cache->cube_mips) {
|
||||
BLO_read_data_address(reader, &cache->cube_mips);
|
||||
for (int i = 0; i < cache->mips_len; i++) {
|
||||
direct_link_lightcache_texture(reader, &cache->cube_mips[i]);
|
||||
}
|
||||
}
|
||||
|
||||
BLO_read_data_address(reader, &cache->cube_data);
|
||||
BLO_read_data_address(reader, &cache->grid_data);
|
||||
}
|
||||
|
||||
/* check for cyclic set-scene,
|
||||
* libs can cause this case which is normally prevented, see (T#####) */
|
||||
#define USE_SETSCENE_CHECK
|
||||
@@ -4512,7 +4471,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce)
|
||||
/* else try to read the cache from file. */
|
||||
BLO_read_data_address(reader, &sce->eevee.light_cache_data);
|
||||
if (sce->eevee.light_cache_data) {
|
||||
direct_link_lightcache(reader, sce->eevee.light_cache_data);
|
||||
EEVEE_lightcache_blend_read_data(reader, sce->eevee.light_cache_data);
|
||||
}
|
||||
}
|
||||
EEVEE_lightcache_info_update(&sce->eevee);
|
||||
|
||||
@@ -170,6 +170,8 @@
|
||||
|
||||
#include "SEQ_sequencer.h"
|
||||
|
||||
#include "engines/eevee/eevee_lightcache.h"
|
||||
|
||||
#include "readfile.h"
|
||||
|
||||
#include <errno.h>
|
||||
@@ -1322,41 +1324,6 @@ static void write_view_settings(BlendWriter *writer, ColorManagedViewSettings *v
|
||||
}
|
||||
}
|
||||
|
||||
static void write_lightcache_texture(BlendWriter *writer, LightCacheTexture *tex)
|
||||
{
|
||||
if (tex->data) {
|
||||
size_t data_size = tex->components * tex->tex_size[0] * tex->tex_size[1] * tex->tex_size[2];
|
||||
if (tex->data_type == LIGHTCACHETEX_FLOAT) {
|
||||
data_size *= sizeof(float);
|
||||
}
|
||||
else if (tex->data_type == LIGHTCACHETEX_UINT) {
|
||||
data_size *= sizeof(uint);
|
||||
}
|
||||
|
||||
/* FIXME: We can't save more than what 32bit systems can handle.
|
||||
* The solution would be to split the texture but it is too late for 2.90. (see T78529) */
|
||||
if (data_size < INT_MAX) {
|
||||
BLO_write_raw(writer, data_size, tex->data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void write_lightcache(BlendWriter *writer, LightCache *cache)
|
||||
{
|
||||
write_lightcache_texture(writer, &cache->grid_tx);
|
||||
write_lightcache_texture(writer, &cache->cube_tx);
|
||||
|
||||
if (cache->cube_mips) {
|
||||
BLO_write_struct_array(writer, LightCacheTexture, cache->mips_len, cache->cube_mips);
|
||||
for (int i = 0; i < cache->mips_len; i++) {
|
||||
write_lightcache_texture(writer, &cache->cube_mips[i]);
|
||||
}
|
||||
}
|
||||
|
||||
BLO_write_struct_array(writer, LightGridCache, cache->grid_len, cache->grid_data);
|
||||
BLO_write_struct_array(writer, LightProbeCache, cache->cube_len, cache->cube_data);
|
||||
}
|
||||
|
||||
static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address)
|
||||
{
|
||||
if (BLO_write_is_undo(writer)) {
|
||||
@@ -1583,7 +1550,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address)
|
||||
/* Eevee Lightcache */
|
||||
if (sce->eevee.light_cache_data && !BLO_write_is_undo(writer)) {
|
||||
BLO_write_struct(writer, LightCache, sce->eevee.light_cache_data);
|
||||
write_lightcache(writer, sce->eevee.light_cache_data);
|
||||
EEVEE_lightcache_blend_write(writer, sce->eevee.light_cache_data);
|
||||
}
|
||||
|
||||
BKE_screen_view3d_shading_blend_write(writer, &sce->display.shading);
|
||||
|
||||
@@ -25,6 +25,7 @@ set(INC
|
||||
../blenfont
|
||||
../blenkernel
|
||||
../blenlib
|
||||
../blenloader
|
||||
../blentranslation
|
||||
../bmesh
|
||||
../depsgraph
|
||||
@@ -42,6 +43,9 @@ set(INC
|
||||
../../../intern/atomic
|
||||
../../../intern/glew-mx
|
||||
../../../intern/guardedalloc
|
||||
|
||||
# dna_type_offsets.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../makesdna/intern
|
||||
)
|
||||
|
||||
set(SRC
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "BKE_global.h"
|
||||
|
||||
#include "BLI_endian_switch.h"
|
||||
#include "BLI_threads.h"
|
||||
|
||||
#include "DEG_depsgraph_build.h"
|
||||
@@ -47,6 +48,8 @@
|
||||
#include "WM_api.h"
|
||||
#include "WM_types.h"
|
||||
|
||||
#include "BLO_read_write.h"
|
||||
|
||||
#include "wm_window.h"
|
||||
|
||||
/* Rounded to nearest PowerOfTwo */
|
||||
@@ -509,6 +512,82 @@ void EEVEE_lightcache_free(LightCache *lcache)
|
||||
MEM_freeN(lcache);
|
||||
}
|
||||
|
||||
static void write_lightcache_texture(BlendWriter *writer, LightCacheTexture *tex)
|
||||
{
|
||||
if (tex->data) {
|
||||
size_t data_size = tex->components * tex->tex_size[0] * tex->tex_size[1] * tex->tex_size[2];
|
||||
if (tex->data_type == LIGHTCACHETEX_FLOAT) {
|
||||
data_size *= sizeof(float);
|
||||
}
|
||||
else if (tex->data_type == LIGHTCACHETEX_UINT) {
|
||||
data_size *= sizeof(uint);
|
||||
}
|
||||
|
||||
/* FIXME: We can't save more than what 32bit systems can handle.
|
||||
* The solution would be to split the texture but it is too late for 2.90. (see T78529) */
|
||||
if (data_size < INT_MAX) {
|
||||
BLO_write_raw(writer, data_size, tex->data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EEVEE_lightcache_blend_write(BlendWriter *writer, LightCache *cache)
|
||||
{
|
||||
write_lightcache_texture(writer, &cache->grid_tx);
|
||||
write_lightcache_texture(writer, &cache->cube_tx);
|
||||
|
||||
if (cache->cube_mips) {
|
||||
BLO_write_struct_array(writer, LightCacheTexture, cache->mips_len, cache->cube_mips);
|
||||
for (int i = 0; i < cache->mips_len; i++) {
|
||||
write_lightcache_texture(writer, &cache->cube_mips[i]);
|
||||
}
|
||||
}
|
||||
|
||||
BLO_write_struct_array(writer, LightGridCache, cache->grid_len, cache->grid_data);
|
||||
BLO_write_struct_array(writer, LightProbeCache, cache->cube_len, cache->cube_data);
|
||||
}
|
||||
|
||||
static void direct_link_lightcache_texture(BlendDataReader *reader, LightCacheTexture *lctex)
|
||||
{
|
||||
lctex->tex = NULL;
|
||||
|
||||
if (lctex->data) {
|
||||
BLO_read_data_address(reader, &lctex->data);
|
||||
if (lctex->data && BLO_read_requires_endian_switch(reader)) {
|
||||
int data_size = lctex->components * lctex->tex_size[0] * lctex->tex_size[1] *
|
||||
lctex->tex_size[2];
|
||||
|
||||
if (lctex->data_type == LIGHTCACHETEX_FLOAT) {
|
||||
BLI_endian_switch_float_array((float *)lctex->data, data_size * sizeof(float));
|
||||
}
|
||||
else if (lctex->data_type == LIGHTCACHETEX_UINT) {
|
||||
BLI_endian_switch_uint32_array((uint *)lctex->data, data_size * sizeof(uint));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lctex->data == NULL) {
|
||||
zero_v3_int(lctex->tex_size);
|
||||
}
|
||||
}
|
||||
|
||||
void EEVEE_lightcache_blend_read_data(BlendDataReader *reader, LightCache *cache)
|
||||
{
|
||||
cache->flag &= ~LIGHTCACHE_NOT_USABLE;
|
||||
direct_link_lightcache_texture(reader, &cache->cube_tx);
|
||||
direct_link_lightcache_texture(reader, &cache->grid_tx);
|
||||
|
||||
if (cache->cube_mips) {
|
||||
BLO_read_data_address(reader, &cache->cube_mips);
|
||||
for (int i = 0; i < cache->mips_len; i++) {
|
||||
direct_link_lightcache_texture(reader, &cache->cube_mips[i]);
|
||||
}
|
||||
}
|
||||
|
||||
BLO_read_data_address(reader, &cache->cube_data);
|
||||
BLO_read_data_address(reader, &cache->grid_data);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
@@ -30,6 +30,8 @@ struct LightCache;
|
||||
struct Scene;
|
||||
struct SceneEEVEE;
|
||||
struct ViewLayer;
|
||||
struct BlendWriter;
|
||||
struct BlendDataReader;
|
||||
|
||||
/* Light Bake */
|
||||
struct wmJob *EEVEE_lightbake_job_create(struct wmWindowManager *wm,
|
||||
@@ -61,3 +63,6 @@ struct LightCache *EEVEE_lightcache_create(const int grid_len,
|
||||
void EEVEE_lightcache_free(struct LightCache *lcache);
|
||||
bool EEVEE_lightcache_load(struct LightCache *lcache);
|
||||
void EEVEE_lightcache_info_update(struct SceneEEVEE *eevee);
|
||||
|
||||
void EEVEE_lightcache_blend_write(struct BlendWriter *writer, struct LightCache *cache);
|
||||
void EEVEE_lightcache_blend_read_data(struct BlendDataReader *reader, struct LightCache *cache);
|
||||
|
||||
Reference in New Issue
Block a user