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