#ifndef _FrameBufferObject_H__ #define _FrameBufferObject_H__ #include #include "common.h" namespace CHCDemoEngine { /** This class implements a wrapper for a color buffer object */ class ColorBufferObject { public: enum FORMAT {RGB_UBYTE, RGBA_UBYTE, RGB_FLOAT_16, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32}; enum WRAP_TYPE {WRAP_REPEAT, WRAP_CLAMP_TO_EDGE, WRAP_CLAMP_TO_BORDER}; enum FILTER_TYPE {FILTER_NEAREST, FILTER_LINEAR}; /** Creates color buffer without mipmap. attachment_idx describes the number of the render target the buffer is attached to */ ColorBufferObject(int w, int h, int attachment_idx , FORMAT c, WRAP_TYPE wrapType, FILTER_TYPE filterType); /** Same as above, with mipmapping enabled. */ ColorBufferObject(int w, int h, int attachment_idx, FORMAT c, WRAP_TYPE wrapType, FILTER_TYPE filterType, FILTER_TYPE filterTypeMipMap ); ~ColorBufferObject(); /** Returns associated texture id. */ inline unsigned int GetTexture() const { return mTexId; } /** Returns width of render target. */ inline int GetWidth() { return mWidth; } /** Returns height of render target. */ inline int GetHeight() { return mHeight; } /** Returns texture data. */ void *ReadTexture() const; protected: void Init(int w, int h, int attachment_idx, FORMAT format, WRAP_TYPE wrapType, FILTER_TYPE filterType, bool useMipMap, FILTER_TYPE filterTypeMipMap ); /////////// int mGlFormat; int mInternalFormat; unsigned int mId; unsigned int mTexId; int mWidth; int mHeight; }; /** This class implements a wrapper for a frame buffer object. */ class FrameBufferObject { public: /// Available depth formats enum DEPTH_FORMAT {DEPTH_NONE, DEPTH_16, DEPTH_24, DEPTH_32}; /** constructor requesting an opengl occlusion query. */ FrameBufferObject(int w, int h, DEPTH_FORMAT d, bool useDepthTex = false); /** Destructor destroying gl resources. */ ~FrameBufferObject(); /** Creates and adds a color buffer to the current frame buffer object. Returns the index that allows to retrieve the color buffer object. */ int AddColorBuffer(ColorBufferObject::FORMAT col, ColorBufferObject::WRAP_TYPE wrapType, ColorBufferObject::FILTER_TYPE filterType); /** Same as above, but enables mipmapping using the specified filter. */ int AddColorBuffer(ColorBufferObject::FORMAT col, ColorBufferObject::WRAP_TYPE wrapType, ColorBufferObject::FILTER_TYPE filterType, ColorBufferObject::FILTER_TYPE filterTypeMipMap); /** Binds this frame buffer object. */ void Bind() const; /////////////////// /** Returns the color buffer object on position i. */ inline ColorBufferObject *GetColorBuffer(int i) const { return mColorBuffers[i]; } /** Returns depth texture id */ inline unsigned int GetDepthTex() const { return mDepthTexId; } /** Returns width of fbo */ inline int GetWidth() { return mWidth; } /** Returns height of fbo */ inline int GetHeight() { return mHeight; } //////////////// /** Initialise a render target (using current clear color) */ static void InitBuffer(FrameBufferObject *fbo, int index); /** Releases any bound frame buffer object. */ static void Release(); protected: std::vector mColorBuffers; unsigned int mId; unsigned int mDepthId; int mHeight; int mWidth; unsigned int mDepthTexId; static int sCurrentFbo; }; } // namespace #endif // _FrameBufferObject_H__