1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef LUA_UNIT_MATERIAL_H 4 #define LUA_UNIT_MATERIAL_H 5 6 // NOTE: some implementation is done in LuaMaterial.cpp 7 8 typedef int GLint; 9 typedef unsigned int GLuint; 10 typedef float GLfloat; 11 typedef unsigned int GLenum; 12 13 #include <vector> 14 using std::vector; 15 #include <stddef.h> 16 17 class CUnit; 18 class LuaMatBin; 19 20 21 /******************************************************************************/ 22 /******************************************************************************/ 23 24 enum LuaMatType { 25 LUAMAT_ALPHA = 0, 26 LUAMAT_OPAQUE = 1, 27 LUAMAT_ALPHA_REFLECT = 2, 28 LUAMAT_OPAQUE_REFLECT = 3, 29 LUAMAT_SHADOW = 4, 30 LUAMAT_TYPE_COUNT = 5 31 }; 32 33 34 /******************************************************************************/ 35 36 class LuaMatRef { 37 38 friend class LuaMatHandler; 39 40 public: LuaMatRef()41 LuaMatRef() : bin(NULL) {} 42 LuaMatRef(const LuaMatRef&); 43 LuaMatRef& operator=(const LuaMatRef&); 44 ~LuaMatRef(); 45 46 void Reset(); 47 48 void AddUnit(CUnit*); 49 void Execute() const; 50 IsActive()51 inline bool IsActive() const { return (bin != NULL); } 52 GetBin()53 inline const LuaMatBin* GetBin() const { return bin; } 54 55 private: 56 LuaMatRef(LuaMatBin* _bin); 57 58 private: 59 LuaMatBin* bin; // can be NULL 60 }; 61 62 63 /******************************************************************************/ 64 /******************************************************************************/ 65 66 class LuaUnitUniforms { 67 public: LuaUnitUniforms()68 LuaUnitUniforms() 69 : haveUniforms(false), 70 speedLoc(-1), 71 healthLoc(-1), 72 unitIDLoc(-1), 73 teamIDLoc(-1), 74 customLoc(-1), 75 customCount(0), 76 customData(NULL) 77 {} 78 LuaUnitUniforms(const LuaUnitUniforms&); 79 LuaUnitUniforms& operator=(const LuaUnitUniforms&); ~LuaUnitUniforms()80 ~LuaUnitUniforms() { delete[] customData; } 81 82 void Execute(CUnit* unit) const; 83 84 void SetCustomCount(int count); 85 86 public: 87 bool haveUniforms; 88 GLint speedLoc; 89 GLint healthLoc; 90 GLint unitIDLoc; 91 GLint teamIDLoc; 92 GLint customLoc; 93 int customCount; 94 GLfloat* customData; 95 96 97 // FIXME: do this differently 98 struct EngineData { 99 GLint location; 100 GLenum type; // GL_FLOAT, GL_FLOAT_VEC3, etc... 101 GLuint size; 102 GLuint count; 103 GLint* intData; 104 GLfloat* floatData; 105 void* data; 106 }; 107 vector<EngineData> uniforms; 108 }; 109 110 111 /******************************************************************************/ 112 113 class LuaUnitLODMaterial { 114 public: LuaUnitLODMaterial()115 LuaUnitLODMaterial() 116 : preDisplayList(0), 117 postDisplayList(0) 118 {} 119 IsActive()120 inline bool IsActive() const { return matref.IsActive(); } 121 AddUnit(CUnit * unit)122 inline void AddUnit(CUnit* unit) { matref.AddUnit(unit); } 123 ExecuteMaterial()124 inline void ExecuteMaterial() const { matref.Execute(); } 125 ExecuteUniforms(CUnit * unit)126 inline void ExecuteUniforms(CUnit* unit) const 127 { 128 uniforms.Execute(unit); 129 } 130 131 public: 132 GLuint preDisplayList; 133 GLuint postDisplayList; 134 LuaMatRef matref; 135 LuaUnitUniforms uniforms; 136 }; 137 138 139 /******************************************************************************/ 140 141 class LuaUnitMaterial { 142 public: LuaUnitMaterial()143 LuaUnitMaterial() : lodCount(0), lastLOD(0) {} 144 145 bool SetLODCount(unsigned int count); 146 bool SetLastLOD(unsigned int count); 147 GetLODCount()148 inline const unsigned int GetLODCount() const { return lodCount; } GetLastLOD()149 inline const unsigned int GetLastLOD() const { return lastLOD; } 150 IsActive(unsigned int lod)151 inline bool IsActive(unsigned int lod) const { 152 if (lod >= lodCount) { 153 return false; 154 } 155 return lodMats[lod].IsActive(); 156 } 157 GetMaterial(unsigned int lod)158 inline LuaUnitLODMaterial* GetMaterial(unsigned int lod) { 159 if (lod >= lodCount) { 160 return NULL; 161 } 162 return &lodMats[lod]; 163 } 164 GetMaterial(unsigned int lod)165 inline const LuaUnitLODMaterial* GetMaterial(unsigned int lod) const { 166 if (lod >= lodCount) { 167 return NULL; 168 } 169 return &lodMats[lod]; 170 } 171 172 private: 173 unsigned int lodCount; 174 unsigned int lastLOD; 175 vector<LuaUnitLODMaterial> lodMats; 176 }; 177 178 179 /******************************************************************************/ 180 /******************************************************************************/ 181 182 183 #endif /* LUA_UNIT_MATERIAL_H */ 184