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.
This commit is contained in:
Jean-Philippe Andre 2015-02-05 22:27:27 +09:00
parent 69818e7c45
commit 7d6bb7fe5a
3 changed files with 48 additions and 12 deletions

View File

@ -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);

View File

@ -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 =

View File

@ -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
}