PageRenderTime 36ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llrender/llglslshader.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 161 lines | 106 code | 22 blank | 33 comment | 0 complexity | 649c0d585701edc360896156c81f60df MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llglslshader.h
  3. * @brief GLSL shader wrappers
  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. #ifndef LL_LLGLSLSHADER_H
  27. #define LL_LLGLSLSHADER_H
  28. #include "llgl.h"
  29. #include "llrender.h"
  30. class LLShaderFeatures
  31. {
  32. public:
  33. bool calculatesLighting;
  34. bool calculatesAtmospherics;
  35. bool hasLighting; // implies no transport (it's possible to have neither though)
  36. bool isAlphaLighting; // indicates lighting shaders need not be linked in (lighting performed directly in alpha shader to match deferred lighting functions)
  37. bool isShiny;
  38. bool isFullbright; // implies no lighting
  39. bool isSpecular;
  40. bool hasWaterFog; // implies no gamma
  41. bool hasTransport; // implies no lighting (it's possible to have neither though)
  42. bool hasSkinning;
  43. bool hasObjectSkinning;
  44. bool hasAtmospherics;
  45. bool hasGamma;
  46. S32 mIndexedTextureChannels;
  47. bool disableTextureIndex;
  48. bool hasAlphaMask;
  49. // char numLights;
  50. LLShaderFeatures();
  51. };
  52. class LLGLSLShader
  53. {
  54. public:
  55. enum
  56. {
  57. SG_DEFAULT = 0,
  58. SG_SKY,
  59. SG_WATER
  60. };
  61. LLGLSLShader();
  62. static GLhandleARB sCurBoundShader;
  63. static LLGLSLShader* sCurBoundShaderPtr;
  64. static S32 sIndexedTextureChannels;
  65. static bool sNoFixedFunction;
  66. void unload();
  67. BOOL createShader(std::vector<std::string> * attributes,
  68. std::vector<std::string> * uniforms);
  69. BOOL attachObject(std::string object);
  70. void attachObject(GLhandleARB object);
  71. void attachObjects(GLhandleARB* objects = NULL, S32 count = 0);
  72. BOOL mapAttributes(const std::vector<std::string> * attributes);
  73. BOOL mapUniforms(const std::vector<std::string> * uniforms);
  74. void mapUniform(GLint index, const std::vector<std::string> * uniforms);
  75. void uniform1i(U32 index, GLint i);
  76. void uniform1f(U32 index, GLfloat v);
  77. void uniform2f(U32 index, GLfloat x, GLfloat y);
  78. void uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z);
  79. void uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
  80. void uniform1iv(U32 index, U32 count, const GLint* i);
  81. void uniform1fv(U32 index, U32 count, const GLfloat* v);
  82. void uniform2fv(U32 index, U32 count, const GLfloat* v);
  83. void uniform3fv(U32 index, U32 count, const GLfloat* v);
  84. void uniform4fv(U32 index, U32 count, const GLfloat* v);
  85. void uniform1i(const std::string& uniform, GLint i);
  86. void uniform1f(const std::string& uniform, GLfloat v);
  87. void uniform2f(const std::string& uniform, GLfloat x, GLfloat y);
  88. void uniform3f(const std::string& uniform, GLfloat x, GLfloat y, GLfloat z);
  89. void uniform4f(const std::string& uniform, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
  90. void uniform1iv(const std::string& uniform, U32 count, const GLint* i);
  91. void uniform1fv(const std::string& uniform, U32 count, const GLfloat* v);
  92. void uniform2fv(const std::string& uniform, U32 count, const GLfloat* v);
  93. void uniform3fv(const std::string& uniform, U32 count, const GLfloat* v);
  94. void uniform4fv(const std::string& uniform, U32 count, const GLfloat* v);
  95. void uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
  96. void uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
  97. void uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
  98. void uniformMatrix2fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v);
  99. void uniformMatrix3fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v);
  100. void uniformMatrix4fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v);
  101. void setMinimumAlpha(F32 minimum);
  102. void vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
  103. void vertexAttrib4fv(U32 index, GLfloat* v);
  104. GLint getUniformLocation(const std::string& uniform);
  105. GLint getUniformLocation(U32 index);
  106. GLint getAttribLocation(U32 attrib);
  107. GLint mapUniformTextureChannel(GLint location, GLenum type);
  108. //enable/disable texture channel for specified uniform
  109. //if given texture uniform is active in the shader,
  110. //the corresponding channel will be active upon return
  111. //returns channel texture is enabled in from [0-MAX)
  112. S32 enableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
  113. S32 disableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
  114. BOOL link(BOOL suppress_errors = FALSE);
  115. void bind();
  116. void unbind();
  117. // Unbinds any previously bound shader by explicitly binding no shader.
  118. static void bindNoShader(void);
  119. U32 mMatHash[LLRender::NUM_MATRIX_MODES];
  120. U32 mLightHash;
  121. GLhandleARB mProgramObject;
  122. std::vector<GLint> mAttribute; //lookup table of attribute enum to attribute channel
  123. std::vector<GLint> mUniform; //lookup table of uniform enum to uniform location
  124. std::map<std::string, GLint> mUniformMap; //lookup map of uniform name to uniform location
  125. std::map<GLint, LLVector4> mValue; //lookup map of uniform location to last known value
  126. std::vector<GLint> mTexture;
  127. S32 mActiveTextureChannels;
  128. S32 mShaderLevel;
  129. S32 mShaderGroup;
  130. BOOL mUniformsDirty;
  131. LLShaderFeatures mFeatures;
  132. std::vector< std::pair< std::string, GLenum > > mShaderFiles;
  133. std::string mName;
  134. };
  135. //UI shader (declared here so llui_libtest will link properly)
  136. extern LLGLSLShader gUIProgram;
  137. //output vec4(color.rgb,color.a*tex0[tc0].a)
  138. extern LLGLSLShader gSolidColorProgram;
  139. #endif