source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h @ 3204

Revision 3204, 3.7 KB checked in by mattausch, 15 years ago (diff)

debug version showing a visualization of the confidence

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