diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/blenkernel/intern/shader_fx.c | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/blenkernel/intern/shader_fx.c')
-rw-r--r-- | source/blender/blenkernel/intern/shader_fx.c | 215 |
1 files changed, 113 insertions, 102 deletions
diff --git a/source/blender/blenkernel/intern/shader_fx.c b/source/blender/blenkernel/intern/shader_fx.c index 6bd120f64a9..98dbc3fc989 100644 --- a/source/blender/blenkernel/intern/shader_fx.c +++ b/source/blender/blenkernel/intern/shader_fx.c @@ -21,7 +21,6 @@ * \ingroup bke */ - #include <stdio.h> #include "MEM_guardedalloc.h" @@ -50,7 +49,7 @@ #include "FX_shader_types.h" -static ShaderFxTypeInfo *shader_fx_types[NUM_SHADER_FX_TYPES] = { NULL }; +static ShaderFxTypeInfo *shader_fx_types[NUM_SHADER_FX_TYPES] = {NULL}; /* *************************************************** */ /* Methods - Evaluation Loops, etc. */ @@ -58,181 +57,193 @@ static ShaderFxTypeInfo *shader_fx_types[NUM_SHADER_FX_TYPES] = { NULL }; /* check if exist grease pencil effects */ bool BKE_shaderfx_has_gpencil(Object *ob) { - ShaderFxData *fx; - for (fx = ob->shader_fx.first; fx; fx = fx->next) { - const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); - if (fxi->type == eShaderFxType_GpencilType) { - return true; - } - } - return false; + ShaderFxData *fx; + for (fx = ob->shader_fx.first; fx; fx = fx->next) { + const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); + if (fxi->type == eShaderFxType_GpencilType) { + return true; + } + } + return false; } void BKE_shaderfx_init(void) { - /* Initialize shaders */ - shaderfx_type_init(shader_fx_types); /* FX_shader_util.c */ + /* Initialize shaders */ + shaderfx_type_init(shader_fx_types); /* FX_shader_util.c */ } ShaderFxData *BKE_shaderfx_new(int type) { - const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(type); - ShaderFxData *fx = MEM_callocN(fxi->struct_size, fxi->struct_name); + const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(type); + ShaderFxData *fx = MEM_callocN(fxi->struct_size, fxi->struct_name); - /* note, this name must be made unique later */ - BLI_strncpy(fx->name, DATA_(fxi->name), sizeof(fx->name)); + /* note, this name must be made unique later */ + BLI_strncpy(fx->name, DATA_(fxi->name), sizeof(fx->name)); - fx->type = type; - fx->mode = eShaderFxMode_Realtime | eShaderFxMode_Render | eShaderFxMode_Expanded; - fx->flag = eShaderFxFlag_StaticOverride_Local; + fx->type = type; + fx->mode = eShaderFxMode_Realtime | eShaderFxMode_Render | eShaderFxMode_Expanded; + fx->flag = eShaderFxFlag_StaticOverride_Local; - if (fxi->flags & eShaderFxTypeFlag_EnableInEditmode) - fx->mode |= eShaderFxMode_Editmode; + if (fxi->flags & eShaderFxTypeFlag_EnableInEditmode) + fx->mode |= eShaderFxMode_Editmode; - if (fxi->initData) fxi->initData(fx); + if (fxi->initData) + fxi->initData(fx); - return fx; + return fx; } -static void shaderfx_free_data_id_us_cb(void *UNUSED(userData), Object *UNUSED(ob), ID **idpoin, int cb_flag) +static void shaderfx_free_data_id_us_cb(void *UNUSED(userData), + Object *UNUSED(ob), + ID **idpoin, + int cb_flag) { - ID *id = *idpoin; - if (id != NULL && (cb_flag & IDWALK_CB_USER) != 0) { - id_us_min(id); - } + ID *id = *idpoin; + if (id != NULL && (cb_flag & IDWALK_CB_USER) != 0) { + id_us_min(id); + } } void BKE_shaderfx_free_ex(ShaderFxData *fx, const int flag) { - const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); + const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); - if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { - if (fxi->foreachIDLink) { - fxi->foreachIDLink(fx, NULL, shaderfx_free_data_id_us_cb, NULL); - } - else if (fxi->foreachObjectLink) { - fxi->foreachObjectLink(fx, NULL, (ShaderFxObjectWalkFunc)shaderfx_free_data_id_us_cb, NULL); - } - } + if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { + if (fxi->foreachIDLink) { + fxi->foreachIDLink(fx, NULL, shaderfx_free_data_id_us_cb, NULL); + } + else if (fxi->foreachObjectLink) { + fxi->foreachObjectLink(fx, NULL, (ShaderFxObjectWalkFunc)shaderfx_free_data_id_us_cb, NULL); + } + } - if (fxi->freeData) fxi->freeData(fx); - if (fx->error) MEM_freeN(fx->error); + if (fxi->freeData) + fxi->freeData(fx); + if (fx->error) + MEM_freeN(fx->error); - MEM_freeN(fx); + MEM_freeN(fx); } void BKE_shaderfx_free(ShaderFxData *fx) { - BKE_shaderfx_free_ex(fx, 0); + BKE_shaderfx_free_ex(fx, 0); } /* check unique name */ bool BKE_shaderfx_unique_name(ListBase *shaders, ShaderFxData *fx) { - if (shaders && fx) { - const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); - return BLI_uniquename(shaders, fx, DATA_(fxi->name), '.', offsetof(ShaderFxData, name), sizeof(fx->name)); - } - return false; + if (shaders && fx) { + const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); + return BLI_uniquename( + shaders, fx, DATA_(fxi->name), '.', offsetof(ShaderFxData, name), sizeof(fx->name)); + } + return false; } bool BKE_shaderfx_dependsOnTime(ShaderFxData *fx) { - const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); + const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); - return fxi->dependsOnTime && fxi->dependsOnTime(fx); + return fxi->dependsOnTime && fxi->dependsOnTime(fx); } const ShaderFxTypeInfo *BKE_shaderfxType_getInfo(ShaderFxType type) { - /* type unsigned, no need to check < 0 */ - if (type < NUM_SHADER_FX_TYPES && shader_fx_types[type]->name[0] != '\0') { - return shader_fx_types[type]; - } - else { - return NULL; - } + /* type unsigned, no need to check < 0 */ + if (type < NUM_SHADER_FX_TYPES && shader_fx_types[type]->name[0] != '\0') { + return shader_fx_types[type]; + } + else { + return NULL; + } } void BKE_shaderfx_copyData_generic(const ShaderFxData *fx_src, ShaderFxData *fx_dst) { - const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx_src->type); + const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx_src->type); - /* fx_dst may have already be fully initialized with some extra allocated data, - * we need to free it now to avoid memleak. */ - if (fxi->freeData) { - fxi->freeData(fx_dst); - } + /* fx_dst may have already be fully initialized with some extra allocated data, + * we need to free it now to avoid memleak. */ + if (fxi->freeData) { + fxi->freeData(fx_dst); + } - const size_t data_size = sizeof(ShaderFxData); - const char *fx_src_data = ((const char *)fx_src) + data_size; - char *fx_dst_data = ((char *)fx_dst) + data_size; - BLI_assert(data_size <= (size_t)fxi->struct_size); - memcpy(fx_dst_data, fx_src_data, (size_t)fxi->struct_size - data_size); + const size_t data_size = sizeof(ShaderFxData); + const char *fx_src_data = ((const char *)fx_src) + data_size; + char *fx_dst_data = ((char *)fx_dst) + data_size; + BLI_assert(data_size <= (size_t)fxi->struct_size); + memcpy(fx_dst_data, fx_src_data, (size_t)fxi->struct_size - data_size); } -static void shaderfx_copy_data_id_us_cb(void *UNUSED(userData), Object *UNUSED(ob), ID **idpoin, int cb_flag) +static void shaderfx_copy_data_id_us_cb(void *UNUSED(userData), + Object *UNUSED(ob), + ID **idpoin, + int cb_flag) { - ID *id = *idpoin; - if (id != NULL && (cb_flag & IDWALK_CB_USER) != 0) { - id_us_plus(id); - } + ID *id = *idpoin; + if (id != NULL && (cb_flag & IDWALK_CB_USER) != 0) { + id_us_plus(id); + } } void BKE_shaderfx_copyData_ex(ShaderFxData *fx, ShaderFxData *target, const int flag) { - const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); + const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); - target->mode = fx->mode; - target->flag = fx->flag; + target->mode = fx->mode; + target->flag = fx->flag; - if (fxi->copyData) { - fxi->copyData(fx, target); - } + if (fxi->copyData) { + fxi->copyData(fx, target); + } - if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { - if (fxi->foreachIDLink) { - fxi->foreachIDLink(target, NULL, shaderfx_copy_data_id_us_cb, NULL); - } - else if (fxi->foreachObjectLink) { - fxi->foreachObjectLink(target, NULL, (ShaderFxObjectWalkFunc)shaderfx_copy_data_id_us_cb, NULL); - } - } + if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { + if (fxi->foreachIDLink) { + fxi->foreachIDLink(target, NULL, shaderfx_copy_data_id_us_cb, NULL); + } + else if (fxi->foreachObjectLink) { + fxi->foreachObjectLink( + target, NULL, (ShaderFxObjectWalkFunc)shaderfx_copy_data_id_us_cb, NULL); + } + } } void BKE_shaderfx_copyData(ShaderFxData *fx, ShaderFxData *target) { - BKE_shaderfx_copyData_ex(fx, target, 0); + BKE_shaderfx_copyData_ex(fx, target, 0); } ShaderFxData *BKE_shaderfx_findByType(Object *ob, ShaderFxType type) { - ShaderFxData *fx = ob->shader_fx.first; + ShaderFxData *fx = ob->shader_fx.first; - for (; fx; fx = fx->next) - if (fx->type == type) - break; + for (; fx; fx = fx->next) + if (fx->type == type) + break; - return fx; + return fx; } void BKE_shaderfx_foreachIDLink(Object *ob, ShaderFxIDWalkFunc walk, void *userData) { - ShaderFxData *fx = ob->shader_fx.first; + ShaderFxData *fx = ob->shader_fx.first; - for (; fx; fx = fx->next) { - const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); + for (; fx; fx = fx->next) { + const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type); - if (fxi->foreachIDLink) fxi->foreachIDLink(fx, ob, walk, userData); - else if (fxi->foreachObjectLink) { - /* each Object can masquerade as an ID, so this should be OK */ - ShaderFxObjectWalkFunc fp = (ShaderFxObjectWalkFunc)walk; - fxi->foreachObjectLink(fx, ob, fp, userData); - } - } + if (fxi->foreachIDLink) + fxi->foreachIDLink(fx, ob, walk, userData); + else if (fxi->foreachObjectLink) { + /* each Object can masquerade as an ID, so this should be OK */ + ShaderFxObjectWalkFunc fp = (ShaderFxObjectWalkFunc)walk; + fxi->foreachObjectLink(fx, ob, fp, userData); + } + } } ShaderFxData *BKE_shaderfx_findByName(Object *ob, const char *name) { - return BLI_findstring(&(ob->shader_fx), name, offsetof(ShaderFxData, name)); + return BLI_findstring(&(ob->shader_fx), name, offsetof(ShaderFxData, name)); } |