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