When trying to attach texture buffer with half floating point to frame buffer it caused GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT , How I can solve this?
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_HALF_FLOAT, NULL);
GLuint depthbf;
glGenRenderbuffers(1, &depthbf);
glBindRenderbuffer(GL_RENDERBUFFER, depthbf);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
GLuint framebf;
glGenFramebuffers(1, &framebf);
glBindFramebuffer(GL_FRAMEBUFFER, framebf);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
glCheckFramebufferStatus(GL_FRAMEBUFFER); // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbf);
glCheckFramebufferStatus(GL_FRAMEBUFFER);//GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
I tested this sample on Mali T760 GPU (Galaxy S6).
when I change this line
with
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
there is no problem but I want to readPixels as floating Point.
glReadPixels(0, 0, width, height, GL_RGBA, GL_FLOAT, data);
after I changes format type to integer 32 bit, I failed to read integer data from frame buffer returned data all zeroes.
while I type data in shader the shader (hard coded) - commented line - the data returned by the values.
I checked if there is any error but no errors found.
Can anyone help me to solve this problem?
/ *********** frame buffer ********** /
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, width, height, 0, GL_RGBA_INTEGER, GL_INT, NULL);
/********* texture ********/
int32_t * data = (int32_t*) malloc(size * sizeof(int32_t));
// for loop to fill data
for (int i = 0; i < size ; i = 4+i) {
data[i] = 1;
data[i+1] = 0;
data[i+2] = 0;
data[i+3] = 0;
}
glGenTextures(1,&_Mat);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,_Mat);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, width, height, 0, GL_RGBA_INTEGER, GL_INT, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
// after run the kernel I read the output buffer by this line
glReadPixels(0, 0, width, height,GL_RGBA_INTEGER, GL_INT, outData);
// ***** fragment Shader *******//
uniform sampler2D myMat;
void main()
{
// just for testing I read the input data
gl_FragColor = texture2D(myMat,vec2(0.5,0.5));
// gl_FragColor = vec4(1,0,0,0);
};
Thanks in advance,
Your sampler type is wrong in the fragment shader if you are reading from an integer texture. Signed and unsigned integer formats have a specialist sampler type (isampler2D for signed integer and usampler2D for unsigned integer), so it's likely just returning black.
Also, you are setting up bilinear filtering (GL_LINEAR) for your texturing filter, which isn't allowed for integer formats. They are not filterable in the standard, and only support GL_NEAREST.
HTH,
Pete
Actually I changed sampler2D to isampler2D after I asked the question.
I removed texturing filter but the output still the same all channels = zeros except alpha channel =1
Any suggestions?