public void RenderStroke(ref Paint paint, ref Scissor scissor, float fringe, float strokeWidth, ArraySegment <Path> paths) { for (var i = 0; i < paths.Count; ++i) { var path = paths.Array[paths.Offset + i]; if (path.Stroke != null) { var stroke = path.Stroke.Value; for (var j = 0; j < stroke.Count; ++j) { _vertexes.Add(stroke.Array[stroke.Offset + j]); } RenderTriangles(ref paint, ref scissor, strokeWidth, fringe, -1.0f, paint.Image != 0 ? RenderingType.FillImage : RenderingType.FillGradient, _vertexes.ToArraySegment(), PrimitiveType.TriangleStrip, false); } } }
public void RenderTriangles(ref Paint paint, ref Scissor scissor, ArraySegment <Vertex> verts) { RenderTriangles(ref paint, ref scissor, 1.0f, 1.0f, -1.0f, RenderingType.Triangles, verts, PrimitiveType.TriangleList, false); }
public void RenderFill(ref Paint paint, ref Scissor scissor, float fringe, Bounds bounds, ArraySegment <Path> paths) { var isConvex = paths.Count == 1 && paths.Array[paths.Offset].Convex == 1; RenderingType renderingType; if (isConvex) { renderingType = paint.Image != 0 ? RenderingType.FillImage : RenderingType.FillGradient; } else { _device.BlendState = _blendStateNoDraw; _device.DepthStencilState = _stencilStateFill1; renderingType = RenderingType.Simple; } for (var i = 0; i < paths.Count; ++i) { var path = paths.Array[paths.Offset + i]; if (path.Fill != null) { var fill = path.Fill.Value; for (var j = 0; j < fill.Count; ++j) { _vertexes.Add(fill.Array[fill.Offset + j]); } SetIndexBufferFill(fill.Count, (fill.Count - 2) * 3); RenderTriangles(ref paint, ref scissor, fringe, fringe, -1.0f, renderingType, _vertexes.ToArraySegment(), PrimitiveType.TriangleList, true); } } if (!isConvex) { _device.BlendState = BlendState.AlphaBlend; _device.DepthStencilState = _stencilStateFill2; _vertexes.Add(new Vertex(bounds.b1, bounds.b2, 0.5f, 1.0f)); _vertexes.Add(new Vertex(bounds.b3, bounds.b2, 0.5f, 1.0f)); _vertexes.Add(new Vertex(bounds.b1, bounds.b4, 0.5f, 1.0f)); _vertexes.Add(new Vertex(bounds.b3, bounds.b4, 0.5f, 1.0f)); RenderTriangles(ref paint, ref scissor, fringe, fringe, -1.0f, RenderingType.FillGradient, _vertexes.ToArraySegment(), PrimitiveType.TriangleStrip, false); _device.DepthStencilState = DepthStencilState.None; } }
private void RenderTriangles(ref Paint paint, ref Scissor scissor, float width, float fringe, float strokeThr, RenderingType renderingType, ArraySegment <Vertex> verts, PrimitiveType primitiveType, bool indexed) { if (verts.Count <= 0 || indexed && _indexesCount <= 0) { return; } var innerColor = premultiplyColor(paint.InnerColor); var outerColor = premultiplyColor(paint.OuterColor); _strokeMult = (width * 0.5f + fringe * 0.5f) / fringe; if (scissor.Extent.X < -0.5f || scissor.Extent.Y < -0.5f) { _scissorTransform.Zero(); _scissorExt.X = 1.0f; _scissorExt.Y = 1.0f; _scissorScale.X = 1.0f; _scissorScale.Y = 1.0f; } else { _scissorTransform = scissor.Transform.BuildInverse(); _scissorExt.X = scissor.Extent.X; _scissorExt.Y = scissor.Extent.Y; _scissorScale.X = (float)Math.Sqrt(scissor.Transform.T1 * scissor.Transform.T1 + scissor.Transform.T3 * scissor.Transform.T3) / fringe; _scissorScale.Y = (float)Math.Sqrt(scissor.Transform.T2 * scissor.Transform.T2 + scissor.Transform.T4 * scissor.Transform.T4) / fringe; } var transform = paint.Transform.BuildInverse(); var transformMatrix = transform.ToMatrix(); _viewSizeParam.SetValue(new Vector2(_device.PresentationParameters.Bounds.Width, _device.PresentationParameters.Bounds.Height)); _scissorMatParam.SetValue(_scissorTransform.ToMatrix()); _scissorExtParam.SetValue(_scissorExt); _scissorScaleParam.SetValue(_scissorScale); _paintMatParam.SetValue(transformMatrix); _extentParam.SetValue(new Vector4(paint.Extent.X, paint.Extent.Y, 0.0f, 0.0f)); _radiusParam.SetValue(new Vector4(paint.Radius, 0.0f, 0.0f, 0.0f)); _featherParam.SetValue(new Vector4(paint.Feather, 0.0f, 0.0f, 0.0f)); _innerColParam.SetValue(innerColor.ToVector4()); _outerColParam.SetValue(outerColor.ToVector4()); // _effect.Parameters["strokeMult"].SetValue(new Vector4(_strokeMult, 0.0f, 0.0f, 0.0f)); if (paint.Image > 0) { var texture = GetTextureById(paint.Image); _textureParam.SetValue(texture); } var technique = _techniques[(int)renderingType]; _effect.CurrentTechnique = technique; foreach (var pass in _effect.CurrentTechnique.Passes) { pass.Apply(); if (indexed) { _device.DrawUserIndexedPrimitives(primitiveType, verts.Array, verts.Offset, verts.Count, _indexes, 0, _indexesCount / 3); } else { var primitiveCount = primitiveType == PrimitiveType.TriangleList ? verts.Count / 3 : verts.Count - 2; _device.DrawUserPrimitives(primitiveType, verts.Array, verts.Offset, primitiveCount); } } _vertexes.Clear(); }