diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2015-01-24 19:07:38 +0300 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2015-01-26 18:36:10 +0300 |
commit | d44890ee75634052f325531766a661a5bcef628f (patch) | |
tree | a6d2bc91990b7d755dfb023dd38a4f705bb558ac /source/blender | |
parent | c5f5012c5a1b30ee757244782584cab087e22999 (diff) |
Code cleanup: de-duplicate codegen texid assignment
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D1026
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 63 |
1 files changed, 27 insertions, 36 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 9b49d232209..56a753ff768 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -387,6 +387,22 @@ const char *GPU_builtin_name(GPUBuiltin builtin) return ""; } +/* assign only one texid per buffer to avoid sampling the same texture twice */ +static void codegen_set_texid(GHash *bindhash, GPUInput *input, int *texid, void *key) +{ + if (BLI_ghash_haskey(bindhash, key)) { + /* Reuse existing texid */ + input->texid = GET_INT_FROM_POINTER(BLI_ghash_lookup(bindhash, key)); + } + else { + /* Allocate new texid */ + input->texid = *texid; + (*texid)++; + input->bindtex = true; + BLI_ghash_insert(bindhash, key, SET_INT_IN_POINTER(input->texid)); + } +} + static void codegen_set_unique_ids(ListBase *nodes) { GHash *bindhash, *definehash; @@ -409,48 +425,23 @@ static void codegen_set_unique_ids(ListBase *nodes) if (codegen_input_has_texture(input) && ((input->source == GPU_SOURCE_TEX) || (input->source == GPU_SOURCE_TEX_PIXEL))) { + /* assign only one texid per buffer to avoid sampling + * the same texture twice */ if (input->link) { - /* input is texture from buffer, assign only one texid per - * buffer to avoid sampling the same texture twice */ - if (!BLI_ghash_haskey(bindhash, input->link)) { - input->texid = texid++; - input->bindtex = true; - BLI_ghash_insert(bindhash, input->link, SET_INT_IN_POINTER(input->texid)); - } - else - input->texid = GET_INT_FROM_POINTER(BLI_ghash_lookup(bindhash, input->link)); + /* input is texture from buffer */ + codegen_set_texid(bindhash, input, &texid, input->link); } else if (input->ima) { - /* input is texture from image, assign only one texid per - * buffer to avoid sampling the same texture twice */ - if (!BLI_ghash_haskey(bindhash, input->ima)) { - input->texid = texid++; - input->bindtex = true; - BLI_ghash_insert(bindhash, input->ima, SET_INT_IN_POINTER(input->texid)); - } - else - input->texid = GET_INT_FROM_POINTER(BLI_ghash_lookup(bindhash, input->ima)); + /* input is texture from image */ + codegen_set_texid(bindhash, input, &texid, input->ima); } else if (input->prv) { - /* input is texture from preview render, assign only one texid per - * buffer to avoid sampling the same texture twice */ - if (!BLI_ghash_haskey(bindhash, input->prv)) { - input->texid = texid++; - input->bindtex = true; - BLI_ghash_insert(bindhash, input->prv, SET_INT_IN_POINTER(input->texid)); - } - else - input->texid = GET_INT_FROM_POINTER(BLI_ghash_lookup(bindhash, input->prv)); + /* input is texture from preview render */ + codegen_set_texid(bindhash, input, &texid, input->prv); } - else { - if (!BLI_ghash_haskey(bindhash, input->tex)) { - /* input is user created texture, check tex pointer */ - input->texid = texid++; - input->bindtex = true; - BLI_ghash_insert(bindhash, input->tex, SET_INT_IN_POINTER(input->texid)); - } - else - input->texid = GET_INT_FROM_POINTER(BLI_ghash_lookup(bindhash, input->tex)); + else if (input->tex) { + /* input is user created texture, check tex pointer */ + codegen_set_texid(bindhash, input, &texid, input->tex); } /* make sure this pixel is defined exactly once */ |