Back to index

nux  3.0.0
IOpenGLFrameBufferObject.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef IOPENGLFRAMEBUFFEROBJECT_H
00024 #define IOPENGLFRAMEBUFFEROBJECT_H
00025 
00026 namespace nux
00027 {
00028 
00029   class IOpenGLResource;
00030   class IOpenGLFrameBufferObject: public IOpenGLResource
00031   {
00032     NUX_DECLARE_OBJECT_TYPE(IOpenGLFrameBufferObject, IOpenGLResource);
00033   public:
00034     virtual ~IOpenGLFrameBufferObject();
00035 
00036     int FormatFrameBufferObject(int Width, int Height, BitmapFormat PixelFormat);
00037     int SetRenderTarget(int ColorAttachmentIndex, ObjectPtr<IOpenGLSurface> pRenderTargetSurface);
00038     int SetDepthSurface(ObjectPtr<IOpenGLSurface> pDepthSurface);
00039     ObjectPtr<IOpenGLSurface> GetRenderTarget(int ColorAttachmentIndex);
00040     ObjectPtr<IOpenGLSurface> GetDepthRenderTarget();
00041 
00042     int Clear(DWORD Flags, FLOAT red, FLOAT green, FLOAT blue, FLOAT alpha, FLOAT Z, DWORD Stencil);
00043 
00044     int Activate(bool WithClippingStack = false);
00045     //### Restore the original opengl back buffer as defined when creating the opengl context(color + depth + stencil).
00046     int Deactivate();
00047     bool IsActive()
00048     {
00049       return _IsActive;
00050     }
00051 
00052     // For 2D screen operations
00053     std::vector<Rect> _ClippingRegionStack;
00054     void PushClippingRegion(Rect rect);
00055     void PopClippingRegion();
00056     void EmptyClippingRegion();
00057     void ApplyClippingRegion();
00058 
00060 
00063     void SetClippingRectangle(const Rect &rect);
00064 
00065     void SetOpenGLClippingRectangle(int x, int y, int width, int height);
00066     Rect GetClippingRegion();
00067     int GetNumberOfClippingRegions() const;
00068 
00069     int GetWidth() const
00070     {
00071       return _Width;
00072     }
00073     int GetHeight() const
00074     {
00075       return _Height;
00076     }
00077 
00078   private:
00079     IOpenGLFrameBufferObject(NUX_FILE_LINE_PROTO);
00080 
00081     int             _Width;
00082     int             _Height;
00083     BitmapFormat    _PixelFormat;
00084     bool            _IsActive;
00085     Rect            _clipping_rect;
00086 
00087     ObjectPtr<IOpenGLSurface>     _Depth_Attachment;
00088     ObjectPtr<IOpenGLSurface>     _Stencil_Attachment;
00089     std::vector< ObjectPtr<IOpenGLSurface> > _Color_AttachmentArray;
00090 
00091     GLFramebufferObject _Fbo;   // The framebuffer object used for rendering to the texture
00092     GLRenderbuffer      _Rbo;
00093 
00094     friend class GpuDevice;
00095   };
00096 
00097 }
00098 
00099 #endif // IOPENGLFRAMEBUFFEROBJECT_H