2

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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
user3500496
  • 97
  • 1
  • 9
  • 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 Jun 22 '14 at 12:27
  • Thx for your help a lot. I use OpenGL ES2.0, not OpenGL 3. why it still happen? – user3500496 Jun 23 '14 at 02:24
  • It is not valid in ES 2.0 either. – Andon M. Coleman Jun 23 '14 at 13:32
  • Thx. But if i insist on using GL_LUMINANCE, is there some solution for OpenGL ES2.0 ? – user3500496 Jun 24 '14 at 02:00
  • 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 Jun 24 '14 at 15:41
  • THX. i have solved it by using GL_RG_EXT. But if i use GL_UNSIGNED_BYTE to define the textureBuffer, it will also get wrong. Only if i use GL_HALF_FLOAT_OES, everything goes well. Could you help me with this? And i have posted the question here, http://stackoverflow.com/questions/24380576/puzzels-about-using-gl-rg-ext-and-gl-unsinged-byte – user3500496 Jun 25 '14 at 00:56

3 Answers3

5

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.

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
1

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).

datenwolf
  • 159,371
  • 13
  • 185
  • 298
0

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

user3500496
  • 97
  • 1
  • 9