diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_codegen.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 4432627ee7e..840b16a4567 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -68,6 +68,9 @@ static char *glsl_material_library = NULL; static const char* GPU_DATATYPE_STR[17] = {"", "float", "vec2", "vec3", "vec4", NULL, NULL, NULL, NULL, "mat3", NULL, NULL, NULL, NULL, NULL, NULL, "mat4"}; +#define LINK_IMAGE_BLENDER 1 +#define LINK_IMAGE_PREVIEW 2 + /* GLSL code parsing for finding function definitions. * These are stored in a hash for lookup when creating a material. */ @@ -194,7 +197,7 @@ static char *gpu_generate_function_prototyps(GHash *hash) * generated code, to avoid have to add the actual code & recompile all */ ghi = BLI_ghashIterator_new(hash); - for (; !BLI_ghashIterator_isDone(ghi); BLI_ghashIterator_step(ghi)) { + for (; BLI_ghashIterator_notDone(ghi); BLI_ghashIterator_step(ghi)) { name = BLI_ghashIterator_getValue(ghi); function = BLI_ghashIterator_getValue(ghi); @@ -234,8 +237,6 @@ GPUFunction *GPU_lookup_function(const char *name) if (!FUNCTION_HASH) { FUNCTION_HASH = BLI_ghash_str_new("GPU_lookup_function gh"); gpu_parse_functions_string(FUNCTION_HASH, glsl_material_library); - /*FUNCTION_PROTOTYPES = gpu_generate_function_prototyps(FUNCTION_HASH); - FUNCTION_LIB = GPU_shader_create_lib(datatoc_gpu_shader_material_glsl);*/ } return (GPUFunction*)BLI_ghash_lookup(FUNCTION_HASH, (void *)name); @@ -339,7 +340,7 @@ static int codegen_input_has_texture(GPUInput *input) { if (input->link) return 0; - else if (input->ima) + else if (input->ima || input->prv) return 1; else return input->tex != NULL; @@ -411,6 +412,17 @@ static void codegen_set_unique_ids(ListBase *nodes) else input->texid = GET_INT_FROM_POINTER(BLI_ghash_lookup(bindhash, 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 = 1; + 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)); + } else { if (!BLI_ghash_haskey(bindhash, input->tex)) { /* input is user created texture, check tex pointer */ @@ -718,7 +730,7 @@ static void GPU_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes) continue; } - if (input->ima || input->tex) + if (input->ima || input->tex || input->prv) BLI_snprintf(input->shadername, sizeof(input->shadername), "samp%d", input->texid); else BLI_snprintf(input->shadername, sizeof(input->shadername), "unf%d", input->id); @@ -726,7 +738,7 @@ static void GPU_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes) /* pass non-dynamic uniforms to opengl */ extract = 0; - if (input->ima || input->tex) { + if (input->ima || input->tex || input->prv) { if (input->bindtex) extract = 1; } @@ -744,7 +756,7 @@ static void GPU_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes) } } - GPU_shader_unbind(shader); + GPU_shader_unbind(); } void GPU_pass_bind(GPUPass *pass, double time, int mipmap) @@ -762,11 +774,14 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap) for (input=inputs->first; input; input=input->next) { if (input->ima) input->tex = GPU_texture_from_blender(input->ima, input->iuser, input->image_isdata, time, mipmap); + else if (input->prv) + input->tex = GPU_texture_from_preview(input->prv, mipmap); if (input->tex && input->bindtex) { GPU_texture_bind(input->tex, input->texid); GPU_shader_uniform_texture(shader, input->shaderloc, input->tex); } + } } @@ -781,7 +796,7 @@ void GPU_pass_update_uniforms(GPUPass *pass) /* pass dynamic inputs to opengl, others were removed */ for (input=inputs->first; input; input=input->next) - if (!(input->ima || input->tex)) + if (!(input->ima || input->tex || input->prv)) GPU_shader_uniform_vector(shader, input->shaderloc, input->type, 1, input->dynamicvec); } @@ -799,11 +814,11 @@ void GPU_pass_unbind(GPUPass *pass) if (input->tex && input->bindtex) GPU_texture_unbind(input->tex); - if (input->ima) + if (input->ima || input->prv) input->tex = NULL; } - GPU_shader_unbind(shader); + GPU_shader_unbind(); } /* Node Link Functions */ @@ -915,9 +930,13 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type) input->type = GPU_VEC4; input->source = GPU_SOURCE_TEX; - input->ima = link->ptr1; - input->iuser = link->ptr2; - input->image_isdata = link->image_isdata; + if (link->image == LINK_IMAGE_PREVIEW) + input->prv = link->ptr1; + else { + input->ima = link->ptr1; + input->iuser = link->ptr2; + input->image_isdata = link->image_isdata; + } input->textarget = GL_TEXTURE_2D; input->textype = GPU_TEX2D; MEM_freeN(link); @@ -1117,7 +1136,7 @@ GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, int isdata) { GPUNodeLink *link = GPU_node_link_create(0); - link->image= 1; + link->image= LINK_IMAGE_BLENDER; link->ptr1= ima; link->ptr2= iuser; link->image_isdata= isdata; @@ -1125,6 +1144,17 @@ GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, int isdata) return link; } +GPUNodeLink *GPU_image_preview(PreviewImage *prv) +{ + GPUNodeLink *link = GPU_node_link_create(0); + + link->image= LINK_IMAGE_PREVIEW; + link->ptr1= prv; + + return link; +} + + GPUNodeLink *GPU_texture(int size, float *pixels) { GPUNodeLink *link = GPU_node_link_create(0); @@ -1336,7 +1366,7 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, GPUVertexAttri /* generate code and compile with opengl */ fragmentcode = code_generate_fragment(nodes, outlink->output, name); vertexcode = code_generate_vertex(nodes); - shader = GPU_shader_create(vertexcode, fragmentcode, glsl_material_library); /*FUNCTION_LIB);*/ + shader = GPU_shader_create(vertexcode, fragmentcode, glsl_material_library, NULL); /* failed? */ if (!shader) { |