I'm trying to load an array of float to a fragment shader using a uniform buffer object, but it doesn't work. In the fragment shader I declared the following uniform block:
/// Spectrum samples.
const int samples = 31;
layout(std140) uniform SpectralDataBlock {
float illuminant[samples];
float object[samples];
};
Then on client side in my C++ code:
float illuminant[31] = {
82.754900,91.486000,93.431800,86.682300,104.865000,117.008000,117.812000,114.861000,115.923000,108.811000,109.354000,
107.802000,104.790000,107.689000,104.405000,104.046000,100.000000,96.334200,95.788000,88.685600,90.006200,89.599100,
87.698700,83.288600,83.699200,80.026800,80.214600,82.277800,78.284200,69.721300,71.609100
};
float object[31] = {
0.051, 0.05, 0.049, 0.049, 0.049, 0.049, 0.048, 0.047, 0.045, 0.044,
0.044, 0.044, 0.044, 0.044, 0.045, 0.047, 0.05, 0.057, 0.072, 0.109,
0.192, 0.332, 0.486, 0.598, 0.654, 0.686, 0.7, 0.707, 0.718, 0.724,
0.729
};
std::copy(illuminant, illuminant + 31, spectralData);
std::copy(object, object + 31, spectralData + 31);
blockId = glGetUniformBlockIndex(program, "SpectralDataBlock");
glUniformBlockBinding(program, blockId, bindingPoint);
glGetActiveUniformBlockiv(program, blockId, GL_UNIFORM_BLOCK_DATA_SIZE, &blockSize);
glGenBuffers(1, &bufferId);
glBindBuffer(GL_UNIFORM_BUFFER, bufferId);
glBufferData(GL_UNIFORM_BUFFER, blockSize, spectralData, GL_DYNAMIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, bindingPoint, bufferId);
Unfortunately, the data doesn't get correctly loaded.
Are there any limitation in OpenGL ES the prevent to use float[] in an uniform buffer object? Are there any error in my code above?