diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_codegen.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 05c459b703d..cc4b092a071 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -59,6 +59,10 @@ extern char datatoc_gpu_shader_material_glsl[]; extern char datatoc_gpu_shader_vertex_glsl[]; + +static char *glsl_material_library = NULL; + + /* structs and defines */ static const char* GPU_DATATYPE_STR[17] = {"", "float", "vec2", "vec3", "vec4", @@ -229,7 +233,7 @@ GPUFunction *GPU_lookup_function(const char *name) { if(!FUNCTION_HASH) { FUNCTION_HASH = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "GPU_lookup_function gh"); - gpu_parse_functions_string(FUNCTION_HASH, datatoc_gpu_shader_material_glsl); + 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);*/ } @@ -248,6 +252,9 @@ void GPU_extensions_exit(void) BLI_ghash_free(FUNCTION_HASH, NULL, (GHashValFreeFP)MEM_freeN); FUNCTION_HASH = NULL; } + + if(glsl_material_library) + MEM_freeN(glsl_material_library); /*if(FUNCTION_PROTOTYPES) { MEM_freeN(FUNCTION_PROTOTYPES); FUNCTION_PROTOTYPES = NULL; @@ -640,6 +647,35 @@ static char *code_generate_vertex(ListBase *nodes) return code; } +int GPU_bicubic_bump_support(void){ + return GLEW_ARB_texture_gather && GLEW_ARB_texture_query_lod && GLEW_VERSION_3_0; +} + +void GPU_code_generate_glsl_lib(void){ + DynStr *ds; + + /* only initialize the library once */ + if(glsl_material_library) + return; + + ds = BLI_dynstr_new(); + + if(GPU_bicubic_bump_support()){ + BLI_dynstr_append(ds, "/* These are needed for high quality bump mapping */\n" + "#version 130\n" + "#extension GL_ARB_texture_gather: enable\n" + "#extension GL_ARB_texture_query_lod: enable\n" + "#define BUMP_BICUBIC\n"); + } + BLI_dynstr_append(ds, datatoc_gpu_shader_material_glsl); + + + glsl_material_library = BLI_dynstr_get_cstring(ds); + + BLI_dynstr_free(ds); +} + + /* GPU pass binding/unbinding */ GPUShader *GPU_pass_shader(GPUPass *pass) @@ -1318,7 +1354,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, datatoc_gpu_shader_material_glsl); /*FUNCTION_LIB);*/ + shader = GPU_shader_create(vertexcode, fragmentcode, glsl_material_library); /*FUNCTION_LIB);*/ /* failed? */ if (!shader) { @@ -1335,7 +1371,7 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, GPUVertexAttri pass->shader = shader; pass->fragmentcode = fragmentcode; pass->vertexcode = vertexcode; - pass->libcode = datatoc_gpu_shader_material_glsl; + pass->libcode = glsl_material_library; /* extract dynamic inputs and throw away nodes */ GPU_nodes_extract_dynamic_inputs(pass, nodes); |