Ejemplo n.º 1
0
        public void RecordDependency(ShaderVariable referencedVariable)
        {
            if (dependantVariables == null && !flowDependant)
            {
                throw new InvalidOperationException("Cannot reference variables while dependencies aren't defined");
            }

            if (flowDependant)
            {
                flowVariables.Add(referencedVariable);
            }

            if (dependantVariables != null)
            {
                foreach (var dependentVariable in dependantVariables)
                {
                    if (referencedVariable == dependentVariable)
                    {
                        continue;
                    }

                    if (!dependencies.TryGetValue(dependentVariable, out HashSet <ShaderVariable> existingDependencies))
                    {
                        existingDependencies = dependencies[dependentVariable] = new HashSet <ShaderVariable>();
                    }

                    existingDependencies.Add(referencedVariable);
                }
            }
        }
Ejemplo n.º 2
0
 public ShaderBuilder(VertexDeclaration vertexDeclaration)
 {
     VertexDeclaration = vertexDeclaration;
     GlPosition        = new ShaderVariable(Context, "gl_Position", "vec4");
     GlFragColor       = new ShaderVariable(Context, "gl_FragColor", "vec4");
     GlFragDepth       = new ShaderVariable(Context, "gl_FragDepth", "float");
 }
Ejemplo n.º 3
0
        public ShaderVariable AddVariable(ShaderContext context, string shaderTypeName)
        {
            var variable = new ShaderVariable(context, nextGenericName, shaderTypeName);

            variables.Add(variable);
            return(variable);
        }
Ejemplo n.º 4
0
        private void assign(ShaderVariable result, Func <string> expression, bool declare, string components = null)
        {
            checkCanReceiveCommands();

            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }
            if (declare && components != null)
            {
                throw new InvalidOperationException("Cannot set components when declaring a variable");
            }
            if (expression != null)
            {
                Dependant(() => declare ?
                          $"{result.ShaderTypeName} {result.Ref} = {expression()}" :
                          components != null ?
                          $"{result.Ref}.{components} = {expression()}" :
                          $"{result.Ref} = {expression()}"
                          , result);
            }
            else if (declare)
            {
                code?.AppendLine($"{result.ShaderTypeName} {result.Name};");
            }
            else
            {
                throw new ArgumentNullException(nameof(expression));
            }
        }
Ejemplo n.º 5
0
        public ShaderVariable AddUniform(ShaderContext context, string name, string shaderTypeName, int count = -1)
        {
            var uniform = new ShaderVariable(context, name, shaderTypeName, count);

            uniforms.Add(uniform);
            return(uniform);
        }
Ejemplo n.º 6
0
        public ShaderVariable Declare(string shaderTypeName, Func <string> expression = null)
        {
            checkCanReceiveCommands();

            var variable = new ShaderVariable(this, nextGenericName, shaderTypeName);

            assign(variable, expression, true, null);
            return(variable);
        }
Ejemplo n.º 7
0
 private void markUsed(ShaderVariable variable)
 {
     if (usedVariables.Add(variable))
     {
         if (dependencies.TryGetValue(variable, out HashSet <ShaderVariable> variableDependencies))
         {
             foreach (var variableDependency in variableDependencies)
             {
                 markUsed(variableDependency);
             }
         }
     }
 }
Ejemplo n.º 8
0
        public ShaderVariable FieldAsVariable(ShaderVariable variable, Field field)
        {
            if (variable == null)
            {
                return(null);
            }

            if (variable.ShaderTypeName != Name)
            {
                throw new InvalidOperationException();
            }
            if (!fields.Contains(field))
            {
                throw new InvalidOperationException();
            }

            return(new ShaderFieldVariable(variable.Context, variable, field));
        }
Ejemplo n.º 9
0
 public bool Uses(ShaderVariable variable)
 {
     return(usedVariables.Contains(variable));
 }
Ejemplo n.º 10
0
 public void Assign(ShaderVariable result, VertexAttribute value, string components = null)
 => assign(result, () => value.Name, false, components);
Ejemplo n.º 11
0
 public void Assign(ShaderVariable result, ShaderVariable value, string components = null)
 => assign(result, () => value.Ref.ToString(), false, components);
Ejemplo n.º 12
0
 public void Assign(ShaderVariable result, Func <string> expression, string components = null)
 => assign(result, expression, false, components);
Ejemplo n.º 13
0
 public ShaderVariable Declare(string shaderTypeName, ShaderVariable value)
 => Declare(shaderTypeName, () => value.Ref.ToString());
Ejemplo n.º 14
0
 public Reference(ShaderVariable variable)
 {
     this.variable = variable;
 }
Ejemplo n.º 15
0
 public void Assign(ShaderVariable value, string components     = null) => Context.Assign(this, value, components);