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