-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFrameBufferObject.h
99 lines (81 loc) · 3.31 KB
/
FrameBufferObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// =================================================================
// File : FrameBufferObject.h
// Desc : A Simple C++ wrapper for handling the OpenGL Frame
// Buffer Object(FBO). The client can access using his
// own customized buffer names rather than using GL ids
// since this makes the management of fbos better.
// Version : 1.0
// Author : Berk Atabek - Copyright 2012
//
//==================================================================
#ifndef FRAMEBUFFEROBJECT_H
#define FRAMEBUFFEROBJECT_H
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <GL/glew.h>
#include <GL/glut.h>
// Buffer's target mode parameter
enum BUFFER_TARGET_MODE {BTM_READ=0, BTM_WRITE, BTM_READ_WRITE };
// Render buffer type
enum RBUFFER_TYPE {RBT_COLOR=0, RBT_DEPTH, RBT_STENCIL};
// texture buffer
enum TEXTURE_BUFFER_TYPE {TBT_COLOR=0,TBT_DEPTH,TBT_STENCIL,TBT_DEPTH_AND_STENCIL};
enum TEXTURE_TYPE {TT_1D=0, TT_2D, TT_3D};
class FrameBufferObject
{
public:
// Constructor/Destructor
FrameBufferObject();
FrameBufferObject(BUFFER_TARGET_MODE mode);
~FrameBufferObject();
// switch to window-system provided buffers
void switchToDefaultSystemBuffers();
// Renderbuffer management methods
void createRenderBuffer(std::string name, RBUFFER_TYPE type, GLenum internalFormat, GLsizei width, GLsizei height);
void createRenderBufferAndAttach(std::string name, RBUFFER_TYPE type, GLenum internalFormat, GLsizei width, GLsizei height);
void deleteRenderBuffer(std::string name);
void attachRenderBuffer(std::string name);
void detachRenderBuffer(std::string name);
bool isRenderBufferUsed(std::string name);
// Texture Object Attachment
void attach1DTexture(std::string name, TEXTURE_BUFFER_TYPE tbtype, GLsizei width, GLint level);
void attach2DTexture(std::string name, TEXTURE_BUFFER_TYPE tbtype, GLsizei width, GLsizei height, GLint level);
void attach3DTexture(std::string name, TEXTURE_BUFFER_TYPE tbtype, GLsizei width, GLsizei height, GLsizei depth, GLint level, GLint layer);
void detachTexture(std::string name);
// Accessors
GLuint getID() const;
const GLuint getRenderBufferID(std::string name)const;
const GLuint getTextureBufferID(std::string name)const;
bool isUsed()const;
unsigned getNumRenderbuffers() const;
unsigned getNumAttachedTexturebuffers() const;
BUFFER_TARGET_MODE getBufferTargetMode()const;
private:
// renderbuffer state
struct RenderBufferFormat {
GLsizei width; // buffer's width
GLsizei height; // buffer's height
GLenum intFormat;
RBUFFER_TYPE bufferType;
};
// texture buffer state
struct TextureBufferFormat {
TEXTURE_BUFFER_TYPE attachmentPoint;
TEXTURE_TYPE type;
GLsizei width;
GLsizei height;
GLsizei depth; // buffer's depth , for volumetric textures
};
// each attachment can be identified by its unique name
// which maps to its associated OpenGL id
std::map<std::string, GLuint>m_renderBufferNames;
std::map<std::string, GLuint>m_attachedTextureNames;
// currently attached buffers list for this fbo
std::map<GLuint, RenderBufferFormat>m_renderbuffers;
std::map<GLuint, TextureBufferFormat>m_texturebuffers;
GLuint m_Id; // FBO id
BUFFER_TARGET_MODE m_BufferTargetMode;
};
#endif