| The upper-left FBO uses a half-float internal format (16 bits per component) but the other 8 FBO's can use a plain ol 'integer-based format. (again, it's 8 rather than 12 because we can ping-pong between two sets of FBO's) Here's how to create a half-float FBO using gl_arb_half_float_pixel: void phCreateFloatSurface(PHsurface *surface, GLboolean depth) { GLenum internalFormat = GL_RGBA16F_ARB; GLenum type = GL_HALF_FLOAT_ARB; GLenum filter = GL_NEAREST; // create a color texture glGenTextures(1, &surface->texture); glBindTexture(GL_TEXTURE_2D, surface->texture); glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, surface->width, surface->height, 0, GL_RGBA, type, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); glBindTexture(GL_TEXTURE_2D, 0); phCheckError("Creation of the color texture for the FBO"); // create depth renderbuffer if (depth) { glGenRenderbuffersEXT(1, &surface->depth); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, surface->depth); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, surface->width, surface->height); phCheckError("Creation of the depth renderbuffer for the FBO"); } else { surface->depth = 0; } // create FBO glGenFramebuffersEXT(1, &surface->fbo); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, surface->fbo); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface->texture, 0); if (depth) glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, surface->depth); phCheckFBO(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); phCheckError("Creation of FBO"); }Note that we use gl_nearest instead of gl_linear. using Linear with a float buffer is often detrimental to performance (or unsupported ). however our example still uses linear filtering for all the non-float FBO's. Well, that about wraps it up. I invite you to check out the source code below. I used plain old C and OpenGL 2.0, so it shoshould be fairly portable. you can copy it, mutilate it, or use it however you want. happy blooming! |