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

Revision 3117, 3.7 KB checked in by mattausch, 16 years ago (diff)

strange errors

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