Revert "Evas GL: Add support for uniforms in the shaders"

This reverts commit 21d08f86e6.
This commit is contained in:
Jean-Philippe Andre 2015-02-12 15:10:53 +09:00
parent cfd337a758
commit 6b48c106d3
9 changed files with 75 additions and 144 deletions

View File

@ -481,7 +481,6 @@ struct _Evas_Engine_GL_Context
GLfloat *texa;
GLfloat *texsam;
GLfloat *texm;
Eina_List *uniforms; /* Evas_GL_Uniform */
Eina_Bool line: 1;
Eina_Bool use_vertex : 1;
Eina_Bool use_color : 1;

View File

@ -1311,107 +1311,6 @@ array_alloc(Evas_Engine_GL_Context *gc, int n)
RALOC(texm, GLfloat, 2);
}
/* Very basic uniform upload support.
* TODO: Optimize out call to glGetUniformLocation(). */
typedef enum _Evas_GL_Uniform_Type Evas_GL_Uniform_Type;
typedef struct _Evas_GL_Uniform Evas_GL_Uniform;
enum _Evas_GL_Uniform_Type {
EVAS_GL_UNIFORM_FLOAT,
EVAS_GL_UNIFORM_VEC2,
EVAS_GL_UNIFORM_VEC4,
// Add more types if needed.
};
struct _Evas_GL_Uniform {
Evas_GL_Uniform_Type type;
Eina_Stringshare *name; // May be NULL if location was found at link time
GLint location;
union {
GLfloat f;
GLfloat vec2[2];
GLfloat vec4[4];
} value;
};
static inline void
push_uniform(Evas_Engine_GL_Context *gc, int n, Evas_GL_Uniform_Type type,
const char *name, GLint loc, ...)
{
Evas_GL_Uniform *u = calloc(1, sizeof(Evas_GL_Uniform));
va_list args;
va_start(args, loc);
if (!gc || !u) return;
u->type = type;
u->location = loc;
if (loc < 0) u->name = eina_stringshare_add(name);
switch (type)
{
case EVAS_GL_UNIFORM_FLOAT:
u->value.f = (GLfloat) va_arg(args, double);
break;
case EVAS_GL_UNIFORM_VEC2:
u->value.vec2[0] = (GLfloat) va_arg(args, double);
u->value.vec2[1] = (GLfloat) va_arg(args, double);
break;
case EVAS_GL_UNIFORM_VEC4:
u->value.vec4[0] = (GLfloat) va_arg(args, double);
u->value.vec4[1] = (GLfloat) va_arg(args, double);
u->value.vec4[2] = (GLfloat) va_arg(args, double);
u->value.vec4[3] = (GLfloat) va_arg(args, double);
break;
default:
eina_stringshare_del(u->name);
free(u);
va_end(args);
return;
}
va_end(args);
gc->pipe[n].array.uniforms = eina_list_append(gc->pipe[n].array.uniforms, u);
}
static inline void
shader_array_uniforms_set(Evas_Engine_GL_Context *gc, int n)
{
Evas_GL_Uniform *u;
GLint loc;
if (!gc || !gc->pipe[n].array.uniforms) return;
EINA_LIST_FREE(gc->pipe[n].array.uniforms, u)
{
if (u->location >= 0)
loc = u->location;
else
loc = glGetUniformLocation(gc->pipe[n].shader.cur_prog, u->name);
if (loc >= 0)
{
switch (u->type)
{
case EVAS_GL_UNIFORM_FLOAT:
glUniform1f(loc, u->value.f);
break;
case EVAS_GL_UNIFORM_VEC2:
glUniform2fv(loc, 1, u->value.vec2);
break;
case EVAS_GL_UNIFORM_VEC4:
glUniform4fv(loc, 1, u->value.vec4);
break;
default: ERR("Unhandled uniform type"); break;
}
}
eina_stringshare_del(u->name);
free(u);
}
}
#define PUSH_UNIFORM(pn, shader, type, name, ...) \
push_uniform(gc, pn, type, #name, gc->shared->shader[shader].uniforms.loc_##name, __VA_ARGS__)
#ifdef GLPIPES
static int
pipe_region_intersects(Evas_Engine_GL_Context *gc, int n,
@ -2688,8 +2587,8 @@ 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 = 0;
gc->pipe[pn].array.use_texsam = 0;
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);
PIPE_GROW(gc, pn, 6);
@ -2751,8 +2650,8 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
if (mtex)
{
double glmdx = 0.f, glmdy = 0.f, glmdw = 1.f, glmdh = 1.f, yinv = -1.f;
double gw = gc->w, gh = gc->h;
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.
@ -2766,13 +2665,34 @@ evas_gl_common_context_image_map_push(Evas_Engine_GL_Context *gc,
yinv = 1.f;
}
if (gw) glmdx = (double) mdx / (double) gw;
if (gh) glmdy = (double) mdy / (double) gh;
if (mdw) glmdw = (double) gw / (double) mdw;
if (mdh) glmdh = (double) gh / (double) mdh;
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;
PUSH_UNIFORM(pn, shader, EVAS_GL_UNIFORM_VEC4, mask_Absolute, glmdx, glmdy, glmdw, glmdh);
PUSH_UNIFORM(pn, shader, EVAS_GL_UNIFORM_FLOAT, yinvert, yinv);
// tex_coordm: mask x,y (on canvas)
PUSH_TEXM(pn, glmdx, glmdy);
PUSH_TEXM(pn, glmdx, glmdy);
PUSH_TEXM(pn, glmdx, glmdy);
PUSH_TEXM(pn, glmdx, glmdy);
PUSH_TEXM(pn, glmdx, glmdy);
PUSH_TEXM(pn, glmdx, glmdy);
// tex_sample: mask 1/w, 1/h
PUSH_TEXSAM(pn, glmdw, glmdh);
PUSH_TEXSAM(pn, glmdw, glmdh);
PUSH_TEXSAM(pn, glmdw, glmdh);
PUSH_TEXSAM(pn, glmdw, glmdh);
PUSH_TEXSAM(pn, glmdw, glmdh);
PUSH_TEXSAM(pn, glmdw, glmdh);
// tex_coorda: mask 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);
@ -3257,6 +3177,16 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
MASK_TEXTURE += 1;
}
else if (gc->pipe[i].array.use_texa && (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);
glVertexAttribPointer(SHAD_TEXA, 2, GL_FLOAT, GL_FALSE, 0, (void *)texa_ptr);
}
else
{
glDisableVertexAttribArray(SHAD_TEXA);
@ -3370,10 +3300,6 @@ shader_array_flush(Evas_Engine_GL_Context *gc)
glDisableVertexAttribArray(SHAD_TEXM);
}
// Push all uniforms
if (gc->pipe[i].array.uniforms)
shader_array_uniforms_set(gc, i);
if (dbgflushnum == 1)
{
const char *types[6] =

View File

@ -2711,9 +2711,8 @@ static const char const map_mask_frag_glsl[] =
"#endif\n"
"#endif\n"
"uniform sampler2D tex, texm;\n"
"uniform vec4 mask_Absolute;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, col;\n"
"varying vec4 mask_Position, col, mask_Absolute;\n"
"void main()\n"
"{\n"
" // FIXME: Use mask coordinates within its texture\n"
@ -2733,17 +2732,20 @@ static const char const map_mask_vert_glsl[] =
"precision highp float;\n"
"#endif\n"
"attribute vec4 vertex, color;\n"
"attribute vec2 tex_coord;\n"
"uniform float yinvert;\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;\n"
"varying vec4 mask_Position, col, mask_Absolute;\n"
"void main()\n"
"{\n"
" gl_Position = mvp * vertex;\n"
" tex_c = tex_coord;\n"
" col = color;\n"
" mask_Position = mvp * vertex * vec4(0.5, yinvert * 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_vert_src =
{
@ -2766,7 +2768,6 @@ static const char const map_mask_nomul_frag_glsl[] =
"void main()\n"
"{\n"
" // FIXME: Use mask coordinates within its texture\n"
" // FIXME: We're abusing varying where we should have uniforms\n"
" vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;\n"
" gl_FragColor = texture2D(tex, tex_c.xy).bgra * texture2D(texm, mpos).a;\n"
"}\n";
@ -2810,9 +2811,8 @@ static const char const map_mask_bgra_frag_glsl[] =
"#endif\n"
"#endif\n"
"uniform sampler2D tex, texm;\n"
"uniform vec4 mask_Absolute;\n"
"varying vec2 tex_c;\n"
"varying vec4 mask_Position, col;\n"
"varying vec4 mask_Position, col, mask_Absolute;\n"
"void main()\n"
"{\n"
" // FIXME: Use mask coordinates within its texture\n"
@ -2832,17 +2832,20 @@ static const char const map_mask_bgra_vert_glsl[] =
"precision highp float;\n"
"#endif\n"
"attribute vec4 vertex, color;\n"
"attribute vec2 tex_coord;\n"
"uniform float yinvert;\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;\n"
"varying vec4 mask_Position, col, mask_Absolute;\n"
"void main()\n"
"{\n"
" gl_Position = mvp * vertex;\n"
" tex_c = tex_coord;\n"
" col = color;\n"
" mask_Position = mvp * vertex * vec4(0.5, yinvert * 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 =
{
@ -2865,7 +2868,6 @@ static const char const map_mask_bgra_nomul_frag_glsl[] =
"void main()\n"
"{\n"
" // FIXME: Use mask coordinates within its texture\n"
" // FIXME: We're abusing varying where we should have uniforms\n"
" vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;\n"
" gl_FragColor = texture2D(tex, tex_c.xy) * texture2D(texm, mpos).a;\n"
"}\n";

View File

@ -6,9 +6,8 @@ precision mediump float;
#endif
#endif
uniform sampler2D tex, texm;
uniform vec4 mask_Absolute;
varying vec2 tex_c;
varying vec4 mask_Position, col;
varying vec4 mask_Position, col, mask_Absolute;
void main()
{
// FIXME: Use mask coordinates within its texture

View File

@ -11,7 +11,6 @@ varying vec4 mask_Position, mask_Absolute;
void main()
{
// FIXME: Use mask coordinates within its texture
// FIXME: We're abusing varying where we should have uniforms
vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;
gl_FragColor = texture2D(tex, tex_c.xy) * texture2D(texm, mpos).a;
}

View File

@ -2,16 +2,20 @@
precision highp float;
#endif
attribute vec4 vertex, color;
attribute vec2 tex_coord;
uniform float yinvert;
attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;
uniform mat4 mvp;
varying vec2 tex_c;
varying vec4 mask_Position, col;
varying vec4 mask_Position, col, mask_Absolute;
void main()
{
gl_Position = mvp * vertex;
tex_c = tex_coord;
col = color;
mask_Position = mvp * vertex * vec4(0.5, yinvert * 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
}

View File

@ -6,9 +6,8 @@ precision mediump float;
#endif
#endif
uniform sampler2D tex, texm;
uniform vec4 mask_Absolute;
varying vec2 tex_c;
varying vec4 mask_Position, col;
varying vec4 mask_Position, col, mask_Absolute;
void main()
{
// FIXME: Use mask coordinates within its texture

View File

@ -11,7 +11,6 @@ varying vec4 mask_Position, mask_Absolute;
void main()
{
// FIXME: Use mask coordinates within its texture
// FIXME: We're abusing varying where we should have uniforms
vec2 mpos = vec2(mask_Position.xy - mask_Absolute.xy) * mask_Absolute.zw;
gl_FragColor = texture2D(tex, tex_c.xy).bgra * texture2D(texm, mpos).a;
}

View File

@ -2,16 +2,20 @@
precision highp float;
#endif
attribute vec4 vertex, color;
attribute vec2 tex_coord;
uniform float yinvert;
attribute vec2 tex_coord, tex_coordm, tex_sample, tex_coorda;
uniform mat4 mvp;
varying vec2 tex_c;
varying vec4 mask_Position, col;
varying vec4 mask_Position, col, mask_Absolute;
void main()
{
gl_Position = mvp * vertex;
tex_c = tex_coord;
col = color;
mask_Position = mvp * vertex * vec4(0.5, yinvert * 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
}