1
votes

I met some problem about using gl_luminance to define FBO. Here is the code i used,

 generateRenderToTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, _maskTexture, _imageWidth, _imageHeight, false);

related code is as follows,

TextureBuffer _maskTexture;

class TextureBuffer {
public:
GLuint texture;
GLuint frameBuffer;
GLenum internalformat;
GLenum format;
GLenum type;
int    w,h;

TextureBuffer() : texture(0), frameBuffer(0) {}
void release() 
{
    if(texture)
    {
        glDeleteTextures(1, &texture);
        texture = 0;
    }
    if(frameBuffer)
    {
        glDeleteFramebuffers(1, &frameBuffer);
        frameBuffer = 0;
    }

}
};

void generateRenderToTexture(GLint internalformat, GLenum format, GLenum type,
                                     TextureBuffer &tb, int w, int h, bool linearInterp)
{
    glGenTextures(1, &tb.texture);
    glBindTexture(GL_TEXTURE_2D, tb.texture);
    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_MIN_FILTER, linearInterp ? GL_LINEAR : GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, linearInterp ? GL_LINEAR : GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, NULL);

    glGenFramebuffers(1, &tb.frameBuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, tb.frameBuffer);
    glClear(_glClearBits);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tb.texture, 0);

    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if(status != GL_FRAMEBUFFER_COMPLETE)
        printf("Framebuffer status: %x", (int)status);

    tb.internalformat = internalformat;
    tb.format = format;
    tb.type = type;
    tb.w = w;
    tb.h = h;
}

The question is when I use,

generateRenderToTexture(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, _maskTexture, _imageWidth, _imageHeight, false);

The code went well. But if use gl_luminance instead,

generateRenderToTexture(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE,  _maskTexture,  _imageWidthOriginal, 

I don't know why i could not use GL_LUMINANCE to define the FBO. Anyone have some useful suggestions to solve this?

3
Your biggest problem here is that GL_LUMINANCE is not a color-renderable format. Yes it is deprecated in GL 3, but unless you have a core profile that will not matter. You can still do pixel transfer with this format (e.g. glReadPixels (...)) and use it for internal texture storage, but what you cannot do even in a compatibility profile is use it as an FBO attachment.Andon M. Coleman
Thx for your help a lot. I use OpenGL ES2.0, not OpenGL 3. why it still happen?user3500496
It is not valid in ES 2.0 either.Andon M. Coleman
Thx. But if i insist on using GL_LUMINANCE, is there some solution for OpenGL ES2.0 ?user3500496
No, there is not. You need a texture swizzle to accomplish what GL_LUMINANCE used to. So unless you use a shader, and a format like GL_R8, you are out of luck.Andon M. Coleman

3 Answers

4
votes

The only formats that are guaranteed to work as color FBO attachments in ES 2.0 are, according to table 4.5 in the spec document:

  • GL_RGBA4
  • GL_RGB5_A1
  • GL_RGB565

Support for rendering to GL_RGBA, which works for you, is not required by the standard. Many implementations support it, though. The OES_rgb8_rgba8 extension adds support for GL_RGB8 and GL_RGBA8 formats as render targets.

GL_LUMINANCE is not supported as a color-renderable format by the standard, and I can't find an extension for it either. It's possible that some implementations could support it, but you certainly can't count on it.

ES 3.0 lists GL_R8 as a color-renderable format. In ES 3.0, the RED/R formats replace the LUMINANCE/ALPHA formats from ES 2.0. So if you can move to ES 3.0, you have support to render to 1-component texture formats.

1
votes

You're using non-extension FBO functions, which were introduced only with OpenGL-3. So unlike FBO extension functions (ending with ARB) those functions are available only with a OpenGL-3 context. In OpenGL-3 the GL_LUMINANCE and GL_ALPHA texture internal formats are deprecated, are not available in core profile. They have been replaced by the GL_RED texture format. You can use an appropriately written shader or texture swizzle parameters to make a GL_RED texture work just like GL_LUMINANCE (swizzle dst.rgb = texture.r) or GL_ALPHA (swizzle dst.a = texture.r).

0
votes

I have solved by using GL_RG_EXT, or GL_RED_EXT, instead.