summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnuj Phogat <anuj.phogat@gmail.com>2014-05-19 11:47:46 -0700
committerIan Romanick <ian.d.romanick@intel.com>2014-05-23 09:52:29 -0700
commited1ffa0197382253a348e1defcc0b84b0f5865c5 (patch)
tree9a5c6bda3cea10c5d538682973737a12b5c6aab5
parent5d056f51abcc7d79158a744582ead6f1ce1276c8 (diff)
meta: Refactor _mesa_meta_setup_blit_shader() to avoid duplicate shader code
Cc: <mesa-stable@lists.freedesktop.org> Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> (cherry picked from commit bee2915210e53585bca27c9c5f7d7407f61bcc0f)
-rw-r--r--src/mesa/drivers/common/meta.c101
1 files changed, 48 insertions, 53 deletions
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index b194b6e71d5..1b2fe8a764c 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -242,10 +242,30 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
GLenum target,
struct blit_shader_table *table)
{
- const char *vs_source;
- char *fs_source;
+ char *vs_source, *fs_source;
void *const mem_ctx = ralloc_context(NULL);
struct blit_shader *shader = choose_blit_shader(target, table);
+ const char *vs_input, *vs_output, *fs_input, *vs_preprocess, *fs_preprocess;
+ const char *fs_output_var, *fs_output_var_decl;
+
+ if (ctx->Const.GLSLVersion < 130) {
+ vs_preprocess = "";
+ vs_input = "attribute";
+ vs_output = "varying";
+ fs_preprocess = "#extension GL_EXT_texture_array : enable";
+ fs_input = "varying";
+ fs_output_var_decl = "";
+ fs_output_var = "gl_FragColor";
+ } else {
+ vs_preprocess = "#version 130";
+ vs_input = "in";
+ vs_output = "out";
+ fs_preprocess = "#version 130";
+ fs_input = "in";
+ fs_output_var_decl = "out vec4 out_color;";
+ fs_output_var = "out_color";
+ shader->func = "texture";
+ }
assert(shader != NULL);
@@ -254,57 +274,32 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
return;
}
- if (ctx->Const.GLSLVersion < 130) {
- vs_source =
- "attribute vec2 position;\n"
- "attribute vec4 textureCoords;\n"
- "varying vec4 texCoords;\n"
- "void main()\n"
- "{\n"
- " texCoords = textureCoords;\n"
- " gl_Position = vec4(position, 0.0, 1.0);\n"
- "}\n";
-
- fs_source = ralloc_asprintf(mem_ctx,
- "#extension GL_EXT_texture_array : enable\n"
- "#extension GL_ARB_texture_cube_map_array: enable\n"
- "uniform %s texSampler;\n"
- "varying vec4 texCoords;\n"
- "void main()\n"
- "{\n"
- " gl_FragColor = %s(texSampler, %s);\n"
- " gl_FragDepth = gl_FragColor.x;\n"
- "}\n",
- shader->type,
- shader->func, shader->texcoords);
- }
- else {
- vs_source = ralloc_asprintf(mem_ctx,
- "#version 130\n"
- "in vec2 position;\n"
- "in vec4 textureCoords;\n"
- "out vec4 texCoords;\n"
- "void main()\n"
- "{\n"
- " texCoords = textureCoords;\n"
- " gl_Position = vec4(position, 0.0, 1.0);\n"
- "}\n");
- fs_source = ralloc_asprintf(mem_ctx,
- "#version 130\n"
- "#extension GL_ARB_texture_cube_map_array: enable\n"
- "uniform %s texSampler;\n"
- "in vec4 texCoords;\n"
- "out vec4 out_color;\n"
- "\n"
- "void main()\n"
- "{\n"
- " out_color = texture(texSampler, %s);\n"
- " gl_FragDepth = out_color.x;\n"
- "}\n",
- shader->type,
- shader->texcoords);
- }
-
+ vs_source = ralloc_asprintf(mem_ctx,
+ "%s\n"
+ "%s vec2 position;\n"
+ "%s vec4 textureCoords;\n"
+ "%s vec4 texCoords;\n"
+ "void main()\n"
+ "{\n"
+ " texCoords = textureCoords;\n"
+ " gl_Position = vec4(position, 0.0, 1.0);\n"
+ "}\n",
+ vs_preprocess, vs_input, vs_input, vs_output);
+
+ fs_source = ralloc_asprintf(mem_ctx,
+ "%s\n"
+ "#extension GL_ARB_texture_cube_map_array: enable\n"
+ "uniform %s texSampler;\n"
+ "%s vec4 texCoords;\n"
+ "%s\n"
+ "void main()\n"
+ "{\n"
+ " vec4 color = %s(texSampler, %s);\n"
+ " %s = color;\n"
+ " gl_FragDepth = color.x;\n"
+ "}\n",
+ fs_preprocess, shader->type, fs_input, fs_output_var_decl,
+ shader->func, shader->texcoords, fs_output_var);
_mesa_meta_compile_and_link_program(ctx, vs_source, fs_source,
ralloc_asprintf(mem_ctx, "%s blit",