/// <summary> /// Initializes a new instance of the <see cref="ShaderGL"/> class. /// </summary> /// <param name="shaderType">Type of the shader.</param> /// <exception cref="ShaderException">Could not create " + shaderType.ToString() + " instance.</exception> public ShaderGL(ShaderType shaderType) { ShaderID = GL.CreateShader(ConvertType(shaderType)); if (0 == ShaderID) { throw new ShaderException("Could not create " + shaderType.ToString() + " instance."); } ShaderType = shaderType; }
/// <summary> /// Compiles the specified shader source code. /// </summary> /// <param name="shaderSourceCode">The shader source code.</param> /// <param name="type">The type.</param> /// <exception cref="ShaderCompileException"></exception> public void Compile(string shaderSourceCode, ShaderType type) { var shader = new ShaderGL(type); if (!shader.Compile(shaderSourceCode)) { var e = new ShaderCompileException(type, shader.Log, shaderSourceCode); shader.Dispose(); throw e; } Attach(shader); }
private TKShaderType ConvertType(ShaderType type) { switch (type) { case ShaderType.ComputeShader: return(TKShaderType.ComputeShader); case ShaderType.FragmentShader: return(TKShaderType.FragmentShader); case ShaderType.GeometryShader: return(TKShaderType.GeometryShader); case ShaderType.TessControlShader: return(TKShaderType.TessControlShader); case ShaderType.TessEvaluationShader: return(TKShaderType.TessEvaluationShader); case ShaderType.VertexShader: return(TKShaderType.VertexShader); default: throw new ArgumentOutOfRangeException("Unknown Shader type"); } }
/// <summary> /// Compiles the specified s shader. /// </summary> /// <param name="sShader">The s shader.</param> /// <param name="type">The type.</param> /// <exception cref="ShaderCompileException"> /// Could not create " + type.ToString() + " object /// or /// Error compiling " + type.ToString() /// </exception> public void Compile(string sShader, ShaderType type) { IsLinked = false; int shaderObject = GL.CreateShader(ConvertType(type)); if (0 == shaderObject) { throw new ShaderCompileException(type, "Could not create " + type.ToString() + " object", string.Empty, sShader); } // Compile vertex shader GL.ShaderSource(shaderObject, sShader); GL.CompileShader(shaderObject); GL.GetShader(shaderObject, ShaderParameter.CompileStatus, out int status_code); LastLog = GL.GetShaderInfoLog(shaderObject); if (1 != status_code) { GL.DeleteShader(shaderObject); throw new ShaderCompileException(type, "Error compiling " + type.ToString(), LastLog, sShader); } GL.AttachShader(ProgramID, shaderObject); shaderIDs.Add(shaderObject); }