|
KGLLib
|
00001 /* 00002 * Copyright 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 * Lesser 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_HDRGLWIDGET_H 00019 #define KGLLIB_HDRGLWIDGET_H 00020 00021 #include "glwidget.h" 00022 00023 00024 namespace KGLLib 00025 { 00026 class RenderTarget; 00027 class Program; 00028 class Shader; 00029 00030 00031 class KGLLIB_EXTRAS_EXPORT HdrGLWidget : public GLWidget 00032 { 00033 Q_OBJECT 00034 public: 00035 explicit HdrGLWidget(QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0); 00036 explicit HdrGLWidget(QGLContext* context, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0); 00037 explicit HdrGLWidget(const QGLFormat& format, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0); 00038 00039 ~HdrGLWidget(); 00040 00044 bool hdrRenderingActive() const { return hdrRenderingSupported() && mHdrRenderingActive; } 00048 bool hdrRenderingSupported() const { return mHdrRenderingSupported; } 00049 00055 float exposure() const { return mExposure; } 00060 bool autoExposure() const { return mAutoExposure; } 00061 00062 float autoExposureSpeed() const { return mAutoExposureSpeed; } 00063 float autoExposureTarget() const { return mAutoExposureTarget; } 00064 00065 bool bloomEnabled() const { return mBloomEnabled; } 00066 00067 bool bloomAfterTonemapping() const { return mBloomAfterTonemapping; } 00068 00069 int bloomDownsize() const { return mBloomDownsize; } 00070 00071 float bloomStrength() const { return mBloomStrength; } 00072 00073 float bloomRamp() const { return mBloomRamp; } 00074 00075 void render2DQuad(float width, float height) const; 00076 void setupOrthoProjection(int width, int height) const; 00077 void activateRenderTarget(RenderTarget* target) const; 00078 void deactivateRenderTarget(RenderTarget* target) const; 00079 00083 void setDataPath(const QString& path); 00084 00085 public slots: 00091 void setHdrRenderingActive(bool active) { mHdrRenderingActive = active; } 00098 void setExposure(float e) { mExposure = e; } 00105 void setAutoExposure(bool a) { mAutoExposure = a; } 00106 00107 void setAutoExposureSpeed(float s) { mAutoExposureSpeed = s; } 00108 void setAutoExposureTarget(float t) { mAutoExposureTarget = t; } 00109 00110 void setBloomEnabled(bool e) { mBloomEnabled = e; } 00111 void setBloomAfterTonemapping(bool e) { mBloomAfterTonemapping = e; } 00112 void setBloomDownsize(int d) { mBloomDownsize = d; } 00113 void setBloomStrength(float s); 00114 00115 protected: 00116 virtual void initializeGL(); 00117 virtual void initializeGL(Renderer* r); 00118 virtual void resizeGL(int width, int height); 00119 virtual void render(); 00120 00121 virtual void renderScene(); 00122 00123 virtual void hdrTonemapping(); 00124 virtual void hdrBloom(); 00125 00126 virtual void calculateHdrExposure(); 00127 00128 virtual float* calculateBlurKernel(float sigma, int radius); 00129 virtual Program* generateBlurProgram(float sigma, int radius, bool horizontal); 00130 virtual Shader* generateBlurVertexShader(float sigma, int radius, bool horizontal); 00131 virtual Shader* generateBlurFragmentShader(float sigma, int radius, bool horizontal); 00132 00133 private: 00134 void init(); 00135 void initGL(); 00136 00137 bool mHdrRenderingSupported; 00138 bool mHdrRenderingActive; 00139 00140 RenderTarget* mSceneRenderTarget; 00141 RenderTarget* mLuminanceDetectionTarget; 00142 RenderTarget* mTonemappingTarget; 00143 RenderTarget* mBloomHTarget; 00144 RenderTarget* mBloomVTarget; 00145 QString mDataPath; 00146 Program* mTonemappingProgram; 00147 Program* mBloomHProgram; 00148 Program* mBloomVProgram; 00149 00150 float mExposure; 00151 bool mAutoExposure; 00152 float mAutoExposureSpeed; 00153 float mAutoExposureTarget; 00154 bool mBloomEnabled; 00155 bool mBloomAfterTonemapping; 00156 int mBloomDownsize; 00157 float mBloomRamp; 00158 float mBloomStrength; 00159 }; 00160 00161 } 00162 00163 #endif 00164
1.7.4