void FrameBuffer::CreateTexturesAndBind() { // Create textures for each buffer. for (int i = 0; i < renderBuffers.Size(); ++i) { RenderBuffer * rb = renderBuffers[i]; // Actually create it. rb->CreateBuffer(); rb->CreateTexture(); // Bind them straight away too. rb->BindTextureToFrameBuffer(); } }
void FrameBuffer::CreateRenderBuffers() { /// OpenGL specific data /// Frame buffer object for deferred shading //GLuint frameBufferObject; // Main frame buffer object to use //GLuint depthBuffer; // Depth buffer to act as Z-buffer for when parsing the input to the frame buffer //GLuint positionTexture; // World coordinate position texture //GLuint diffuseTexture; // Diffuse texture //GLuint depthTexture; // Depth texture //GLuint normalTexture; // Normal texture // GLuint error; /// Setup main Frame buffer object if (frameBufferObject == -1) frameBufferObject = GLFrameBuffers::New(); error = glGetError(); /// Bind it for manipulatoin. glBindFramebuffer(GL_FRAMEBUFFER, frameBufferObject); AssertGLError("FrameBuffer::CreateRenderBuffers"); /// Establish some variables before we try tweaking properties.. Vector2i textureSize = size; /* /// Try oversampling o-o bool overSampling = false; if (overSampling){ glEnable( GL_MULTISAMPLE ); textureSize *= 2; } else glDisable(GL_MULTISAMPLE); */ /// Setup Render buffers AssertGLError("FrameBuffer::CreateRenderBuffers"); // Delete the old buffers as needed. for (int i = 0; i < renderBuffers.Size(); ++i) { RenderBuffer * rb = renderBuffers[i]; std::cout<<"\nDeallocating renderBuffer.."; delete rb; } renderBuffers.Clear(); // Create the buffers. RenderBuffer * depthBuf = new RenderBuffer("Depthbuf", BufferType::DEPTH_BUFFER, BufferStorageType::DEPTH_16F, textureSize), * diffBuf = new RenderBuffer("Diffuse", BufferType::COLOR_BUFFER_1, ColorStorageType(), textureSize)//, // * norBuf = new RenderBuffer(BufferType::COLOR_BUFFER_2, BufferStorageType::RGB_16F, textureSize), // * posBuf = new RenderBuffer(BufferType::COLOR_BUFFER_3, BufferStorageType::RGB_32F, textureSize) ; // Try adding the rest later on..? renderBuffers.Add(depthBuf); renderBuffers.Add(diffBuf); // renderBuffers.Add(norBuf); // renderBuffers.Add(posBuf); // Bind to 0 when done. glBindRenderbuffer(GL_RENDERBUFFER, 0); AssertGLError("FrameBuffer::CreateRenderBuffers"); // Create textures for each buffer. for (int i = 0; i < renderBuffers.Size(); ++i) { RenderBuffer * rb = renderBuffers[i]; // Actually create it. rb->CreateBuffer(); rb->CreateTexture(); // Bind them straight away too. rb->BindTextureToFrameBuffer(); } int frameBufferColorAttachmentsSet = 7; GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); // Check that status of our generated frame buffer AssertGLError("FrameBuffer::CreateRenderBuffers"); // Check that frame buffer is okay to work on. int result = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); switch(result) { case GL_FRAMEBUFFER_COMPLETE: // yay :3 break; case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: std::cout<<"\nINFO: Framebuffer incomplete attachment."; break; case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: std::cout<<"\nINFO: Framebuffer incomplete, missing attachment. Attach an image!"; break; case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: std::cout<<"\nINFO: Framebuffer incomplete draw buffer."; break; case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: std::cout<<"\nINFO: Framebuffer incomplete read buffer."; break; case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: std::cout<<"\nINFO: Framebuffer incomplete multisample."; break; case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: std::cout<<"\nINFO: Framebuffer incomplete layer targets."; break; case GL_FRAMEBUFFER_UNSUPPORTED: std::cout<<"\nINFO: Framebuffer unsupported."; break; default: std::cout<<"\nINFO: Unknown error in framebuffer ..."; break; } if (result != GL_FRAMEBUFFER_COMPLETE) { glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); std::cout<<"\nINFO: FrameBuffer not ready to be used."; SleepThread(10); return; } /// Only have frame buffer parameters in OpenGL 4.3 core and above... if (GL_VERSION_MAJOR >= 4 && GL_VERSION_MINOR >= 3){ /// Set frame buffer parameters // glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 512); // glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 512); // glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, 4); error = glGetError(); } // Unbind our frame buffer object, along with its attached render buffers glBindFramebuffer(GL_FRAMEBUFFER, 0); AssertGLError("FrameBuffer::CreateRenderBuffers"); // Ok! good = true; }