示例#1
0
 public static Shader LoadShader(string vShaderPath, string fShaderPath, string name)
 {
     if (!Shaders.ContainsKey(name))
     {
         Shaders[name] = LoadShaderFromFile(vShaderPath, fShaderPath);
     }
     return(Shaders[name]);
 }
示例#2
0
        public void AddShader(string pass, Shader shader)
        {
            if (!Shaders.ContainsKey(pass))
            {
                Shaders.Add(pass, new List <Shader>());
            }

            Shaders[pass].Add(shader);
        }
        private void AddShader(Shader shader)
        {
            if (shader == null)
            {
                throw new ArgumentNullException("shader");
            }

            if (Shaders.ContainsKey(shader.Type))
            {
                throw new InvalidOperationException($"ShaderProgram.AddShader ({Name}): Program already contains a shader of type {shader.Type.ToString()}");
            }

            Shaders.Add(shader.Type, shader);
        }
示例#4
0
 public bool TryAddShader(Shader shader)
 {
     if ((shader == null) || string.IsNullOrEmpty(shader.Name) || Shaders.ContainsKey(shader.Name))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(shader.Material) || !Materials.ContainsKey(shader.Material))
     {
         return(false);
     }
     if (!string.IsNullOrEmpty(shader.Texture) && !Textures.ContainsKey(shader.Texture))
     {
         return(false);
     }
     Shaders.Add(shader.Name, shader);
     return(true);
 }
示例#5
0
 public bool TryAddMesh(Mesh mesh)
 {
     if ((mesh == null) || string.IsNullOrEmpty(mesh.Name) || Meshes.ContainsKey(mesh.Name))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(mesh.Shader) || !Shaders.ContainsKey(mesh.Shader))
     {
         return(false);
     }
     if (!mesh.IsTrianglesCorrect())
     {
         return(false);
     }
     Meshes.Add(mesh.Name, mesh);
     return(true);
 }
示例#6
0
        public void LoadModels()
        {
            DirectoryInfo Folder = new DirectoryInfo(ModelLocation);

            if (Folder.Exists)
            {
                FileInfo[] ConfigFiles = Folder.GetFiles();

                foreach (FileInfo CurrentFile in ConfigFiles)
                {
                    if (CurrentFile.Extension.Equals(".obj"))
                    {
                        string        Name     = CurrentFile.Name.Remove(CurrentFile.Name.Length - 4, 4);
                        GeometryModel NewModel = ModelUtil.ImportOBJModel(CurrentFile.FullName);

                        string[] ModelMaterialData = GetModelMaterialData(Name);

                        if (ModelMaterialData.Length != 0)
                        {
                            for (int i = 0; i < ModelMaterialData.Length; i++)
                            {
                                if (ModelMaterialData[i].Length == 0 || ModelMaterialData[i].StartsWith("//") || ModelMaterialData[i].StartsWith("#"))
                                {
                                    continue;
                                }
                                string Key   = ModelMaterialData[i].Split(new char[] { ':' })[0].Trim();
                                string Value = ModelMaterialData[i].Split(new char[] { ':' })[1].Trim();

                                if (Key.ToLower().StartsWith("shader"))
                                {
                                    if (Shaders.ContainsKey(Value))
                                    {
                                        NewModel.Shader = Shaders[Value].Clone();
                                    }
                                }
                                if (Key.ToLower().StartsWith("depthshader"))
                                {
                                    if (Shaders.ContainsKey(Value))
                                    {
                                        NewModel.DepthShader = Shaders[Value].Clone();
                                    }
                                }
                                else
                                {
                                    if (Textures.ContainsKey(Value))
                                    {
                                        NewModel.AddTexture(Key, Value);
                                    }
                                }
                            }


                            if (NewModel.Shader == null || NewModel.DepthShader == null)
                            {
                                continue;
                            }
                            //Debug.WriteLine(Name);
                            NewModel.Name = Name;
                            Models.Add(Name, NewModel);
                        }
                    }
                }
            }
        }