0
votes

I've implemented sample code to convert YUV colorspace to RGB using openGL ES 3.0 for android. I've vertex & fragment shaders where i defined converison formula.

I've created textures as below,

glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &ytex);
glBindTexture(GL_TEXTURE_2D,ytex);
GLint textureBinding;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
if(textureBinding == 0)
{
        char* infoLog = (char*) malloc(100);
        glGetProgramInfoLog(programObject, textureBinding, NULL, infoLog);
        errormsg = infoLog;
        free (infoLog);
}
// Setup the texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//Define the texture image
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 640, 480, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, yBuffer);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ytex, 0);

glActiveTexture(GL_TEXTURE1);
glGenTextures(1, &utex);
glBindTexture(GL_TEXTURE_2D,utex);
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
if(textureBinding == 0)
{
        char* infoLog = (char*) malloc(100);
        glGetProgramInfoLog(programObject, textureBinding, NULL, infoLog);
        errormsg = infoLog;
        free (infoLog);
}

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
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_LUMINANCE, 320, 240, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, uBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, utex, 0);
glActiveTexture(GL_TEXTURE2);
glGenTextures(1, &vtex);
glBindTexture(GL_TEXTURE_2D,vtex);
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
if(textureBinding == 0)
{
        char* infoLog = (char*) malloc(100);
        glGetProgramInfoLog(programObject, textureBinding, NULL, infoLog);
        errormsg = infoLog;
        free (infoLog);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 320, 240, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);

I'm not getting any errors when i verify using glGetError().

The output of textures i dont want to display on viewport, instead i want to store it in one buffer in order to use the output later. So i created framebuffer and render buffer as below,

//Framebuffer
glGenFramebuffers(1, &fboId);
glBindFramebuffer(GL_FRAMEBUFFER, fboId);


glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, vtex, 0);
//Check the framebuffer status
GLint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
{
        char* infoLog = (char*) malloc(100);
        glGetProgramInfoLog(programObject, status, NULL, infoLog);
        errormsg = infoLog;
        free (infoLog);}

When i verify the status it is always returning 36054(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT), but the same returning GL_FRAMEBUFFER_COMPLETE when i unbind the buffer before calling glCheckFrameBufferStatus()

     glbindFrameBuffer(GL_FRAMEBUFFER, 0);

So later i want to read the output from the framebuffer using glReadpixels(), but that is also failing. Please someone help how to resolve this issue?

2

2 Answers

2
votes

36054 means GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT check your view's frame is right ?

0
votes

There is no implementation of OpenGL / OpenGL ES supports alpha or luminance textures as color-renderable. You can replicate the behavior with GL_R8,GL_RG8. These two formats are very useful when you want to draw into a one or two-channel image format using an FBO (since GL_LUMINANCE, GL_ALPHA and GL_LUMINANCE_ALPHA are not color-renderable formats).

Try replacing internal format with GL_R8 and format with GL_RED.