GL_OES_framebuffer_object

Supported Hardware

Series5, Series5XT, Series6, Series6XE, Series6XT

Valid APIs

OpenGL ES 1.x

Description

This extension defines a simple interface for drawing to rendering destinations other than the buffers provided to the GL by the windowing-system. This allows things to be drawn independently of VSync and enables multi-pass algorithms that previously would have been limited to using CopyTexImage2D on the main framebuffer. Framebuffers allow you to attach colour, depth and stencil attachments to be used as drawing buffers, and then bind the framebuffer to be drawn into. Subsequent draw operations will then take place in this framebuffer, until the main framebuffer is rebound. Textures attached in this way can then be read back in subsequent drawing operations. This extension also introduces "Renderbuffers", which work similarly to a texture but are managed by the GPU entirely, and cannot be read back later. They are typically used for things like a depth buffer where the end result does not matter and will never need flushing.

Note

This extension is part of the OpenGL ES 1.x Extension Pack Specification and is core functionality in OpenGL ES 2.0 and 3.0.

Registry Link

http://www.khronos.org/registry/gles/extensions/OES/OES_framebuffer_object.txt

Example

void Initialise() 
{ 
	// Create a framebuffer object 
	GLint framebufferObject; 
	glGenFramebuffersOES(1, &framebufferObject); 
	// Bind the framebuffer object to the current state 
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebufferObject) 
	// Create a depth renderbuffer 
	GLint renderBuffer; 
	glGenRenderbuffersOES(1, &renderBuffer); 
	// Bind and initialise it. 
	glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderBuffer); 
	glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, 1024, 1024); 
	// Attach the renderbuffer to the framebuffer 
	glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT,  
						GL_RENDERBUFFER_OES,  renderBuffer); 
	// Create a colour texture 
	GLint texture; 
	glGenTextures(1, &texture); 
	// Bind and initialise the texture 
	glBindTexture(GL_TEXTURE_2D, texture); 
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, 
							GL_UNSIGNED_BYTE, NULL); 
	// Attach the texture to the framebuffer 
	glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOUR_ATTACHMENT0_OES,  
								GL_TEXTURE_2D, texture, 0); 
	// Check framebuffer is complete 
	if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) 
	{ 
		// An error has occurred 
	} 
} 
void Render() 
{ 
	// Bind the framebuffer for rendering 
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebufferObject) 
	// Draw something 
	glDraw(...); 
	// Bind the default (EGL provided) framebuffer to actually draw to the screen 
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0) 
	// Draw something else, generally using the result of the framebuffer object's render. 
	glDraw(...); 
	// SwapBuffers 
	eglSwapBuffers(); 
}