diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_codegen.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 139 |
1 files changed, 25 insertions, 114 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 360f3dbf63f..f02aee8d8af 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -64,101 +64,9 @@ extern char datatoc_gpu_shader_vertex_glsl[]; /* structs and defines */ -typedef enum GPUDataSource { - GPU_SOURCE_VEC_UNIFORM, - GPU_SOURCE_BUILTIN, - GPU_SOURCE_TEX_PIXEL, - GPU_SOURCE_TEX, - GPU_SOURCE_ATTRIB -} GPUDataSource; - static const char* GPU_DATATYPE_STR[17] = {"", "float", "vec2", "vec3", "vec4", NULL, NULL, NULL, NULL, "mat3", NULL, NULL, NULL, NULL, NULL, NULL, "mat4"}; -struct GPUNode { - struct GPUNode *next, *prev; - - const char *name; - int tag; - - ListBase inputs; - ListBase outputs; -}; - -struct GPUNodeLink { - GPUNodeStack *socket; - - int attribtype; - const char *attribname; - - int image; - - int texture; - int texturesize; - - void *ptr1, *ptr2; - - int dynamic; - - int type; - int users; - - GPUTexture *dynamictex; - - GPUBuiltin builtin; - - struct GPUOutput *output; -}; - -typedef struct GPUOutput { - struct GPUOutput *next, *prev; - - GPUNode *node; - int type; /* data type = length of vector/matrix */ - GPUNodeLink *link; /* output link */ - int id; /* unique id as created by code generator */ -} GPUOutput; - -typedef struct GPUInput { - struct GPUInput *next, *prev; - - GPUNode *node; - - int type; /* datatype */ - int source; /* data source */ - - int id; /* unique id as created by code generator */ - int texid; /* number for multitexture */ - int attribid; /* id for vertex attributes */ - int bindtex; /* input is responsible for binding the texture? */ - int definetex; /* input is responsible for defining the pixel? */ - int textarget; /* GL_TEXTURE_* */ - int textype; /* datatype */ - - struct Image *ima; /* image */ - struct ImageUser *iuser;/* image user */ - float *dynamicvec; /* vector data in case it is dynamic */ - GPUTexture *tex; /* input texture, only set at runtime */ - int shaderloc; /* id from opengl */ - char shadername[32]; /* name in shader */ - - float vec[16]; /* vector data */ - GPUNodeLink *link; - int dynamictex; /* dynamic? */ - int attribtype; /* attribute type */ - char attribname[32]; /* attribute name */ - int attribfirst; /* this is the first one that is bound */ - GPUBuiltin builtin; /* builtin uniform */ -} GPUInput; - -struct GPUPass { - struct GPUPass *next, *prev; - - ListBase inputs; - struct GPUOutput *output; - struct GPUShader *shader; -}; - /* GLSL code parsing for finding function definitions. * These are stored in a hash for lookup when creating a material. */ @@ -245,8 +153,6 @@ static void gpu_parse_functions_string(GHash *hash, char *code) if(!type && gpu_str_prefix(code, "sampler2DShadow")) type= GPU_SHADOW2D; - if(!type && gpu_str_prefix(code, "sampler1D")) - type= GPU_TEX1D; if(!type && gpu_str_prefix(code, "sampler2D")) type= GPU_TEX2D; @@ -298,9 +204,7 @@ static char *gpu_generate_function_prototyps(GHash *hash) else if(function->paramqual[a] == FUNCTION_QUAL_INOUT) BLI_dynstr_append(ds, "inout "); - if(function->paramtype[a] == GPU_TEX1D) - BLI_dynstr_append(ds, "sampler1D"); - else if(function->paramtype[a] == GPU_TEX2D) + if(function->paramtype[a] == GPU_TEX2D) BLI_dynstr_append(ds, "sampler2D"); else if(function->paramtype[a] == GPU_SHADOW2D) BLI_dynstr_append(ds, "sampler2DShadow"); @@ -542,7 +446,6 @@ static void codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes) /* create exactly one sampler for each texture */ if (codegen_input_has_texture(input) && input->bindtex) BLI_dynstr_appendf(ds, "uniform %s samp%d;\n", - (input->textype == GPU_TEX1D)? "sampler1D": (input->textype == GPU_TEX2D)? "sampler2D": "sampler2DShadow", input->texid); } @@ -947,6 +850,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type) input->textarget = GL_TEXTURE_2D; input->textype = type; input->dynamictex = 1; + input->dynamicdata = link->ptr2; MEM_freeN(link); } else if(link->texture) { @@ -955,14 +859,9 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type) input->source = GPU_SOURCE_TEX; input->textype = type; - if (type == GPU_TEX1D) { - input->tex = GPU_texture_create_1D(link->texturesize, link->ptr1, NULL); - input->textarget = GL_TEXTURE_1D; - } - else { - input->tex = GPU_texture_create_2D(link->texturesize, link->texturesize, link->ptr2, NULL); - input->textarget = GL_TEXTURE_2D; - } + //input->tex = GPU_texture_create_2D(link->texturesize, link->texturesize, link->ptr2, NULL); + input->tex = GPU_texture_create_2D(link->texturesize, 1, link->ptr1, NULL); + input->textarget = GL_TEXTURE_2D; MEM_freeN(link->ptr1); MEM_freeN(link); @@ -993,8 +892,11 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type) input->source = GPU_SOURCE_VEC_UNIFORM; memcpy(input->vec, link->ptr1, type*sizeof(float)); - if(link->dynamic) + if(link->dynamic) { input->dynamicvec= link->ptr1; + input->dynamictype= link->dynamictype; + input->dynamicdata= link->ptr2; + } MEM_freeN(link); } @@ -1102,12 +1004,12 @@ static void gpu_nodes_get_vertex_attributes(ListBase *nodes, GPUVertexAttribs *a input->attribfirst = 1; attribs->layer[a].type = input->attribtype; - attribs->layer[a].glindex = input->attribid; + attribs->layer[a].attribid = input->attribid; BLI_strncpy(attribs->layer[a].name, input->attribname, sizeof(attribs->layer[a].name)); } else - input->attribid = attribs->layer[a].glindex; + input->attribid = attribs->layer[a].attribid; } } } @@ -1148,13 +1050,15 @@ GPUNodeLink *GPU_uniform(float *num) return link; } -GPUNodeLink *GPU_dynamic_uniform(float *num) +GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data) { GPUNodeLink *link = GPU_node_link_create(0); link->ptr1= num; - link->ptr2= NULL; + link->ptr2= data; link->dynamic= 1; + link->dynamictype = dynamictype; + return link; } @@ -1181,12 +1085,14 @@ GPUNodeLink *GPU_texture(int size, float *pixels) return link; } -GPUNodeLink *GPU_dynamic_texture(GPUTexture *tex) +GPUNodeLink *GPU_dynamic_texture(GPUTexture *tex, int dynamictype, void *data) { GPUNodeLink *link = GPU_node_link_create(0); link->dynamic = 1; link->dynamictex = tex; + link->dynamictype = dynamictype; + link->ptr2 = data; return link; } @@ -1389,8 +1295,6 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, GPUVertexAttri 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);*/ - MEM_freeN(fragmentcode); - MEM_freeN(vertexcode); /* failed? */ if (!shader) { @@ -1405,6 +1309,9 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink, GPUVertexAttri pass->output = outlink->output; pass->shader = shader; + pass->fragmentcode = fragmentcode; + pass->vertexcode = vertexcode; + pass->libcode = datatoc_gpu_shader_material_glsl; /* extract dynamic inputs and throw away nodes */ GPU_nodes_extract_dynamic_inputs(pass, nodes); @@ -1417,6 +1324,10 @@ void GPU_pass_free(GPUPass *pass) { GPU_shader_free(pass->shader); GPU_inputs_free(&pass->inputs); + if (pass->fragmentcode) + MEM_freeN(pass->fragmentcode); + if (pass->vertexcode) + MEM_freeN(pass->vertexcode); MEM_freeN(pass); } |