public void SetArrayData(ShaderProgram shader , ShaderUniformName arrayName , ShaderUniformName dataName , IShaderDataOwner provider , int index) { foreach (ShaderUniform uni in shader.uniforms) { if (uni.name == dataName && uni.arrayName == arrayName && uni.arrayIndex == index) { bool set = provider.SetUniform(shader, uni.location, uni.name); if (!set) { Logger.LogError(Logger.ErrorState.Critical, "ShaderUniformManager.SetArrayData. Provider does not have " + GetUniformName(arrayName) + "." + GetUniformName(dataName)); } return; } } Logger.LogError(Logger.ErrorState.Critical, "ShaderUniformManager.SetArrayData. Shader " + shader.programName + " does not use data: " + GetUniformName(arrayName) + "[" + index + "]." + GetUniformName(dataName)); foreach (ShaderUniform uni in shader.uniforms) { if (uni.arrayIndex != -1) { Logger.LogInfo(shader.programName + " uses " + GetUniformName(uni.arrayName) + "[" + uni.arrayIndex + "]." + GetUniformName(uni.name)); } } }
private void PassLightData(IShaderDataOwner light, int lightIndex) { ShaderUniformManager man = ShaderUniformManager.GetSingleton(); man.SetArrayData(activeProgram, ShaderUniformName.LightsArray, ShaderUniformName.LightPositionOrDirection, light, lightIndex); man.SetArrayData(activeProgram, ShaderUniformName.LightsArray, ShaderUniformName.LightColor, light, lightIndex); man.SetArrayData(activeProgram, ShaderUniformName.LightsArray, ShaderUniformName.LinearAttenuation, light, lightIndex); man.SetArrayData(activeProgram, ShaderUniformName.LightsArray, ShaderUniformName.QuadraticAttenuation, light, lightIndex); }
public void SetData(ShaderProgram shader , ShaderUniformName dataName , IShaderDataOwner provider) { bool set = TrySetData(shader, dataName, provider); if (!set) { Logger.LogError(Logger.ErrorState.Unoptimal, "ShaderUniformManager.SetData. Shader " + shader.programName + " does not use " + GetUniformName(dataName)); } }
public void RenderPointLight(IShaderDataOwner light, int lightIndex) { if (activeProgram == null) { Logger.LogError(Logger.ErrorState.Critical, "RenderLight, no active shader"); return; } if (lightIndex == 0) { Logger.LogError(Logger.ErrorState.Limited, "RenderLight, point lights must have index greater than 0"); } PassLightData(light, lightIndex); }
public void RenderDirectionalLight(IShaderDataOwner light, int lightIndex) { if (activeProgram == null) { Logger.LogError(Logger.ErrorState.Critical, "RenderLight, no active shader"); return; } if (lightIndex != 0) { Logger.LogError(Logger.ErrorState.Limited, "RenderLight, directional lights must have index 0"); } PassLightData(light, lightIndex); }
public bool TrySetData(ShaderProgram shader , ShaderUniformName dataName , IShaderDataOwner provider) { bool set = false; foreach (ShaderUniform uni in shader.uniforms) { if (uni.name == dataName) { set = provider.SetUniform(shader, uni.location, uni.name); if (!set) { Logger.LogError(Logger.ErrorState.Critical, "ShaderUniformManager.SetData. Provider does not have " + GetUniformName(dataName)); } break; } } return(set); }
public void RenderShaderDataOwnerMesh(DrawableMesh mesh, IShaderDataOwner owner) { if (mesh == null) { Logger.LogError(Logger.ErrorState.Critical, "RenderMesh, no mesh given"); return; } SetActiveShader(mesh.ShaderProgram); if (activeProgram == null) { Logger.LogError(Logger.ErrorState.Critical, "RenderMesh, no active shader"); return; } List <ShaderUniformName> ownerUniforms = owner.GetUniforms(); ShaderUniformManager man = ShaderUniformManager.GetSingleton(); foreach (ShaderUniformName name in ownerUniforms) { man.SetData(activeProgram, name, owner); } if (mesh != owner) { List <ShaderUniformName> meshUniforms = mesh.GetUniforms(); foreach (ShaderUniformName name in meshUniforms) { man.SetData(activeProgram, name, mesh); } } if (mesh.BoundMaterial != null) { MaterialManager matMan = MaterialManager.GetSingleton(); matMan.SetMaterialToShader(mesh.BoundMaterial, activeProgram); } mesh.draw(); }