Beispiel #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);
		}
		public void Enable(ShaderTechniqueArgumentIndices p)
		{
			if (p.inVert >= 0 && this.v != null)
			{
				GL.EnableVertexAttribArray(p.inVert);
				GL.VertexAttribPointer(p.inVert, 3, VertexAttribPointerType.Float, true, 4 * 3, (Vector3[])this.v);
			}
			if (p.inNorm >= 0 && this.n != null)
			{
				GL.EnableVertexAttribArray(p.inNorm);
				GL.VertexAttribPointer(p.inNorm, 3, VertexAttribPointerType.Float, true, 4 * 3, (Vector3[])this.n);
			}
			if (p.inTangent >= 0 && this.t != null)
			{
				GL.EnableVertexAttribArray(p.inTangent);
				GL.VertexAttribPointer(p.inTangent, 3, VertexAttribPointerType.Float, true, 4 * 3, (Vector3[])this.t);
			}
			if (p.inBiTangent >= 0 && this.b != null)
			{
				GL.EnableVertexAttribArray(p.inBiTangent);
				GL.VertexAttribPointer(p.inBiTangent, 3, VertexAttribPointerType.Float, true, 4 * 3, (Vector3[])this.b);
			}
			if (p.inCol >= 0 && this.c != null)
			{
				GL.EnableVertexAttribArray(p.inCol);
				GL.VertexAttribPointer(p.inCol, 4, VertexAttribPointerType.Float, true, 4 * 4, (Vector4[])this.c);
			}
			if (p.inUV0 >= 0 && this.uv0 != null)
			{
				GL.EnableVertexAttribArray(p.inUV0);
				GL.VertexAttribPointer(p.inUV0, 3, VertexAttribPointerType.Float, true, 4 * 3, (Vector3[])this.uv0);
			}
			if (p.inUV1 >= 0 && this.uv1 != null)
			{
				GL.EnableVertexAttribArray(p.inUV1);
				GL.VertexAttribPointer(p.inUV1, 3, VertexAttribPointerType.Float, true, 4 * 3, (Vector3[])this.uv1);
			}
		}
		public void Disable(ShaderTechniqueArgumentIndices p)
		{
			if (p.inVert >= 0)
			{
				GL.DisableVertexAttribArray(p.inVert);
			}
			if (p.inNorm >= 0)
			{
				GL.DisableVertexAttribArray(p.inNorm);
			}
			if (p.inTangent >= 0)
			{
				GL.DisableVertexAttribArray(p.inTangent);
			}
			if (p.inBiTangent >= 0)
			{
				GL.DisableVertexAttribArray(p.inBiTangent);
			}
			if (p.inCol >= 0)
			{
				GL.DisableVertexAttribArray(p.inCol);
			}
			if (p.inUV0 >= 0)
			{
				GL.DisableVertexAttribArray(p.inUV0);
			}
			if (p.inUV1 >= 0)
			{
				GL.DisableVertexAttribArray(p.inUV1);
			}
		}
Beispiel #4
0
		public ShaderTechniqueArgumentIndices GetProgram(DefaultProgramOptions po)
		{
			ShaderTechniqueArgumentIndices p;
			if (!this.generatedProgramms.TryGetValue(po, out p))
			{
				p = new ShaderTechniqueArgumentIndices();
				int f = this.GenFragmentShader(po.FragmentShaderOptions);
				int v = this.GenVertexShader(po.VertexShaderOptions);
				GenProgram(ref p, v, f);

				this.generatedProgramms[po] = p;
			}
			return p;
		}
