Jump to content

  • Log In with Google      Sign In   
  • Create Account

uniform location contradicting documentation


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Plerion   Members   -  Reputation: 368

Like
0Likes
Like

Posted 14 February 2013 - 10:27 AM

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



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7978

Like
0Likes
Like

Posted 14 February 2013 - 11:28 AM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 Plerion   Members   -  Reputation: 368

Like
0Likes
Like

Posted 14 February 2013 - 01:29 PM

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.



#4 noizex   Members   -  Reputation: 868

Like
0Likes
Like

Posted 14 February 2013 - 06:10 PM

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



#5 Plerion   Members   -  Reputation: 368

Like
0Likes
Like

Posted 17 February 2013 - 01:04 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS