Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00024
00025 #include "GL/glew.h"
00026 #include <stdlib.h>
00027 #include "GlobalUtil.h"
00028 #include "FrameBufferObject.h"
00029
00030
00031 int FrameBufferObject::UseSingleFBO=1;
00032 GLuint FrameBufferObject::GlobalFBO=0;
00033
00035
00037
00038 FrameBufferObject::FrameBufferObject(int autobind)
00039 {
00040 if(UseSingleFBO && GlobalFBO)
00041 {
00042 _fboID = GlobalFBO;
00043 }else
00044 {
00045 glGenFramebuffersEXT(1, &_fboID);
00046 if(UseSingleFBO )GlobalFBO = _fboID;
00047 }
00048 if(autobind ) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fboID);
00049 }
00050
00051 FrameBufferObject::~FrameBufferObject()
00052 {
00053 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
00054 if(!UseSingleFBO )
00055 {
00056 glDeleteFramebuffersEXT (1,&_fboID);
00057 }
00058 }
00059
00060 void FrameBufferObject::DeleteGlobalFBO()
00061 {
00062 if(UseSingleFBO)
00063 {
00064 glDeleteFramebuffersEXT (1,&GlobalFBO);
00065 GlobalFBO = 0;
00066 }
00067 }
00068
00069 void FrameBufferObject::AttachDepthTexture(GLenum textureTarget, GLuint texID)
00070 {
00071
00072 glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, textureTarget, texID, 0);
00073 }
00074
00075 void FrameBufferObject::AttachTexture(GLenum textureTarget, GLenum attachment, GLuint texId)
00076 {
00077 glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment, textureTarget, texId, 0);
00078 }
00079
00080 void FrameBufferObject::BindFBO()
00081 {
00082 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fboID);
00083 }
00084
00085 void FrameBufferObject::UnbindFBO()
00086 {
00087 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
00088 }
00089
00090 void FrameBufferObject::UnattachTex(GLenum attachment)
00091 {
00092 glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, 0, 0 );
00093 }
00094
00095 void FrameBufferObject::AttachRenderBuffer(GLenum attachment, GLuint buffID)
00096 {
00097 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attachment, GL_RENDERBUFFER_EXT, buffID);
00098
00099 }
00100
00101 void FrameBufferObject:: UnattachRenderBuffer(GLenum attachment)
00102 {
00103 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attachment, GL_RENDERBUFFER_EXT, 0);
00104 }
00105