Hello. I am trying to uppload an array of matrices to my glsl shader. I don't think my way of doing it is the correc way:
void Shader::setMatrixArray(std::string name, std::vector<glm::mat4>matrices)
{
glUniformMatrix4fv(m_uniformLocation[name], matrices.size(), GL_FALSE,(float*)&matrices[0]);
Helper::logError("failed to set matrix array");
}
if I check my list of uniform locations using a break point i noticed that, the g_skeleton (the matrix array) varible has the same location as my projection matrix:
+ [0] ("g_projection", 0) std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,int>
+ [1] ("g_skeleton", 0) std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,int>
+ [2] ("g_view", 1) std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,int>
+ [3] ("g_world", 2) std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,int>
Is this normal?
They are declared like this in my vertex shader:
#version 330
#define MAX_BONE_COUNT 40
uniform mat4 g_view;
uniform mat4 g_projection;
uniform mat4 g_world;
uniform mat4 g_skeleton[MAX_BONE_COUNT];
etc....
And just to be thorugh, this is how i save my uniforms:
bool Shader::addUniformVariable(std::string name)
{
int location = glGetUniformLocation(m_program, name.c_str());
Helper::logError("Shader::addUniformVariable() failed");
if(location == -1)
{
return false;
}
m_uniformLocation[name] = location;
return true;
}
If I dont use the matrix array evrything works just fine.