[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 |
|
---|
[3017] | 17 | enum FORMAT { RGB_UBYTE, RGBA_UBYTE, RGB_FLOAT_16, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32 };
|
---|
| 18 |
|
---|
[2965] | 19 | enum WRAP_TYPE { WRAP_REPEAT, WRAP_CLAMP_TO_EDGE };
|
---|
| 20 | enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR };
|
---|
[2855] | 21 |
|
---|
[2965] | 22 |
|
---|
| 23 | /** Creates color buffer without mipmap. attachment_idx describes
|
---|
| 24 | the number of the render target the buffer is attached to
|
---|
| 25 | */
|
---|
[2855] | 26 | ColorBufferObject(int w, int h,
|
---|
[2965] | 27 | int attachment_idx ,
|
---|
| 28 | FORMAT c,
|
---|
[2856] | 29 | WRAP_TYPE wrapType,
|
---|
[2965] | 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,
|
---|
[2856] | 37 | FILTER_TYPE filterType,
|
---|
[2965] | 38 | FILTER_TYPE filterTypeMipMap
|
---|
| 39 | );
|
---|
[2856] | 40 |
|
---|
[2878] | 41 | ~ColorBufferObject();
|
---|
[3117] | 42 | /** Returns associated texture id.
|
---|
| 43 | */
|
---|
[2966] | 44 | inline unsigned int GetTexture() const { return mTexId; }
|
---|
[3117] | 45 | /** Returns width of render target.
|
---|
| 46 | */
|
---|
[2966] | 47 | inline int GetWidth() { return mWidth; }
|
---|
[3117] | 48 | /** Returns height of render target.
|
---|
| 49 | */
|
---|
[2966] | 50 | inline int GetHeight() { return mHeight; }
|
---|
[2965] | 51 | /** Returns texture data.
|
---|
| 52 | */
|
---|
| 53 | void *ReadTexture() const;
|
---|
| 54 |
|
---|
[2966] | 55 |
|
---|
[2965] | 56 |
|
---|
[2856] | 57 | protected:
|
---|
| 58 |
|
---|
[2965] | 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;
|
---|
[2856] | 74 | unsigned int mId;
|
---|
| 75 | unsigned int mTexId;
|
---|
[2965] | 76 |
|
---|
| 77 | int mWidth;
|
---|
| 78 | int mHeight;
|
---|
[2855] | 79 | };
|
---|
| 80 |
|
---|
| 81 |
|
---|
[3117] | 82 | /** This class implements a wrapper for a frame buffer object.
|
---|
[2855] | 83 | */
|
---|
| 84 | class FrameBufferObject
|
---|
| 85 | {
|
---|
| 86 | public:
|
---|
| 87 |
|
---|
[3117] | 88 | /// Available depth formats
|
---|
[2965] | 89 | enum DEPTH_FORMAT {DEPTH_NONE, DEPTH_16, DEPTH_24, DEPTH_32};
|
---|
[2859] | 90 |
|
---|
[2855] | 91 | /** constructor requesting an opengl occlusion query.
|
---|
| 92 | */
|
---|
[2862] | 93 | FrameBufferObject(int w, int h, DEPTH_FORMAT d, bool useDepthTex = false);
|
---|
[3117] | 94 | /** Destructor destroying gl resources.
|
---|
| 95 | */
|
---|
[2878] | 96 | ~FrameBufferObject();
|
---|
[2855] | 97 | /** Creates and adds a color buffer to the current frame buffer object.
|
---|
[2859] | 98 | Returns the index that allows to retrieve the color buffer object.
|
---|
[2855] | 99 | */
|
---|
[2867] | 100 | int AddColorBuffer(ColorBufferObject::FORMAT col,
|
---|
[2859] | 101 | ColorBufferObject::WRAP_TYPE wrapType,
|
---|
[2965] | 102 | ColorBufferObject::FILTER_TYPE filterType);
|
---|
[2855] | 103 |
|
---|
[2965] | 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 |
|
---|
[2861] | 111 | /** Binds this frame buffer object.
|
---|
| 112 | */
|
---|
| 113 | void Bind() const;
|
---|
[3117] | 114 |
|
---|
| 115 | ///////////////////
|
---|
| 116 |
|
---|
| 117 | /** Returns the color buffer object on position i.
|
---|
[2861] | 118 | */
|
---|
[3117] | 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 | */
|
---|
[3006] | 125 | inline int GetWidth() { return mWidth; }
|
---|
[3117] | 126 | /** Returns height of fbo
|
---|
| 127 | */
|
---|
[3006] | 128 | inline int GetHeight() { return mHeight; }
|
---|
| 129 |
|
---|
| 130 |
|
---|
[3117] | 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 |
|
---|
[2855] | 140 | protected:
|
---|
| 141 |
|
---|
| 142 | std::vector<ColorBufferObject *> mColorBuffers;
|
---|
| 143 |
|
---|
| 144 | unsigned int mId;
|
---|
| 145 | unsigned int mDepthId;
|
---|
| 146 |
|
---|
| 147 | int mHeight;
|
---|
| 148 | int mWidth;
|
---|
[2862] | 149 |
|
---|
| 150 | unsigned int mDepthTexId;
|
---|
[3007] | 151 |
|
---|
| 152 | static int sCurrentFbo;
|
---|
[2855] | 153 | };
|
---|
| 154 |
|
---|
[3117] | 155 |
|
---|
[2855] | 156 | } // namespace
|
---|
[3117] | 157 |
|
---|
[2855] | 158 | #endif // _FrameBufferObject_H__ |
---|