00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023 #ifndef __VR3SHADERMANAGER_H__
00024 #define __VR3SHADERMANAGER_H__
00025
00026
00027 #include <map>
00028
00030
00035 typedef void (*f_prepareshader) ( GLuint program, std::string& vs,
00036 std::string& gs, std::string& fs,
00037 std::string& es, const std::string*& ss );
00038
00040
00044 typedef void (*f_uniformloc)(GLuint);
00045
00047
00111 class VR3ShaderManager {
00112
00114 VR3ShaderManager();
00115
00116
00117
00119
00120
00122
00127 static GLuint ms_std_programs[2][2][2][2];
00128
00130
00133 static const f_prepareshader ms_std_prepfuncs[2][2][2][2];
00134
00136
00140 static const f_uniformloc ms_std_unilocfuncs[2][2][2][2];
00141
00143 struct UniformArray {
00145 GLint uniforms[VR3_NUM_STD_UNIFORMS];
00146 };
00147
00149
00156 static std::map< GLuint, UniformArray > ms_std_uniforms;
00157
00159
00165 static std::string ms_occlprob_code;
00166
00168
00169
00170
00172
00173
00175
00178 static std::map<GLenum, GLuint> ms_bg_programs;
00179
00181 struct BgUniformArray {
00183 GLint uniforms[VR3_NUM_BG_UNIFORMS];
00184 };
00185
00187
00193 static std::map< GLuint, BgUniformArray > ms_bg_uniforms;
00194
00196
00197
00198
00200
00201
00203
00205 static GLuint ms_shad_program;
00206
00208
00213 static GLint ms_shad_uniforms[VR3_NUM_SHAD_UNIFORMS];
00214
00216
00217
00218
00220
00221
00223
00227 static GLuint ms_blur_programs[2];
00228
00230
00235 static GLint ms_blur_uniforms[2][VR3_NUM_BLUR_UNIFORMS];
00236
00238
00239
00240
00241
00242 #if defined(_WIN32) || defined(_WIN64)
00243
00245
00246
00248
00250 static GLuint ms_text_program;
00251
00253
00258 static GLint ms_text_uniforms[VR3_NUM_TEXT_UNIFORMS];
00259
00261
00262 #endif
00263
00264
00265
00267
00268
00270
00276 static void RemLinesContaining(const std::string& str, std::string& shad);
00277
00279
00287 static void ReplaceIntToken( const std::string& torep, GLint value,
00288 std::string& shad );
00289
00291
00299 static void ReplaceAllIntToken( const std::string& torep, GLint value,
00300 std::string& shad );
00301
00303
00310 static void ReplaceStringToken( const std::string& torep,
00311 const std::string& rep, std::string& shad );
00312
00314
00322 static void ReplaceAllStringToken( const std::string& torep,
00323 const std::string& rep, std::string& shad );
00324
00326
00334 static void GenerateOcclusionCode(const std::string*& shad);
00335
00337
00338
00339
00341
00342
00344
00348 static void LinkProgram(GLuint program);
00349
00351
00359 static void CompileAttach( GLuint program,
00360 const char* source, GLenum type );
00361
00363
00364
00365
00385
00387 static void PrepareShadersFFFF( GLuint program, std::string& vs,
00388 std::string& gs, std::string& fs,
00389 std::string& es, const std::string*& ss );
00391 static void PrepareShadersTFFF( GLuint program, std::string& vs,
00392 std::string& gs, std::string& fs,
00393 std::string& es, const std::string*& ss );
00395 static void PrepareShadersFTFF( GLuint program, std::string& vs,
00396 std::string& gs, std::string& fs,
00397 std::string& es, const std::string*& ss );
00399 static void PrepareShadersTTFF( GLuint program, std::string& vs,
00400 std::string& gs, std::string& fs,
00401 std::string& es, const std::string*& ss );
00403 static void PrepareShadersFFTF( GLuint program, std::string& vs,
00404 std::string& gs, std::string& fs,
00405 std::string& es, const std::string*& ss );
00407 static void PrepareShadersTFTF( GLuint program, std::string& vs,
00408 std::string& gs, std::string& fs,
00409 std::string& es, const std::string*& ss );
00411 static void PrepareShadersFFTT( GLuint program, std::string& vs,
00412 std::string& gs, std::string& fs,
00413 std::string& es, const std::string*& ss );
00415 static void PrepareShadersFTFT( GLuint program, std::string& vs,
00416 std::string& gs, std::string& fs,
00417 std::string& es, const std::string*& ss );
00419 static void PrepareShadersTFTT( GLuint program, std::string& vs,
00420 std::string& gs, std::string& fs,
00421 std::string& es, const std::string*& ss );
00423 static void PrepareShadersTTFT( GLuint program, std::string& vs,
00424 std::string& gs, std::string& fs,
00425 std::string& es, const std::string*& ss );
00427
00428
00429
00440
00442 static void GetUniformLocsFFFF(GLuint program);
00444 static void GetUniformLocsTFFF(GLuint program);
00446 static void GetUniformLocsFTFF(GLuint program);
00448 static void GetUniformLocsTTFF(GLuint program);
00450 static void GetUniformLocsFFTF(GLuint program);
00452 static void GetUniformLocsTFTF(GLuint program);
00454 static void GetUniformLocsFFTT(GLuint program);
00456 static void GetUniformLocsFTFT(GLuint program);
00458 static void GetUniformLocsTFTT(GLuint program);
00460 static void GetUniformLocsTTFT(GLuint program);
00461
00463
00470 static void GetUniformLocsShadowAlgorithm(GLuint program);
00471
00473
00474 public:
00475
00477
00493 static GLuint GetShaderProgram( bool fl_difftex, bool fl_lightmap,
00494 bool fl_normmap, bool fl_dispmap,
00495 const GLint*& unilocs );
00496
00498
00506 static GLuint GetBgShaderProgram( GLenum textype, const GLint*& unilocs );
00507
00509
00516 static GLuint GetShadShaderProgram( const GLint*& unilocs );
00517
00519
00526 static void GetBlurShaderPrograms( GLuint programs[], const GLint* unilocs[] );
00527
00528
00529 #if defined(_WIN32) || defined(_WIN64)
00530
00532
00539 static GLuint GetTextShaderProgram( const GLint*& unilocs );
00540
00541 #endif // windows only
00542
00544
00555 static void LoadExtShaderProgram( const char* vs, const char* gs,
00556 const char* fs, VR3ShaderProgram* shadprog );
00557 };
00558
00559 #endif