uniform location contradicting documentation

Started by
3 comments, last by Plerion 11 years, 2 months ago

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

Advertisement

Explicit locations for uniforms are only valid in GL4.3, so if you're using a lower version (currently only NVIDIA have a GL4.3 driver) you won't have this functionality. Instead you need to do the glGetUniformLocation dance for each uniform you're using.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Thats very disappointing, i find this to be one of the central features a programmable stage should have (but hey, giving users the ability to debug an OpenGL application was introduced in mid 2010, so yeah...). Im using several permutations of a shader and because i dont have the slightest bit of control over what happens during compilation i have to retrieve every uniform for every permutation separately... *sigh*

Anway, thanks for your reply, i didnt see the box on the right, probably because i expected something as trivial as this to be implemented.

Any particular reason why you're not using Uniform Buffer Objects?


Where are we and when are we and who are we?
How many people in how many places at how many times?

I have no idea if there is one. Im currently forced to use OpenGL and i reall do not like it. I looked it up in the documentation but once again i fail to understand if there is a reason to not use them. What im talking about:

Core in version 4.3 Core since version 3.1

First of all: http://weknowmemes.com/wp-content/uploads/2011/09/epic-jackie-chan-template.png about the numbers

I think i can live with 3.1 but obviously not with 4.3. And then again i have no idea what to compare opengl 3.1 to, but the fact that its from 2009 makes me think that it cannot be compared to direct3d 9 which is from 2002 which then again would be way to restricting.

This topic is closed to new replies.

Advertisement