Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL ES 3.0. Floating point texture

I have OpenGL ES 3.0 and I'm trying to create a texture:

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;

(for this code glGetError() return 0)

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

But when attaching to framebuffer the glCheckFramebufferStatus(GL_FRAMEBUFFER) return 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;
}

What am I doing wrong?

like image 884
user2881543 Avatar asked Nov 01 '22 12:11

user2881543


1 Answers

Textures attached to GL_COLOR_ATTACHMENTn are required to use color-renderable format. Unfortunately, float formats are not color-renderable. For list of color-renderable formats, check Table 3.12 in http://www.khronos.org/registry/gles/specs/3.0/es_spec_3.0.2.pdf

like image 143
Srđan Tot Avatar answered Nov 15 '22 04:11

Srđan Tot