1 // Utility code for loading GLSL shaders. 2 // Has support for auto-reload, see glsl_refresh 3 4 #pragma once 5 6 #include <map> 7 #include <string> 8 #include <time.h> 9 10 #include "Common/GPU/OpenGL/GLCommon.h" 11 12 // Represent a compiled and linked vshader/fshader pair. 13 // A just-constructed object is valid but cannot be used as a shader program, meaning that 14 // yes, you can declare these as globals if you like. 15 struct GLSLProgram { 16 char name[16]; 17 char vshader_filename[256]; 18 char fshader_filename[256]; 19 const char *vshader_source; 20 const char *fshader_source; 21 time_t vshader_mtime; 22 time_t fshader_mtime; 23 24 // Locations to some common uniforms. Hardcoded for speed. 25 GLint sampler0; 26 GLint sampler1; 27 GLint u_worldviewproj; 28 GLint u_world; 29 GLint u_viewproj; 30 GLint u_fog; // rgb = color, a = density 31 GLint u_sundir; 32 GLint u_camerapos; 33 34 GLint a_position; 35 GLint a_color; 36 GLint a_normal; 37 GLint a_texcoord0; 38 GLint a_texcoord1; 39 40 // Private to the implementation, do not touch 41 GLuint vsh_; 42 GLuint fsh_; 43 GLuint program_; 44 }; 45 46 // C API, old skool. Not much point either... 47 48 // From files (VFS) 49 GLSLProgram *glsl_create(const char *vshader_file, const char *fshader_file, std::string *error_message = 0); 50 // Directly from source code 51 GLSLProgram *glsl_create_source(const char *vshader_src, const char *fshader_src, std::string *error_message = 0); 52 void glsl_destroy(GLSLProgram *program); 53 54 // If recompilation of the program fails, the program is untouched and error messages 55 // are logged and the function returns false. 56 bool glsl_recompile(GLSLProgram *program, std::string *error_message = 0); 57 void glsl_bind(const GLSLProgram *program); 58 const GLSLProgram *glsl_get_program(); 59 void glsl_unbind(); 60 int glsl_attrib_loc(const GLSLProgram *program, const char *name); 61 int glsl_uniform_loc(const GLSLProgram *program, const char *name); 62