예제 #1
0
        public void SetVertexArray(int VbIndex, int Stride, byte[] Buffer, GalVertexAttrib[] Attribs)
        {
            EnsureVbInitialized(VbIndex);

            VertexBuffers[VbIndex].PrimCount = Buffer.Length / Stride;

            VbInfo Vb = VertexBuffers[VbIndex];

            IntPtr Length = new IntPtr(Buffer.Length);

            GL.BindBuffer(BufferTarget.ArrayBuffer, Vb.VboHandle);
            GL.BufferData(BufferTarget.ArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            GL.BindVertexArray(Vb.VaoHandle);

            for (int Attr = 0; Attr < 16; Attr++)
            {
                GL.DisableVertexAttribArray(Attr);
            }

            for (int Index = 0; Index < Attribs.Length; Index++)
            {
                GalVertexAttrib Attrib = Attribs[Index];

                GL.EnableVertexAttribArray(Index);

                GL.BindBuffer(BufferTarget.ArrayBuffer, Vb.VboHandle);

                bool Unsigned =
                    Attrib.Type == GalVertexAttribType.Unorm ||
                    Attrib.Type == GalVertexAttribType.Uint ||
                    Attrib.Type == GalVertexAttribType.Uscaled;

                bool Normalize =
                    Attrib.Type == GalVertexAttribType.Snorm ||
                    Attrib.Type == GalVertexAttribType.Unorm;

                VertexAttribPointerType Type = 0;

                if (Attrib.Type == GalVertexAttribType.Float)
                {
                    Type = VertexAttribPointerType.Float;
                }
                else
                {
                    Type = AttribTypes[Attrib.Size] + (Unsigned ? 1 : 0);
                }

                int Size   = AttribElements[Attrib.Size];
                int Offset = Attrib.Offset;

                GL.VertexAttribPointer(Index, Size, Type, Normalize, Stride, Offset);
            }

            GL.BindVertexArray(0);
        }
예제 #2
0
        public void DrawElements(int VbIndex, int First, GalPrimitiveType PrimType)
        {
            VbInfo Vb = VertexBuffers[VbIndex];

            PrimitiveType Mode = OGLEnumConverter.GetPrimitiveType(PrimType);

            GL.BindVertexArray(Vb.VaoHandle);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBuffer.IboHandle);

            GL.DrawElements(Mode, IndexBuffer.Count, IndexBuffer.Type, First);
        }
예제 #3
0
        public void DrawArrays(int VbIndex, int First, int PrimCount, GalPrimitiveType PrimType)
        {
            if (PrimCount == 0)
            {
                return;
            }

            VbInfo Vb = VertexBuffers[VbIndex];

            GL.BindVertexArray(Vb.VaoHandle);

            GL.DrawArrays(OGLEnumConverter.GetPrimitiveType(PrimType), First, PrimCount);
        }
예제 #4
0
        private void EnsureVbInitialized(int VbIndex)
        {
            VbInfo Vb = VertexBuffers[VbIndex];

            if (Vb.VaoHandle == 0)
            {
                Vb.VaoHandle = GL.GenVertexArray();
            }

            if (Vb.VboHandle == 0)
            {
                Vb.VboHandle = GL.GenBuffer();
            }

            VertexBuffers[VbIndex] = Vb;
        }