I would like to know what is accepted practice for allocating uniform buffers. These uniforms are specifically going to be updated frequently.
Method #1: "Direct Allocation"
FloatBuffer directBuffer = BufferUtils.createFloatBuffer(16);
// Render Loop
while (condition) {
myMatrix.putInto(directBuffer);
glUniformMatrix4fv(uniformLocation, false, directBuffer);
}
Method #2: "Stack Allocation"
// Render Loop
while (condition) {
try (MemoryStack stack = pushStack()) {
FloatBuffer stackBuffer = stack.mallocFloat(16);
myMatrix.putInto(stackBuffer);
glUniformMatrix4fv(uniformLocation, false, stackBuffer);
}
}
The potentially naïve side of me would like to believe that Method #1 would be most ideal. Because the buffer can be recycled each render call and utilized throughout the program's lifetime.