internal BufferObject(BufferTarget target, BufferUsageHint hint)
 {
     Id = GManager.GenBuffer();
     Target = target;
     UsageHint = hint;
     Size = -1;
 }
Exemple #2
0
        public SpriteInstanceBuffer()
        {
            VAO = GManager.GenVertexArray();
            GL.BindVertexArray(VAO);

            float[] vertexData = new float[]
            {
                -0.5f, -0.5f,
                0.5f, -0.5f,
                -0.5f, 0.5f,
                0.5f, 0.5f
            };

            int floatSize = sizeof(float);

            // Setup buffers
            VertexBuffer = GManager.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, vertexData.Length * floatSize, vertexData, BufferUsageHint.StaticDraw);
            GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 0, IntPtr.Zero);

            PositionBuffer = GManager.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, PositionBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(MaxSprites * 2 * floatSize), IntPtr.Zero, BufferUsageHint.StreamDraw);
            GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 0, IntPtr.Zero);

            ColorBuffer = GManager.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, ColorBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(MaxSprites * 4 * sizeof(byte)), IntPtr.Zero, BufferUsageHint.StreamDraw);
            GL.VertexAttribPointer(2, 4, VertexAttribPointerType.UnsignedByte, true, 0, IntPtr.Zero);

            OrientationBuffer = GManager.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, OrientationBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(MaxSprites * 3 * floatSize), IntPtr.Zero, BufferUsageHint.StreamDraw);
            GL.VertexAttribPointer(3, 3, VertexAttribPointerType.Float, false, 0, IntPtr.Zero);

            GL.BindVertexArray(0);
        }