我有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);
但是当附加到framebuffer时,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;
}
我做错了什么?
答案 0 :(得分:2)
附加到 GL_COLOR_ATTACHMENTn 的纹理需要使用颜色可渲染格式。不幸的是,浮点格式不是颜色可渲染的。有关颜色可渲染格式的列表,请查看http://www.khronos.org/registry/gles/specs/3.0/es_spec_3.0.2.pdf
中的表3.12