예제 #1
0
        public QuadVertexBuffer(int amountQuads, BufferUsageHint usage)
            : base(amountQuads * 4, usage)
        {
            int amountIndices = amountQuads * 6;

            if (amountIndices > QuadIndexData.MaxAmountIndices)
            {
                ushort[] indices = new ushort[amountIndices];

                for (ushort i = 0, j = 0; j < amountIndices; i += 4, j += 6)
                {
                    indices[j]     = i;
                    indices[j + 1] = (ushort)(i + 1);
                    indices[j + 2] = (ushort)(i + 3);
                    indices[j + 3] = (ushort)(i + 2);
                    indices[j + 4] = (ushort)(i + 3);
                    indices[j + 5] = (ushort)(i + 1);
                }

                GLWrapper.BindBuffer(BufferTarget.ElementArrayBuffer, QuadIndexData.EBO_ID);
                GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(amountIndices * sizeof(ushort)), indices, BufferUsageHint.StaticDraw);

                QuadIndexData.MaxAmountIndices = amountIndices;
            }
        }
        protected override void Initialise()
        {
            base.Initialise();

            int amountIndices = amountQuads * 6;

            if (amountIndices > QuadIndexData.MaxAmountIndices)
            {
                ushort[] indices = new ushort[amountIndices];

                for (ushort i = 0, j = 0; j < amountIndices; i += TextureGLSingle.VERTICES_PER_QUAD, j += 6)
                {
                    indices[j]     = i;
                    indices[j + 1] = (ushort)(i + 1);
                    indices[j + 2] = (ushort)(i + 3);
                    indices[j + 3] = (ushort)(i + 2);
                    indices[j + 4] = (ushort)(i + 3);
                    indices[j + 5] = (ushort)(i + 1);
                }

                GLWrapper.BindBuffer(BufferTarget.ElementArrayBuffer, QuadIndexData.EBO_ID);
                GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(amountIndices * sizeof(ushort)), indices, BufferUsageHint.StaticDraw);

                QuadIndexData.MaxAmountIndices = amountIndices;
            }
        }
예제 #3
0
        private void resize(int amountVertices)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(ToString(), "Can not resize disposed vertex buffers.");
            }

            T[] oldVertices = Vertices;
            Vertices = new T[amountVertices];

            if (oldVertices != null)
            {
                for (int i = 0; i < oldVertices.Length && i < Vertices.Length; ++i)
                {
                    Vertices[i] = oldVertices[i];
                }
            }

            if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId))
            {
                bind_attributes();
            }

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * Stride), IntPtr.Zero, usage);
        }
예제 #4
0
        public override void Bind(bool forRendering)
        {
            base.Bind(forRendering);

            if (forRendering)
            {
                GLWrapper.BindBuffer(BufferTarget.ElementArrayBuffer, LinearIndexData.EBO_ID);
            }
        }
 protected override void PreDrawMesh()
 {
     profile.Save();
     GL.FrontFace(FrontFaceDirection.Ccw);
     GLWrapper.PushScissorState(false);
     GLWrapper.PushDepthInfo(new DepthInfo(false));
     GLWrapper.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
     GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, 0);
 }
예제 #6
0
        public virtual void Bind(bool forRendering)
        {
            Debug.Assert(!IsDisposed);

            if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId))
            {
                bind_attributes();
            }
        }
예제 #7
0
        public override void Bind(bool forRendering)
        {
            base.Bind(forRendering);

            if (forRendering)
            {
                GLWrapper.BindBuffer(BufferTarget.ElementArrayBuffer, QuadIndexData.EboId);
            }
        }
예제 #8
0
        /// <summary>
        /// Initialises this <see cref="VertexBuffer{T}"/>. Guaranteed to be run on the draw thread.
        /// </summary>
        protected virtual void Initialise()
        {
            ThreadSafety.EnsureDrawThread();

            GL.GenBuffers(1, out vboId);

            if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId))
                VertexUtils<DepthWrappingVertex<T>>.Bind();

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * STRIDE), IntPtr.Zero, usage);
        }
예제 #9
0
        public virtual void Bind(bool forRendering)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(ToString(), "Can not bind disposed vertex buffers.");
            }

            if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId))
            {
                VertexUtils <T> .Bind();
            }
        }
예제 #10
0
        public virtual void Bind(bool forRendering)
        {
            if (IsDisposed)
                throw new ObjectDisposedException(ToString(), "Can not bind disposed vertex buffers.");

            if (!isInitialised)
            {
                Initialise();
                isInitialised = true;
            }

            if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId))
                VertexUtils<DepthWrappingVertex<T>>.Bind();
        }
예제 #11
0
        private void resize(int amountVertices)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(ToString(), "Can not resize disposed vertex buffers.");
            }

            Array.Resize(ref Vertices, amountVertices);

            if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId))
            {
                VertexUtils <T> .Bind();
            }

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * STRIDE), IntPtr.Zero, usage);
        }
예제 #12
0
        protected override void Initialise()
        {
            base.Initialise();

            if (amountVertices > LinearIndexData.MaxAmountIndices)
            {
                ushort[] indices = new ushort[amountVertices];

                for (ushort i = 0; i < amountVertices; i++)
                {
                    indices[i] = i;
                }

                GLWrapper.BindBuffer(BufferTarget.ElementArrayBuffer, LinearIndexData.EBO_ID);
                GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(amountVertices * sizeof(ushort)), indices, BufferUsageHint.StaticDraw);

                LinearIndexData.MaxAmountIndices = amountVertices;
            }
        }
예제 #13
0
        public LinearVertexBuffer(int amountVertices, PrimitiveType type, BufferUsageHint usage)
            : base(amountVertices, usage)
        {
            Type = type;

            if (amountVertices > LinearIndexData.MaxAmountIndices)
            {
                ushort[] indices = new ushort[amountVertices];

                for (ushort i = 0; i < amountVertices; i++)
                {
                    indices[i] = i;
                }

                GLWrapper.BindBuffer(BufferTarget.ElementArrayBuffer, LinearIndexData.EBO_ID);
                GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(amountVertices * sizeof(ushort)), indices, BufferUsageHint.StaticDraw);

                LinearIndexData.MaxAmountIndices = amountVertices;
            }
        }
예제 #14
0
        private void resize(int amountVertices)
        {
            Debug.Assert(!IsDisposed);

            T[] oldVertices = Vertices;
            Vertices = new T[amountVertices];

            if (oldVertices != null)
            {
                for (int i = 0; i < oldVertices.Length && i < Vertices.Length; ++i)
                {
                    Vertices[i] = oldVertices[i];
                }
            }

            if (GLWrapper.BindBuffer(BufferTarget.ArrayBuffer, vboId))
            {
                bind_attributes();
            }

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * stride), IntPtr.Zero, usage);
        }