1

我遇到了一些关于使用 gl_luminance 定义 FBO 的问题。这是我使用的代码,

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

相关代码如下,

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;
}

问题是当我使用时,

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

代码进展顺利。但如果使用 gl_luminance 代替,

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

我不知道为什么我不能使用 GL_LUMINANCE 来定义 FBO。有人有一些有用的建议来解决这个问题吗?

4

3 回答 3

4

根据规范文档中的表 4.5,保证在 ES 2.0 中用作彩色 FBO 附件的唯一格式是:

  • GL_RGBA4
  • GL_RGB5_A1
  • GL_RGB565

标准不要求支持渲染为适合您的 GL_RGBA。不过,许多实现都支持它。OES_rgb8_rgba8 扩展增加了对渲染目标的支持GL_RGB8和格式化。GL_RGBA8

GL_LUMINANCE标准不支持作为可渲染颜色的格式,我也找不到它的扩展名。某些实现可能会支持它,但您当然不能指望它。

ES 3.0GL_R8列为可呈现颜色的格式。在 ES 3.0 中,RED/R格式替换了ES 2.0 中的LUMINANCE/ALPHA格式。因此,如果您可以迁移到 ES 3.0,您就可以支持渲染为 1-component 纹理格式。

于 2014-06-22T13:58:00.080 回答
1

您正在使用仅在 OpenGL-3 中引入的非扩展 FBO 函数。因此,与 FBO 扩展函数(以 结尾ARB)不同,这些函数仅在 OpenGL-3 上下文中可用。在 OpenGL-3 中,不推荐使用 GL_LUMINANCE 和 GL_ALPHA 纹理内部格式,在核心配置文件中不可用。它们已被 GL_RED 纹理格式取代。您可以使用适当编写的着色器或纹理 swizzle 参数来使 GL_RED 纹理像dst.rgb = texture.rGL_LUMINANCE (swizzle) 或 GL_ALPHA (swizzle dst.a = texture.r) 一样工作。

于 2014-06-22T11:10:46.740 回答
0

我已经通过使用 GL_RG_EXT 或 GL_RED_EXT 来解决。

于 2014-06-24T07:07:47.927 回答