public void SetShader(IShaderProgramImp program) { _currentTextureUnit = 0; _shaderParam2TexUnit.Clear(); GL.UseProgram(((ShaderProgramImp)program).Program); }
public float GetParamValue(IShaderProgramImp program, IShaderParam param) { float f; GL.GetUniform(((ShaderProgramImp)program).Program, ((ShaderParam)param).handle, out f); return(f); }
public IShaderParam GetShaderParam(IShaderProgramImp shaderProgram, string paramName) { int h = GL.GetUniformLocation(((ShaderProgramImp)shaderProgram).Program, paramName); return((h == -1) ? null : new ShaderParam { handle = h }); }
/// <summary> /// Initializes a new instance of the <see cref="ShaderProgram"/> class. /// </summary> /// <param name="renderContextImp">The <see cref="IRenderContextImp"/>.</param> /// <param name="shaderProgramImp">The <see cref="IShaderProgramImp"/>.</param> internal ShaderProgram(IRenderContextImp renderContextImp, IShaderProgramImp shaderProgramImp) { _spi = shaderProgramImp; _rci = renderContextImp; _paramsByName = new Dictionary <string, ShaderParamInfo>(); foreach (ShaderParamInfo info in _rci.GetShaderParamList(_spi)) { _paramsByName.Add(info.Name, info); } }
public IList <ShaderParamInfo> GetShaderParamList(IShaderProgramImp shaderProgram) { var sp = (ShaderProgramImp)shaderProgram; int nParams; GL.GetProgram(sp.Program, ProgramParameter.ActiveUniforms, out nParams); List <ShaderParamInfo> list = new List <ShaderParamInfo>(); for (int i = 0; i < nParams; i++) { ActiveUniformType t; var ret = new ShaderParamInfo(); ret.Name = GL.GetActiveUniform(sp.Program, i, out ret.Size, out t); ret.Handle = GetShaderParam(sp, ret.Name); switch (t) { case ActiveUniformType.Int: ret.Type = typeof(int); break; case ActiveUniformType.Float: ret.Type = typeof(float); break; case ActiveUniformType.FloatVec2: ret.Type = typeof(float2); break; case ActiveUniformType.FloatVec3: ret.Type = typeof(float3); break; case ActiveUniformType.FloatVec4: ret.Type = typeof(float4); break; case ActiveUniformType.FloatMat4: ret.Type = typeof(float4x4); break; case ActiveUniformType.Sampler2D: //TODO ret.Type = typeof (sampler?); break; default: throw new ArgumentOutOfRangeException(); } list.Add(ret); } return(list); }
/// <summary> /// Initializes a new instance of the <see cref="ShaderProgram"/> class. /// </summary> /// <param name="renderContextImp">The <see cref="IRenderContextImp"/>.</param> /// <param name="shaderProgramImp">The <see cref="IShaderProgramImp"/>.</param> internal ShaderProgram(IRenderContextImp renderContextImp, IShaderProgramImp shaderProgramImp) { _spi = shaderProgramImp; _rci = renderContextImp; _paramsByName = new Dictionary<string, IShaderParam>(); foreach (ShaderParamInfo info in _rci.GetShaderParamList(_spi)) { _paramsByName.Add(info.Name, info.Handle); } //_paramsByName = new Dictionary<string, ShaderParamInfo>(); //foreach (ShaderParamInfo info in _rci.GetShaderParamList(_spi)) //{ // ShaderParamInfo newInfo = new ShaderParamInfo() // { // Handle = info.Handle, // Name = info.Name, // Type = info.Type, // Size = info.Size, // }; // _paramsByName.Add(info.Name, newInfo); //} }
/// <summary> /// Sets the shaderprogram onto the GL Rendercontext. /// </summary> /// <param name="program">The shaderprogram.</param> public void SetShader(IShaderProgramImp program) { _currentTextureUnit = 0; _shaderParam2TexUnit.Clear(); GL.UseProgram(((ShaderProgramImp) program).Program); }
/// <summary> /// Gets the shader parameter list of a specific <see cref="IShaderProgramImp" />. /// </summary> /// <param name="shaderProgram">The shader program.</param> /// <returns>All Shader parameters of a shaderprogram are returned.</returns> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public IList<ShaderParamInfo> GetShaderParamList(IShaderProgramImp shaderProgram) { var sp = (ShaderProgramImp)shaderProgram; int nParams; GL.GetProgram(sp.Program, ProgramParameter.ActiveUniforms, out nParams); var list = new List<ShaderParamInfo>(); for (int i = 0; i < nParams; i++) { ActiveUniformType t; var ret = new ShaderParamInfo(); ret.Name = GL.GetActiveUniform(sp.Program, i, out ret.Size, out t); ret.Handle = GetShaderParam(sp, ret.Name); switch (t) { case ActiveUniformType.Int: ret.Type = typeof(int); break; case ActiveUniformType.Float: ret.Type = typeof(float); break; case ActiveUniformType.FloatVec2: ret.Type = typeof(float2); break; case ActiveUniformType.FloatVec3: ret.Type = typeof(float3); break; case ActiveUniformType.FloatVec4: ret.Type = typeof(float4); break; case ActiveUniformType.FloatMat4: ret.Type = typeof(float4x4); break; case ActiveUniformType.Sampler2D: ret.Type = typeof (ITexture); break; default: throw new ArgumentOutOfRangeException(); } list.Add(ret); } return list; }
/// <summary> /// Gets the shader parameter. /// The Shader parameter is used to bind values inside of shaderprograms that run on the graphics card. /// Do not use this function in frequent updates as it transfers information from graphics card to the cpu which takes time. /// </summary> /// <param name="shaderProgram">The shader program.</param> /// <param name="paramName">Name of the parameter.</param> /// <returns>The Shader parameter is returned if the name is found, otherwise null.</returns> public IShaderParam GetShaderParam(IShaderProgramImp shaderProgram, string paramName) { int h = GL.GetUniformLocation(((ShaderProgramImp)shaderProgram).Program, paramName); return (h == -1) ? null : new ShaderParam { handle = h }; }
/// <summary> /// Gets the float parameter value inside a shaderprogram by using a <see cref="IShaderParam" /> as search reference. /// Do not use this function in frequent updates as it transfers information from graphics card to the cpu which takes time. /// </summary> /// <param name="program">The program.</param> /// <param name="param">The parameter.</param> /// <returns>A float number (default is 0).</returns> public float GetParamValue(IShaderProgramImp program, IShaderParam param) { float f; GL.GetUniform(((ShaderProgramImp)program).Program, ((ShaderParam)param).handle, out f); return f; }
public float GetParamValue(IShaderProgramImp shaderProgram, IShaderParam param) { throw new System.NotImplementedException(); }
public IShaderParam GetShaderParam(IShaderProgramImp shaderProgram, string paramName) { throw new System.NotImplementedException(); }
public IList <ShaderParamInfo> GetShaderParamList(IShaderProgramImp shaderProgram) { throw new System.NotImplementedException(); }
public void RemoveShader(IShaderProgramImp sp) { throw new NotImplementedException(); }
public void SetShader(IShaderProgramImp shaderProgramImp) { throw new System.NotImplementedException(); }