static int setUniform(GLint progHandle, ActiveUniform *u) { int error; GLint location; dbgPrint(DBGLVL_INFO, "setUniform(%i, %s)\n", progHandle, u->name); /* handle the special case of a uninitialized sampler uniform */ if (isSamplerType(u->type)) { GLint numTexUnits, maxTexCoords, maxCombinedTextureImageUnits; ORIG_GL(glGetIntegerv)(GL_MAX_TEXTURE_COORDS, &maxTexCoords); ORIG_GL(glGetIntegerv)(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxCombinedTextureImageUnits); numTexUnits = maxTexCoords > maxCombinedTextureImageUnits ? maxTexCoords : maxCombinedTextureImageUnits; if (((GLint*)u->value)[0] < 0 || ((GLint*)u->value)[0] >= numTexUnits) { dbgPrint(DBGLVL_INFO, "Sampler \"%s\" seems to be uninitialized (%i/%i/%i); ignoring\n", u->name, ((GLint*)u->value)[0], maxTexCoords, maxCombinedTextureImageUnits); return DBG_NO_ERROR; } } location = ORIG_GL(glGetUniformLocation)(progHandle, u->name); error = glError(); if (error) { return error; } if (location < 0) { dbgPrint(DBGLVL_INFO, "HMM, A UNIFORM NAMED \"%s\" IS NOT KNOWN TO " "THE PROGRAM\n", u->name); return DBG_NO_ERROR; } if (isMatrixType(u->type)) { switch (u->type) { case GL_FLOAT_MAT2: ORIG_GL(glUniformMatrix2fv)(location, u->size, 0, u->value); break; case GL_FLOAT_MAT2x3: ORIG_GL(glUniformMatrix2x3fv)(location, u->size, 0, u->value); break; case GL_FLOAT_MAT2x4: ORIG_GL(glUniformMatrix2x4fv)(location, u->size, 0, u->value); break; case GL_FLOAT_MAT3: ORIG_GL(glUniformMatrix3fv)(location, u->size, 0, u->value); break; case GL_FLOAT_MAT3x2: ORIG_GL(glUniformMatrix3x2fv)(location, u->size, 0, u->value); break; case GL_FLOAT_MAT3x4: ORIG_GL(glUniformMatrix3x4fv)(location, u->size, 0, u->value); break; case GL_FLOAT_MAT4: ORIG_GL(glUniformMatrix4fv)(location, u->size, 0, u->value); break; case GL_FLOAT_MAT4x2: ORIG_GL(glUniformMatrix4x2fv)(location, u->size, 0, u->value); break; case GL_FLOAT_MAT4x3: ORIG_GL(glUniformMatrix4x3fv)(location, u->size, 0, u->value); break; } } else if (isIntType(u->type)) { switch (uniformNumElements(u)) { case 1: ORIG_GL(glUniform1iv)(location, u->size, u->value); break; case 2: ORIG_GL(glUniform2iv)(location, u->size, u->value); break; case 3: ORIG_GL(glUniform3iv)(location, u->size, u->value); break; case 4: ORIG_GL(glUniform4iv)(location, u->size, u->value); break; } } else if (isUIntType(u->type)) { switch (uniformNumElements(u)) { case 1: ORIG_GL(glUniform1uivEXT)(location, u->size, u->value); break; case 2: ORIG_GL(glUniform2uivEXT)(location, u->size, u->value); break; case 3: ORIG_GL(glUniform3uivEXT)(location, u->size, u->value); break; case 4: ORIG_GL(glUniform4uivEXT)(location, u->size, u->value); break; } } else { /* float type */ switch (uniformNumElements(u)) { case 1: ORIG_GL(glUniform1fv)(location, u->size, u->value); break; case 2: ORIG_GL(glUniform2fv)(location, u->size, u->value); break; case 3: ORIG_GL(glUniform3fv)(location, u->size, u->value); break; case 4: ORIG_GL(glUniform4fv)(location, u->size, u->value); break; } } error = glError(); if (error) { return error; } else { return DBG_NO_ERROR; } }
bool UniformMatrix::isDefault(const string &name, GLenum type) { return isMatrixType(type) && isDefaultName(name); }