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