forked from nlichtenberg/OpenGL_Framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFramebuffer.h
More file actions
71 lines (52 loc) · 1.94 KB
/
Framebuffer.h
File metadata and controls
71 lines (52 loc) · 1.94 KB
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
//============================================================================
// Distributed under the MIT License. Author: Raphael Menges
//============================================================================
// Framebuffer for own purposes.
#ifndef FRAMEBUFFER_H
#define FRAMEBUFFER_H
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <vector>
class Framebuffer
{
public:
// Enumeration of color formats
enum ColorFormat
{
RGB, RGBA
};
// Constructor
Framebuffer(int width, int height, bool superSampling = false);
// Destructor
virtual ~Framebuffer();
// Bind framebuffer
void bind() const;
// Unbind (binds default, as long as it is zero)
void unbind() const;
// Resizing (needs bound framebuffer). Returns whether size changed
bool resize(int width, int height);
bool resize(int width, int height, bool superSampling);
// Add attachment (needs bound framebuffer)
void addAttachment(ColorFormat colorFormat);
// Get texture handle of color attachment
GLuint getAttachment(int number) const { return colorAttachments.at(number).first; }
// Get whether using super sampling
bool superSampling() const { return mSuperSampling; }
// Get multiplier of super sampling
int getSuperSamplingMultiplier() const { return mSuperSamplingMultiplier; }
// Get pixel width and height of framebuffer. Inclusive super sampling
int getWidth() const { return mWidth; }
int getHeight() const { return mHeight; }
private:
// Pair of color format and texture handle
typedef std::pair<GLuint, ColorFormat> ColorAttachment;
// Members
std::vector<ColorAttachment> colorAttachments;
GLuint mFramebuffer;
GLuint mDepthStencil;
int mWidth = -1;
int mHeight = -1;
bool mSuperSampling = false;
const int mSuperSamplingMultiplier = 2; // more than 2 make advanced filtering at composition necessary
};
#endif // FRAMEBUFFER_H