OpenGL ES 3 - Uniform buffer object with float array 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, &amp;blockSize);

glGenBuffers(1, &amp;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?
Let's review what the specification says about std140 layout of arrays:


  If the member is an array of scalars or vectors, the base alignment and array stride are set to match the base alignment of a single array element, according to rules (1), (2), and (3), and rounded up to the base alignment of a vec4. The array may have padding at the end; the base offset of the member following the array is rounded up to the next multiple of the base alignment.


Emphasis added.

So, if you have an array of float, the array stride shall be the same as the base alignment of a vec4. Also, each array will be padded at the end to the base alignment of a vec4. Yes, a float[] takes up the same room as a vec4[] of the same size.

Welcome to the wonderful world of std140 layout.

If you want to have a real array of floats in a UBO... well, it's best to avoid wanting that. But if you have absolutely no other choice, then I suggest making it an array of vec4. Obviously, the size of this array will be the size you actually want, divided by 4 and rounded up:

const int samples = 31;
const int arraySize = ((samples + 3) / 4);


To fetch a single float from this array, use math:

arrayOfVec4[index / 4][index % 4]


Note that OpenGL ES 3.0 does allow non-constant array indexing of vec and mat types. It also allows the integer operations needed to pull this off.