Commit: c8663d856aac87aba0b4b1be7e03a08e96b54d44
Author: Nicholas Bishop
Date:   Sat Jan 24 13:25:49 2015 +0100
Branches: cycles-ptex-12
https://developer.blender.org/rBc8663d856aac87aba0b4b1be7e03a08e96b54d44

Temporary squash commit of gpu_codegen.c cleanup

===================================================================

M       source/blender/gpu/GPU_material.h
M       source/blender/gpu/intern/gpu_codegen.c
M       source/blender/gpu/intern/gpu_codegen.h
M       source/blender/gpu/intern/gpu_material.c
M       source/blender/makesdna/DNA_customdata_types.h

===================================================================

diff --git a/source/blender/gpu/GPU_material.h 
b/source/blender/gpu/GPU_material.h
index 09a5653..a65a123 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -32,6 +32,7 @@
 #ifndef __GPU_MATERIAL_H__
 #define __GPU_MATERIAL_H__
 
+#include "DNA_customdata_types.h" /* for CustomDataType */
 #include "DNA_listBase.h"
 
 #include "BLI_sys_types.h" /* for bool */
@@ -68,6 +69,7 @@ typedef struct GPULamp GPULamp;
 /* Functions to create GPU Materials nodes */
 
 typedef enum GPUType {
+       /* The value indicates the number of elements in each type */
        GPU_NONE = 0,
        GPU_FLOAT = 1,
        GPU_VEC2 = 2,
@@ -75,6 +77,7 @@ typedef enum GPUType {
        GPU_VEC4 = 4,
        GPU_MAT3 = 9,
        GPU_MAT4 = 16,
+
        GPU_TEX2D = 1002,
        GPU_SHADOW2D = 1003,
        GPU_ATTRIB = 3001
@@ -120,13 +123,40 @@ typedef struct GPUNodeStack {
        short sockettype;
 } GPUNodeStack;
 
-GPUNodeLink *GPU_attribute(int type, const char *name);
+typedef enum GPUDynamicType {
+       GPU_DYNAMIC_NONE = 0,
+       GPU_DYNAMIC_OBJECT_VIEWMAT = 1,
+       GPU_DYNAMIC_OBJECT_MAT = 2,
+       GPU_DYNAMIC_OBJECT_VIEWIMAT = 3,
+       GPU_DYNAMIC_OBJECT_IMAT = 4,
+       GPU_DYNAMIC_OBJECT_COLOR = 5,
+       GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE = 15,
+
+       GPU_DYNAMIC_LAMP_FIRST = 6,
+       GPU_DYNAMIC_LAMP_DYNVEC = 6,
+       GPU_DYNAMIC_LAMP_DYNCO = 7,
+       GPU_DYNAMIC_LAMP_DYNIMAT = 8,
+       GPU_DYNAMIC_LAMP_DYNPERSMAT = 9,
+       GPU_DYNAMIC_LAMP_DYNENERGY = 10,
+       GPU_DYNAMIC_LAMP_DYNCOL = 11,
+       GPU_DYNAMIC_LAMP_LAST = 11,
+       GPU_DYNAMIC_SAMPLER_2DBUFFER = 12,
+       GPU_DYNAMIC_SAMPLER_2DIMAGE = 13,
+       GPU_DYNAMIC_SAMPLER_2DSHADOW = 14,
+       GPU_DYNAMIC_LAMP_DISTANCE = 16,
+       GPU_DYNAMIC_LAMP_ATT1 = 17,
+       GPU_DYNAMIC_LAMP_ATT2 = 18,
+       GPU_DYNAMIC_LAMP_SPOTSIZE = 19,
+       GPU_DYNAMIC_LAMP_SPOTBLEND = 20,
+} GPUDynamicType;
+
+GPUNodeLink *GPU_attribute(CustomDataType type, const char *name);
 GPUNodeLink *GPU_uniform(float *num);
-GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data);
+GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void 
*data);
 GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, bool 
is_data);
 GPUNodeLink *GPU_image_preview(struct PreviewImage *prv);
 GPUNodeLink *GPU_texture(int size, float *pixels);
-GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, int dynamictype, void 
*data);
+GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, GPUDynamicType 
dynamictype, void *data);
 GPUNodeLink *GPU_builtin(GPUBuiltin builtin);
 GPUNodeLink *GPU_opengl_builtin(GPUOpenGLBuiltin builtin);
 
@@ -180,33 +210,6 @@ void GPU_shaderesult_set(GPUShadeInput *shi, 
GPUShadeResult *shr);
 
 /* Export GLSL shader */
 
