Exemple #1
0
        public int GetUniformLocation(ShaderUniformName uniformName)
        {
            foreach (ShaderUniform a in uniforms)
            {
                if (a.name == uniformName)
                {
                    return(a.location);
                }
            }
            ShaderUniformManager uniMan = ShaderUniformManager.GetSingleton();

            Logger.LogError(Logger.ErrorState.Limited, "Uniform " + uniMan.GetUniformName(uniformName) + " location not found in shader program " + programName);
            return(-1);
        }
Exemple #2
0
        // 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");
                    }
                }
            }
        }