Reputation: 3
Im doing trillinear interpolation using Shader Storage Buffer Object. So i access my ssbo in fragment shader like this:
layout(std430, binding = 0) buffer ColorSSBO { int value[]; };
int c000 = value[x0 + y0 * dataWidth + z0 * area];
int c100 = value[x1 + y0 * dataWidth + z0 * area];
int c010 = value[x0 + y1 * dataWidth + z0 * area];
int c110 = value[x1 + y1 * dataWidth + z0 * area];
int c001 = value[x0 + y0 * dataWidth + z1 * area];
int c101 = value[x1 + y0 * dataWidth + z1 * area];
int c011 = value[x0 + y1 * dataWidth + z1 * area];
int c111 = value[x1 + y1 * dataWidth + z1 * area];
It is becoming very inefficient since this buffer is huge, if I could read multiple elements of the array at once it would be great, or at least those that go in a row
I dont need to modify this array, I feel like I missing something, maybe there is some keyword for readonly
this is how I load ssbo using lwjgl:
public void loadSSBO(int[][] values){
if (ssbo != 0) GL15.glDeleteBuffers(ssbo);
int size = values[0].length;
long pixelSIZE = size * (Integer.SIZE / 8);
ssbo = GL15.glGenBuffers();
GL33.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, ssbo);
GL15.glBufferData(GL43.GL_SHADER_STORAGE_BUFFER, pixelSIZE * values.length, GL15.GL_STATIC_DRAW); // declare buffer
for (int i = 0; i < values.length; i++) {
GL15.glBufferSubData(GL43.GL_SHADER_STORAGE_BUFFER, pixelSIZE * i, values[i]);
}
GL33.glBindBufferBase(GL43.GL_SHADER_STORAGE_BUFFER, 0, ssbo);
GL33.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, 0); //unbind
}
Upvotes: 0
Views: 512