Exemplo n.º 1
0
        private void UpdateData(int mipmap)
        {
            if (Boxes.Count == 0)
            {
                return;
            }

            int floatCount = Boxes.Count * 2 * 4; // each box has 4 edges with 2 float component

            if (positionBuffer == null || positionBuffer.ByteSize < floatCount * sizeof(float))
            {
                // resize buffer
                positionBuffer?.Dispose();
                positionBuffer = new UploadBuffer(floatCount * sizeof(float), BindFlags.VertexBuffer);
            }

            // fill buffer
            var data = new float[floatCount];
            var dim  = images.Size.GetMip(mipmap);
            // offset float coordinates by half a unit so the quad covers the area
            var offset = Size2.Zero.ToCoords(dim.XY);

            for (var i = 0; i < Boxes.Count; i++)
            {
                var box = Boxes[i];

                // top left
                data[i * 8]     = ToCanonical(box.Start.X - offset.X);
                data[i * 8 + 1] = ToCanonical(box.Start.Y - offset.Y);
                // top right
                data[i * 8 + 2] = ToCanonical(box.End.X + offset.X);
                data[i * 8 + 3] = ToCanonical(box.Start.Y - offset.Y);
                // bot left
                data[i * 8 + 4] = ToCanonical(box.Start.X - offset.X);
                data[i * 8 + 5] = ToCanonical(box.End.Y + offset.Y);
                // bot right
                data[i * 8 + 6] = ToCanonical(box.End.X + offset.X);
                data[i * 8 + 7] = ToCanonical(box.End.Y + offset.Y);
            }

            // upload buffer
            positionBuffer.SetData(data);
        }
Exemplo n.º 2
0
 public void Dispose()
 {
     shader?.Dispose();
     paramBuffer?.Dispose();
 }