summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-02-05 22:27:27 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-02-05 22:31:35 +0900
commit7d6bb7fe5af6ea8efb88ed9438a6d4e1a2b67ef8 (patch)
treec36f2bd88dc289bf01ed3cc516da579ede48d829
parent69818e7c45743efb21071412278d205c6892c18e (diff)
Evas masking: Fix GL masking with maps and stuff
This fixes an issue spotted after the previous fix. Passing the Y-invert flag is necessary because in the usual case a map is rendered with Y-invert (OpenGL coords vs. Evas coords) but in case a map is rendered in an FBO (another map's surface) then Y-invert must be unset.
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_context.c43
-rw-r--r--src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x8
-rw-r--r--src/modules/evas/engines/gl_common/shader/map_mask_bgra_vert.shd9
3 files changed, 48 insertions, 12 deletions
diff --git a/src/modules/evas/engines/gl_common/evas_gl_context.c b/src/modules/evas/engines/gl_common/evas_gl_context.c
index 9736d570dd..55118ea81d 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_context.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_context.c
@@ -2706,6 +2706,7 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
2706 gc->pipe[pn].array.use_texuv2 = (utexture || uvtexture) ? 1 : 0; 2706 gc->pipe[pn].array.use_texuv2 = (utexture || uvtexture) ? 1 : 0;
2707 gc->pipe[pn].array.use_texuv3 = (utexture) ? 1 : 0; 2707 gc->pipe[pn].array.use_texuv3 = (utexture) ? 1 : 0;
2708 gc->pipe[pn].array.use_texm = !!mtex; 2708 gc->pipe[pn].array.use_texm = !!mtex;
2709 gc->pipe[pn].array.use_texa = !!mtex;
2709 gc->pipe[pn].array.use_texsam = gc->pipe[pn].array.use_texm; 2710 gc->pipe[pn].array.use_texsam = gc->pipe[pn].array.use_texm;
2710 2711
2711 pipe_region_expand(gc, pn, x, y, w, h); 2712 pipe_region_expand(gc, pn, x, y, w, h);
@@ -2768,17 +2769,27 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
2768 2769
2769 if (mtex) 2770 if (mtex)
2770 { 2771 {
2771 GLfloat glmdx = 0.f, glmdy = 0.f, glmdw = 1.f, glmdh = 1.f; 2772 GLfloat glmdx = 0.f, glmdy = 0.f, glmdw = 1.f, glmdh = 1.f, yinv = -1.f;
2773 GLfloat gw = gc->w, gh = gc->h;
2772 2774
2773 // Note: I couldn't write any test case where it was necessary 2775 // Note: I couldn't write any test case where it was necessary
2774 // to know the mask position in its texture. Thus these unused vars. 2776 // to know the mask position in its texture. Thus these unused vars.
2775 (void) mx; (void) my; (void) mw; (void) mh; 2777 (void) mx; (void) my; (void) mw; (void) mh;
2776 2778
2777 if (gc->w) glmdx = (GLfloat) mdx / (GLfloat) gc->w; 2779 if (!((gc->pipe[0].shader.surface == gc->def_surface) ||
2778 if (gc->h) glmdy = (GLfloat) mdy / (GLfloat) gc->h; 2780 (!gc->pipe[0].shader.surface)))
2779 if (mdw) glmdw = (GLfloat) gc->w / (GLfloat) mdw; 2781 {
2780 if (mdh) glmdh = (GLfloat) gc->h / (GLfloat) mdh ; 2782 gw = gc->pipe[0].shader.surface->w;
2783 gh = gc->pipe[0].shader.surface->h;
2784 yinv = 1.f;
2785 }
2781 2786
2787 if (gw) glmdx = (GLfloat) mdx / (GLfloat) gw;
2788 if (gh) glmdy = (GLfloat) mdy / (GLfloat) gh;
2789 if (mdw) glmdw = (GLfloat) gw / (GLfloat) mdw;
2790 if (mdh) glmdh = (GLfloat) gh / (GLfloat) mdh;
2791
2792 // FIXME!!!
2782 // We seriously need uniforms here. Abusing tex_coordm for storage. 2793 // We seriously need uniforms here. Abusing tex_coordm for storage.
2783 // Passing mask x,y (on canvas) to the fragment shader 2794 // Passing mask x,y (on canvas) to the fragment shader
2784 PUSH_TEXM(pn, glmdx, glmdy); 2795 PUSH_TEXM(pn, glmdx, glmdy);
@@ -2796,6 +2807,14 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
2796 PUSH_TEXSAM(pn, glmdw, glmdh); 2807 PUSH_TEXSAM(pn, glmdw, glmdh);
2797 PUSH_TEXSAM(pn, glmdw, glmdh); 2808 PUSH_TEXSAM(pn, glmdw, glmdh);
2798 2809
2810 // Abusing tex_coorda to pass Y-invert flag
2811 PUSH_TEXA(pn, 1.f, yinv);
2812 PUSH_TEXA(pn, 1.f, yinv);
2813 PUSH_TEXA(pn, 1.f, yinv);
2814 PUSH_TEXA(pn, 1.f, yinv);
2815 PUSH_TEXA(pn, 1.f, yinv);
2816 PUSH_TEXA(pn, 1.f, yinv);
2817
2799 //DBG("Orig %d,%d - %dx%d --> %f,%f - %f x %f", mdx, mdy, mdw, mdh, 2818 //DBG("Orig %d,%d - %dx%d --> %f,%f - %f x %f", mdx, mdy, mdw, mdh,
2800 // glmdx, glmdy, glmdw, glmdh); 2819 // glmdx, glmdy, glmdw, glmdh);
2801 } 2820 }
@@ -3284,7 +3303,7 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
3284 } 3303 }
3285 3304
3286 /* Alpha plane */ 3305 /* Alpha plane */
3287 if (gc->pipe[i].array.use_texa) 3306 if (gc->pipe[i].array.use_texa && (gc->pipe[i].region.type != RTYPE_MAP))
3288 { 3307 {
3289 glEnableVertexAttribArray(SHAD_TEXA); 3308 glEnableVertexAttribArray(SHAD_TEXA);
3290 GLERR(__FUNCTION__, __FILE__, __LINE__, ""); 3309 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
@@ -3324,6 +3343,18 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
3324 3343
3325 MASK_TEXTURE += 1; 3344 MASK_TEXTURE += 1;
3326 } 3345 }
3346 else if (gc->pipe[i].region.type == RTYPE_MAP)
3347 {
3348 /* FIXME:
3349 * This is a workaround as we hijack some tex ids
3350 * (namely tex_coordm, tex_coorda and tex_sample) for map masking.
3351 * These masking shaders should definitely use uniforms.
3352 */
3353 glEnableVertexAttribArray(SHAD_TEXA);
3354 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
3355 glVertexAttribPointer(SHAD_TEXA, 2, GL_FLOAT, GL_FALSE, 0, (void *)texa_ptr);
3356 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
3357 }
3327 else 3358 else
3328 { 3359 {
3329 glDisableVertexAttribArray(SHAD_TEXA); 3360 glDisableVertexAttribArray(SHAD_TEXA);
diff --git a/src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x b/src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x
index cffc70b636..3a32e0933f 100644
--- a/src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x
+++ b/src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x
@@ -2833,7 +2833,7 @@ static const char const map_mask_bgra_vert_glsl[] =
2833 "precision highp float;\n" 2833 "precision highp float;\n"
2834 "#endif\n" 2834 "#endif\n"
2835 "attribute vec4 vertex, color;\n" 2835 "attribute vec4 vertex, color;\n"
2836 "attribute vec2 tex_coord, tex_coordm, tex_sample;\n" 2836 "attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;\n"
2837 "uniform mat4 mvp;\n" 2837 "uniform mat4 mvp;\n"
2838 "varying vec2 tex_c;\n" 2838 "varying vec2 tex_c;\n"
2839 "varying vec4 mask_Position, col, mask_Absolute;\n" 2839 "varying vec4 mask_Position, col, mask_Absolute;\n"
@@ -2842,8 +2842,10 @@ static const char const map_mask_bgra_vert_glsl[] =
2842 " gl_Position = mvp * vertex;\n" 2842 " gl_Position = mvp * vertex;\n"
2843 " tex_c = tex_coord;\n" 2843 " tex_c = tex_coord;\n"
2844 " col = color;\n" 2844 " col = color;\n"
2845 " // Assume Y-invert on mask, normalize (screen to texture mode coordinates)\n" 2845 " // tex_coorda contains the Y-invert flag\n"
2846 " mask_Position = mvp * vertex * vec4(0.5, -0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n" 2846 " // tex_coordm contains the X,Y position of the mask\n"
2847 " // tex_sample contains the W,H size of the mask (inverted)\n"
2848 " mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
2847 " mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords\n" 2849 " mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords\n"
2848 "}\n"; 2850 "}\n";
2849Evas_GL_Program_Source shader_map_mask_bgra_vert_src = 2851Evas_GL_Program_Source shader_map_mask_bgra_vert_src =
diff --git a/src/modules/evas/engines/gl_common/shader/map_mask_bgra_vert.shd b/src/modules/evas/engines/gl_common/shader/map_mask_bgra_vert.shd
index a7a537d26b..7b0c9684e7 100644
--- a/src/modules/evas/engines/gl_common/shader/map_mask_bgra_vert.shd
+++ b/src/modules/evas/engines/gl_common/shader/map_mask_bgra_vert.shd
@@ -2,7 +2,7 @@
2precision highp float; 2precision highp float;
3#endif 3#endif
4attribute vec4 vertex, color; 4attribute vec4 vertex, color;
5attribute vec2 tex_coord, tex_coordm, tex_sample; 5attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;
6uniform mat4 mvp; 6uniform mat4 mvp;
7varying vec2 tex_c; 7varying vec2 tex_c;
8varying vec4 mask_Position, col, mask_Absolute; 8varying vec4 mask_Position, col, mask_Absolute;
@@ -12,7 +12,10 @@ void main()
12 tex_c = tex_coord; 12 tex_c = tex_coord;
13 col = color; 13 col = color;
14 14
15 // Assume Y-invert on mask, normalize (screen to texture mode coordinates) 15 // tex_coorda contains the Y-invert flag
16 mask_Position = mvp * vertex * vec4(0.5, -0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0); 16 // tex_coordm contains the X,Y position of the mask
17 // tex_sample contains the W,H size of the mask (inverted)
18
19 mask_Position = mvp * vertex * vec4(tex_coorda.x * 0.5, tex_coorda.y * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
17 mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords 20 mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords
18} 21}