Beispiel #1
0
            public ISurfaceShader As(string programName)
            {
                var program = new ReloadableShaderProgram(shaders);

                manager.Add(program, programName);
                return(program);
            }
Beispiel #2
0
        private void registerProgramForItsShaders(ReloadableShaderProgram shaderProgram)
        {
            foreach (var shader in shaderProgram.Shaders)
            {
                programsByShader.TryGetValue(shader, out var programs);
                if (programs == null)
                {
                    programs = new List <ReloadableShaderProgram>();
                    programsByShader.Add(shader, programs);
                }

                programs.Add(shaderProgram);
            }
        }
Beispiel #3
0
        public void Add(ReloadableShaderProgram shaderProgram, string name)
        {
            if (programs.ContainsKey(name))
            {
                throw new ArgumentException($"Tried adding shader program with name '{name} which is already taken.");
            }

            // make sure all shaders can be added so in case of error our internal state stays valid
            var shadersToAdd = getUnknownShadersOfProgramAndFailOnNameCollision(shaderProgram, name);

            // add shaders we don't know yet
            foreach (var shader in shadersToAdd)
            {
                Add(shader, name);
            }

            programs.Add(name, shaderProgram);

            registerProgramForItsShaders(shaderProgram);
        }
Beispiel #4
0
        private List <ReloadableShader> getUnknownShadersOfProgramAndFailOnNameCollision(
            ReloadableShaderProgram shaderProgram, string name)
        {
            return(shaderProgram.Shaders.Where(
                       shader =>
            {
                if (shaderNames.ContainsKey(shader))
                {
                    return false;
                }

                var shadersOfType = shaders[shader.Type];
                if (shadersOfType.ContainsKey(name))
                {
                    throw new ArgumentException(
                        $"Tried adding unknown {shader.Type} under name '{name}', but name is already taken.");
                }

                return true;
            }
                       ).ToList());
        }
Beispiel #5
0
 public ISurfaceShader As(string programName)
 {
     var program = new ReloadableShaderProgram(this.shaders);
     this.manager.Add(program, programName);
     return program;
 }
Beispiel #6
0
        public void Add(ReloadableShaderProgram shaderProgram, string name)
        {
            var knownShaders = new bool[shaderProgram.Shaders.Count];

            // make sure all shaders can be added so in case of error our internal state stays valid
            for (int i = 0; i < shaderProgram.Shaders.Count; i++)
            {
                var shader = shaderProgram.Shaders[i];
                if (this.shaderNames.ContainsKey(shader))
                {
                    knownShaders[i] = true;
                }
                else
                {
                    var dict = this.shaders[shader.Type];
                    if (dict.ContainsKey(name))
                    {
                        throw new ArgumentException(
                            string.Format("Tried adding unknown {0} under name '{1}', but name already taken.", 
                                shader.Type, name));
                    }
                }
            }

            // add shaders we don't know yet
            for (int i = 0; i < shaderProgram.Shaders.Count; i++)
            {
                if (!knownShaders[i])
                {
                    var shader = shaderProgram.Shaders[i];
                    this.Add(shader, name);
                }
            }

            this.programs.Add(name, shaderProgram);
            
            // register program for all shaders
            foreach (var shader in shaderProgram.Shaders)
            {
                List<ReloadableShaderProgram> programs;
                this.programsByShader.TryGetValue(shader, out programs);
                if (programs == null)
                {
                    programs = new List<ReloadableShaderProgram>();
                    this.programsByShader.Add(shader, programs);
                }
                programs.Add(shaderProgram);
            }
        }
Beispiel #7
0
        private bool tryReloadProgramIfContainsReloadedShaders(ReloadableShaderProgram program)
        {
            try
            {
                program.ReloadIfContainsAny(this.reloadedShaders);

                return true;
            }
            catch (Exception e)
            {
                // linking program with new shader failed
            }
            return false;
        }
Beispiel #8
0
 private bool tryReloadProgram(ReloadableShaderProgram program)
 {       
     try
     {
         program.Reload();
         
         return true;
     }
     catch (Exception e)
     {
         // linking program with new shader failed
     }
     return false;
 }