On 09/11/2012 07:32 PM, Anuj Phogat wrote:
glsl version of _mesa_meta_GenerateMipmap() would require separate
shaders for glsl 120 and 130.

V2: Removed the code for integer textures as ARB is planning to
     disallow automatic mipmap generation for integer textures.

NOTE: This is a candidate for stable branches.

Signed-off-by: Anuj Phogat<anuj.pho...@gmail.com>
---
  src/mesa/drivers/common/meta.c |   79 ++++++++++++++++++++++++++++++----------
  1 files changed, 59 insertions(+), 20 deletions(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 16110c5..5cb4f0c 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -3063,24 +3063,10 @@ setup_glsl_generate_mipmap(struct gl_context *ctx,
        GLfloat x, y, tex[3];
     };
     struct glsl_sampler sampler;
+   static const char *glsl_out_type = "vec4";

Do you really need that variable? Could you just pass "vec4" as an argument to the ralloc_asprintf() call?


+   const char *vs_source;
+   const char *fs_template;

-   static const char *vs_source =
-      "attribute vec2 position;\n"
-      "attribute vec3 textureCoords;\n"
-      "varying vec3 texCoords;\n"
-      "void main()\n"
-      "{\n"
-      "   texCoords = textureCoords;\n"
-      "   gl_Position = vec4(position, 0.0, 1.0);\n"
-      "}\n";
-   static const char *fs_template =
-      "uniform %s texSampler;\n"
-      "varying vec3 texCoords;\n"
-      "void main()\n"
-      "{\n"
-      "   gl_FragColor = %s(texSampler, %s);\n"
-      "}\n";
-
     static const char *vs_int_source =
        "#version 130\n"
        "in vec2 position;\n"
@@ -3102,8 +3088,50 @@ setup_glsl_generate_mipmap(struct gl_context *ctx,
        "   out_color = texture(tex2d, texCoords.xy);\n"
        "}\n";
     char *fs_source;
+   const char *extension_mode;
     GLuint vs, fs;

+   if (ctx->Const.GLSLVersion<  130) {
+      vs_source =
+         "attribute vec2 position;\n"
+         "attribute vec3 textureCoords;\n"
+         "varying vec3 texCoords;\n"
+         "void main()\n"
+         "{\n"
+         "   texCoords = textureCoords;\n"
+         "   gl_Position = vec4(position, 0.0, 1.0);\n"
+         "}\n";
+      fs_template =
+         "#extension GL_EXT_texture_array : %s\n"
+         "uniform %s texSampler;\n"
+         "varying vec3 texCoords;\n"
+         "void main()\n"
+         "{\n"
+         "   gl_FragColor = %s(texSampler, %s);\n"
+         "}\n";
+   } else {
+      vs_source =
+         "#version 130\n"
+         "in vec2 position;\n"
+         "in vec3 textureCoords;\n"
+         "out vec3 texCoords;\n"
+         "void main()\n"
+         "{\n"
+         "   texCoords = textureCoords;\n"
+         "   gl_Position = vec4(position, 0.0, 1.0);\n"
+         "}\n";
+      fs_template =
+         "#version 130\n"
+         "uniform %s texSampler;\n"
+         "in vec3 texCoords;\n"
+         "out %s out_color;\n"
+         "\n"
+         "void main()\n"
+         "{\n"
+         "   out_color = texture(texSampler, %s);\n"
+         "}\n";
+    }
+
     /* Check if already initialized */
     if (mipmap->ArrayObj != 0)
        return;
@@ -3125,9 +3153,20 @@ setup_glsl_generate_mipmap(struct gl_context *ctx,
     setup_texture_sampler(target,&sampler);
     mem_ctx = ralloc_context(NULL);

-   fs_source = ralloc_asprintf(mem_ctx, fs_template,
-                               sampler.type, sampler.func,
-                               sampler.texcoords);
+   if (ctx->Const.GLSLVersion<  130) {
+      extension_mode = ((target == GL_TEXTURE_1D_ARRAY) ||
+                        (target == GL_TEXTURE_2D_ARRAY)) ?
+                       "require" : "disable";
+
+      fs_source = ralloc_asprintf(mem_ctx, fs_template,
+                                  extension_mode, sampler.type,
+                                  sampler.func, sampler.texcoords);
+   }
+   else {
+      fs_source = ralloc_asprintf(mem_ctx, fs_template,
+                                  sampler.type, glsl_out_type,
+                                  sampler.texcoords);
+   }

     vs = compile_shader_with_debug(ctx, GL_VERTEX_SHADER, vs_source);
     fs = compile_shader_with_debug(ctx, GL_FRAGMENT_SHADER, fs_source);


Looks OK to me.

Reviewed-by: Brian Paul <bri...@vmware.com>

-Brian
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to