1 //----------------------------------------------------------------------------- 2 // Shader 3 //----------------------------------------------------------------------------- 4 5 #ifndef __SHADER_H__ 6 #define __SHADER_H__ 7 8 #include "texture.h" 9 #include "layer.h" 10 #include "files.h" 11 12 /** 13 * Shader manager. 14 * The shader manager is used to store every shader used by the current 15 * opened BSP. 16 * @todo Add q3render shaders 17 * @todo Finish shader support (support portal shaders and other 18 * shaders features) 19 * @todo Try to change the shadermanager so we don't need to have 2 shader 20 * references in surface class. 21 */ 22 class ShaderManager 23 { 24 public: 25 26 /** 27 * Allocate space for the references. 28 * @param num the shader table size 29 */ 30 ShaderManager(const int num = MAX_NSHADERS); 31 ~ShaderManager(void); 32 33 /** 34 * Adds shader to the references. 35 * @param name the shader name 36 * @param flags the flags for shaders 37 * @param contents the shader content 38 * @param type the shader type 39 * @return the shader index in shader manager 40 */ 41 int AddShader(const char * name, 42 int flags = 0, 43 int contents = 0, 44 int type = FACETYPE_NORMAL); 45 46 /** 47 * Un-adds a shader reference. 48 * @param num the shader to unreference 49 */ 50 void DeleteShader(const int num); 51 52 /** 53 * Return shader of the reference. 54 * @param num the shader index to get 55 * @return a pointer to existing shader or 56 * NULL pointer if shader does not exist 57 * @test This function was inline before 58 */ 59 Shader *GetShader(const int num); 60 61 /** 62 * Gets the name of a registered shader. 63 * @param num the shader index 64 * @return the shader name is shader number exists, NULL pointer if not 65 */ 66 char* GetShaderName(const int num); 67 68 /** 69 * Gets the index of a shader in the list. 70 * @param name the shader name 71 * @return the shader index 72 */ 73 int GetShaderNum(const char* name); 74 75 /** 76 * Gets tje number of registered shaders. 77 * @return the number of registered shaders 78 */ 79 int GetShadersNum(void); 80 81 /** 82 * Reset all reference counts. 83 */ 84 void ResetAll(void); 85 86 /** 87 * Updates the shaders acording to the references. 88 * @param pak_search enable the shaders search in pak files if true 89 */ 90 void Update(bool pak_search = true); 91 92 /** 93 * Delete all the shaders. 94 */ 95 void DeleteAll(void); 96 97 private: 98 99 void DefaultShader(int i); 100 Shader * CreateShader(void); 101 Layer * CreateLayer(void); 102 void DeleteReference(int i); 103 104 ShaderHash *ShaderTable; 105 int max_refs; 106 int num_refs; 107 108 LayerManager layers; 109 TextureManager textures; 110 }; 111 112 //----------------------------------------------------------------------------- 113 // ShaderFile 114 //----------------------------------------------------------------------------- 115 116 class ShaderFile : public VFile 117 { 118 public: 119 ShaderFile(const char *name, const char *pakname = ""); 120 ~ShaderFile(); 121 122 char *GetShaderName(void); 123 void SetShaderPos(int pos); 124 int GetShaderPos(void); 125 void Parse(Shader *shad, LayerManager* layers, TextureManager* textures); 126 void Skip(void); 127 128 // si hago lo que dije de no reservar memoria para todos los shaders a la vez, parse, se 129 // deber�a encargar de hacerlo y devolver un puntero. 130 131 private: 132 void ParseLayer(Shader *shad, Layer *llayer, TextureManager* textures); 133 134 //void ParseParameters(Shader *shader, Layer *pass, const shaderkey_t *keys); 135 float ParseFunc(void); 136 }; 137 138 #endif 139