Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Riakiotakis <kalast@gmail.com>2014-04-02 16:07:45 +0400
committerAntony Riakiotakis <kalast@gmail.com>2014-04-02 16:08:04 +0400
commit965e5039f5d158c7c89d525e83b830f9ad10adc0 (patch)
tree14c65dd638311dcec90f8d9ee56fcb4b738e6310 /source/blender
parent26b2645d62f3f60b0125dcb14a8daa03920a6031 (diff)
Refactor to recent matcap built-ins to not use the built in system.
Those variables would get declared on fragment shader level and since we use reserved opengl variables, some compilers would throw an error (NVIDIA allows, some ATI compilers may break). Instead, use a separate opengl built-in category especially for them. This works on NVIDIA, and will wait for tests of this commit from ATI users.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/gpu/GPU_material.h8
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c39
-rw-r--r--source/blender/gpu/intern/gpu_codegen.h3
-rw-r--r--source/blender/gpu/intern/gpu_material.c2
4 files changed, 40 insertions, 12 deletions
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index 3571b3e2a0d..101fd67af2c 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -85,10 +85,13 @@ typedef enum GPUBuiltin {
GPU_VIEW_NORMAL = 32,
GPU_OBCOLOR = 64,
GPU_AUTO_BUMPSCALE = 128,
- GPU_MATCAP_NORMAL = 256,
- GPU_COLOR = 512,
} GPUBuiltin;
+typedef enum GPUOpenGLBuiltin {
+ GPU_MATCAP_NORMAL = 1,
+ GPU_COLOR = 2,
+} GPUOpenGLBuiltin;
+
typedef enum GPUBlendMode {
GPU_BLEND_SOLID = 0,
GPU_BLEND_ADD = 1,
@@ -115,6 +118,7 @@ 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_builtin(GPUBuiltin builtin);
+GPUNodeLink *GPU_opengl_builtin(GPUOpenGLBuiltin builtin);
bool GPU_link(GPUMaterial *mat, const char *name, ...);
bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...);
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 18b512309bd..2687157d01b 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -365,10 +365,6 @@ const char *GPU_builtin_name(GPUBuiltin builtin)
return "unfobcolor";
else if (builtin == GPU_AUTO_BUMPSCALE)
return "unfobautobumpscale";
- else if (builtin == GPU_MATCAP_NORMAL)
- return "gl_SecondaryColor";
- else if (builtin == GPU_COLOR)
- return "gl_Color";
else
return "";
}
@@ -583,8 +579,15 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
else
BLI_dynstr_appendf(ds, "cons%d", input->id);
}
- else if (input->source == GPU_SOURCE_ATTRIB)
+ else if (input->source == GPU_SOURCE_ATTRIB) {
BLI_dynstr_appendf(ds, "var%d", input->attribid);
+ }
+ else if (input->source == GPU_SOURCE_OPENGL_BUILTIN) {
+ if (input->oglbuiltin == GPU_MATCAP_NORMAL)
+ BLI_dynstr_append(ds, "gl_SecondaryColor");
+ else if (input->oglbuiltin == GPU_COLOR)
+ BLI_dynstr_append(ds, "gl_Color");
+ }
BLI_dynstr_append(ds, ", ");
}
@@ -670,14 +673,14 @@ static char *code_generate_vertex(ListBase *nodes)
BLI_dynstr_appendf(ds, "\tvar%d = att%d;\n", input->attribid, input->attribid);
}
/* unfortunately special handling is needed here because we abuse gl_Color/gl_SecondaryColor flat shading */
- else if (input->source == GPU_SOURCE_BUILTIN) {
- if (input->builtin == GPU_MATCAP_NORMAL) {
+ else if (input->source == GPU_SOURCE_OPENGL_BUILTIN) {
+ if (input->oglbuiltin == GPU_MATCAP_NORMAL) {
/* remap to 0.0 - 1.0 range. This is done because OpenGL 2.0 clamps colors
* between shader stages and we want the full range of the normal */
BLI_dynstr_appendf(ds, "\tvec3 matcapcol = vec3(0.5, 0.5, 0.5) * varnormal + vec3(0.5, 0.5, 0.5);\n");
BLI_dynstr_appendf(ds, "\tgl_FrontSecondaryColor = vec4(matcapcol, 1.0);\n");
}
- else if (input->builtin == GPU_COLOR) {
+ else if (input->oglbuiltin == GPU_COLOR) {
BLI_dynstr_appendf(ds, "\tgl_FrontColor = gl_Color;\n");
}
}
@@ -747,7 +750,8 @@ static void GPU_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
/* attributes don't need to be bound, they already have
* an id that the drawing functions will use */
if (input->source == GPU_SOURCE_ATTRIB ||
- input->source == GPU_SOURCE_BUILTIN)
+ input->source == GPU_SOURCE_BUILTIN ||
+ input->source == GPU_SOURCE_OPENGL_BUILTIN)
{
continue;
}
@@ -915,6 +919,14 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
MEM_freeN(link);
}
+ else if (link->oglbuiltin) {
+ /* builtin uniform */
+ input->type = type;
+ input->source = GPU_SOURCE_OPENGL_BUILTIN;
+ input->oglbuiltin = link->oglbuiltin;
+
+ MEM_freeN(link);
+ }
else if (link->output) {
/* link to a node output */
input->type = type;
@@ -1207,6 +1219,15 @@ GPUNodeLink *GPU_builtin(GPUBuiltin builtin)
return link;
}
+GPUNodeLink *GPU_opengl_builtin(GPUOpenGLBuiltin builtin)
+{
+ GPUNodeLink *link = GPU_node_link_create(0);
+
+ link->oglbuiltin = builtin;
+
+ return link;
+}
+
bool GPU_link(GPUMaterial *mat, const char *name, ...)
{
GPUNode *node;
diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h
index 2e4cfe2e37c..b6db923e5c2 100644
--- a/source/blender/gpu/intern/gpu_codegen.h
+++ b/source/blender/gpu/intern/gpu_codegen.h
@@ -70,6 +70,7 @@ GPUFunction *GPU_lookup_function(const char *name);
typedef enum GPUDataSource {
GPU_SOURCE_VEC_UNIFORM,
GPU_SOURCE_BUILTIN,
+ GPU_SOURCE_OPENGL_BUILTIN,
GPU_SOURCE_TEX_PIXEL,
GPU_SOURCE_TEX,
GPU_SOURCE_ATTRIB
@@ -108,6 +109,7 @@ struct GPUNodeLink {
GPUTexture *dynamictex;
GPUBuiltin builtin;
+ GPUOpenGLBuiltin oglbuiltin;
struct GPUOutput *output;
};
@@ -155,6 +157,7 @@ typedef struct GPUInput {
char attribname[32]; /* attribute name */
int attribfirst; /* this is the first one that is bound */
GPUBuiltin builtin; /* builtin uniform */
+ GPUOpenGLBuiltin oglbuiltin; /* opengl built in varying */
} GPUInput;
struct GPUPass {
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index f512212779d..0f05a7f0cda 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -1535,7 +1535,7 @@ static GPUNodeLink *gpu_material_preview_matcap(GPUMaterial *mat, Material *ma)
* matcap normal holds the normal remapped to the 0.0 - 1.0 range. To take advantage of flat shading, we abuse
* the built in secondary color of opengl. Color is just the regular color, which should include mask value too.
* This also needs flat shading so we use the primary opengl color built-in */
- GPU_link(mat, "material_preview_matcap", GPU_uniform(&ma->r), GPU_image_preview(ma->preview), GPU_builtin(GPU_MATCAP_NORMAL), GPU_builtin(GPU_COLOR), &outlink);
+ GPU_link(mat, "material_preview_matcap", GPU_uniform(&ma->r), GPU_image_preview(ma->preview), GPU_opengl_builtin(GPU_MATCAP_NORMAL), GPU_opengl_builtin(GPU_COLOR), &outlink);
return outlink;
}