struct _Evas_GL_Program
{
unsigned int flags, hitcount, tex_count;
+ struct {
+ GLuint mvp, rotation_id;
+ } uniform;
GLuint prog;
Eina_Bool reset : 1;
if (gc->state.current.prog != PRG_INVALID)
{
- glUseProgram(gc->state.current.prog->prog);
- glUniformMatrix4fv(glGetUniformLocation(gc->state.current.prog->prog, "mvp"), 1, GL_FALSE, gc->shared->proj);
+ prog = gc->state.current.prog;
+ glUseProgram(prog->prog);
+ glUniform1i(prog->uniform.rotation_id, gc->rot / 90);
+ glUniformMatrix4fv(prog->uniform.mvp, 1, GL_FALSE, gc->shared->proj);
}
}
if (!gw || !gh || !mw || !mh || !mtex->pt->w || !mtex->pt->h)
return EINA_FALSE;
- /* vertex shader:
- * vec4 mask_Position = mvp * vertex * vec4(0.5, sign(mask_coord.w) * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
- * tex_m = mask_Position.xy * abs(mask_coord.zw) + mask_coord.xy;
+ /* Vertex shader:
+ *
+ * INPUTS:
+ * vec4 mask_coord = vec4(glmx, glmy, glmw, glmh);
+ * int rotation_id = gc->rot / 90;
+ *
+ * CODE:
+ * vec4 mask_Position = mvp * vertex * vec4(0.5, sign(mask_coord.w) * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
+ * vec2 pos[4]; // no ctor-style init because of GLSL-ES (version 100)
+ * pos[0] = vec2(mask_Position.xy);
+ * pos[1] = vec2(1.0 - mask_Position.y, mask_Position.x);
+ * pos[2] = vec2(1.0 - mask_Position.xy);
+ * pos[3] = vec2(mask_Position.y, 1.0 - mask_Position.x);
+ * tex_m = pos[rotation_id].xy * abs(mask_coord.zw) + mask_coord.xy;
*/
glmx = (double)((mtex->x * mw) - (mtex->w * mx)) / (double)(mw * mtex->pt->w);
glmy = (double)((mtex->y * mh) - (mtex->h * my)) / (double)(mh * mtex->pt->h);
PUSH_MASKSAM(pn, samx, samy, cnt);
}
- /*
- DBG("%d,%d %dx%d --> %f , %f - %f x %f [gc %dx%d, tex %d,%d %dx%d, pt %dx%d]",
- mx, my, mw, mh,
- glmx, glmy, glmw, glmh,
- gc->w, gc->h, mtex->x, mtex->y, mtex->w, mtex->h, mtex->pt->w, mtex->pt->h);
- */
-
return EINA_TRUE;
}
glUseProgram(prog->prog);
if (prog->reset)
{
- glUniformMatrix4fv(glGetUniformLocation(prog->prog, "mvp"), 1, GL_FALSE, gc->shared->proj);
+ glUniform1i(prog->uniform.rotation_id, gc->rot / 90);
+ glUniformMatrix4fv(prog->uniform.mvp, 1, GL_FALSE, gc->shared->proj);
prog->reset = EINA_FALSE;
}
}
p->prog = prg;
p->reset = EINA_TRUE;
p->bin_saved = EINA_TRUE;
+ p->uniform.mvp = glGetUniformLocation(prg, "mvp");
+ p->uniform.rotation_id = glGetUniformLocation(prg, "rotation_id");
evas_gl_common_shader_textures_bind(p);
finish:
if (p)
{
shared->needs_shaders_flush = 1;
+ p->uniform.mvp = glGetUniformLocation(p->prog, "mvp");
+ p->uniform.rotation_id = glGetUniformLocation(p->prog, "rotation_id");
evas_gl_common_shader_textures_bind(p);
eina_hash_add(shared->shaders_hash, &flags, p);
}
" * col\n"
"#endif\n"
"#ifdef SHD_MASK\n"
- " * ma\n"
+ " * ma\n"
"#endif\n"
"#ifdef SHD_TEXA\n"
" * texture2D(texa, tex_a).r\n"
"#endif\n"
"attribute vec4 vertex;\n"
"uniform mat4 mvp;\n"
+ "/* Window rotation by id 0,1,2,3 (represents 0,90,180,270) */\n"
+ "uniform int rotation_id;\n"
"/* All except nomul */\n"
"#ifndef SHD_NOMUL\n"
"attribute vec4 color;\n"
"#ifdef SHD_MASK\n"
" // mask_coord.w contains the Y-invert flag\n"
" // position on screen in [0..1] range of current pixel\n"
- " vec4 mask_Position = mvp * vertex * vec4(0.5, sign(mask_coord.w) * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
- " tex_m = mask_Position.xy * abs(mask_coord.zw) + mask_coord.xy;\n"
+ " vec4 window_Position = mvp * vertex * vec4(0.5, sign(mask_coord.w) * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
+ " vec2 pos[4];\n"
+ " pos[0] = vec2(window_Position.xy);\n"
+ " pos[1] = vec2(1.0 - window_Position.y, window_Position.x);\n"
+ " pos[2] = vec2(1.0 - window_Position.xy);\n"
+ " pos[3] = vec2(window_Position.y, 1.0 - window_Position.x);\n"
+ " tex_m = pos[rotation_id] * abs(mask_coord.zw) + mask_coord.xy;\n"
"#endif\n"
"}\n";
* col
#endif
#ifdef SHD_MASK
- * ma
+ * ma
#endif
#ifdef SHD_TEXA
* texture2D(texa, tex_a).r
attribute vec4 vertex;
uniform mat4 mvp;
+/* Window rotation by id 0,1,2,3 (represents 0,90,180,270) */
+uniform int rotation_id;
+
/* All except nomul */
#ifndef SHD_NOMUL
attribute vec4 color;
#ifdef SHD_MASK
// mask_coord.w contains the Y-invert flag
// position on screen in [0..1] range of current pixel
- vec4 mask_Position = mvp * vertex * vec4(0.5, sign(mask_coord.w) * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
- tex_m = mask_Position.xy * abs(mask_coord.zw) + mask_coord.xy;
+ vec4 window_Position = mvp * vertex * vec4(0.5, sign(mask_coord.w) * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
+ vec2 pos[4];
+ pos[0] = vec2(window_Position.xy);
+ pos[1] = vec2(1.0 - window_Position.y, window_Position.x);
+ pos[2] = vec2(1.0 - window_Position.xy);
+ pos[3] = vec2(window_Position.y, 1.0 - window_Position.x);
+ tex_m = pos[rotation_id] * abs(mask_coord.zw) + mask_coord.xy;
#endif
}