Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            UniformVariableBase uniformVar = obj as UniformVariableBase;

            if (uniformVar == null)
            {
                return(false);
            }
            return(this.VarName == uniformVar.VarName);
        }
Ejemplo n.º 2
0
        private UniformVariableBase GetUniformVar(TokenList <EnumTokenTypeGLSLCompiler> tokenList, int index)
        {
            UniformVariableBase uniformVar = null;
            string varType = tokenList[index + 1].Detail;

            if (varType == "float")
            {
                uniformVar = new UniformFloat(tokenList[index + 2].Detail);
            }
            else if (varType == "vec2")
            {
                uniformVar = new UniformVec2(tokenList[index + 2].Detail);
            }
            else if (varType == "vec3")
            {
                uniformVar = new UniformVec3(tokenList[index + 2].Detail);
            }
            else if (varType == "vec4")
            {
                uniformVar = new UniformVec4(tokenList[index + 2].Detail);
            }
            else if (varType == "mat2")
            {
                uniformVar = new UniformMat2(tokenList[index + 2].Detail);
            }
            else if (varType == "mat3")
            {
                uniformVar = new UniformMat3(tokenList[index + 2].Detail);
            }
            else if (varType == "mat4")
            {
                uniformVar = new UniformMat4(tokenList[index + 2].Detail);
            }
            else
            {
                throw new NotImplementedException();
            }

            return(uniformVar);
        }
Ejemplo n.º 3
0
        private UniformVariableBase[] GetAllUniformVariables(CodeShader[] allShaderCodes)
        {
            List <UniformVariableBase> result = new List <UniformVariableBase>();

            foreach (var shaderCode in allShaderCodes)
            {
                var lexi = new LexicalAnalyzerGLSLCompiler(shaderCode.SourceCode);
                TokenList <EnumTokenTypeGLSLCompiler> tokenList = lexi.Analyze();
                var uniformVarTokens = new List <Token <EnumTokenTypeGLSLCompiler> >();
                uniformVarTokens.Add(new Token <EnumTokenTypeGLSLCompiler>()
                {
                    TokenType = EnumTokenTypeGLSLCompiler.identifier, Detail = "uniform",
                });
                uniformVarTokens.Add(new Token <EnumTokenTypeGLSLCompiler>()
                {
                    TokenType = EnumTokenTypeGLSLCompiler.identifier, Detail = "",
                });
                uniformVarTokens.Add(new Token <EnumTokenTypeGLSLCompiler>()
                {
                    TokenType = EnumTokenTypeGLSLCompiler.identifier, Detail = "",
                });
                int index = -3;
                while (index < tokenList.Count)
                {
                    index = tokenList.KMP(uniformVarTokens, index + 3, new UniformTokensComparer());
                    if (index >= 0)
                    {
                        UniformVariableBase uniformVar = GetUniformVar(tokenList, index);
                        result.Add(uniformVar);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(result.Distinct().ToArray());
        }