diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/llpostprocess.h | 274 |
1 files changed, 274 insertions, 0 deletions
diff --git a/linden/indra/newview/llpostprocess.h b/linden/indra/newview/llpostprocess.h new file mode 100644 index 0000000..d6926e4 --- /dev/null +++ b/linden/indra/newview/llpostprocess.h | |||
@@ -0,0 +1,274 @@ | |||
1 | /** | ||
2 | * @file llpostprocess.h | ||
3 | * @brief LLPostProcess class definition | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2007-2009, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at | ||
21 | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
22 | * | ||
23 | * By copying, modifying or distributing this software, you acknowledge | ||
24 | * that you have read and understood your obligations described above, | ||
25 | * and agree to abide by those obligations. | ||
26 | * | ||
27 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
28 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
29 | * COMPLETENESS OR PERFORMANCE. | ||
30 | * $/LicenseInfo$ | ||
31 | */ | ||
32 | |||
33 | #ifndef LL_POSTPROCESS_H | ||
34 | #define LL_POSTPROCESS_H | ||
35 | |||
36 | #include <map> | ||
37 | #include <fstream> | ||
38 | #include "llgl.h" | ||
39 | #include "llglheaders.h" | ||
40 | |||
41 | class LLPostProcess | ||
42 | { | ||
43 | public: | ||
44 | |||
45 | typedef enum _QuadType { | ||
46 | QUAD_NORMAL, | ||
47 | QUAD_NOISE, | ||
48 | QUAD_BLOOM_EXTRACT, | ||
49 | QUAD_BLOOM_COMBINE | ||
50 | } QuadType; | ||
51 | |||
52 | /// GLSL Shader Encapsulation Struct | ||
53 | typedef std::map<const char *, GLuint> glslUniforms; | ||
54 | |||
55 | struct PostProcessTweaks : public LLSD { | ||
56 | inline PostProcessTweaks() : LLSD(LLSD::emptyMap()) | ||
57 | { | ||
58 | } | ||
59 | |||
60 | inline LLSD & brightMult() { | ||
61 | return (*this)["brightness_multiplier"]; | ||
62 | } | ||
63 | |||
64 | inline LLSD & noiseStrength() { | ||
65 | return (*this)["noise_strength"]; | ||
66 | } | ||
67 | |||
68 | inline LLSD & noiseSize() { | ||
69 | return (*this)["noise_size"]; | ||
70 | } | ||
71 | |||
72 | inline LLSD & extractLow() { | ||
73 | return (*this)["extract_low"]; | ||
74 | } | ||
75 | |||
76 | inline LLSD & extractHigh() { | ||
77 | return (*this)["extract_high"]; | ||
78 | } | ||
79 | |||
80 | inline LLSD & bloomWidth() { | ||
81 | return (*this)["bloom_width"]; | ||
82 | } | ||
83 | |||
84 | inline LLSD & bloomStrength() { | ||
85 | return (*this)["bloom_strength"]; | ||
86 | } | ||
87 | |||
88 | inline LLSD & brightness() { | ||
89 | return (*this)["brightness"]; | ||
90 | } | ||
91 | |||
92 | inline LLSD & contrast() { | ||
93 | return (*this)["contrast"]; | ||
94 | } | ||
95 | |||
96 | inline LLSD & contrastBaseR() { | ||
97 | return (*this)["contrast_base"][0]; | ||
98 | } | ||
99 | |||
100 | inline LLSD & contrastBaseG() { | ||
101 | return (*this)["contrast_base"][1]; | ||
102 | } | ||
103 | |||
104 | inline LLSD & contrastBaseB() { | ||
105 | return (*this)["contrast_base"][2]; | ||
106 | } | ||
107 | |||
108 | inline LLSD & contrastBaseIntensity() { | ||
109 | return (*this)["contrast_base"][3]; | ||
110 | } | ||
111 | |||
112 | inline LLSD & saturation() { | ||
113 | return (*this)["saturation"]; | ||
114 | } | ||
115 | |||
116 | inline LLSD & useNightVisionShader() { | ||
117 | return (*this)["enable_night_vision"]; | ||
118 | } | ||
119 | |||
120 | inline LLSD & useBloomShader() { | ||
121 | return (*this)["enable_bloom"]; | ||
122 | } | ||
123 | |||
124 | inline LLSD & useColorFilter() { | ||
125 | return (*this)["enable_color_filter"]; | ||
126 | } | ||
127 | |||
128 | |||
129 | inline F32 getBrightMult() const { | ||
130 | return F32((*this)["brightness_multiplier"].asReal()); | ||
131 | } | ||
132 | |||
133 | inline F32 getNoiseStrength() const { | ||
134 | return F32((*this)["noise_strength"].asReal()); | ||
135 | } | ||
136 | |||
137 | inline F32 getNoiseSize() const { | ||
138 | return F32((*this)["noise_size"].asReal()); | ||
139 | } | ||
140 | |||
141 | inline F32 getExtractLow() const { | ||
142 | return F32((*this)["extract_low"].asReal()); | ||
143 | } | ||
144 | |||
145 | inline F32 getExtractHigh() const { | ||
146 | return F32((*this)["extract_high"].asReal()); | ||
147 | } | ||
148 | |||
149 | inline F32 getBloomWidth() const { | ||
150 | return F32((*this)["bloom_width"].asReal()); | ||
151 | } | ||
152 | |||
153 | inline F32 getBloomStrength() const { | ||
154 | return F32((*this)["bloom_strength"].asReal()); | ||
155 | } | ||
156 | |||
157 | inline F32 getBrightness() const { | ||
158 | return F32((*this)["brightness"].asReal()); | ||
159 | } | ||
160 | |||
161 | inline F32 getContrast() const { | ||
162 | return F32((*this)["contrast"].asReal()); | ||
163 | } | ||
164 | |||
165 | inline F32 getContrastBaseR() const { | ||
166 | return F32((*this)["contrast_base"][0].asReal()); | ||
167 | } | ||
168 | |||
169 | inline F32 getContrastBaseG() const { | ||
170 | return F32((*this)["contrast_base"][1].asReal()); | ||
171 | } | ||
172 | |||
173 | inline F32 getContrastBaseB() const { | ||
174 | return F32((*this)["contrast_base"][2].asReal()); | ||
175 | } | ||
176 | |||
177 | inline F32 getContrastBaseIntensity() const { | ||
178 | return F32((*this)["contrast_base"][3].asReal()); | ||
179 | } | ||
180 | |||
181 | inline F32 getSaturation() const { | ||
182 | return F32((*this)["saturation"].asReal()); | ||
183 | } | ||
184 | |||
185 | }; | ||
186 | |||
187 | bool initialized; | ||
188 | PostProcessTweaks tweaks; | ||
189 | |||
190 | // the map of all availible effects | ||
191 | LLSD mAllEffects; | ||
192 | |||
193 | private: | ||
194 | LLPointer<LLImageGL> mSceneRenderTexture ; | ||
195 | LLPointer<LLImageGL> mNoiseTexture ; | ||
196 | LLPointer<LLImageGL> mTempBloomTexture ; | ||
197 | |||
198 | |||
199 | |||
200 | public: | ||
201 | LLPostProcess(void); | ||
202 | |||
203 | ~LLPostProcess(void); | ||
204 | |||
205 | void apply(unsigned int width, unsigned int height); | ||
206 | void invalidate() ; | ||
207 | |||
208 | /// Perform global initialization for this class. | ||
209 | static void initClass(void); | ||
210 | |||
211 | // Cleanup of global data that's only inited once per class. | ||
212 | static void cleanupClass(); | ||
213 | |||
214 | void setSelectedEffect(std::string const & effectName); | ||
215 | |||
216 | inline std::string const & getSelectedEffect(void) const { | ||
217 | return mSelectedEffectName; | ||
218 | } | ||
219 | |||
220 | void saveEffect(std::string const & effectName); | ||
221 | |||
222 | private: | ||
223 | /// read in from file | ||
224 | std::string mShaderErrorString; | ||
225 | unsigned int screenW; | ||
226 | unsigned int screenH; | ||
227 | |||
228 | float noiseTextureScale; | ||
229 | |||
230 | /// Shader Uniforms | ||
231 | glslUniforms nightVisionUniforms; | ||
232 | glslUniforms bloomExtractUniforms; | ||
233 | glslUniforms bloomBlurUniforms; | ||
234 | glslUniforms colorFilterUniforms; | ||
235 | |||
236 | // the name of currently selected effect in mAllEffects | ||
237 | //invariant: tweaks == mAllEffects[mSelectedEffectName] | ||
238 | std::string mSelectedEffectName; | ||
239 | |||
240 | /// General functions | ||
241 | void initialize(unsigned int width, unsigned int height); | ||
242 | void doEffects(void); | ||
243 | void applyShaders(void); | ||
244 | bool shadersEnabled(void); | ||
245 | |||
246 | /// Night Vision Functions | ||
247 | void createNightVisionShader(void); | ||
248 | void applyNightVisionShader(void); | ||
249 | |||
250 | /// Bloom Functions | ||
251 | void createBloomShader(void); | ||
252 | void applyBloomShader(void); | ||
253 | |||
254 | /// Color Filter Functions | ||
255 | void createColorFilterShader(void); | ||
256 | void applyColorFilterShader(void); | ||
257 | |||
258 | /// OpenGL Helper Functions | ||
259 | void getShaderUniforms(glslUniforms & uniforms, GLhandleARB & prog); | ||
260 | void createTexture(LLPointer<LLImageGL>& texture, unsigned int width, unsigned int height); | ||
261 | void copyFrameBuffer(U32 & texture, unsigned int width, unsigned int height); | ||
262 | void createNoiseTexture(LLPointer<LLImageGL>& texture); | ||
263 | bool checkError(void); | ||
264 | void checkShaderError(GLhandleARB shader); | ||
265 | void drawOrthoQuad(unsigned int width, unsigned int height, QuadType type); | ||
266 | void viewOrthogonal(unsigned int width, unsigned int height); | ||
267 | void changeOrthogonal(unsigned int width, unsigned int height); | ||
268 | void viewPerspective(void); | ||
269 | }; | ||
270 | |||
271 | extern LLPostProcess * gPostProcess; | ||
272 | |||
273 | |||
274 | #endif // LL_POSTPROCESS_H | ||