-typedef enum GPUDynamicType {
-       GPU_DYNAMIC_NONE = 0,
-       GPU_DYNAMIC_OBJECT_VIEWMAT = 1,
-       GPU_DYNAMIC_OBJECT_MAT = 2,
-       GPU_DYNAMIC_OBJECT_VIEWIMAT = 3,
-       GPU_DYNAMIC_OBJECT_IMAT = 4,
-       GPU_DYNAMIC_OBJECT_COLOR = 5,
-       GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE = 15,
-
-       GPU_DYNAMIC_LAMP_FIRST = 6,
-       GPU_DYNAMIC_LAMP_DYNVEC = 6,
-       GPU_DYNAMIC_LAMP_DYNCO = 7,
-       GPU_DYNAMIC_LAMP_DYNIMAT = 8,
-       GPU_DYNAMIC_LAMP_DYNPERSMAT = 9,
-       GPU_DYNAMIC_LAMP_DYNENERGY = 10,
-       GPU_DYNAMIC_LAMP_DYNCOL = 11,
-       GPU_DYNAMIC_LAMP_LAST = 11,
-       GPU_DYNAMIC_SAMPLER_2DBUFFER = 12,
-       GPU_DYNAMIC_SAMPLER_2DIMAGE = 13,
-       GPU_DYNAMIC_SAMPLER_2DSHADOW = 14,
-       GPU_DYNAMIC_LAMP_DISTANCE = 16,
-       GPU_DYNAMIC_LAMP_ATT1 = 17,
-       GPU_DYNAMIC_LAMP_ATT2 = 18,
-       GPU_DYNAMIC_LAMP_SPOTSIZE = 19,
-       GPU_DYNAMIC_LAMP_SPOTBLEND = 20,
-} GPUDynamicType;
-
 typedef enum GPUDataType {
        GPU_DATA_NONE = 0,
        GPU_DATA_1I = 1,        // 1 integer
diff --git a/source/blender/gpu/intern/gpu_codegen.c 
b/source/blender/gpu/intern/gpu_codegen.c
index 1f9efdc..56a753f 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -62,14 +62,32 @@ extern char datatoc_gpu_shader_vertex_world_glsl[];
 static char *glsl_material_library = NULL;
 
 
-/* structs and defines */
-
+/* type definitions and constants */
+
+enum {
+       MAX_FUNCTION_NAME = 64
+};
+enum {
+       MAX_PARAMETER = 32
+};
+
+typedef enum {
+       FUNCTION_QUAL_IN,
+       FUNCTION_QUAL_OUT,
+       FUNCTION_QUAL_INOUT
+} GPUFunctionQual;
+
+typedef struct GPUFunction {
+       char name[MAX_FUNCTION_NAME];
+       GPUType paramtype[MAX_PARAMETER];
+       GPUFunctionQual paramqual[MAX_PARAMETER];
+       int totparam;
+} GPUFunction;
+
+/* Indices match the GPUType enum */
 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. */
 
@@ -126,7 +144,9 @@ static char *gpu_str_skip_token(char *str, char *token, int 
max)
 static void gpu_parse_functions_string(GHash *hash, char *code)
 {
        GPUFunction *function;
-       int i, type, qual;
+       GPUType type;
+       GPUFunctionQual qual;
+       int i;
 
        while ((code = strstr(code, "void "))) {
                function = MEM_callocN(sizeof(GPUFunction), "GPUFunction");
@@ -146,7 +166,7 @@ static void gpu_parse_functions_string(GHash *hash, char 
*code)
                                code = gpu_str_skip_token(code, NULL, 0);
 
                        /* test for type */
-                       type= 0;
+                       type= GPU_NONE;
                        for (i=1; i<=16; i++) {
                                if (GPU_DATATYPE_STR[i] && gpu_str_prefix(code, 
GPU_DATATYPE_STR[i])) {
                                        type= i;
@@ -160,7 +180,7 @@ static void gpu_parse_functions_string(GHash *hash, char 
*code)
                                type= GPU_TEX2D;
 
                        if (type) {
-                               /* add paramater */
+                               /* add parameter */
                                code = gpu_str_skip_token(code, NULL, 0);
                                code = gpu_str_skip_token(code, NULL, 0);
                                function->paramqual[function->totparam]= qual;
@@ -231,7 +251,7 @@ static char *gpu_generate_function_prototyps(GHash *hash)
 }
 #endif
 
-GPUFunction *GPU_lookup_function(const char *name)
+static GPUFunction *gpu_lookup_function(const char *name)
 {
        if (!FUNCTION_HASH) {
                FUNCTION_HASH = BLI_ghash_str_new("GPU_lookup_function gh");
@@ -320,7 +340,7 @@ static void codegen_convert_datatype(DynStr *ds, int from, 
int to, const char *t
        }
 }
 
-static void codegen_print_datatype(DynStr *ds, int type, float *data)
+static void codegen_print_datatype(DynStr *ds, const GPUType type, float *data)
 {
        int i;
 
@@ -367,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;
@@ -382,68 +418,43 @@ static void codegen_set_unique_ids(ListBase *nodes)
                for (input=node->inputs.first; input; input=input->next) {
                        /* set id for unique names of uniform variables */
                        input->id = id++;
-                       input->bindtex = 0;
-                       input->definetex = 0;
+                       input->bindtex = false;
+                       input->definetex = false;
 
                        /* set texid used for settings texture slot with 
multitexture */
                        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 = 1;
-                                               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 = 1;
-                                               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 = 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));
+                                       /* 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 = 1;
-                                               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 
*/
                                if (input->source == GPU_SOURCE_TEX_PIXEL) {
                                        if (input->ima) {
                                                if 
(!BLI_ghash_haskey(definehash, input->ima)) {
-                                                       input->definetex = 1;
+                                                       input->definetex = true;
                                                        
BLI_ghash_insert(definehash, input->ima, SET_INT_IN_POINTER(input->texid));
                                                }
                                        }
                                        else {
                                                if 
(!BLI_ghash_haskey(definehash, input->link)) {
-                                                       input->definetex = 1;
+                                                       input->definetex = true;
                                                        BLI_ghash_i

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to