private void LoadShaderAsset(BasicShaderAssetData shaderAsset) { if (shaderAsset.IsLoaded) { return; } string vs = Utils.LoadEmbeddedResourceAsString(shaderAsset.VertexShaderName); string fs = Utils.LoadEmbeddedResourceAsString(shaderAsset.FragmentShaderName); int status_code; string info; int vertexObject = GL.CreateShader(ShaderType.VertexShader); int fragmentObject = GL.CreateShader(ShaderType.FragmentShader); shaderAsset.VertexObjectHandle = vertexObject; shaderAsset.FragmentObjectHandle = fragmentObject; GL.ShaderSource(vertexObject, vs); GL.CompileShader(vertexObject); GL.GetShaderInfoLog(vertexObject, out info); GL.GetShader(vertexObject, ShaderParameter.CompileStatus, out status_code); if (status_code != 1) { throw new ApplicationException(info); } GL.ShaderSource(fragmentObject, fs); GL.CompileShader(fragmentObject); GL.GetShaderInfoLog(fragmentObject, out info); GL.GetShader(fragmentObject, ShaderParameter.CompileStatus, out status_code); if (status_code != 1) { throw new ApplicationException(info); } int program = GL.CreateProgram(); GL.AttachShader(program, fragmentObject); GL.AttachShader(program, vertexObject); shaderAsset.ProgramHandle = program; GL.BindAttribLocation(program, VertexAttribIndex.Vertex, "in_position"); GL.BindAttribLocation(program, VertexAttribIndex.Normal, "in_normal"); GL.BindAttribLocation(program, VertexAttribIndex.Uv, "in_uv"); GL.LinkProgram(program); shaderAsset.ModelviewProjectionMatrixLocation = GL.GetUniformLocation( program, "modelview_projection_matrix"); shaderAsset.IsLoaded = true; }
private void UnloadShaderAsset(BasicShaderAssetData shaderAsset) { if (shaderAsset.IsLoaded) { GL.DeleteProgram(shaderAsset.ProgramHandle); GL.DeleteShader(shaderAsset.FragmentObjectHandle); GL.DeleteShader(shaderAsset.VertexObjectHandle); } shaderAsset.IsLoaded = false; }