diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-07-27 11:16:30 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-07-27 11:18:13 +0300 |
commit | e977fe985f019b7b28c022ffb0ca8fb37f6418ee (patch) | |
tree | b5df0659b64279839bc67c06c2f70e4532bd3f5d /intern/cycles/render | |
parent | fe8d8aa27e26f1f8e4d5e1e3fcb6fc6288ebf226 (diff) |
Cycles: Cleanup in image manager, switch statement instead of if-else
Allows to catch enumerator values which are missing from being handled.
Also use `const char*`, no need to construct string just to throw it away.
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/image.cpp | 36 | ||||
-rw-r--r-- | intern/cycles/render/image.h | 2 |
2 files changed, 19 insertions, 19 deletions
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp index 27d6ae78289..854eddac716 100644 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@ -253,24 +253,23 @@ int ImageManager::flattened_slot_to_type_index(int flat_slot, ImageDataType *typ return flat_slot >> IMAGE_DATA_TYPE_SHIFT; } -string ImageManager::name_from_type(int type) +const char* ImageManager::name_from_type(ImageDataType type) { - if(type == IMAGE_DATA_TYPE_FLOAT4) - return "float4"; - else if(type == IMAGE_DATA_TYPE_FLOAT) - return "float"; - else if(type == IMAGE_DATA_TYPE_BYTE) - return "byte"; - else if(type == IMAGE_DATA_TYPE_HALF4) - return "half4"; - else if(type == IMAGE_DATA_TYPE_HALF) - return "half"; - else if(type == IMAGE_DATA_TYPE_USHORT) - return "ushort"; - else if(type == IMAGE_DATA_TYPE_USHORT4) - return "ushort4"; - else - return "byte4"; + switch(type) { + case IMAGE_DATA_TYPE_FLOAT4: return "float4"; + case IMAGE_DATA_TYPE_BYTE4: return "byte4"; + case IMAGE_DATA_TYPE_HALF4: return "half4"; + case IMAGE_DATA_TYPE_FLOAT: return "float"; + case IMAGE_DATA_TYPE_BYTE: return "byte"; + case IMAGE_DATA_TYPE_HALF: return "half"; + case IMAGE_DATA_TYPE_USHORT4: return "ushort4"; + case IMAGE_DATA_TYPE_USHORT: return "ushort"; + case IMAGE_DATA_NUM_TYPES: + assert(!"System enumerator type, should never be used"); + return ""; + } + assert(!"Unhandled image data type"); + return ""; } static bool image_equals(ImageManager::Image *image, @@ -732,7 +731,8 @@ void ImageManager::device_load_image(Device *device, /* Slot assignment */ int flat_slot = type_index_to_flattened_slot(slot, type); - img->mem_name = string_printf("__tex_image_%s_%03d", name_from_type(type).c_str(), flat_slot); + img->mem_name = string_printf("__tex_image_%s_%03d", + name_from_type(type), flat_slot); /* Free previous texture in slot. */ if(img->mem) { diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h index 5932c24cb74..627ad3ce6aa 100644 --- a/intern/cycles/render/image.h +++ b/intern/cycles/render/image.h @@ -152,7 +152,7 @@ private: int max_flattened_slot(ImageDataType type); int type_index_to_flattened_slot(int slot, ImageDataType type); int flattened_slot_to_type_index(int flat_slot, ImageDataType *type); - string name_from_type(int type); + const char* name_from_type(ImageDataType type); void device_load_image(Device *device, Scene *scene, |