protected override DX11IndexedGeometry GetGeom(DX11RenderContext context, int slice) { RoundRect roundrect = new RoundRect() { CornerResolution = this.FInRes[slice], EnableCenter = this.FInCenter[slice], InnerRadius = this.FInInner[slice], OuterRadius = this.FInOuter[slice] }; return context.Primitives.RoundRect(roundrect); }
public DX11IndexedGeometry RoundRect(RoundRect settings) { Vector2 inner = settings.InnerRadius; float outer = settings.OuterRadius; int ires = settings.CornerResolution; DX11IndexedGeometry geom = new DX11IndexedGeometry(device); geom.PrimitiveType = settings.PrimitiveType; geom.Tag = settings; List <Pos4Norm3Tex2Vertex> vl = new List <Pos4Norm3Tex2Vertex>(); List <int> il = new List <int>(); int idx = 0; float ucy = Convert.ToSingle(inner.Y + outer); float ucx = Convert.ToSingle(inner.X + outer); float mx = ucx * 2.0f; float my = ucy * 2.0f; //Need 1 quad for center if (settings.EnableCenter) { idx = SetQuad(vl, il, 0.0f, 0.0f, inner.X, inner.Y, idx, mx, my); } //Need 2 quads up/down idx = SetQuad(vl, il, 0.0f, ucy, inner.X, (float)outer, idx, mx, my); idx = SetQuad(vl, il, 0.0f, -ucy, inner.X, (float)outer, idx, mx, my); //Need 2 quads left/right idx = SetQuad(vl, il, -ucx, 0.0f, (float)outer, inner.Y, idx, mx, my); idx = SetQuad(vl, il, ucx, 0.0f, (float)outer, inner.Y, idx, mx, my); float radius = (float)outer * 2.0f; //Add the 4 corners idx = SetSegment(vl, il, inner.X, inner.Y, 0.0f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, -inner.X, inner.Y, 0.25f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, -inner.X, -inner.Y, 0.5f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, inner.X, -inner.Y, 0.75f, radius, ires, idx, mx, my); geom.VertexBuffer = DX11VertexBuffer.CreateImmutable <Pos4Norm3Tex2Vertex>(device, vl.ToArray()); geom.IndexBuffer = DX11IndexBuffer.CreateImmutable(device, il.ToArray()); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.HasBoundingBox = false; return(geom); }
public DX11IndexedGeometry RoundRect(RoundRect settings) { Vector2 inner = settings.InnerRadius; float outer = settings.OuterRadius; int ires = settings.CornerResolution; DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.PrimitiveType = settings.PrimitiveType; geom.Tag = settings; List <Pos4Norm3Tex2Vertex> vl = new List <Pos4Norm3Tex2Vertex>(); List <int> il = new List <int>(); int idx = 0; float ucy = Convert.ToSingle(inner.Y + outer); float ucx = Convert.ToSingle(inner.X + outer); float mx = ucx * 2.0f; float my = ucy * 2.0f; //Need 1 quad for center if (settings.EnableCenter) { idx = SetQuad(vl, il, 0.0f, 0.0f, inner.X, inner.Y, idx, mx, my); } //Need 2 quads up/down idx = SetQuad(vl, il, 0.0f, ucy, inner.X, (float)outer, idx, mx, my); idx = SetQuad(vl, il, 0.0f, -ucy, inner.X, (float)outer, idx, mx, my); //Need 2 quads left/right idx = SetQuad(vl, il, -ucx, 0.0f, (float)outer, inner.Y, idx, mx, my); idx = SetQuad(vl, il, ucx, 0.0f, (float)outer, inner.Y, idx, mx, my); float radius = (float)outer * 2.0f; //Add the 4 corners idx = SetSegment(vl, il, inner.X, inner.Y, 0.0f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, -inner.X, inner.Y, 0.25f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, -inner.X, -inner.Y, 0.5f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, inner.X, -inner.Y, 0.75f, radius, ires, idx, mx, my); DataStream ds = new DataStream(vl.Count * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; ds.WriteRange(vl.ToArray()); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); var indexstream = new DataStream(il.Count * 4, true, true); indexstream.WriteRange(il.ToArray()); indexstream.Position = 0; geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vl.Count; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = false; return(geom); }
public DX11IndexedGeometry RoundRect(RoundRect settings) { Vector2 inner = settings.InnerRadius; float outer = settings.OuterRadius; int ires = settings.CornerResolution; DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.PrimitiveType = settings.PrimitiveType; geom.Tag = settings; List<Pos4Norm3Tex2Vertex> vl = new List<Pos4Norm3Tex2Vertex>(); List<int> il = new List<int>(); int idx = 0; float ucy = Convert.ToSingle(inner.Y + outer); float ucx = Convert.ToSingle(inner.X + outer); float mx = ucx * 2.0f; float my = ucy * 2.0f; //Need 1 quad for center if (settings.EnableCenter) { idx = SetQuad(vl, il, 0.0f, 0.0f, inner.X, inner.Y, idx, mx, my); } //Need 2 quads up/down idx = SetQuad(vl, il, 0.0f, ucy, inner.X, (float)outer, idx, mx, my); idx = SetQuad(vl, il, 0.0f, -ucy, inner.X, (float)outer, idx, mx, my); //Need 2 quads left/right idx = SetQuad(vl, il, -ucx, 0.0f, (float)outer, inner.Y, idx, mx, my); idx = SetQuad(vl, il, ucx, 0.0f, (float)outer, inner.Y, idx, mx, my); float radius = (float)outer * 2.0f; //Add the 4 corners idx = SetSegment(vl, il, inner.X, inner.Y, 0.0f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, -inner.X, inner.Y, 0.25f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, -inner.X, -inner.Y, 0.5f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, inner.X, -inner.Y, 0.75f, radius, ires, idx, mx, my); DataStream ds = new DataStream(vl.Count * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; ds.WriteRange(vl.ToArray()); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); var indexstream = new DataStream(il.Count * 4, true, true); indexstream.WriteRange(il.ToArray()); indexstream.Position = 0; geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vl.Count; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = false; return geom; }