// Sets all materials that apply public void SetMaterialToShader(Material meshMaterial, ShaderProgram program) { if (program == null) { Logger.LogError(Logger.ErrorState.Limited, "MaterialManager> No program given, cannot set material"); return; } if (meshMaterial == null) { SetMaterialToShader(defaultMaterial, program); return; } ShaderUniformManager man = ShaderUniformManager.GetSingleton(); // Must try each supported texture uniform foreach (KeyValuePair <ShaderUniformName, TextureMap> entry in defaultMaterial.textureMaps) { ShaderUniformName uniform = entry.Key; if (!man.DoesShaderSupportUniform(program, uniform)) { continue; } int location = man.GetDataLocation(program, uniform); if (location == ShaderUniformManager.GetInvalidDataLocation()) { Logger.LogError(Logger.ErrorState.Limited, "MaterialManager: Shader says to support texture map " + man.GetUniformName(uniform) + " but there is no location for it"); continue; } // IMPORTANT PART ! if (meshMaterial.textureMaps.ContainsKey(uniform)) { SetTextureUniform(program, location, uniform, meshMaterial.textureMaps[uniform]); } else { if (defaultMaterial.textureMaps.ContainsKey(uniform)) { SetTextureUniform(program, location, uniform, defaultMaterial.textureMaps[uniform]); } else { Logger.LogError(Logger.ErrorState.Limited, "MaterialManager: Shader wants a texture map " + man.GetUniformName(uniform) + " that is not in default material"); } } } }