Beispiel #5
0
		public static void GenProgram(ref ShaderTechniqueArgumentIndices p, int v, int f)
		{
			p.ProgramId = GL.CreateProgram();
			OpenTKHelper.Assert();
			GL.AttachShader(p.ProgramId, v);
			OpenTKHelper.Assert();
			GL.AttachShader(p.ProgramId, f);
			OpenTKHelper.Assert();
			GL.LinkProgram(p.ProgramId);

			string programInfoLog;
			GL.GetProgramInfoLog(p.ProgramId, out programInfoLog);
			Debug.WriteLine(programInfoLog);
			OpenTKHelper.Assert();

			p.inVert = GL.GetAttribLocation(p.ProgramId, "inVert");
			OpenTKHelper.Assert();
			p.inUV0 = GL.GetAttribLocation(p.ProgramId, "inUV0");
			OpenTKHelper.Assert();
			p.inUV1 = GL.GetAttribLocation(p.ProgramId, "inUV1");
			OpenTKHelper.Assert();
			p.inCol = GL.GetAttribLocation(p.ProgramId, "inCol");
			OpenTKHelper.Assert();
			p.inNorm = GL.GetAttribLocation(p.ProgramId, "inNorm");
			OpenTKHelper.Assert();
			p.inTangent = GL.GetAttribLocation(p.ProgramId, "inTangent");
			OpenTKHelper.Assert();
			p.inBiTangent = GL.GetAttribLocation(p.ProgramId, "inBiTangent");
			OpenTKHelper.Assert();
			p.inSkinWeights = GL.GetAttribLocation(p.ProgramId, "inSkinWeights");
			OpenTKHelper.Assert();
			p.inSkinIndices = GL.GetAttribLocation(p.ProgramId, "inSkinIndices");
			OpenTKHelper.Assert();

			p.inPMVMat = GL.GetUniformLocation(p.ProgramId, "inPMVMat");
			OpenTKHelper.Assert();
			p.inMVMat = GL.GetUniformLocation(p.ProgramId, "inMVMat");
			OpenTKHelper.Assert();
			p.inMVRotMat = GL.GetUniformLocation(p.ProgramId, "inMVRotMat");
			OpenTKHelper.Assert();
			p.inModelRotMat = GL.GetUniformLocation(p.ProgramId, "inModelRotMat");
			OpenTKHelper.Assert();
			p.inModelPos = GL.GetUniformLocation(p.ProgramId, "inModelPos");
			OpenTKHelper.Assert();
			p.inEyePos = GL.GetUniformLocation(p.ProgramId, "inEyePos");
			OpenTKHelper.Assert();
			p.inCamPos = GL.GetUniformLocation(p.ProgramId, "inCamPos");
			OpenTKHelper.Assert();
			p.inSampler0 = GL.GetUniformLocation(p.ProgramId, "inSampler0");
			OpenTKHelper.Assert();
			p.inSampler1 = GL.GetUniformLocation(p.ProgramId, "inSampler1");
			OpenTKHelper.Assert();
			p.inSampler2 = GL.GetUniformLocation(p.ProgramId, "inSampler2");
			OpenTKHelper.Assert();
			p.inSampler3 = GL.GetUniformLocation(p.ProgramId, "inSampler3");
			OpenTKHelper.Assert();
			p.inAlphaTestValue = GL.GetUniformLocation(p.ProgramId, "inAlphaTestValue");
			OpenTKHelper.Assert();
			p.inMaterialAmbient = GL.GetUniformLocation(p.ProgramId, "inMaterialAmbient");
			OpenTKHelper.Assert();
			p.inMaterialDiffuse = GL.GetUniformLocation(p.ProgramId, "inMaterialDiffuse");
			OpenTKHelper.Assert();
			p.inEmissive = GL.GetUniformLocation(p.ProgramId, "inEmissive");
			OpenTKHelper.Assert();
			p.inAmbient = GL.GetUniformLocation(p.ProgramId, "inAmbient");
			OpenTKHelper.Assert();
			p.inDiffuse = GL.GetUniformLocation(p.ProgramId, "inDiffuse");
			OpenTKHelper.Assert();
			p.inDiffuseDir = GL.GetUniformLocation(p.ProgramId, "inDiffuseDir");
			OpenTKHelper.Assert();
			p.inFogNear = GL.GetUniformLocation(p.ProgramId, "inFogNear");
			OpenTKHelper.Assert();
			p.inFogRange = GL.GetUniformLocation(p.ProgramId, "inFogRange");
			OpenTKHelper.Assert();
			p.inFogColour = GL.GetUniformLocation(p.ProgramId, "inFogColour");
			OpenTKHelper.Assert();
			p.inSkinMats = GL.GetUniformLocation(p.ProgramId, "inSkinMats");
			OpenTKHelper.Assert();
			p.inUVOffset = GL.GetUniformLocation(p.ProgramId, "inUVOffset");
			OpenTKHelper.Assert();

			p.inTVScale = GL.GetUniformLocation(p.ProgramId, "inTVScale");
			OpenTKHelper.Assert();
			p.inUVScale = GL.GetUniformLocation(p.ProgramId, "inUVScale");
			OpenTKHelper.Assert();
			p.inUV1Scale = GL.GetUniformLocation(p.ProgramId, "inUV1Scale");
			OpenTKHelper.Assert();
			p.inUV2Scale = GL.GetUniformLocation(p.ProgramId, "inUV2Scale");
			OpenTKHelper.Assert();
			p.inUV3Scale = GL.GetUniformLocation(p.ProgramId, "inUV3Scale");
			OpenTKHelper.Assert();
			p.inTextureSize = GL.GetUniformLocation(p.ProgramId, "inTextureSize");
			OpenTKHelper.Assert();
			p.inTextureSize1 = GL.GetUniformLocation(p.ProgramId, "inTextureSize1");
			OpenTKHelper.Assert();
			p.inTextureSize2 = GL.GetUniformLocation(p.ProgramId, "inTextureSize2");
			OpenTKHelper.Assert();
			p.inTextureSize3 = GL.GetUniformLocation(p.ProgramId, "inTextureSize3");
			OpenTKHelper.Assert();
			p.inOOTextureSize = GL.GetUniformLocation(p.ProgramId, "inOOTextureSize");
			OpenTKHelper.Assert();
			p.inOOTextureSize1 = GL.GetUniformLocation(p.ProgramId, "inOOTextureSize1");
			OpenTKHelper.Assert();
			p.inOOTextureSize2 = GL.GetUniformLocation(p.ProgramId, "inOOTextureSize2");
			OpenTKHelper.Assert();
			p.inOOTextureSize3 = GL.GetUniformLocation(p.ProgramId, "inOOTextureSize3");
			OpenTKHelper.Assert();
			p.inDisplaySize = GL.GetUniformLocation(p.ProgramId, "inDisplaySize");
			OpenTKHelper.Assert();
			p.inDeviceSize = GL.GetUniformLocation(p.ProgramId, "inDeviceSize");
			OpenTKHelper.Assert();
			p.inDisplayRotScaleMat = GL.GetUniformLocation(p.ProgramId, "inDisplayRotScaleMat");
			OpenTKHelper.Assert();
			p.inPipelineConfig = GL.GetUniformLocation(p.ProgramId, "inPipelineConfig");
			OpenTKHelper.Assert();

			p.inSpecular = GL.GetUniformLocation(p.ProgramId, "inSpecular");
			OpenTKHelper.Assert();
			p.inMaterialSpecular = GL.GetUniformLocation(p.ProgramId, "inMaterialSpecular");
			OpenTKHelper.Assert();
			p.inSpecularHalfVec = GL.GetUniformLocation(p.ProgramId, "inSpecularHalfVec");
			OpenTKHelper.Assert();
		}
