Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
 internal static void EnsureValid(GLHandle handle)
 {
     if (handle == GLHandle.Zero)
     {
         throw new InvalidOperationException("OpenGL error: Invalid handle generated.");
     }
 }
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
        /// <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;
        }
Exemplo n.º 6
0
        /// <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;
        }
Exemplo n.º 7
0
        /// <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;
        }
Exemplo n.º 8
0
        /// <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;
        }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
0
        /// <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;
        }
Exemplo n.º 11
0
        /// <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;
        }
Exemplo n.º 12
0
        /// <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;
        }
Exemplo n.º 13
0
        /// <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;
        }
Exemplo n.º 14
0
        /// <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;
        }
Exemplo n.º 15
0
        /// <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;
        }
Exemplo n.º 16
0
        /// <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;
        }
Exemplo n.º 17
0
        /// <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;
        }
Exemplo n.º 18
0
        /// <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;
        }
Exemplo n.º 19
0
        /// <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;
        }
Exemplo n.º 20
0
        /// <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;
        }
Exemplo n.º 21
0
        /// <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;
        }