Ejemplo n.º 1
0
            /// <summary>
            /// Update the reference Buffer, using this technique.
            /// </summary>
            /// <param name="ctx">
            /// A <see cref="GraphicsContext"/> used for allocating resources.
            /// </param>
            public override void Create(GraphicsContext ctx)
            {
                if (ctx.Extensions.DirectStateAccess_ARB || ctx.Version.IsCompatible(Gl.Version_450))
                {
                    if (!ctx.Extensions.BufferStorage_ARB || !Buffer.Immutable)
                    {
                        // Emulates glBufferStorage error checking (only for size)
                        if (Buffer.Immutable && Buffer.Size != 0)
                        {
                            throw new GlException(ErrorCode.InvalidOperation);
                        }

                        Gl.NamedBufferData(Buffer.ObjectName, _Size, _Array, Buffer.Hint);
                    }
                    else
                    {
                        if (Buffer.Immutable)
                        {
                            Gl.NamedBufferStorage(Buffer.ObjectName, _Size, _Array, Buffer.UsageMask);
                        }
                        else
                        {
                            Gl.NamedBufferData(Buffer.ObjectName, _Size, _Array, Buffer.Hint);
                        }
                    }
                }
                else
                {
                    if (!ctx.Extensions.BufferStorage_ARB || !Buffer.Immutable)
                    {
                        // Emulates glBufferStorage error checking (only for size)
                        if (Buffer.Immutable && Buffer.Size != 0)
                        {
                            throw new GlException(ErrorCode.InvalidOperation);
                        }

                        Gl.BufferData(Buffer.Target, _Size, _Array, Buffer.Hint);
                    }
                    else
                    {
                        if (Buffer.Immutable)
                        {
                            Gl.BufferStorage(Buffer.Target, _Size, _Array, Buffer.UsageMask);
                        }
                        else
                        {
                            Gl.BufferData(Buffer.Target, _Size, _Array, Buffer.Hint);
                        }
                    }
                }

                // Explictly check for errors
                Gl.CheckErrors();

                Buffer.Size = _Size;
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Create the texture, using this technique.
 /// </summary>
 /// <param name="ctx">
 /// A <see cref="GraphicsContext"/> used for allocating resources.
 /// </param>
 public override void Create(GraphicsContext ctx)
 {
     if (!Buffer.Immutable || !ctx.Extensions.BufferStorage_ARB)
     {
         Gl.BufferData(Buffer.Target, _Size, _Array, Buffer.Hint);
     }
     else
     {
         Gl.BufferStorage(Buffer.Target, _Size, _Array, Buffer.UsageMask);
     }
     Buffer.Size = _Size;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Reset the allocated GPU buffer for this Buffer.
        /// </summary>
        /// <param name="ctx">
        ///
        /// </param>
        /// <param name="size">
        /// A <see cref="UInt32"/> that determine the size of the buffer object GPU buffer, in bytes.
        /// </param>
        /// <param name="data">
        ///
        /// </param>
        protected void CreateGpuBuffer(GraphicsContext ctx, uint size, IntPtr data)
        {
            if (Immutable && _GpuBufferSize > 0)
            {
                throw new InvalidOperationException("buffer is immutable");
            }

            if (Immutable && ctx.Extensions.BufferStorage_ARB)
            {
                Gl.BufferStorage(Target, size, data, (uint)_UsageMask);
                Gl.CheckErrors();
            }
            else
            {
                Gl.BufferData(Target, size, data, Hint);
                if (CpuBufferAddress != IntPtr.Zero)
                {
                    Gl.BufferSubData(Target, IntPtr.Zero, _GpuBufferSize, CpuBufferAddress);
                }
            }

            // Store GPU buffer size
            _GpuBufferSize = size;
        }
Ejemplo n.º 4
0
            private void CreateCompatible(GraphicsContext ctx)
            {
                if (!ctx.Extensions.BufferStorage_ARB || !Buffer.Immutable)
                {
                    // Emulates glBufferStorage error checking (only for size)
                    if (Buffer.Immutable && Buffer.Size != 0)
                    {
                        throw new GlException(ErrorCode.InvalidOperation);
                    }

                    Gl.BufferData(Buffer.Target, _Size, IntPtr.Zero, Buffer.Hint);
                }
                else
                {
                    if (Buffer.Immutable)
                    {
                        Gl.BufferStorage(Buffer.Target, _Size, IntPtr.Zero, Buffer.UsageMask);
                    }
                    else
                    {
                        Gl.BufferData(Buffer.Target, _Size, IntPtr.Zero, Buffer.Hint);
                    }
                }
            }