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