1 #ifndef _OGL_SHADER_ 2 #define _OGL_SHADER_ 3 /* 4 OGL_SHADER.H 5 6 Copyright (C) 2009 by Clemens Unterkofler and the Aleph One developers 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 3 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 This license is contained in the file "COPYING", 19 which is included with this source code; it is available online at 20 http://www.gnu.org/licenses/gpl.html 21 22 Implements OpenGL vertex/fragment shader class 23 */ 24 25 #include <string> 26 #include <map> 27 #include "OGL_Headers.h" 28 #include "FileHandler.h" 29 30 class Shader { 31 32 friend class XML_ShaderParser; 33 friend class Shader_MML_Parser; 34 public: 35 enum UniformName { 36 U_Texture0, 37 U_Texture1, 38 U_Texture2, 39 U_Texture3, 40 U_Time, 41 U_Pulsate, 42 U_Wobble, 43 U_Flare, 44 U_BloomScale, 45 U_BloomShift, 46 U_Repeat, 47 U_OffsetX, 48 U_OffsetY, 49 U_Pass, 50 U_UseFog, 51 U_Visibility, 52 U_Depth, 53 U_StrictDepthMode, 54 U_Glow, 55 U_LandscapeInverseMatrix, 56 U_ScaleX, 57 U_ScaleY, 58 U_Yaw, 59 U_Pitch, 60 U_SelfLuminosity, 61 U_GammaAdjust, 62 U_LogicalWidth, 63 U_LogicalHeight, 64 U_PixelWidth, 65 U_PixelHeight, 66 NUMBER_OF_UNIFORM_LOCATIONS 67 }; 68 69 enum ShaderType { 70 S_Blur, 71 S_Bloom, 72 S_Landscape, 73 S_LandscapeBloom, 74 S_Sprite, 75 S_SpriteBloom, 76 S_Invincible, 77 S_InvincibleBloom, 78 S_Invisible, 79 S_InvisibleBloom, 80 S_Wall, 81 S_WallBloom, 82 S_Bump, 83 S_BumpBloom, 84 S_Gamma, 85 NUMBER_OF_SHADER_TYPES 86 }; 87 private: 88 89 GLhandleARB _programObj; 90 std::string _vert; 91 std::string _frag; 92 int16 _passes; 93 bool _loaded; 94 95 static const char* _shader_names[NUMBER_OF_SHADER_TYPES]; 96 static std::vector<Shader> _shaders; 97 98 static const char* _uniform_names[NUMBER_OF_UNIFORM_LOCATIONS]; 99 GLint _uniform_locations[NUMBER_OF_UNIFORM_LOCATIONS]; 100 float _cached_floats[NUMBER_OF_UNIFORM_LOCATIONS]; 101 getUniformLocation(UniformName name)102 GLint getUniformLocation(UniformName name) { 103 if (_uniform_locations[name] == -1) { 104 _uniform_locations[name] = glGetUniformLocationARB(_programObj, _uniform_names[name]); 105 } 106 return _uniform_locations[name]; 107 } 108 109 public: 110 get(ShaderType type)111 static Shader* get(ShaderType type) { return &_shaders[type]; } 112 static void loadAll(); 113 static void unloadAll(); 114 Shader()115 Shader() : _programObj(0), _passes(-1), _loaded(false) {} 116 Shader(const std::string& name); 117 Shader(const std::string& name, FileSpecifier& vert, FileSpecifier& frag, int16& passes); 118 ~Shader(); 119 120 void load(); 121 void init(); 122 void enable(); 123 void unload(); 124 void setFloat(UniformName name, float); // shader must be enabled 125 void setMatrix4(UniformName name, float *f); 126 127 int16 passes(); 128 129 static void disable(); 130 }; 131 132 133 class InfoTree; 134 void parse_mml_opengl_shader(const InfoTree& root); 135 void reset_mml_opengl_shader(); 136 137 #endif 138