public void SetActiveShader(ShaderProgram shader) { if (shader == null) { Logger.LogError(Logger.ErrorState.Critical, "SetActiveShader, no shader given"); return; } if (activeProgram != shader) { activeProgram = shader; activeProgram.Use(); ShaderUniformManager man = ShaderUniformManager.GetSingleton(); if (man.DoesShaderUseCamera(activeProgram)) { RenderCamera(); } if (man.DoesShaderUseLights(activeProgram)) { RenderActiveLights(); } if (man.DoesShaderSupportUniform(activeProgram, ShaderUniformName.CubeMap)) { MaterialManager matMan = MaterialManager.GetSingleton(); matMan.SetFromMaterialToShader(activeSkybox, ShaderUniformName.CubeMap, activeProgram); if (man.DoesShaderSupportUniform(activeProgram, ShaderUniformName.SkyboxRotationMatrix)) { int rotLoc = activeProgram.GetUniformLocation(ShaderUniformName.SkyboxRotationMatrix); activeProgram.SetMatrix4Uniform(rotLoc, ref activeSkyboxRotation); } } } }
public void SetFromMaterialToShader(Material mat, ShaderUniformName uniform, ShaderProgram program) { ShaderUniformManager man = ShaderUniformManager.GetSingleton(); if (man.DoesShaderSupportUniform(program, uniform)) { int location = man.GetDataLocation(program, uniform); if (mat.textureMaps.ContainsKey(uniform)) { SetTextureUniform(program, location, uniform, mat.textureMaps[uniform]); } } }
// 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"); } } } }