glGetAttribLocation and a -1 return value?

Started by
17 comments, last by MARS_999 15 years, 2 months ago
From a quick (and pretty tired) look at it, it should work alright. I'm actually not entirely sure what glGetAttribLocation is supposed to return when you bind the streams manually. Logically it should just echo the stream binding, but I never tried it. There is a kind of non-orthogonality in the standard here, since you are allowed to manually bind to an unused attribute, yet you cannot query it. I also do manual binding in my engine, but I directly use the bound vertex attribute stream indices without re-querying them. Have you tried that ? Does that work ?

Ah wait a second. Do you actually use a GS in that example ?
Advertisement
Hey YannL, no I send in a empty string and it doesn't setup the GS.

Add, I am going to ask this because I am not seeing straight anymore, do I need to setup my VBO and IBO before I setup the shaders? I wouldn't think so, but I am really reaching here.
Quote:Original post by MARS_999
Hey YannL, no I send in a empty string and it doesn't setup the GS.
Sent an empty string where?

I would advise you try two things:
a) comment out the manual binding, and see if you get attribute locations
b) don't use getAttrib, instead just bind to the locations you manually set

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

if(!gsFilename.empty())
that there is "" so it skips the code blocks...

Anyway, I commented out the getAttrib() and used the glBindAttribLocation() and still nothing, like I said I don't even get gl_Normal to show up in the list when its printed off. Why is that? I have gl_Normal in the damn VS.... Why I am so pissed is, the code is pulled from my engine, but I am not understanding why its not working, when 1. No errors from the shader logs, other than glGetError() throwing and invalid value after the shader is shutdown.
Well, I am afraid that I am out of advice at this point. Do you have access to a copy of gDEBugger?

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

My bet:
The compiler optimized the code, removing unused variables. If you try to bind to an unused variable you will get -1 as a result.

Just a test'n'try, but how about changing your lightDir calculation from

lightDir = lightDir * TBN;

to

lightDir = TBN * lightDir;

Does it help ?

--
Ashaman
Hey someone with a similar problem.

For some reason glGetUniformLocationARB, always returns -1.

I am currently at the point where I copied all the code to set up shaders from a tutorial and it still does not work.

Greetz Jaap
Just a shot in the dark here, but do you actually use 'lightDir' inside the fragment shader? I know it's a dumb question but since the vs/fs are linked in a program, the driver is free to "optimize" out unused varyings. I'm not sure if it does, i'm just guessing.

HellRaiZer
HellRaiZer
As someone else already pointed out, you need to actually use the register at some point in the shader, my problem was, I thought/assumed it only needed to be used in the shader in which I declared it in. e.g. attributes are only vertex shader so I figured I only need to do something in the VS such as assign it to a new variable and that would be good enough. Nope, the compiler is smart enough to see you never used it to do anything so it will -1 it and not use it. You need to actually do something with it in the FS also from what I could tell... Maybe that isn't the case but when I passed the attribute as a varying with some math done on it in the VS, and did something with it in the FS it assigned a index, but just multiplying it by a value in the VS and doing nothing else with it, gave me a -1.

Hope this clears up for others.

This topic is closed to new replies.

Advertisement