PageRenderTime 27ms CodeModel.GetById 10ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llrender/llpostprocess.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 266 lines | 166 code | 62 blank | 38 comment | 0 complexity | cdb8785ffb53020683f076b7a9c1e0ea MD5 | raw file
  1/** 
  2 * @file llpostprocess.h
  3 * @brief LLPostProcess class definition
  4 *
  5 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_POSTPROCESS_H
 28#define LL_POSTPROCESS_H
 29
 30#include <map>
 31#include <fstream>
 32#include "llgl.h"
 33#include "llglheaders.h"
 34
 35class LLPostProcess 
 36{
 37public:
 38
 39	typedef enum _QuadType {
 40		QUAD_NORMAL,
 41		QUAD_NOISE,
 42		QUAD_BLOOM_EXTRACT,
 43		QUAD_BLOOM_COMBINE
 44	} QuadType;
 45
 46	/// GLSL Shader Encapsulation Struct
 47	typedef std::map<const char *, GLuint> glslUniforms;
 48
 49	struct PostProcessTweaks : public LLSD {
 50		inline PostProcessTweaks() : LLSD(LLSD::emptyMap())
 51		{
 52		}
 53
 54		inline LLSD & brightMult() {
 55			return (*this)["brightness_multiplier"];
 56		}
 57
 58		inline LLSD & noiseStrength() {
 59			return (*this)["noise_strength"];
 60		}
 61
 62		inline LLSD & noiseSize() {
 63			return (*this)["noise_size"];
 64		}
 65
 66		inline LLSD & extractLow() {
 67			return (*this)["extract_low"];
 68		}
 69
 70		inline LLSD & extractHigh() {
 71			return (*this)["extract_high"];
 72		}
 73
 74		inline LLSD & bloomWidth() {
 75			return (*this)["bloom_width"];
 76		}
 77
 78		inline LLSD & bloomStrength() {
 79			return (*this)["bloom_strength"];
 80		}
 81
 82		inline LLSD & brightness() {
 83			return (*this)["brightness"];
 84		}
 85
 86		inline LLSD & contrast() {
 87			return (*this)["contrast"];
 88		}
 89
 90		inline LLSD & contrastBaseR() {
 91			return (*this)["contrast_base"][0];
 92		}
 93
 94		inline LLSD & contrastBaseG() {
 95			return (*this)["contrast_base"][1];
 96		}
 97
 98		inline LLSD & contrastBaseB() {
 99			return (*this)["contrast_base"][2];
100		}
101
102		inline LLSD & contrastBaseIntensity() {
103			return (*this)["contrast_base"][3];
104		}
105
106		inline LLSD & saturation() {
107			return (*this)["saturation"];
108		}
109
110		inline LLSD & useNightVisionShader() {
111			return (*this)["enable_night_vision"];
112		}
113
114		inline LLSD & useBloomShader() {
115			return (*this)["enable_bloom"];
116		}
117
118		inline LLSD & useColorFilter() {
119			return (*this)["enable_color_filter"];
120		}
121
122
123		inline F32 getBrightMult() const {
124			return F32((*this)["brightness_multiplier"].asReal());
125		}
126
127		inline F32 getNoiseStrength() const {
128			return F32((*this)["noise_strength"].asReal());
129		}
130
131		inline F32 getNoiseSize() const {
132			return F32((*this)["noise_size"].asReal());
133		}
134
135		inline F32 getExtractLow() const {
136			return F32((*this)["extract_low"].asReal());
137		}
138
139		inline F32 getExtractHigh() const {
140			return F32((*this)["extract_high"].asReal());
141		}
142
143		inline F32 getBloomWidth() const {
144			return F32((*this)["bloom_width"].asReal());
145		}
146
147		inline F32 getBloomStrength() const {
148			return F32((*this)["bloom_strength"].asReal());
149		}
150
151		inline F32 getBrightness() const {
152			return F32((*this)["brightness"].asReal());
153		}
154
155		inline F32 getContrast() const {
156			return F32((*this)["contrast"].asReal());
157		}
158
159		inline F32 getContrastBaseR() const {
160			return F32((*this)["contrast_base"][0].asReal());
161		}
162
163		inline F32 getContrastBaseG() const {
164			return F32((*this)["contrast_base"][1].asReal());
165		}
166
167		inline F32 getContrastBaseB() const {
168			return F32((*this)["contrast_base"][2].asReal());
169		}
170
171		inline F32 getContrastBaseIntensity() const {
172			return F32((*this)["contrast_base"][3].asReal());
173		}
174
175		inline F32 getSaturation() const {
176			return F32((*this)["saturation"].asReal());
177		}
178
179	};
180	
181	bool initialized;
182	PostProcessTweaks tweaks;
183
184	// the map of all availible effects
185	LLSD mAllEffects;
186
187private:
188	LLPointer<LLImageGL> mSceneRenderTexture ;
189	LLPointer<LLImageGL> mNoiseTexture ;
190	LLPointer<LLImageGL> mTempBloomTexture ;
191
192public:
193	LLPostProcess(void);
194
195	~LLPostProcess(void);
196
197	void apply(unsigned int width, unsigned int height);
198	void invalidate() ;
199
200	/// Perform global initialization for this class.
201	static void initClass(void);
202
203	// Cleanup of global data that's only inited once per class.
204	static void cleanupClass();
205
206	void setSelectedEffect(std::string const & effectName);
207
208	inline std::string const & getSelectedEffect(void) const {
209		return mSelectedEffectName;
210	}
211
212	void saveEffect(std::string const & effectName);
213
214private:
215		/// read in from file
216	std::string mShaderErrorString;
217	unsigned int screenW;
218	unsigned int screenH;
219
220	float noiseTextureScale;
221	
222	/// Shader Uniforms
223	glslUniforms nightVisionUniforms;
224	glslUniforms bloomExtractUniforms;
225	glslUniforms bloomBlurUniforms;
226	glslUniforms colorFilterUniforms;
227
228	// the name of currently selected effect in mAllEffects
229	// invariant: tweaks == mAllEffects[mSelectedEffectName]
230	std::string mSelectedEffectName;
231
232	/// General functions
233	void initialize(unsigned int width, unsigned int height);
234	void doEffects(void);
235	void applyShaders(void);
236	bool shadersEnabled(void);
237
238	/// Night Vision Functions
239	void createNightVisionShader(void);
240	void applyNightVisionShader(void);
241
242	/// Bloom Functions
243	void createBloomShader(void);
244	void applyBloomShader(void);
245
246	/// Color Filter Functions
247	void createColorFilterShader(void);
248	void applyColorFilterShader(void);
249
250	/// OpenGL Helper Functions
251	void getShaderUniforms(glslUniforms & uniforms, GLhandleARB & prog);
252	void createTexture(LLPointer<LLImageGL>& texture, unsigned int width, unsigned int height);
253	void copyFrameBuffer(U32 & texture, unsigned int width, unsigned int height);
254	void createNoiseTexture(LLPointer<LLImageGL>& texture);
255	bool checkError(void);
256	void checkShaderError(GLhandleARB shader);
257	void drawOrthoQuad(unsigned int width, unsigned int height, QuadType type);
258	void viewOrthogonal(unsigned int width, unsigned int height);
259	void changeOrthogonal(unsigned int width, unsigned int height);
260	void viewPerspective(void);
261};
262
263extern LLPostProcess * gPostProcess;
264
265
266#endif // LL_POSTPROCESS_H