5

我有 OpenGL ES 3.0,我正在尝试创建纹理:

case 1: glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, width, height, 0, GL_RED, GL_HALF_FLOAT, 0); break;
case 2: glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, width, height, 0, GL_RG, GL_HALF_FLOAT, 0); break;
case 3: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_HALF_FLOAT, 0); break;

(对于此代码 glGetError() 返回 0)

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

但是当附加到帧缓冲区时,glCheckFramebufferStatus(GL_FRAMEBUFFER) 返回 36054。

Surface CreateSurface(GLsizei width, GLsizei height, int numComponents)
{
 GLuint fboHandle;
 glGenFramebuffers(1, &fboHandle);
 glBindFramebuffer(GL_FRAMEBUFFER, fboHandle);

 GLuint textureHandle;
 glGenTextures(1, &textureHandle);
 glBindTexture(GL_TEXTURE_2D, textureHandle);
 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, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

 switch (numComponents) {
        case 1: glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, width, height, 0, GL_RED, GL_HALF_FLOAT, 0); break;
        case 2: glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, width, height, 0, GL_RG, GL_HALF_FLOAT, 0); break;
        case 3: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_HALF_FLOAT, 0); break;
        default: PezFatalError("Illegal slab format.");
    }


 PezCheckCondition(GL_NO_ERROR == glGetError(), "Unable to create normals texture");

 GLuint colorbuffer;
 glGenRenderbuffers(1, &colorbuffer);
 glBindRenderbuffer(GL_RENDERBUFFER, colorbuffer);
 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureHandle, 0);
 PezCheckCondition(GL_NO_ERROR == glGetError(), "Unable to attach color buffer");

 PezCheckCondition(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER), "Unable to create FBO.");
 Surface surface = { fboHandle, textureHandle, numComponents };

 glClearColor(0, 0, 0, 0);
 glClear(GL_COLOR_BUFFER_BIT);
 glBindFramebuffer(GL_FRAMEBUFFER, 0);

 return surface;
}

我究竟做错了什么?

4

1 回答 1

2

附加到GL_COLOR_ATTACHMENTn的纹理需要使用颜色渲染格式。不幸的是,浮点格式不能进行颜色渲染。有关可呈现颜色的格式列表,请查看http://www.khronos.org/registry/gles/specs/3.0/es_spec_3.0.2.pdf中的表 3.12

于 2013-10-15T11:17:28.837 回答