KGLLib
extras/kgllib/rendertarget.h
00001 /*
00002  * Copyright (C) 2008 Rivo Laks <rivolaks@hot.ee>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef KGLLIB_RENDERTARGET_H
00019 #define KGLLIB_RENDERTARGET_H
00020 
00021 #include "kgllib.h"
00022 
00023 #include <QtCore/QSize>
00024 
00025 namespace KGLLib
00026 {
00027 
00028 class Texture;
00029 
00030 class KGLLIB_EXTRAS_EXPORT RenderTarget
00031 {
00032 public:
00037     explicit RenderTarget(Texture* color);
00046     RenderTarget(int width, int height, bool hasDepth = false, GLint textureFormat = GL_RGBA);
00052 //     RenderTarget(Texture* color, Texture* depth);
00053 
00054     virtual ~RenderTarget();
00055 
00056     bool enable();
00057     bool disable();
00058 
00059     Texture* texture() const  { return mColorTexture; }
00060     int width() const;
00061     int height() const;
00062     QSize size() const;
00063 
00064     bool isValid() const  { return mValid; }
00065 
00066     static bool isSupported();
00067 
00068 protected:
00069     Texture* createColorTexture(int w, int h, GLint textureFormat = GL_RGBA);
00070     Texture* createDepthTexture(int w, int h);
00071     GLuint createDepthBuffer(int w, int h);
00072 
00073     void attachColorTexture(Texture* tex);
00074     void attachDepthTexture(Texture* tex);
00075     void attachDepthBuffer(GLuint buffer);
00076 
00077     bool startInit();
00078     void endInit();
00079 
00080 private:
00081     bool mValid;
00082     bool mOwnColorTexture;
00083     Texture* mColorTexture;
00084 //     Texture* mDepthTexture;
00085 
00086     GLuint mFramebuffer;
00087     GLuint mDepthBuffer;
00088 };
00089 
00090 }
00091 
00092 #endif