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)
downloadefl-7d6bb7fe5af6ea8efb88ed9438a6d4e1a2b67ef8.tar.gz
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,
gc->pipe[pn].array.use_texuv2 = (utexture || uvtexture) ? 1 : 0;
gc->pipe[pn].array.use_texuv3 = (utexture) ? 1 : 0;
gc->pipe[pn].array.use_texm = !!mtex;
+ gc->pipe[pn].array.use_texa = !!mtex;
gc->pipe[pn].array.use_texsam = gc->pipe[pn].array.use_texm;
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,
if (mtex)
{
- GLfloat glmdx = 0.f, glmdy = 0.f, glmdw = 1.f, glmdh = 1.f;
+ GLfloat glmdx = 0.f, glmdy = 0.f, glmdw = 1.f, glmdh = 1.f, yinv = -1.f;
+ GLfloat gw = gc->w, gh = gc->h;
// Note: I couldn't write any test case where it was necessary
// to know the mask position in its texture. Thus these unused vars.
(void) mx; (void) my; (void) mw; (void) mh;
- if (gc->w) glmdx = (GLfloat) mdx / (GLfloat) gc->w;
- if (gc->h) glmdy = (GLfloat) mdy / (GLfloat) gc->h;
- if (mdw) glmdw = (GLfloat) gc->w / (GLfloat) mdw;
- if (mdh) glmdh = (GLfloat) gc->h / (GLfloat) mdh ;
+ if (!((gc->pipe[0].shader.surface == gc->def_surface) ||
+ (!gc->pipe[0].shader.surface)))
+ {
+ gw = gc->pipe[0].shader.surface->w;
+ gh = gc->pipe[0].shader.surface->h;
+ yinv = 1.f;
+ }
+ if (gw) glmdx = (GLfloat) mdx / (GLfloat) gw;
+ if (gh) glmdy = (GLfloat) mdy / (GLfloat) gh;
+ if (mdw) glmdw = (GLfloat) gw / (GLfloat) mdw;
+ if (mdh) glmdh = (GLfloat) gh / (GLfloat) mdh;
+
+ // FIXME!!!
// We seriously need uniforms here. Abusing tex_coordm for storage.
// Passing mask x,y (on canvas) to the fragment shader
PUSH_TEXM(pn, glmdx, glmdy);
@@ -2796,6 +2807,14 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
PUSH_TEXSAM(pn, glmdw, glmdh);
PUSH_TEXSAM(pn, glmdw, glmdh);
+ // Abusing tex_coorda to pass Y-invert flag
+ PUSH_TEXA(pn, 1.f, yinv);
+ PUSH_TEXA(pn, 1.f, yinv);
+ PUSH_TEXA(pn, 1.f, yinv);
+ PUSH_TEXA(pn, 1.f, yinv);
+ PUSH_TEXA(pn, 1.f, yinv);
+ PUSH_TEXA(pn, 1.f, yinv);
+
//DBG("Orig %d,%d - %dx%d --> %f,%f - %f x %f", mdx, mdy, mdw, mdh,
// glmdx, glmdy, glmdw, glmdh);
}
@@ -3284,7 +3303,7 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
}
/* Alpha plane */
- if (gc->pipe[i].array.use_texa)
+ if (gc->pipe[i].array.use_texa && (gc->pipe[i].region.type != RTYPE_MAP))
{
glEnableVertexAttribArray(SHAD_TEXA);
GLERR(__FUNCTION__, __FILE__, __LINE__, "");
@@ -3324,6 +3343,18 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
MASK_TEXTURE += 1;
}
+ else if (gc->pipe[i].region.type == RTYPE_MAP)
+ {
+ /* FIXME:
+ * This is a workaround as we hijack some tex ids
+ * (namely tex_coordm, tex_coorda and tex_sample) for map masking.
+ * These masking shaders should definitely use uniforms.
+ */
+ glEnableVertexAttribArray(SHAD_TEXA);
+ GLERR(__FUNCTION__, __FILE__, __LINE__, "");
+ glVertexAttribPointer(SHAD_TEXA, 2, GL_FLOAT, GL_FALSE, 0, (void *)texa_ptr);
+ GLERR(__FUNCTION__, __FILE__, __LINE__, "");
+ }
else
{
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[] =
"precision highp float;\n"
"#endif\n"
"attribute vec4 vertex, color;\n"
- "attribute vec2 tex_coord, tex_coordm, tex_sample;\n"
+ "attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;\n"
"uniform mat4 mvp;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, col, mask_Absolute;\n"
@@ -2842,8 +2842,10 @@ static const char const map_mask_bgra_vert_glsl[] =
" gl_Position = mvp * vertex;\n"
" tex_c = tex_coord;\n"
" col = color;\n"
- " // Assume Y-invert on mask, normalize (screen to texture mode coordinates)\n"
- " mask_Position = mvp * vertex * vec4(0.5, -0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
+ " // tex_coorda contains the Y-invert flag\n"
+ " // tex_coordm contains the X,Y position of the mask\n"
+ " // tex_sample contains the W,H size of the mask (inverted)\n"
+ " 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"
" mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords\n"
"}\n";
Evas_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 @@
precision highp float;
#endif
attribute vec4 vertex, color;
-attribute vec2 tex_coord, tex_coordm, tex_sample;
+attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;
uniform mat4 mvp;
varying vec2 tex_c;
varying vec4 mask_Position, col, mask_Absolute;
@@ -12,7 +12,10 @@ void main()
tex_c = tex_coord;
col = color;
- // Assume Y-invert on mask, normalize (screen to texture mode coordinates)
- mask_Position = mvp * vertex * vec4(0.5, -0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
+ // tex_coorda contains the Y-invert flag
+ // tex_coordm contains the X,Y position of the mask
+ // tex_sample contains the W,H size of the mask (inverted)
+
+ 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);
mask_Absolute = vec4(tex_coordm, tex_sample); // x, y, 1/w, 1/h on canvas in GL coords
}