PDA

View Full Version : Passing unifrom glm::vec3 array to shader



deejay
03-12-2014, 01:14 AM
Hello guys,

Im trying to pass an array with vec3 to a fragmentshader.
My code looks like this, but I think it`s wrong:



bool Shader::SetShaderVec3ArrayParameter(const char* pName, vec3 pValue[])
{
int loc = glGetUniformLocation(m_shaderProgram, pName);
if (loc >= 0)
{
glUniform3fv(loc, sizeof(pValue),(float*)pValue);

return true;
}

return false;
}



can anyone tell me how to pass an array of vec3 to a shader as an uniform variable?!
Thanks in advance

Chris_F
03-12-2014, 02:58 AM
What version of OpenGL are you using?

In OpenGL 4 I would maybe create a uniform buffer with glBufferStorage (if available to you) otherwiese glBufferData. I would then use glBindBufferBase with an explicit binding point, as to avoid any shader reflection.

ex:



layout(binding = 0, std140) uniform SomeBlock
{
vec3 data[MAX_DATA_ARRAY_SIZE];
};

Agent D
03-12-2014, 06:29 AM
bool Shader::SetShaderVec3ArrayParameter(const char* pName, vec3 pValue[])
{
....
glUniform3fv(loc, sizeof(pValue),(float*)pValue);
....
}


pValue is a pointer to a vec3. sizeof(pValue) is the size of a pointer as a multiple as the size of a char. Probably 8 or 4 or something.
What is your vec3 anyway? Does it really store exactely 3 float value with no padding whatsoever?

deejay
03-12-2014, 09:29 AM
[CODE]

What is your vec3 anyway? Does it really store exactely 3 float value with no padding whatsoever?

vec3 is a glm::vec3 from an OpenGl Mathematics library

glm.g-truc.net/0.9.5/index.html


I thought that it stores 3 float values as a vec3. When I pass just one vec3, everything works fine. Only the array isn`t working.

deejay
03-12-2014, 09:31 AM
What version of OpenGL are you using?
[/code]

I`m using OpenGL 4. I don`t think that I get your code right :o. Can you describe it more in detail?

Chris_F
03-12-2014, 10:49 PM
I`m using OpenGL 4. I don`t think that I get your code right :o. Can you describe it more in detail?

http://www.opengl.org/sdk/docs/man/docbook4/xhtml/glBufferStorage.xml

https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glBindBufferBase.xml

http://www.opengl.org/registry/specs/ARB/shading_language_420pack.txt

http://www.opengl.org/wiki/Interface_Block_%28GLSL%29#Uniform_blocks