Beispiel #6
0
		private void BindShaderArgs(ref ShaderTechniqueArgumentIndices p)
		{
			this.EvalShaderTechniqueArguments();

			if (p.inPMVMat >= 0)
			{
				GL.UniformMatrix4(p.inPMVMat, false, ref this.args.inPMVMat);
			}
			if (p.inMVMat >= 0)
			{
				GL.UniformMatrix4(p.inMVMat, false, ref this.args.inMVMat);
			}
			if (p.inMVRotMat >= 0)
			{
				GL.UniformMatrix3(p.inMVRotMat, 9, false, BuildMat3x3(ref this.args.inMVRotMat));
			}
			if (p.inModelRotMat >= 0)
			{
				GL.UniformMatrix3(p.inModelRotMat, 9, false, BuildMat3x3(ref this.args.inModelRotMat));
			}
			if (p.inModelPos >= 0)
			{
				GL.Uniform3(p.inModelPos, ref this.args.inModelPos);
			}
			if (p.inCamPos >= 0)
			{
				GL.Uniform3(p.inCamPos, ref this.args.inCamPos);
			}
			if (p.inEyePos >= 0)
			{
				GL.Uniform3(p.inEyePos, ref this.args.inEyePos);
			}
			if (p.inAlphaTestValue >= 0)
			{
				GL.Uniform1(p.inAlphaTestValue, this.args.inAlphaTestValue);
			}
			if (p.inMaterialAmbient >= 0)
			{
				GL.Uniform4(p.inMaterialAmbient, this.args.inMaterialAmbient);
			}
			if (p.inMaterialDiffuse >= 0)
			{
				GL.Uniform4(p.inMaterialDiffuse, this.args.inMaterialDiffuse);
			}
			if (p.inSampler0 >= 0)
			{
				GL.Uniform1(p.inSampler0, 0);
			}
			if (p.inSampler1 >= 0)
			{
				GL.Uniform1(p.inSampler1, 1);
			}
			if (p.inSampler2 >= 0)
			{
				GL.Uniform1(p.inSampler2, 2);
			}
			if (p.inSampler3 >= 0)
			{
				GL.Uniform1(p.inSampler3, 3);
			}
			if (p.inEmissive >= 0)
			{
				GL.Uniform4(p.inEmissive, this.args.inEmissive);
			}
			if (p.inAmbient >= 0)
			{
				GL.Uniform4(p.inAmbient, this.args.inAmbient);
			}
			if (p.inDiffuse >= 0)
			{
				GL.Uniform4(p.inDiffuse, this.args.inDiffuse);
			}
			if (p.inDiffuseDir >= 0)
			{
				GL.Uniform3(p.inDiffuseDir, this.args.inDiffuseDir);
			}
			if (p.inFogNear >= 0)
			{
				GL.Uniform1(p.inFogNear, this.args.inFogNear);
			}
			if (p.inFogRange >= 0)
			{
				GL.Uniform1(p.inFogRange, this.args.inFogRange);
			}
			if (p.inFogColour >= 0)
			{
				GL.Uniform4(p.inFogColour, this.args.inFogColour);
			}
			if (p.inUVOffset >= 0)
			{
				GL.Uniform2(p.inUVOffset, this.args.inUVOffset);
			}

			if (p.inTVScale >= 0)
			{
				GL.Uniform2(p.inTVScale, this.args.inTVScale);
			}
			if (p.inUVScale >= 0)
			{
				GL.Uniform2(p.inUVScale, this.args.inUVScale);
			}
			if (p.inUV1Scale >= 0)
			{
				GL.Uniform2(p.inUV1Scale, this.args.inUV1Scale);
			}
			if (p.inUV2Scale >= 0)
			{
				GL.Uniform2(p.inUV2Scale, this.args.inUV2Scale);
			}
			if (p.inUV3Scale >= 0)
			{
				GL.Uniform2(p.inUV3Scale, this.args.inUV3Scale);
			}
			if (p.inTextureSize >= 0)
			{
				GL.Uniform2(p.inTextureSize, this.args.inTextureSize);
			}
			if (p.inTextureSize1 >= 0)
			{
				GL.Uniform2(p.inTextureSize1, this.args.inTextureSize1);
			}
			if (p.inTextureSize2 >= 0)
			{
				GL.Uniform2(p.inTextureSize2, this.args.inTextureSize2);
			}
			if (p.inTextureSize3 >= 0)
			{
				GL.Uniform2(p.inTextureSize3, this.args.inTextureSize3);
			}
			if (p.inOOTextureSize >= 0)
			{
				GL.Uniform2(p.inOOTextureSize, this.args.inOOTextureSize);
			}
			if (p.inOOTextureSize1 >= 0)
			{
				GL.Uniform2(p.inOOTextureSize1, this.args.inOOTextureSize1);
			}
			if (p.inOOTextureSize2 >= 0)
			{
				GL.Uniform2(p.inOOTextureSize2, this.args.inOOTextureSize2);
			}
			if (p.inOOTextureSize3 >= 0)
			{
				GL.Uniform2(p.inOOTextureSize3, this.args.inOOTextureSize3);
			}
			if (p.inDisplaySize >= 0)
			{
				GL.Uniform2(p.inDisplaySize, this.args.inDisplaySize);
			}
			if (p.inDeviceSize >= 0)
			{
				GL.Uniform2(p.inDeviceSize, this.args.inDeviceSize);
			}
			if (p.inDisplayRotScaleMat >= 0)
			{
				GL.UniformMatrix3(p.inDisplayRotScaleMat, 9, false, BuildMat3x3(ref this.args.inDisplayRotScaleMat));
			}
			if (p.inSpecular >= 0)
			{
				GL.Uniform4(p.inSpecular, this.args.inSpecular);
			}
			if (p.inMaterialSpecular >= 0)
			{
				GL.Uniform4(p.inMaterialSpecular, this.args.inMaterialSpecular);
			}
			if (p.inSpecularHalfVec >= 0)
			{
				GL.Uniform3(p.inSpecularHalfVec, this.args.inSpecularHalfVec);
			}

			//GL.UseProgram(0);
			OpenTKHelper.Assert();
		}