1 | #ifndef _FrameBufferObject_H__
|
---|
2 | #define _FrameBufferObject_H__
|
---|
3 |
|
---|
4 | #include <vector>
|
---|
5 | #include "common.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace CHCDemoEngine
|
---|
9 | {
|
---|
10 |
|
---|
11 | /** This class implements a wrapper for a color buffer object
|
---|
12 | */
|
---|
13 | class ColorBufferObject
|
---|
14 | {
|
---|
15 | public:
|
---|
16 |
|
---|
17 | enum FORMAT { RGB_UBYTE, RGBA_UBYTE, RGB_FLOAT_16, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32 };
|
---|
18 |
|
---|
19 | enum WRAP_TYPE { WRAP_REPEAT, WRAP_CLAMP_TO_EDGE };
|
---|
20 | enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR };
|
---|
21 |
|
---|
22 |
|
---|
23 | /** Creates color buffer without mipmap. attachment_idx describes
|
---|
24 | the number of the render target the buffer is attached to
|
---|
25 | */
|
---|
26 | ColorBufferObject(int w, int h,
|
---|
27 | int attachment_idx ,
|
---|
28 | FORMAT c,
|
---|
29 | WRAP_TYPE wrapType,
|
---|
30 | FILTER_TYPE filterType);
|
---|
31 |
|
---|
32 | /** Same as above, with mipmapping enabled.
|
---|
33 | */
|
---|
34 | ColorBufferObject(int w, int h,
|
---|
35 | int attachment_idx,
|
---|
36 | FORMAT c,
|
---|
37 | WRAP_TYPE wrapType,
|
---|
38 | FILTER_TYPE filterType,
|
---|
39 | FILTER_TYPE filterTypeMipMap
|
---|
40 | );
|
---|
41 |
|
---|
42 | ~ColorBufferObject();
|
---|
43 |
|
---|
44 | inline unsigned int GetTexture() const { return mTexId; }
|
---|
45 |
|
---|
46 | inline int GetWidth() { return mWidth; }
|
---|
47 |
|
---|
48 | inline int GetHeight() { return mHeight; }
|
---|
49 | /** Returns texture data.
|
---|
50 | */
|
---|
51 | void *ReadTexture() const;
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 | protected:
|
---|
56 |
|
---|
57 | void Init(int w, int h,
|
---|
58 | int attachment_idx,
|
---|
59 | FORMAT format,
|
---|
60 | WRAP_TYPE wrapType,
|
---|
61 | FILTER_TYPE filterType,
|
---|
62 | bool useMipMap,
|
---|
63 | FILTER_TYPE filterTypeMipMap
|
---|
64 | );
|
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 | ///////////
|
---|
69 |
|
---|
70 | int mGlFormat;
|
---|
71 | int mInternalFormat;
|
---|
72 | unsigned int mId;
|
---|
73 | unsigned int mTexId;
|
---|
74 |
|
---|
75 | int mWidth;
|
---|
76 | int mHeight;
|
---|
77 | };
|
---|
78 |
|
---|
79 |
|
---|
80 | /** This class implements a wrapper for a frame buffer object
|
---|
81 | */
|
---|
82 | class FrameBufferObject
|
---|
83 | {
|
---|
84 | public:
|
---|
85 |
|
---|
86 | enum DEPTH_FORMAT {DEPTH_NONE, DEPTH_16, DEPTH_24, DEPTH_32};
|
---|
87 |
|
---|
88 | /** constructor requesting an opengl occlusion query.
|
---|
89 | */
|
---|
90 | FrameBufferObject(int w, int h, DEPTH_FORMAT d, bool useDepthTex = false);
|
---|
91 |
|
---|
92 | ~FrameBufferObject();
|
---|
93 | /** Creates and adds a color buffer to the current frame buffer object.
|
---|
94 | Returns the index that allows to retrieve the color buffer object.
|
---|
95 | */
|
---|
96 | int AddColorBuffer(ColorBufferObject::FORMAT col,
|
---|
97 | ColorBufferObject::WRAP_TYPE wrapType,
|
---|
98 | ColorBufferObject::FILTER_TYPE filterType);
|
---|
99 |
|
---|
100 | /** Same as above, but enables mipmapping using the specified filter.
|
---|
101 | */
|
---|
102 | int AddColorBuffer(ColorBufferObject::FORMAT col,
|
---|
103 | ColorBufferObject::WRAP_TYPE wrapType,
|
---|
104 | ColorBufferObject::FILTER_TYPE filterType,
|
---|
105 | ColorBufferObject::FILTER_TYPE filterTypeMipMap);
|
---|
106 |
|
---|
107 | /** Returns the color buffer object on position i.
|
---|
108 | */
|
---|
109 | ColorBufferObject *GetColorBuffer(int i) const { return mColorBuffers[i]; }
|
---|
110 | /** Binds this frame buffer object.
|
---|
111 | */
|
---|
112 | void Bind() const;
|
---|
113 | /** Releases any bound frame buffer object.
|
---|
114 | */
|
---|
115 | static void Release();
|
---|
116 |
|
---|
117 | unsigned int GetDepthTex() const { return mDepthTexId; }
|
---|
118 |
|
---|
119 | inline int GetWidth() { return mWidth; }
|
---|
120 |
|
---|
121 | inline int GetHeight() { return mHeight; }
|
---|
122 |
|
---|
123 |
|
---|
124 | protected:
|
---|
125 |
|
---|
126 | std::vector<ColorBufferObject *> mColorBuffers;
|
---|
127 |
|
---|
128 | unsigned int mId;
|
---|
129 | unsigned int mDepthId;
|
---|
130 |
|
---|
131 | int mHeight;
|
---|
132 | int mWidth;
|
---|
133 |
|
---|
134 | unsigned int mDepthTexId;
|
---|
135 |
|
---|
136 | static int sCurrentFbo;
|
---|
137 | };
|
---|
138 |
|
---|
139 | } // namespace
|
---|
140 | #endif // _FrameBufferObject_H__ |
---|