PageRenderTime 164ms CodeModel.GetById 3ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_POSTPROCESS_H
  27. #define LL_POSTPROCESS_H
  28. #include <map>
  29. #include <fstream>
  30. #include "llgl.h"
  31. #include "llglheaders.h"
  32. class LLPostProcess
  33. {
  34. public:
  35. typedef enum _QuadType {
  36. QUAD_NORMAL,
  37. QUAD_NOISE,
  38. QUAD_BLOOM_EXTRACT,
  39. QUAD_BLOOM_COMBINE
  40. } QuadType;
  41. /// GLSL Shader Encapsulation Struct
  42. typedef std::map<const char *, GLuint> glslUniforms;
  43. struct PostProcessTweaks : public LLSD {
  44. inline PostProcessTweaks() : LLSD(LLSD::emptyMap())
  45. {
  46. }
  47. inline LLSD & brightMult() {
  48. return (*this)["brightness_multiplier"];
  49. }
  50. inline LLSD & noiseStrength() {
  51. return (*this)["noise_strength"];
  52. }
  53. inline LLSD & noiseSize() {
  54. return (*this)["noise_size"];
  55. }
  56. inline LLSD & extractLow() {
  57. return (*this)["extract_low"];
  58. }
  59. inline LLSD & extractHigh() {
  60. return (*this)["extract_high"];
  61. }
  62. inline LLSD & bloomWidth() {
  63. return (*this)["bloom_width"];
  64. }
  65. inline LLSD & bloomStrength() {
  66. return (*this)["bloom_strength"];
  67. }
  68. inline LLSD & brightness() {
  69. return (*this)["brightness"];
  70. }
  71. inline LLSD & contrast() {
  72. return (*this)["contrast"];
  73. }
  74. inline LLSD & contrastBaseR() {
  75. return (*this)["contrast_base"][0];
  76. }
  77. inline LLSD & contrastBaseG() {
  78. return (*this)["contrast_base"][1];
  79. }
  80. inline LLSD & contrastBaseB() {
  81. return (*this)["contrast_base"][2];
  82. }
  83. inline LLSD & contrastBaseIntensity() {
  84. return (*this)["contrast_base"][3];
  85. }
  86. inline LLSD & saturation() {
  87. return (*this)["saturation"];
  88. }
  89. inline LLSD & useNightVisionShader() {
  90. return (*this)["enable_night_vision"];
  91. }
  92. inline LLSD & useBloomShader() {
  93. return (*this)["enable_bloom"];
  94. }
  95. inline LLSD & useColorFilter() {
  96. return (*this)["enable_color_filter"];
  97. }
  98. inline F32 getBrightMult() const {
  99. return F32((*this)["brightness_multiplier"].asReal());
  100. }
  101. inline F32 getNoiseStrength() const {
  102. return F32((*this)["noise_strength"].asReal());
  103. }
  104. inline F32 getNoiseSize() const {
  105. return F32((*this)["noise_size"].asReal());
  106. }
  107. inline F32 getExtractLow() const {
  108. return F32((*this)["extract_low"].asReal());
  109. }
  110. inline F32 getExtractHigh() const {
  111. return F32((*this)["extract_high"].asReal());
  112. }
  113. inline F32 getBloomWidth() const {
  114. return F32((*this)["bloom_width"].asReal());
  115. }
  116. inline F32 getBloomStrength() const {
  117. return F32((*this)["bloom_strength"].asReal());
  118. }
  119. inline F32 getBrightness() const {
  120. return F32((*this)["brightness"].asReal());
  121. }
  122. inline F32 getContrast() const {
  123. return F32((*this)["contrast"].asReal());
  124. }
  125. inline F32 getContrastBaseR() const {
  126. return F32((*this)["contrast_base"][0].asReal());
  127. }
  128. inline F32 getContrastBaseG() const {
  129. return F32((*this)["contrast_base"][1].asReal());
  130. }
  131. inline F32 getContrastBaseB() const {
  132. return F32((*this)["contrast_base"][2].asReal());
  133. }
  134. inline F32 getContrastBaseIntensity() const {
  135. return F32((*this)["contrast_base"][3].asReal());
  136. }
  137. inline F32 getSaturation() const {
  138. return F32((*this)["saturation"].asReal());
  139. }
  140. };
  141. bool initialized;
  142. PostProcessTweaks tweaks;
  143. // the map of all availible effects
  144. LLSD mAllEffects;
  145. private:
  146. LLPointer<LLImageGL> mSceneRenderTexture ;
  147. LLPointer<LLImageGL> mNoiseTexture ;
  148. LLPointer<LLImageGL> mTempBloomTexture ;
  149. public:
  150. LLPostProcess(void);
  151. ~LLPostProcess(void);
  152. void apply(unsigned int width, unsigned int height);
  153. void invalidate() ;
  154. /// Perform global initialization for this class.
  155. static void initClass(void);
  156. // Cleanup of global data that's only inited once per class.
  157. static void cleanupClass();
  158. void setSelectedEffect(std::string const & effectName);
  159. inline std::string const & getSelectedEffect(void) const {
  160. return mSelectedEffectName;
  161. }
  162. void saveEffect(std::string const & effectName);
  163. private:
  164. /// read in from file
  165. std::string mShaderErrorString;
  166. unsigned int screenW;
  167. unsigned int screenH;
  168. float noiseTextureScale;
  169. /// Shader Uniforms
  170. glslUniforms nightVisionUniforms;
  171. glslUniforms bloomExtractUniforms;
  172. glslUniforms bloomBlurUniforms;
  173. glslUniforms colorFilterUniforms;
  174. // the name of currently selected effect in mAllEffects
  175. // invariant: tweaks == mAllEffects[mSelectedEffectName]
  176. std::string mSelectedEffectName;
  177. /// General functions
  178. void initialize(unsigned int width, unsigned int height);
  179. void doEffects(void);
  180. void applyShaders(void);
  181. bool shadersEnabled(void);
  182. /// Night Vision Functions
  183. void createNightVisionShader(void);
  184. void applyNightVisionShader(void);
  185. /// Bloom Functions
  186. void createBloomShader(void);
  187. void applyBloomShader(void);
  188. /// Color Filter Functions
  189. void createColorFilterShader(void);
  190. void applyColorFilterShader(void);
  191. /// OpenGL Helper Functions
  192. void getShaderUniforms(glslUniforms & uniforms, GLhandleARB & prog);
  193. void createTexture(LLPointer<LLImageGL>& texture, unsigned int width, unsigned int height);
  194. void copyFrameBuffer(U32 & texture, unsigned int width, unsigned int height);
  195. void createNoiseTexture(LLPointer<LLImageGL>& texture);
  196. bool checkError(void);
  197. void checkShaderError(GLhandleARB shader);
  198. void drawOrthoQuad(unsigned int width, unsigned int height, QuadType type);
  199. void viewOrthogonal(unsigned int width, unsigned int height);
  200. void changeOrthogonal(unsigned int width, unsigned int height);
  201. void viewPerspective(void);
  202. };
  203. extern LLPostProcess * gPostProcess;
  204. #endif // LL_POSTPROCESS_H