commit 7e8a9d7fea3eb03be16881c0274250003619f7ef
parent d930ee22fe4e5586e779f5fd19cd520c76911f02
Author: Brian Swetland <swetland@frotz.net>
Date: Sun, 10 Feb 2013 00:46:56 -0800
glapp: deal with smarter shader compilers
It's possible some attributes will be optimized away especially if you
don't like the pixel shader at the same time (as we do for early
validation). Do a binding pass on initConfig() after compiling the
full program to make sure we're up to date.
Diffstat:
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/common/glapp.cc b/common/glapp.cc
@@ -188,6 +188,8 @@ void config_attr_info(GLAttrInfo *ai, unsigned count, int vidx, unsigned stride)
unsigned n;
for (n = 0; n < count; n++, ai++) {
if (ai->vidx != vidx) continue;
+ if (ai->index < 0)
+ continue;
if (ai->kind == KIND_ATTRIB_POINTER) {
printf("VTX ATR idx=%d sz=%d type=%d norm=%d stride=%d off=%d\n",
ai->index, ai->size, ai->type, ai->normalized, stride, ai->pointer);
@@ -201,12 +203,22 @@ void config_attr_info(GLAttrInfo *ai, unsigned count, int vidx, unsigned stride)
stride, OFF2PTR(ai->pointer));
CHECK();
}
- if (ai->divisor)
+ if (ai->divisor) {
glVertexAttribDivisor(ai->index, ai->divisor);
+ CHECK();
+ }
glEnableVertexAttribArray(ai->index);
}
}
+void bind_attr_info(GLAttrInfo *ai, AttribInfo *in, unsigned count, unsigned pgm) {
+ for (int n = 0; n < count; n++, ai++, in++) {
+ ai->index = glGetAttribLocation(pgm, in->name);
+ if (ai->index < 0)
+ printx("WARNING: cannot find attribute '%s' (late)\n", in->name);
+ }
+}
+
/* map attribute names to indices, and adapt layout parameters for GL */
int setup_attr_info(GLAttrInfo **out, AttribInfo *in, unsigned count, unsigned pgm) {
GLAttrInfo *ai = (GLAttrInfo*) malloc(sizeof(GLAttrInfo) * count);
@@ -218,7 +230,7 @@ int setup_attr_info(GLAttrInfo **out, AttribInfo *in, unsigned count, unsigned p
ai[n].vidx = in->slot;
ai[n].index = glGetAttribLocation(pgm, in->name);
if (ai[n].index < 0)
- return error("cannot find attribute '%s'", in->name);
+ printx("WARNING: cannot find attribute '%s' (early)\n", in->name);
ai[n].pointer = in->offset;
ai[n].divisor = in->divisor;
switch (in->format) {
@@ -360,6 +372,7 @@ int App::compileShader(VertexShader *vs, const char *fn,
glDeleteShader(id);
return error("vertex shader '%s' bind error", fn);
}
+ vs->info = layout;
vs->count = lcount;
vs->vs = id;
printx("VertexShader %d compiled\n", id);
@@ -421,6 +434,7 @@ int App::initConfig(InputConfiguration *ic, VertexShader *vs, PixelShader *ps) {
glDeleteProgram(pgm);
return error("program link error");
}
+ bind_attr_info(vs->ai, vs->info, vs->count, pgm);
glGenVertexArrays(1, &vao);
CHECK();
glBindVertexArray(ic->vao);
@@ -570,4 +584,4 @@ void App::setBlend(int enable) {
glEnable(GL_BLEND);
else
glDisable(GL_BLEND);
-}
-\ No newline at end of file
+}