Exemplo n.º 1
0
		public ShaderContext(ShaderTechnique shaderTechnique)
		{
			this.shaderTechnique = shaderTechnique;
			this.vs = DefaultShaders.GenShader(ShaderType.VertexShader, shaderTechnique.VertexShaderSource);
			this.fs = DefaultShaders.GenShader(ShaderType.FragmentShader, shaderTechnique.FragmentShaderSource);
			this.indices = new ShaderTechniqueArgumentIndices();
			DefaultShaders.GenProgram(ref this.indices, this.vs, this.fs);
		}
Exemplo n.º 2
0
		public Managed Parse(TextParser parser, string defaultName)
		{
			ShaderTechnique shader = new ShaderTechnique(this.resourceManager);
			shader.Name = defaultName;
			shader.BasePath = parser.BasePath;

			parser.Consume("CIwGxShaderTechnique");
			parser.Consume("{");
			for (;;)
			{
				var attribute = parser.Lexem;
				if (attribute == "}")
				{
					parser.Consume();
					break;
				}
				if (attribute == "name")
				{
					parser.Consume();
					shader.Name = parser.ConsumeString();
					continue;
				}
				if (attribute == "param")
				{
					this.ParseParam(parser, shader);
					continue;
				}
				if (attribute == "shader")
				{
					parser.Consume();
					attribute = parser.Lexem;
					if (attribute == "vertex")
					{
						this.ParseVertexShader(parser, shader);
					}
					else if (attribute == "fragment")
					{
						this.ParseFragmentShader(parser, shader);
					}
					else
					{
						parser.UnknownLexemError();
					}
					continue;
				}
				parser.UnknownLexemError();
			}
			return shader;
		}
Exemplo n.º 3
0
		private void ParseFloatParam(TextParser parser, ShaderTechnique shader, string paramName, int numArgs)
		{
			var a = new float[numArgs];
			for (int i = 0; i < a.Length; ++i)
			{
				a[i] = parser.ConsumeFloat();
			}
			shader.AddParam(new ShaderTechniqueFloatParam(paramName, a));
		}
Exemplo n.º 4
0
		private void ParseVertexShader(TextParser parser, ShaderTechnique shader)
		{
			parser.Consume();

			shader.VertexShaderSource = parser.ConsumeBlock();
		}
Exemplo n.º 5
0
		private void ParseVec3Param(TextParser parser, ShaderTechnique shader, string paramName, int numArgs)
		{
			var a = new Vector3[numArgs];
			for (int i = 0; i < a.Length; ++i)
			{
				var x = parser.ConsumeFloat();
				var y = parser.ConsumeFloat();
				var z = parser.ConsumeFloat();
				a[i] = new Vector3(x, y, z);
			}
			shader.AddParam(new ShaderTechniqueVec3Param(paramName, a));
		}
Exemplo n.º 6
0
		private void ParseParam(TextParser parser, ShaderTechnique shader)
		{
			parser.Consume("param");
			var paramName = parser.ConsumeString();
			var typeName = parser.ConsumeString();
			var numArgs = parser.ConsumeInt();
			switch (typeName)
			{
				case "float":
					this.ParseFloatParam(parser, shader, paramName, numArgs);
					break;
				case "vec3":
					this.ParseVec3Param(parser, shader, paramName, numArgs);
					break;
				default:
					parser.Error(string.Format(CultureInfo.InvariantCulture, "Unknown param type {0}", typeName));
					break;
			}
		}
Exemplo n.º 7
0
		private void ParseFragmentShader(TextParser parser, ShaderTechnique shader)
		{
			parser.Consume();
			shader.FragmentShaderSource = parser.ConsumeBlock();
		}
Exemplo n.º 8
0
		private ShaderTechniqueArgumentIndices GetShaderProgram(ShaderTechnique shaderTechnique)
		{
			var shaderContext = shaderTechnique.ContextData as ShaderContext;
			if (shaderContext == null)
			{
				shaderTechnique.ContextData = shaderContext = new ShaderContext(shaderTechnique);
			}
			return shaderContext.Indices;
		}