Hello,
I'm trying to set up UBOs in my application but I'm not able to get the uniform' sizes in my uniform block.
Here is the code I use to get the size :
private void setUpUniformsOffsetsAndSizes(UniformBufferObjectInfos uniformBufferObjectInfos) {
int shaderProgramID = uniformBufferObjectInfos.getShaderProgramID();
String[] uniformNames = uniformBufferObjectInfos.getUniformsNames();
int nbUniforms = uniformNames.length;
// Retrieve the index of each uniform
IntBuffer uniformIndices = BufferUtils.createIntBuffer(nbUniforms);
GL31.glGetUniformIndices(shaderProgramID, uniformNames, uniformIndices);
// Retrieve the offset of each uniform
IntBuffer uniformsOffsets = BufferUtils.createIntBuffer(nbUniforms);
GL31.glGetActiveUniformsiv(shaderProgramID, uniformIndices, GL31.GL_UNIFORM_OFFSET, uniformsOffsets);
// Retrieve the size of each uniform
IntBuffer uniformsSizes = BufferUtils.createIntBuffer(nbUniforms);
GL31.glGetActiveUniformsiv(shaderProgramID, uniformIndices, GL31.GL_UNIFORM_SIZE, uniformsSizes);
// Store offset and size in UniformBufferObjectInfos
uniformBufferObjectInfos.setUniformsOffsets(uniformsOffsets);
uniformBufferObjectInfos.setUniformsSizes(uniformsSizes);
}
But I always get 1 when I'm asking for the sizes... My shader code is like this (I need the offset even if i'm using std140 here) :
layout (std140, binding = 0) uniform BlobSettings {
// Base Offset // Base Alignment // Aligned Offset
vec4 innerColor; // 0 // 16 // 0 - 15
vec4 outerColor; // 16 // 16 // 16 - 31
float radiusInner; // 32 // 4 // 32 - 35
float radiusOuter; // 36 // 4 // 36 - 40
};
Am I doing wrong ?
And finally, why does the BufferUtils class prevent us from doing like :
ByteBuffer updatedData = BufferUtils.createByteBuffer(4));
// do some stuff
bytes[] array = updatedData.array();
Because at some point in my code I need to convert my ByteBuffer to an array of bytes so the only solution I found was not to use BufferUtils :
ByteBuffer byteBuffer = ByteBuffer.allocate(values.length * 4).order(ByteOrder.nativeOrder());
for(float value : values) {
byteBuffer.putFloat(value);
}
byte[] bytesValues = byteBuffer.array();
Thanks for your help