Hy,
Here is my code. It’s java, but the glCommands are nearly the same:
ssbo=glGenBuffers();
calcPointsShaderProgram.bind();
int pointscount=width*height;
glBindBuffer(GL_COPY_WRITE_BUFFER,ssbo);
glBufferData(GL_COPY_WRITE_BUFFER, FloatBuffer.allocate(pointscount*4), GL_DYNAMIC_DRAW);
glBindBuffer(GL_COPY_WRITE_BUFFER,0);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER,0,ssbo);
glMemoryBarrier(GL_ALL_BARRIER_BITS);
int tmpTexture=glGenTextures();
glBindTexture(GL_TEXTURE_2D, tmpTexture);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen_width, screen_height, 0, GL_RGB, GL_FLOAT, (ByteBuffer) null);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,0);
//glCopyImageSubData(feedbackTexture,GL_TEXTURE_2D,0,0,0,0,tmpTexture,GL_TEXTURE_2D,0,0,0,0,screen_width,screen_height,1);//falsch kopiert?
glBindFramebuffer(GL_READ_FRAMEBUFFER,feedbackFbo);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,tmpTexture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, screen_width,screen_height, 0);
glBindTexture(GL_TEXTURE_2D,0);
glBindFramebuffer(GL_READ_FRAMEBUFFER,0);
glActiveTexture(GL_TEXTURE0);
//glBindTexture(GL_TEXTURE_2D,feedbackTexture);
glBindTexture(GL_TEXTURE_2D,tmpTexture);
//glBindImageTexture(0, feedbackTexture, 0, false, 0, GL_READ_ONLY, GL_RGBA32F);
calcPointsShaderProgram.setUniform("fragCoordMap",0);
glDispatchCompute(1,1,1);
glMemoryBarrier(GL_ALL_BARRIER_BITS);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER,0,ssbo);
float[] pointsOutput=new float[pointscount];
glGetBufferSubData(GL_SHADER_STORAGE_BUFFER,0, pointsOutput);
for(int i=0;i<pointsOutput.length;i+=4){
if((pointsOutput[i]!=0||pointsOutput[i+1]!=0||pointsOutput[i+2]!=0)&&!(Float.isNaN(pointsOutput[i])||Float.isNaN(pointsOutput[i+1])||Float.isNaN(pointsOutput[i+2]))){
System.out.println((i+1)+"X: "+pointsOutput[i]+" Y: "+pointsOutput[i+1]+" Z: "+pointsOutput[i+2]);
}
}
And the glsl code:
#version 430
layout(local_size_x=1,local_size_y=1,local_size_z=1) in;
layout(std430, binding=0) buffer output_buffer
{
vec4 points[];//Vec3 will also be aligned as vec4!!!!
};
layout (binding = 1) uniform sampler2D fragCoordMap;
void main()
{
float zvalue=1.0*textureLod(fragCoordMap,vec2(0,0),0).x;
points[0]=vec4(textureLod(fragCoordMap,vec2(0,0),0).xy,zvalue,1.0);
}
So…The first problem is: All values of the texture are 0.0 . I tested the texture exactly before dispatching the compute and all values were written. Also in the shader I can read the correct texturesize without problems.
Second: For some reason I can maximal use two values from the texture in the vec4 constructor. Everything else causes, that there is no value in the feedbackbuffer.
Means:
points[0]=vec4(textureLod(fragCoordMap,vec2(0,0),0).xy,zvalue,1.0);
works!
But
float zvalue=1.0*textureLod(fragCoordMap,vec2(0,0),0).x;
points[0]=vec4(textureLod(fragCoordMap,vec2(0,0),0).xy,zvalue,1.0);
or
points[0]=vec4(textureLod(fragCoordMap,vec2(0,0),0).xyz,1.0);
doesn’t work!
First I thought it’s caused by mipmapping, but this should be fixed by the Usage of the Lod-function;
I hope you can help me!
Thank you in Advance
Destranix
(P.S.: In some points my code might not be optimized…That’s cause I’m not yet ready with it…So please don’t care about performance issues…)