PageRenderTime 29ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llrender/llglstates.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 265 lines | 199 code | 30 blank | 36 comment | 2 complexity | 2f3a78e6cf076b4de982974f332bb492 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llglstates.h
  3. * @brief LLGL states definitions
  4. *
  5. * $LicenseInfo:firstyear=2001&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. //THIS HEADER SHOULD ONLY BE INCLUDED FROM llgl.h
  27. #ifndef LL_LLGLSTATES_H
  28. #define LL_LLGLSTATES_H
  29. #include "llimagegl.h"
  30. //----------------------------------------------------------------------------
  31. class LLGLDepthTest
  32. {
  33. // Enabled by default
  34. public:
  35. LLGLDepthTest(GLboolean depth_enabled, GLboolean write_enabled = GL_TRUE, GLenum depth_func = GL_LEQUAL);
  36. ~LLGLDepthTest();
  37. void checkState();
  38. GLboolean mPrevDepthEnabled;
  39. GLenum mPrevDepthFunc;
  40. GLboolean mPrevWriteEnabled;
  41. private:
  42. static GLboolean sDepthEnabled; // defaults to GL_FALSE
  43. static GLenum sDepthFunc; // defaults to GL_LESS
  44. static GLboolean sWriteEnabled; // defaults to GL_TRUE
  45. };
  46. //----------------------------------------------------------------------------
  47. class LLGLSDefault
  48. {
  49. protected:
  50. LLGLEnable mColorMaterial;
  51. LLGLDisable mAlphaTest, mBlend, mCullFace, mDither, mFog,
  52. mLineSmooth, mLineStipple, mNormalize, mPolygonSmooth,
  53. mTextureGenQ, mTextureGenR, mTextureGenS, mTextureGenT,
  54. mGLMultisample;
  55. public:
  56. LLGLSDefault()
  57. :
  58. // Enable
  59. mColorMaterial(GL_COLOR_MATERIAL),
  60. // Disable
  61. mAlphaTest(GL_ALPHA_TEST),
  62. mBlend(GL_BLEND),
  63. mCullFace(GL_CULL_FACE),
  64. mDither(GL_DITHER),
  65. mFog(GL_FOG),
  66. mLineSmooth(GL_LINE_SMOOTH),
  67. mLineStipple(GL_LINE_STIPPLE),
  68. mNormalize(GL_NORMALIZE),
  69. mPolygonSmooth(GL_POLYGON_SMOOTH),
  70. mTextureGenQ(GL_TEXTURE_GEN_Q),
  71. mTextureGenR(GL_TEXTURE_GEN_R),
  72. mTextureGenS(GL_TEXTURE_GEN_S),
  73. mTextureGenT(GL_TEXTURE_GEN_T),
  74. mGLMultisample(GL_MULTISAMPLE_ARB)
  75. { }
  76. };
  77. class LLGLSObjectSelect
  78. {
  79. protected:
  80. LLGLDisable mBlend, mFog, mAlphaTest;
  81. LLGLEnable mCullFace;
  82. public:
  83. LLGLSObjectSelect()
  84. : mBlend(GL_BLEND), mFog(GL_FOG),
  85. mAlphaTest(GL_ALPHA_TEST),
  86. mCullFace(GL_CULL_FACE)
  87. { }
  88. };
  89. class LLGLSObjectSelectAlpha
  90. {
  91. protected:
  92. LLGLEnable mAlphaTest;
  93. public:
  94. LLGLSObjectSelectAlpha()
  95. : mAlphaTest(GL_ALPHA_TEST)
  96. {}
  97. };
  98. //----------------------------------------------------------------------------
  99. class LLGLSUIDefault
  100. {
  101. protected:
  102. LLGLEnable mBlend, mAlphaTest;
  103. LLGLDisable mCullFace;
  104. LLGLDepthTest mDepthTest;
  105. public:
  106. LLGLSUIDefault()
  107. : mBlend(GL_BLEND), mAlphaTest(GL_ALPHA_TEST),
  108. mCullFace(GL_CULL_FACE),
  109. mDepthTest(GL_FALSE, GL_TRUE, GL_LEQUAL)
  110. {}
  111. };
  112. class LLGLSNoAlphaTest // : public LLGLSUIDefault
  113. {
  114. protected:
  115. LLGLDisable mAlphaTest;
  116. public:
  117. LLGLSNoAlphaTest()
  118. : mAlphaTest(GL_ALPHA_TEST)
  119. {}
  120. };
  121. //----------------------------------------------------------------------------
  122. class LLGLSFog
  123. {
  124. protected:
  125. LLGLEnable mFog;
  126. public:
  127. LLGLSFog()
  128. : mFog(GL_FOG)
  129. {}
  130. };
  131. class LLGLSNoFog
  132. {
  133. protected:
  134. LLGLDisable mFog;
  135. public:
  136. LLGLSNoFog()
  137. : mFog(GL_FOG)
  138. {}
  139. };
  140. //----------------------------------------------------------------------------
  141. class LLGLSPipeline
  142. {
  143. protected:
  144. LLGLEnable mCullFace;
  145. LLGLDepthTest mDepthTest;
  146. public:
  147. LLGLSPipeline()
  148. : mCullFace(GL_CULL_FACE),
  149. mDepthTest(GL_TRUE, GL_TRUE, GL_LEQUAL)
  150. { }
  151. };
  152. class LLGLSPipelineAlpha // : public LLGLSPipeline
  153. {
  154. protected:
  155. LLGLEnable mBlend, mAlphaTest;
  156. public:
  157. LLGLSPipelineAlpha()
  158. : mBlend(GL_BLEND),
  159. mAlphaTest(GL_ALPHA_TEST)
  160. { }
  161. };
  162. class LLGLSPipelineEmbossBump
  163. {
  164. protected:
  165. LLGLDisable mFog;
  166. public:
  167. LLGLSPipelineEmbossBump()
  168. : mFog(GL_FOG)
  169. { }
  170. };
  171. class LLGLSPipelineSelection
  172. {
  173. protected:
  174. LLGLDisable mCullFace;
  175. public:
  176. LLGLSPipelineSelection()
  177. : mCullFace(GL_CULL_FACE)
  178. {}
  179. };
  180. class LLGLSPipelineAvatar
  181. {
  182. protected:
  183. LLGLEnable mNormalize;
  184. public:
  185. LLGLSPipelineAvatar()
  186. : mNormalize(GL_NORMALIZE)
  187. {}
  188. };
  189. class LLGLSPipelineSkyBox
  190. {
  191. protected:
  192. LLGLDisable mAlphaTest, mCullFace, mFog;
  193. public:
  194. LLGLSPipelineSkyBox()
  195. : mAlphaTest(GL_ALPHA_TEST), mCullFace(GL_CULL_FACE), mFog(GL_FOG)
  196. { }
  197. };
  198. class LLGLSTracker
  199. {
  200. protected:
  201. LLGLEnable mCullFace, mBlend, mAlphaTest;
  202. public:
  203. LLGLSTracker() :
  204. mCullFace(GL_CULL_FACE),
  205. mBlend(GL_BLEND),
  206. mAlphaTest(GL_ALPHA_TEST)
  207. { }
  208. };
  209. //----------------------------------------------------------------------------
  210. class LLGLSSpecular
  211. {
  212. public:
  213. F32 mShininess;
  214. LLGLSSpecular(const LLColor4& color, F32 shininess)
  215. {
  216. mShininess = shininess;
  217. if (mShininess > 0.0f)
  218. {
  219. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color.mV);
  220. S32 shiny = (S32)(shininess*128.f);
  221. shiny = llclamp(shiny,0,128);
  222. glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, shiny);
  223. }
  224. }
  225. ~LLGLSSpecular()
  226. {
  227. if (mShininess > 0.f)
  228. {
  229. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, LLColor4(0.f,0.f,0.f,0.f).mV);
  230. glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0);
  231. }
  232. }
  233. };
  234. //----------------------------------------------------------------------------
  235. #endif