| 166 | }; |
| 167 | |
| 168 | class Program { |
| 169 | public: |
| 170 | GLuint gl_program; |
| 171 | std::string name; |
| 172 | int shader_ids[kMaxShaderTypes]; |
| 173 | std::vector<GLint> tex_uniform; |
| 174 | typedef ska::flat_hash_map<std::string, GLint> UniformAddressCacheMap; |
| 175 | UniformAddressCacheMap uniform_address_cache; |
| 176 | typedef ska::flat_hash_map<GLint, GLint> UniformOffsetCacheMap; |
| 177 | UniformOffsetCacheMap uniform_offset_cache; |
| 178 | typedef ska::flat_hash_map<std::string, GLint> AttribAddressCacheMap; |
| 179 | AttribAddressCacheMap attrib_address_cache; |
| 180 | typedef ska::flat_hash_map<GLint, std::vector<GLfloat> > UniformValueCacheMap; |
| 181 | UniformValueCacheMap uniform_value_cache; |
| 182 | std::vector<GLint> commonShaderUniforms; |
| 183 | |
| 184 | public: |
| 185 | template <typename T> |
| 186 | void SetUniform(CommonShaderUniformIDs uniformID, const T& value) { |
| 187 | SetUniform(commonShaderUniforms[uniformID], value); |
| 188 | } |
| 189 | void SetUniform(GLint uniformID, const mat4& value) { |
| 190 | // note that this avoids all of the caching that would otherwise happen |
| 191 | glUniformMatrix4fv(uniformID, 1, GL_FALSE, value); |
| 192 | } |
| 193 | void SetUniform(GLint uniformID, const mat3& value) { |
| 194 | // note that this avoids all of the caching that would otherwise happen |
| 195 | glUniformMatrix3fv(uniformID, 1, GL_FALSE, value); |
| 196 | } |
| 197 | }; |
| 198 | |
| 199 | class Shaders { |
| 200 | private: |