Project

General

Profile

Statistics
| Branch: | Revision:

root / rgbdslam / external / siftgpu / src / SiftGPU / FrameBufferObject.cpp @ 9240aaa3

History | View | Annotate | Download (2.82 KB)

1 9240aaa3 Alex
////////////////////////////////////////////////////////////////////////////
2
//        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
//
22
////////////////////////////////////////////////////////////////////////////
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
31
int                FrameBufferObject::UseSingleFBO=1;
32
GLuint        FrameBufferObject::GlobalFBO=0;
33
34
//////////////////////////////////////////////////////////////////////
35
// Construction/Destruction
36
//////////////////////////////////////////////////////////////////////
37
38
FrameBufferObject::FrameBufferObject(int autobind)
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
51
FrameBufferObject::~FrameBufferObject()
52
{
53
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
54
        if(!UseSingleFBO )
55
        {
56
                glDeleteFramebuffersEXT (1,&_fboID);
57
        }
58
}
59
60
void FrameBufferObject::DeleteGlobalFBO()
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
80
void FrameBufferObject::BindFBO()
81
{
82
  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fboID);
83
}
84
85
void FrameBufferObject::UnbindFBO()
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
101
void FrameBufferObject:: UnattachRenderBuffer(GLenum attachment)
102
{
103
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attachment, GL_RENDERBUFFER_EXT, 0);
104
}