/// <summary> /// Binds the given <see cref="IndexBuffer"/> object to the <see cref="RenderContext"/>. /// </summary> /// <param name="ibo">The <see cref="IndexBuffer"/> object to bind.</param> public void BindIndexBuffer(IndexBuffer ibo) { if (ibo == null) { if (IndexBufferHandle == GLHandle.Zero) { return; } GL.BindBuffer(BufferTarget.ElementArrayBuffer, GLHandle.Zero); IndexBufferHandle = GLHandle.Zero; IndexBuffer.BoundContext = null; IndexBuffer = null; return; } ibo.EnsureUndisposed(); if (IndexBufferHandle == ibo.Handle) { return; } GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo.Handle); IndexBufferHandle = ibo.Handle; IndexBuffer = ibo; IndexBuffer.BoundContext = this; }
internal static void EnsureValid(GLHandle handle) { if (handle == GLHandle.Zero) { throw new InvalidOperationException("OpenGL error: Invalid handle generated."); } }
/// <summary> /// Binds the given <see cref="FrameBuffer"/> object to the <see cref="RenderContext"/>. /// </summary> /// <param name="fbo">The <see cref="FrameBuffer"/> object to bind.</param> public void BindFrameBuffer(FrameBuffer fbo) { if (fbo == null) { if (FrameBufferHandle == GLHandle.Zero) { return; } GL.BindFramebuffer(FramebufferTarget.Framebuffer, GLHandle.Zero); FrameBufferHandle = GLHandle.Zero; FrameBuffer.BoundContext = null; FrameBuffer = null; return; } fbo.EnsureUndisposed(); if (FrameBufferHandle == fbo.Handle) { return; } GL.BindFramebuffer(FramebufferTarget.Framebuffer, fbo.Handle); FrameBufferHandle = fbo.Handle; FrameBuffer = fbo; FrameBuffer.BoundContext = this; }
/// <summary> /// Binds the given <see cref="ShaderProgram"/> object to the <see cref="RenderContext"/>. /// </summary> /// <param name="program">The <see cref="ShaderProgram"/> object to bind.</param> public void BindShaderProgram(ShaderProgram program) { if (program == null) { if (ShaderProgramHandle == GLHandle.Zero) { return; } GL.UseProgram(GLHandle.Zero); ShaderProgramHandle = GLHandle.Zero; ShaderProgram.BoundContext = null; ShaderProgram = null; return; } program.EnsureUndisposed(); if (ShaderProgramHandle == program.Handle) { return; } GL.UseProgram(program.Handle); ShaderProgramHandle = program.Handle; ShaderProgram = program; ShaderProgram.BoundContext = this; }
/// <summary> /// Binds the given <see cref="VertexBuffer"/> object to the <see cref="RenderContext"/>. /// </summary> /// <param name="vbo">The <see cref="VertexBuffer"/> object to bind.</param> public void BindVertexBuffer(VertexBuffer vbo) { if (vbo == null) { if (VertexBufferHandle == GLHandle.Zero) { return; } GL.BindBuffer(BufferTarget.ArrayBuffer, GLHandle.Zero); VertexBufferHandle = GLHandle.Zero; VertexBuffer.BoundContext = null; VertexBuffer = null; return; } vbo.EnsureUndisposed(); if (VertexBufferHandle == vbo.Handle) { return; } GL.BindBuffer(BufferTarget.ArrayBuffer, vbo.Handle); VertexBufferHandle = vbo.Handle; VertexBuffer = vbo; VertexBuffer.BoundContext = this; }
/// <summary> /// Binds the given <see cref="PixelBuffer"/> object to the <see cref="RenderContext"/>. /// </summary> /// <param name="pbo">The <see cref="PixelBuffer"/> object to bind.</param> public void BindPixelBuffer(PixelBuffer pbo) { if (pbo == null) { if (PixelBufferHandle == GLHandle.Zero) { return; } GL.BindBuffer(BufferTarget.PixelUnpackBuffer, GLHandle.Zero); PixelBufferHandle = GLHandle.Zero; PixelBuffer.BoundContext = null; PixelBuffer = null; return; } pbo.EnsureUndisposed(); if (PixelBufferHandle == pbo.Handle) { return; } GL.BindBuffer(BufferTarget.PixelUnpackBuffer, pbo.Handle); PixelBufferHandle = pbo.Handle; PixelBuffer = pbo; PixelBuffer.BoundContext = this; }
/// <summary> /// Ensures that there is no active <see cref="ShaderProgram"/> object bound to the RenderContext. /// </summary> public void UnbindShaderProgram() { if (_shaderProgramHandle == GLHandle.Zero) { return; } GL.UseProgram(GLHandle.Zero); _shaderProgramHandle = GLHandle.Zero; _shaderProgram.BoundContext = null; _shaderProgram = null; }
/// <summary> /// Ensures that there is no active <see cref="Buffers.FrameBuffer"/> object bound to the RenderContext. /// </summary> public void UnbindFrameBuffer() { if (_frameBufferHandle == GLHandle.Zero) { return; } GL.BindFramebuffer(FramebufferTarget.Framebuffer, GLHandle.Zero); _frameBufferHandle = GLHandle.Zero; _frameBuffer.BoundContext = null; _frameBuffer = null; }
/// <summary> /// Ensures that there is no active <see cref="PixelBuffer"/> object bound to the RenderContext. /// </summary> public void UnbindPixelBuffer() { if (_pixelBufferHandle == GLHandle.Zero) { return; } GL.BindBuffer(BufferTarget.PixelUnpackBuffer, GLHandle.Zero); _pixelBufferHandle = GLHandle.Zero; _pixelBuffer.BoundContext = null; _pixelBuffer = null; }
/// <summary> /// Ensures that there is no active <see cref="VertexBuffer"/> object bound to the RenderContext. /// </summary> public void UnbindVertexBuffer() { if (_vertexBufferHandle == GLHandle.Zero) { return; } GL.BindBuffer(BufferTarget.ArrayBuffer, GLHandle.Zero); _vertexBufferHandle = GLHandle.Zero; _vertexBuffer.BoundContext = null; _vertexBuffer = null; }
/// <summary> /// Ensures that there is no active <see cref="IndexBuffer"/> object bound to the RenderContext. /// </summary> public void UnbindIndexBuffer() { if (_indexBufferHandle == GLHandle.Zero) { return; } GL.BindBuffer(BufferTarget.ElementArrayBuffer, GLHandle.Zero); _indexBufferHandle = GLHandle.Zero; _indexBuffer.BoundContext = null; _indexBuffer = null; }
/// <summary> /// Ensures that the given <see cref="IndexBuffer"/> object is unbound. /// </summary> /// <param name="ibo">The <see cref="IndexBuffer"/> object to ensure is unbound.</param> public void UnbindIndexBuffer(IndexBuffer ibo) { if (ibo == null) { throw new ArgumentNullException(nameof(ibo)); } if (IndexBufferHandle != ibo.Handle) { return; } GL.BindBuffer(BufferTarget.ElementArrayBuffer, GLHandle.Zero); IndexBufferHandle = GLHandle.Zero; IndexBuffer.BoundContext = null; IndexBuffer = null; }
/// <summary> /// Ensures that the given <see cref="FrameBuffer"/> object is unbound. /// </summary> /// <param name="fbo">The <see cref="FrameBuffer"/> object to ensure is unbound.</param> public void UnbindFrameBuffer(FrameBuffer fbo) { if (fbo == null) { throw new ArgumentNullException(nameof(fbo)); } if (FrameBufferHandle != fbo.Handle) { return; } GL.BindFramebuffer(FramebufferTarget.Framebuffer, GLHandle.Zero); FrameBufferHandle = GLHandle.Zero; FrameBuffer.BoundContext = null; FrameBuffer = null; }
/// <summary> /// Ensures that the given <see cref="VertexBuffer"/> object is unbound. /// </summary> /// <param name="vbo">The <see cref="VertexBuffer"/> object to ensure is unbound.</param> public void UnbindVertexBuffer(VertexBuffer vbo) { if (vbo == null) { throw new ArgumentNullException(nameof(vbo)); } if (VertexBufferHandle != vbo.Handle) { return; } GL.BindBuffer(BufferTarget.ArrayBuffer, GLHandle.Zero); VertexBufferHandle = GLHandle.Zero; VertexBuffer.BoundContext = null; VertexBuffer = null; }
/// <summary> /// Ensures that the given <see cref="ShaderProgram"/> object is unbound. /// </summary> /// <param name="program">The <see cref="ShaderProgram"/> object to ensure is unbound.</param> public void UnbindShaderProgram(ShaderProgram program) { if (program == null) { throw new ArgumentNullException(nameof(program)); } if (ShaderProgramHandle != program.Handle) { return; } GL.UseProgram(GLHandle.Zero); ShaderProgramHandle = GLHandle.Zero; ShaderProgram.BoundContext = null; ShaderProgram = null; }
/// <summary> /// Ensures that the given <see cref="PixelBuffer"/> object is unbound. /// </summary> /// <param name="pbo">The <see cref="PixelBuffer"/> object to ensure is unbound.</param> public void UnbindPixelBuffer(PixelBuffer pbo) { if (pbo == null) { throw new ArgumentNullException(nameof(pbo)); } if (PixelBufferHandle != pbo.Handle) { return; } GL.BindBuffer(BufferTarget.PixelUnpackBuffer, GLHandle.Zero); PixelBufferHandle = GLHandle.Zero; PixelBuffer.BoundContext = null; PixelBuffer = null; }
/// <summary> /// Binds the given <see cref="ShaderProgram"/> object to the <see cref="RenderContext"/>. /// </summary> /// <param name="program">The <see cref="ShaderProgram"/> object to bind.</param> public void BindShaderProgram(ShaderProgram program) { if (program == null) { throw new ArgumentNullException(nameof(program)); } program.EnsureUndisposed(); if (_shaderProgramHandle == program.Handle) { return; } GL.UseProgram(program.Handle); _shaderProgramHandle = program.Handle; _shaderProgram = program; _shaderProgram.BoundContext = this; }
/// <summary> /// Binds the given <see cref="VertexBuffer"/> object to the <see cref="RenderContext"/>. /// </summary> /// <param name="vbo">The <see cref="VertexBuffer"/> object to bind.</param> public void BindVertexBuffer(VertexBuffer vbo) { if (vbo == null) { throw new ArgumentNullException(nameof(vbo)); } vbo.EnsureUndisposed(); if (_vertexBufferHandle == vbo.Handle) { return; } GL.BindBuffer(BufferTarget.ArrayBuffer, vbo.Handle); _vertexBufferHandle = vbo.Handle; _vertexBuffer = vbo; _vertexBuffer.BoundContext = this; }
/// <summary> /// Binds the given <see cref="IndexBuffer"/> object to the <see cref="RenderContext"/>. /// </summary> /// <param name="ibo">The <see cref="IndexBuffer"/> object to bind.</param> public void BindIndexBuffer(IndexBuffer ibo) { if (ibo == null) { throw new ArgumentNullException(nameof(ibo)); } ibo.EnsureUndisposed(); if (_indexBufferHandle == ibo.Handle) { return; } GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo.Handle); _indexBufferHandle = ibo.Handle; _indexBuffer = ibo; _indexBuffer.BoundContext = this; }
/// <summary> /// Binds the given <see cref="PixelBuffer"/> object to the <see cref="RenderContext"/>. /// </summary> /// <param name="pbo">The <see cref="PixelBuffer"/> object to bind.</param> public void BindPixelBuffer(PixelBuffer pbo) { if (pbo == null) { throw new ArgumentNullException(nameof(pbo)); } pbo.EnsureUndisposed(); if (_pixelBufferHandle == pbo.Handle) { return; } GL.BindBuffer(BufferTarget.PixelUnpackBuffer, pbo.Handle); _pixelBufferHandle = pbo.Handle; _pixelBuffer = pbo; _pixelBuffer.BoundContext = this; }
/// <summary> /// Binds the given <see cref="_frameBuffer"/> object to the <see cref="RenderContext"/>. /// </summary> /// <param name="fbo">The <see cref="_frameBuffer"/> object to bind.</param> public void BindFrameBuffer(FrameBuffer fbo) { if (fbo == null) { UnbindFrameBuffer(); return; } fbo.EnsureUndisposed(); if (_frameBufferHandle == fbo.Handle) { return; } GL.BindFramebuffer(FramebufferTarget.Framebuffer, fbo.Handle); _frameBufferHandle = fbo.Handle; _frameBuffer = fbo; _frameBuffer.BoundContext = this; }