Hello everyone,
In the documentation i have found the following article about uniforms in the web:
http://www.opengl.org/wiki/Uniform_(GLSL)
I guess this is some sort of reference or documentation of OpenGL but as always with OpenGL im not sure if can be taken serious or if its once more one of those "Hey vendor, you can implement it like that if you feel like it but if not do whatever you want because we want to be free."-Documentations...
Anyway, i found the following in said article:
layout(location = 2) uniform mat4 modelToWorldMatrix;Calling glGetUniformLocation(prog, "modelToWorldMatrix");? with this guaranteed to return 2.
Ok, fair enough, so i wrote the following in my shader:
layout(location = 16) uniform sampler2D alphaTexture;
According to the documentation 16 is a perfectly valid uniform location as the card has to support at least 1024. So i ran my program and set a breakpoint on the following:
gTextureInput->setTexture(L"alphaTexture", mAlphaTexture);
Which resulted in the following call:
bool Program::tryGetUniformIndex(const std::wstring& name, uint32& index) {
auto itr = mUniformMap.find(name);
if(itr != mUniformMap.end()) {
index = itr->second;
return true;
}
GLint ret = glGetUniformLocation(mProgram, toAnsi(name).c_str());
if(ret == -1)
return false;
index = static_cast<uint32>(ret);
return true;
}
Very well, i expected ret to be 16 as i checked "name" to be "alphaTexture" but to my surprise it was 4. I tested various values from 0 to 128 but glGetUniformLocation NEVER returned that number (except of course if i set it to 4).
I dont know if its my english but i somehow understand "guaranteed" to be slightly different from what i observe.
Does anyone have some more insight on that?
Greetings
Plerion