VIGS: Use proper shader versions 24/17024/1
authorStanislav Vorobiov <s.vorobiov@samsung.com>
Sat, 1 Mar 2014 09:11:16 +0000 (13:11 +0400)
committerStanislav Vorobiov <s.vorobiov@samsung.com>
Sat, 1 Mar 2014 09:11:16 +0000 (13:11 +0400)
We need to use 120 shaders when in legacy mode and
140 shaders when in GL3 mode

Change-Id: Ic9cd8aee5a9dd936c57f40c9d255f7497f158c45

hw/vigs/vigs_gl_backend.c

index a0175208e012d1f1a0cb49e303b4a12a11bf9feb..c20d45749b9ee180f61759c8e4698599332319aa 100644 (file)
@@ -128,7 +128,8 @@ static __inline struct vigs_winsys_gl_surface
  * @{
  */
 
-static const char *g_vs_tex_source =
+static const char *g_vs_tex_source_gl2 =
+    "#version 120\n\n"
     "attribute vec4 vertCoord;\n"
     "uniform mat4 proj;\n"
     "attribute vec2 texCoord;\n"
@@ -139,7 +140,20 @@ static const char *g_vs_tex_source =
     "    gl_Position = proj * vertCoord;\n"
     "}\n";
 
-static const char *g_fs_tex_source =
+static const char *g_vs_tex_source_gl3 =
+    "#version 140\n\n"
+    "in vec4 vertCoord;\n"
+    "uniform mat4 proj;\n"
+    "in vec2 texCoord;\n"
+    "out vec2 v_texCoord;\n"
+    "void main()\n"
+    "{\n"
+    "    v_texCoord = texCoord;\n"
+    "    gl_Position = proj * vertCoord;\n"
+    "}\n";
+
+static const char *g_fs_tex_source_gl2 =
+    "#version 120\n\n"
     "uniform sampler2D tex;\n"
     "varying vec2 v_texCoord;\n"
     "void main()\n"
@@ -147,7 +161,18 @@ static const char *g_fs_tex_source =
     "    gl_FragColor = texture2D(tex, v_texCoord);\n"
     "}\n";
 
-static const char *g_vs_color_source =
+static const char *g_fs_tex_source_gl3 =
+    "#version 140\n\n"
+    "uniform sampler2D tex;\n"
+    "in vec2 v_texCoord;\n"
+    "out vec4 FragColor;\n"
+    "void main()\n"
+    "{\n"
+    "    FragColor = texture(tex, v_texCoord);\n"
+    "}\n";
+
+static const char *g_vs_color_source_gl2 =
+    "#version 120\n\n"
     "attribute vec4 vertCoord;\n"
     "uniform mat4 proj;\n"
     "void main()\n"
@@ -155,13 +180,32 @@ static const char *g_vs_color_source =
     "    gl_Position = proj * vertCoord;\n"
     "}\n";
 
-static const char *g_fs_color_source =
+static const char *g_vs_color_source_gl3 =
+    "#version 140\n\n"
+    "in vec4 vertCoord;\n"
+    "uniform mat4 proj;\n"
+    "void main()\n"
+    "{\n"
+    "    gl_Position = proj * vertCoord;\n"
+    "}\n";
+
+static const char *g_fs_color_source_gl2 =
+    "#version 120\n\n"
     "uniform vec4 color;\n"
     "void main()\n"
     "{\n"
     "    gl_FragColor = color;\n"
     "}\n";
 
+static const char *g_fs_color_source_gl3 =
+    "#version 140\n\n"
+    "uniform vec4 color;\n"
+    "out vec4 FragColor;\n"
+    "void main()\n"
+    "{\n"
+    "    FragColor = color;\n"
+    "}\n";
+
 static GLuint vigs_gl_create_shader(struct vigs_gl_backend *backend,
                                     const char *source,
                                     GLenum type)
@@ -1367,16 +1411,16 @@ bool vigs_gl_backend_init(struct vigs_gl_backend *gl_backend)
     }
 
     gl_backend->tex_prog_vs_id = vigs_gl_create_shader(gl_backend,
-                                                       g_vs_tex_source,
-                                                       GL_VERTEX_SHADER);
+        (gl_backend->is_gl_2 ? g_vs_tex_source_gl2 : g_vs_tex_source_gl3),
+        GL_VERTEX_SHADER);
 
     if (!gl_backend->tex_prog_vs_id) {
         goto fail;
     }
 
     gl_backend->tex_prog_fs_id = vigs_gl_create_shader(gl_backend,
-                                                       g_fs_tex_source,
-                                                       GL_FRAGMENT_SHADER);
+        (gl_backend->is_gl_2 ? g_fs_tex_source_gl2 : g_fs_tex_source_gl3),
+        GL_FRAGMENT_SHADER);
 
     if (!gl_backend->tex_prog_fs_id) {
         goto fail;
@@ -1395,16 +1439,16 @@ bool vigs_gl_backend_init(struct vigs_gl_backend *gl_backend)
     gl_backend->tex_prog_texCoord_loc = gl_backend->GetAttribLocation(gl_backend->tex_prog_id, "texCoord");
 
     gl_backend->color_prog_vs_id = vigs_gl_create_shader(gl_backend,
-                                                         g_vs_color_source,
-                                                         GL_VERTEX_SHADER);
+        (gl_backend->is_gl_2 ? g_vs_color_source_gl2 : g_vs_color_source_gl3),
+        GL_VERTEX_SHADER);
 
     if (!gl_backend->color_prog_vs_id) {
         goto fail;
     }
 
     gl_backend->color_prog_fs_id = vigs_gl_create_shader(gl_backend,
-                                                         g_fs_color_source,
-                                                         GL_FRAGMENT_SHADER);
+        (gl_backend->is_gl_2 ? g_fs_color_source_gl2 : g_fs_color_source_gl3),
+        GL_FRAGMENT_SHADER);
 
     if (!gl_backend->color_prog_fs_id) {
         goto fail;