private void DeleteVBOs() { GL.DeleteBuffer(this.positionVboHandle); GL.DeleteBuffer(this.elementsHandle); Utility.CheckWebGLError(); GL.BindBuffer(GL.GL_ARRAY_BUFFER, null); Utility.CheckWebGLError(); }
public void Delete() { //GL.DetachShader(ShaderProgramObject, vertexShader.ShaderObject); //GL.DetachShader(ShaderProgramObject, fragmentShader.ShaderObject); //vertexShader.Delete(); //fragmentShader.Delete(); GL.DeleteProgram(ShaderProgramObject); ShaderProgramObject = null; }
public uint GetAttributeLocation(string attributeName) { // If we don't have the attribute name in the dictionary, get it's // location and add it. if (attributeNamesToLocations.ContainsKey(attributeName) == false) { int location = GL.GetAttribLocation(ShaderProgramObject, attributeName); attributeNamesToLocations[attributeName] = (uint)location; } // Return the attribute location. return(attributeNamesToLocations[attributeName]); }
public JSObject GetUniformLocation(string uniformName) { // If we don't have the uniform name in the dictionary, get it's // location and add it. if (uniformNamesToLocations.ContainsKey(uniformName) == false) { uniformNamesToLocations[uniformName] = GL.GetUniformLocation(ShaderProgramObject, uniformName); // TODO: if it's not found, we should probably throw an exception. } // Return the uniform location. return(uniformNamesToLocations[uniformName]); }
/// <summary> /// Creates the shader program. /// </summary> /// <param name="vertexShaderSource">The vertex shader source.</param> /// <param name="fragmentShaderSource">The fragment shader source.</param> /// <param name="attributeLocations">The attribute locations. This is an optional array of /// uint attribute locations to their names.</param> /// <exception cref="ShaderCompilationException"></exception> public void Create(string vertexShaderSource, string fragmentShaderSource, Dictionary <uint, string> attributeLocations) { // Create the shaders. vertexShader.Create(GL.GL_VERTEX_SHADER, vertexShaderSource); fragmentShader.Create(GL.GL_FRAGMENT_SHADER, fragmentShaderSource); // Create the program, attach the shaders. ShaderProgramObject = GL.CreateProgram(); GL.AttachShader(ShaderProgramObject, vertexShader.ShaderObject); GL.AttachShader(ShaderProgramObject, fragmentShader.ShaderObject); // Before we link, bind any vertex attribute locations. if (attributeLocations != null) { foreach (var vertexAttributeLocation in attributeLocations) { GL.BindAttribLocation(ShaderProgramObject, vertexAttributeLocation.Key, vertexAttributeLocation.Value); } } // Now we can link the program. GL.LinkProgram(ShaderProgramObject); // Now that we've compiled and linked the shader, check it's link status. If it's not linked properly, we're // going to throw an exception. if (GetLinkStatus() == false) { string log = this.GetInfoLog(); throw new ShaderCompilationException( string.Format("Failed to link shader program with ID {0}. Log: {1}", ShaderProgramObject, log), log); } if (vertexShader.GetCompileStatus() == false) { string log = vertexShader.GetInfoLog(); throw new Exception(log); } if (fragmentShader.GetCompileStatus() == false) { string log = fragmentShader.GetInfoLog(); throw new Exception(log); } GL.DetachShader(ShaderProgramObject, vertexShader.ShaderObject); GL.DetachShader(ShaderProgramObject, fragmentShader.ShaderObject); vertexShader.Delete(); fragmentShader.Delete(); }
public void Init(IntPtr windowHandle, Size size) { //CreateOpenGLContext((IntPtr)windowHandle);//done in Xamarin.Android //InitGLEW();//done in Xamarin.Android this.shapeMaterial.Init(); this.imageMaterial.Init(); this.glyphMaterial.Init(); // Other state GL.Disable(GL.GL_CULL_FACE); GL.Disable(GL.GL_DEPTH_TEST); GL.DepthFunc(GL.GL_NEVER); GL.Enable(GL.GL_SCISSOR_TEST); Utility.CheckGLESError(); }
public void LoadImage(Rgba32[] data, int width, int height) { this.textureData = data; this.Width = width; this.Height = height; // create opengl texture object GL.ActiveTexture(GL.GL_TEXTURE0); this.textureObject = GL.CreateTexture(); GL.BindTexture(GL.GL_TEXTURE_2D, this.textureObject); //GL.TexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, this.Width, this.Height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, this.textureData); //sampler settings GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, (int)GL.GL_CLAMP); GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, (int)GL.GL_CLAMP); GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); Utility.CheckWebGLError(); }
private void CreateVBOs() { this.positionVboHandle = GL.CreateBuffer(); this.elementsHandle = GL.CreateBuffer(); GL.BindBuffer(GL.GL_ARRAY_BUFFER, this.positionVboHandle); GL.BindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, this.elementsHandle); this.vaoHandle = GL.CreateVertexArray(); GL.BindVertexArray(this.vaoHandle); GL.BindBuffer(GL.GL_ARRAY_BUFFER, this.positionVboHandle); GL.EnableVertexAttribArray(this.attributePositon); GL.EnableVertexAttribArray(this.attributeUV); GL.EnableVertexAttribArray(this.attributeColor); GL.VertexAttribPointer(this.attributePositon, 2, GL.GL_FLOAT, false, Marshal.SizeOf <DrawVertex>(), Marshal.OffsetOf <DrawVertex>("pos").ToInt32()); GL.VertexAttribPointer(this.attributeUV, 2, GL.GL_FLOAT, false, Marshal.SizeOf <DrawVertex>(), Marshal.OffsetOf <DrawVertex>("uv").ToInt32()); GL.VertexAttribPointer(this.attributeColor, 4, GL.GL_FLOAT, true, Marshal.SizeOf <DrawVertex>(), Marshal.OffsetOf <DrawVertex>("color").ToInt32()); Utility.CheckWebGLError(); }
/// <summary> /// Load an image from a file. /// </summary> /// <param name="filePath"></param> public void LoadImage(string filePath) { // check file header, save texture data to buffer using (Stream stream = Utility.ReadFile(filePath)) { this.image = Image.Load <Rgba32>(stream); this.textureData = this.image.GetPixelSpan().ToArray(); this.Width = this.image.Width; this.Height = this.image.Height; } // create opengl texture object GL.ActiveTexture(GL.GL_TEXTURE0); this.textureObject = GL.CreateTexture(); GL.BindTexture(GL.GL_TEXTURE_2D, this.textureObject); //GL.TexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, this.Width, this.Height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, this.textureData); //sampler settings GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, (int)GL.GL_CLAMP); GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, (int)GL.GL_CLAMP); GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); Utility.CheckWebGLError(); }
public void Create(uint shaderType, string source) { // Create the OpenGL shader object. ShaderObject = GL.CreateShader(shaderType); if (ShaderObject == null) { throw new InvalidOperationException("GL.CreateShader failed."); } // Set the shader source. GL.ShaderSource(ShaderObject, source); // Compile the shader object. GL.CompileShader(ShaderObject); // Now that we've compiled the shader, check it's compilation status. If it's not compiled properly, we're // going to throw an exception. if (GetCompileStatus() == false) { string log = GetInfoLog(); throw new ShaderCompilationException( $"Failed to compile shader with ID {this.ShaderObject}. Log: {log}", log); } }
public void Unbind() { GL.UseProgram(null); }
public void Delete() { GL.DeleteShader(ShaderObject); ShaderObject = null; }
public void SetUniformMatrix4(string uniformName, float[] m) { GL.UniformMatrix4(GetUniformLocation(uniformName), false, m); }
public void SetUniform(string uniformName, float v1, float v2, float v3, float v4) { GL.Uniform4(GetUniformLocation(uniformName), v1, v2, v3, v4); }
public void SetUniform(string uniformName, float v1, float v2) { GL.Uniform2(GetUniformLocation(uniformName), v1, v2); }
public void SetUniform(string uniformName, float v1) { GL.Uniform1(GetUniformLocation(uniformName), v1); }
public void SetUniform(string uniformName, int v1, int v2, int v3) { GL.Uniform3(GetUniformLocation(uniformName), v1, v2, v3); }
public bool GetCompileStatus() { return(GL.GetShaderParameter(ShaderObject, GL.GL_COMPILE_STATUS) == GL.GL_TRUE); }
/// <summary> /// Get the compile info log. /// </summary> /// <returns></returns> public string GetInfoLog() { return(GL.GetShaderInfoLog(ShaderObject)); }
public void Dispose() { GL.DeleteTexture(this.textureObject); Utility.CheckWebGLError(); }
public void Bind() { GL.UseProgram(ShaderProgramObject); }
public void BindAttributeLocation(uint location, string attribute) { GL.BindAttribLocation(ShaderProgramObject, location, attribute); }
public bool GetLinkStatus() { return(GL.GetProgramParameter(ShaderProgramObject, GL.GL_LINK_STATUS) == GL.GL_TRUE); }
public void Clear(Color clearColor) { GL.ClearColor((float)clearColor.R, (float)clearColor.G, (float)clearColor.B, (float)clearColor.A); GL.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); }
public string GetInfoLog() { return(GL.GetProgramInfoLog(ShaderProgramObject)); }