};
struct _Evas_GL_Uniform {
- Eina_Stringshare *name;
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];
};
static inline void
-push_uniform(Evas_Engine_GL_Context *gc, int n, Evas_GL_Uniform_Type type, const char *name, ...)
+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, name);
+ va_start(args, loc);
if (!gc || !u) return;
- u->name = eina_stringshare_add(name);
u->type = type;
+ u->location = loc;
+ if (loc < 0) u->name = eina_stringshare_add(name);
switch (type)
{
u->value.vec4[3] = (GLfloat) va_arg(args, double);
break;
default:
+ eina_stringshare_del(u->name);
free(u);
va_end(args);
return;
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)
{
- GLint loc = glGetUniformLocation(gc->pipe[n].shader.cur_prog, u->name);
- GLERR(__FUNCTION__, __FILE__, __LINE__, "glUniform");
+ if (u->location >= 0)
+ loc = u->location;
+ else
+ {
+ loc = glGetUniformLocation(gc->pipe[n].shader.cur_prog, u->name);
+ GLERR(__FUNCTION__, __FILE__, __LINE__, "glGetUniformLocation");
+ }
if (loc >= 0)
{
switch (u->type)
}
}
-#define PUSH_UNIFORM(pn, type, name, ...) push_uniform(gc, pn, type, name, __VA_ARGS__)
+#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
{
double samx = (double)(sw) / (double)(tex->pt->w * w * 4);
double samy = (double)(sh) / (double)(tex->pt->h * h * 4);
- PUSH_UNIFORM(pn, EVAS_GL_UNIFORM_VEC2, "sample", samx, samy);
+ PUSH_UNIFORM(pn, shader, EVAS_GL_UNIFORM_VEC2, sample, samx, samy);
}
PUSH_MASK(pn, mtex, mx, my, mw, mh);
if (mdw) glmdw = (double) gw / (double) mdw;
if (mdh) glmdh = (double) gh / (double) mdh;
- PUSH_UNIFORM(pn, EVAS_GL_UNIFORM_VEC4, "mask_Absolute", glmdx, glmdy, glmdw, glmdh);
- PUSH_UNIFORM(pn, EVAS_GL_UNIFORM_FLOAT, "yinvert", yinv);
+ PUSH_UNIFORM(pn, shader, EVAS_GL_UNIFORM_VEC4, mask_Absolute, glmdx, glmdy, glmdw, glmdh);
+ PUSH_UNIFORM(pn, shader, EVAS_GL_UNIFORM_FLOAT, yinvert, yinv);
//DBG("Orig %d,%d - %dx%d --> %f,%f - %f x %f", mdx, mdy, mdw, mdh,
// glmdx, glmdy, glmdw, glmdh);
}
}
+#define ATTACH_UNIFORM(p, name) do { \
+ p->uniforms.loc_##name = glGetUniformLocation(p->prog, #name); \
+ } while (0)
+
static int
_evas_gl_common_shader_program_binary_init(Evas_GL_Program *p,
const char *pname,
goto finish;
}
+ ATTACH_UNIFORM(p, sample);
+ ATTACH_UNIFORM(p, yinvert);
+ ATTACH_UNIFORM(p, mask_Absolute);
+
res = 1;
finish:
ERR("Abort compile of shader vert (%s): %s", name, vert->src);
return 0;
}
+
+ ATTACH_UNIFORM(p, sample);
+ ATTACH_UNIFORM(p, yinvert);
+ ATTACH_UNIFORM(p, mask_Absolute);
+
return 1;
}