ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
FrameBufferObject.cpp
Go to the documentation of this file.
1 // File: FrameBufferObject.cpp
3 // Author: Changchang Wu
4 // Description : Implementation of FrameBufferObject Class
5 //
6 //
7 //
8 // Copyright (c) 2007 University of North Carolina at Chapel Hill
9 // All Rights Reserved
10 //
11 // Permission to use, copy, modify and distribute this software and its
12 // documentation for educational, research and non-profit purposes, without
13 // fee, and without a written agreement is hereby granted, provided that the
14 // above copyright notice and the following paragraph appear in all copies.
15 //
16 // The University of North Carolina at Chapel Hill make no representations
17 // about the suitability of this software for any purpose. It is provided
18 // 'as is' without express or implied warranty.
19 //
20 // Please send BUG REPORTS to ccwu@cs.unc.edu
21 //
23 
24 
25 #include "GL/glew.h"
26 #include <stdlib.h>
27 #include "GlobalUtil.h"
28 #include "FrameBufferObject.h"
29 
30 //whether use only one FBO globally
32 GLuint FrameBufferObject::GlobalFBO=0;
33 
35 // Construction/Destruction
37 
39 {
40  if(UseSingleFBO && GlobalFBO)
41  {
42  _fboID = GlobalFBO;
43  }else
44  {
45  glGenFramebuffersEXT(1, &_fboID);
46  if(UseSingleFBO )GlobalFBO = _fboID;
47  }
48  if(autobind ) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fboID);
49 }
50 
52 {
53  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
54  if(!UseSingleFBO )
55  {
56  glDeleteFramebuffersEXT (1,&_fboID);
57  }
58 }
59 
61 {
62  if(UseSingleFBO)
63  {
64  glDeleteFramebuffersEXT (1,&GlobalFBO);
65  GlobalFBO = 0;
66  }
67 }
68 
69 void FrameBufferObject::AttachDepthTexture(GLenum textureTarget, GLuint texID)
70 {
71 
72  glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, textureTarget, texID, 0);
73 }
74 
75 void FrameBufferObject::AttachTexture(GLenum textureTarget, GLenum attachment, GLuint texId)
76 {
77  glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment, textureTarget, texId, 0);
78 }
79 
81 {
82  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fboID);
83 }
84 
86 {
87  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
88 }
89 
90 void FrameBufferObject::UnattachTex(GLenum attachment)
91 {
92  glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, 0, 0 );
93 }
94 
95 void FrameBufferObject::AttachRenderBuffer(GLenum attachment, GLuint buffID)
96 {
97  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attachment, GL_RENDERBUFFER_EXT, buffID);
98 
99 }
100 
102 {
103  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attachment, GL_RENDERBUFFER_EXT, 0);
104 }
105 
static void AttachRenderBuffer(GLenum attachment, GLuint buffID)
static void DeleteGlobalFBO()
static void UnbindFBO()
static void UnattachRenderBuffer(GLenum attachment)
FrameBufferObject(int autobind=1)
static void AttachDepthTexture(GLenum textureTarget, GLuint texID)
static void AttachTexture(GLenum textureTarget, GLenum attachment, GLuint texID)
static void UnattachTex(GLenum attachment)