void _drawTextDrawMeshCallback(uiPaint p, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha, float strokeMult, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { if (!this._applyClip(textBlobBounds)) { ObjectPool <TextBlobMesh> .release(textMesh); return; } var layer = this._currentLayer; if (notEmoji) { layer.draws.Add(CanvasShader.texAlpha(layer, p, textMesh, tex)); } else { uiPaint paintWithWhite = new uiPaint(p); paintWithWhite.color = uiColor.white; if (EmojiUtils.image == null) { ObjectPool <TextBlobMesh> .release(textMesh); return; } var raw_mesh = textMesh.resolveMesh(); var meshmesh = raw_mesh.duplicate(); ObjectPool <TextBlobMesh> .release(textMesh); layer.draws.Add(CanvasShader.tex(layer, paintWithWhite, meshmesh, EmojiUtils.image)); } }
void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha, float strokeMult, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { if (!this._applyClip(fillMesh.bounds)) { ObjectPool <uiMeshMesh> .release(fillMesh); ObjectPool <uiMeshMesh> .release(strokeMesh); return; } var layer = this._currentLayer; if (convex) { layer.draws.Add(CanvasShader.convexFill(layer, p, fillMesh)); } else { layer.draws.Add(CanvasShader.fill0(layer, fillMesh)); layer.draws.Add(CanvasShader.fill1(layer, p, fillMesh.boundsMesh)); } if (strokeMesh != null) { layer.draws.Add(CanvasShader.strokeAlpha(layer, p, alpha, strokeMult, strokeMesh)); layer.draws.Add(CanvasShader.stroke1(layer, strokeMesh.duplicate())); } }
void _drawWithMaskFilter(uiRect meshBounds, uiPaint paint, uiMaskFilter maskFilter, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha, float strokeMult, Texture tex, uiRect texBound, TextBlobMesh textMesh, bool notEmoji, _drawPathDrawMeshCallbackDelegate drawCallback) { var layer = this._currentLayer; var clipBounds = layer.layerBounds; uiRect?stackBounds; bool iior; layer.clipStack.getBounds(out stackBounds, out iior); if (stackBounds != null) { clipBounds = uiRectHelper.intersect(clipBounds, stackBounds.Value); } if (clipBounds.isEmpty) { this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh); return; } var state = layer.currentState; float sigma = state.scale * maskFilter.sigma; if (sigma <= 0) { this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh); return; } float sigma3 = 3 * sigma; var maskBounds = uiRectHelper.inflate(meshBounds, sigma3); maskBounds = uiRectHelper.intersect(maskBounds, uiRectHelper.inflate(clipBounds, sigma3)); if (maskBounds.isEmpty) { this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh); return; } var maskLayer = this._createMaskLayer(layer, maskBounds, drawCallback, paint, convex, alpha, strokeMult, tex, texBound, textMesh, fillMesh, strokeMesh, notEmoji); var blurLayer = this._createBlurLayer(maskLayer, sigma, sigma, layer); var blurMesh = ImageMeshGenerator.imageMesh(null, uiRectHelper.one, maskBounds); if (!this._applyClip(blurMesh.bounds)) { ObjectPool <uiMeshMesh> .release(blurMesh); return; } layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer)); }
void _drawPathDrawMeshQuit(uiMeshMesh fillMesh, uiMeshMesh strokeMesh, TextBlobMesh textMesh) { ObjectPool <uiMeshMesh> .release(fillMesh); ObjectPool <uiMeshMesh> .release(strokeMesh); ObjectPool <TextBlobMesh> .release(textMesh); }
public override void clear() { ObjectPool <uiMeshMesh> .release(this._mesh); this._mesh = null; this._resolved = false; this.textBlob = null; }
public static MeshInfo create(MeshKey key, uiMeshMesh mesh, long textureVersion, int timeToLive = 5) { var meshInfo = ObjectPool <MeshInfo> .alloc(); meshInfo.mesh = mesh; meshInfo.key = key; meshInfo.textureVersion = textureVersion; meshInfo.touch(timeToLive); return(meshInfo); }
public override void clear() { ObjectPool <uiMeshMesh> .release(this.mesh); this.saveCount = 0; this.mesh = null; this.convex = false; this.isRect = false; this._genId = 0; this._isIntersectionOfRects = false; this._invMat = null; }
public override void clear() { this._paths.Clear(); this._points.Clear(); ObjectPool <uiMeshMesh> .release(this._fillMesh); this._fillMesh = null; ObjectPool <uiMeshMesh> .release(this._strokeMesh); this._strokeMesh = null; }
public override void clear() { this._paths.Clear(); this._points.Clear(); ObjectPool <uiMeshMesh> .release(this._fillMesh); this._fillMesh = null; ObjectPool <uiMeshMesh> .release(this._strokeMesh); this._strokeMesh = null; this._shapeHint = uiPath.uiPathShapeHint.Other; }
public static PictureFlusher.CmdDraw stroke0(PictureFlusher.RenderLayer layer, uiPaint paint, float alpha, uiMeshMesh mesh) { var mat = _stroke0Mat.getMaterial(paint.blendMode, layer.ignoreClip); _getShaderPassAndProps(layer, paint, mesh.matrix, alpha, 0.0f, out var pass, out var props); return(PictureFlusher.CmdDraw.create( mesh: mesh, pass: pass, material: mat, properties: props )); }
void _drawPathDrawMeshCallback2(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { if (!this._applyClip(mesh.bounds)) { ObjectPool <uiMeshMesh> .release(mesh); return; } var layer = this._currentLayer; layer.draws.Add(CanvasShader.stroke0(layer, p, alpha, mesh)); layer.draws.Add(CanvasShader.stroke1(layer, mesh.duplicate())); }
RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds, _drawPathDrawMeshCallbackDelegate drawCallback, uiPaint paint, bool convex, float alpha, float strokeMult, Texture tex, uiRect texBound, TextBlobMesh textMesh, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool notEmoji) { var textureWidth = Mathf.CeilToInt(maskBounds.width * this._devicePixelRatio); if (textureWidth < 1) { textureWidth = 1; } var textureHeight = Mathf.CeilToInt(maskBounds.height * this._devicePixelRatio); if (textureHeight < 1) { textureHeight = 1; } var maskLayer = RenderLayer.create( rtID: Shader.PropertyToID(this._getNewRenderTextureKey()), width: textureWidth, height: textureHeight, layerBounds: maskBounds, filterMode: FilterMode.Bilinear, noMSAA: true ); parentLayer.addLayer(maskLayer); this._layers.Add(maskLayer); this._currentLayer = maskLayer; var parentState = parentLayer.states[parentLayer.states.Count - 1]; var maskState = maskLayer.states[maskLayer.states.Count - 1]; maskState.matrix = parentState.matrix; drawCallback.Invoke(uiPaint.shapeOnly(paint), fillMesh, strokeMesh, convex, alpha, strokeMult, tex, texBound, textMesh, notEmoji); var removed = this._layers.removeLast(); D.assert(removed == maskLayer); this._currentLayer = this._layers[this._layers.Count - 1]; return(maskLayer); }
public static PictureFlusher.CmdDraw texRT(PictureFlusher.RenderLayer layer, uiPaint paint, uiMeshMesh mesh, PictureFlusher.RenderLayer renderLayer) { var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip); _getShaderPassAndProps(layer, paint, mesh.matrix, 1.0f, 0.0f, out var pass, out var props); props.SetInt(_texModeId, 1); // pre alpha return(PictureFlusher.CmdDraw.create( mesh: mesh, pass: pass, material: mat, properties: props, layerId: renderLayer.rtID )); }
public static PictureFlusher.CmdDraw fill0(PictureFlusher.RenderLayer layer, uiMeshMesh mesh) { Vector4 viewport = layer.viewport; var mat = _fill0Mat.getMaterial(layer.ignoreClip); var pass = 0; var props = ObjectPool <MaterialPropertyBlockWrapper> .alloc(); props.SetVector(_viewportId, viewport); return(PictureFlusher.CmdDraw.create( mesh: mesh, pass: pass, material: mat, properties: props )); }
public static PictureFlusher.CmdDraw fill1(PictureFlusher.RenderLayer layer, uiPaint paint, uiMeshMesh mesh) { var mat = _fill1Mat.getMaterial(paint.blendMode); _getShaderPassAndProps(layer, paint, mesh.matrix, 1.0f, 0.0f, out var pass, out var props); var ret = PictureFlusher.CmdDraw.create( mesh: mesh.boundsMesh, pass: pass, material: mat, properties: props ); ObjectPool <uiMeshMesh> .release(mesh); return(ret); }
public static CmdDraw create(uiMeshMesh mesh = null, TextBlobMesh textMesh = null, int pass = 0, MaterialPropertyBlockWrapper properties = null, int?layerId = null, Material material = null, Image image = null, Mesh meshObj = null, bool meshObjCreated = false) { CmdDraw newCmd = ObjectPool <CmdDraw> .alloc(); newCmd.mesh = mesh; newCmd.textMesh = textMesh; newCmd.pass = pass; newCmd.properties = properties; newCmd.layerId = layerId; newCmd.material = material; newCmd.image = image; newCmd.meshObj = meshObj; newCmd.meshObjCreated = meshObjCreated; return(newCmd); }
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, uiPaint paint, uiMeshMesh mesh, TextBlobMesh textMesh, Texture tex) { var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip); var meshMatrix = mesh != null ? mesh.matrix : textMesh.matrix; _getShaderPassAndProps(layer, paint, meshMatrix, 1.0f, 0.0f, out var pass, out var props); tex.filterMode = paint.filterMode; props.SetTexture(_texId, tex); props.SetInt(_texModeId, 2); // alpha only return(PictureFlusher.CmdDraw.create( mesh: mesh, textMesh: textMesh, pass: pass, material: mat, properties: props )); }
public static PictureFlusher.CmdDraw tex(PictureFlusher.RenderLayer layer, uiPaint paint, uiMeshMesh mesh, Image image) { var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip); _getShaderPassAndProps(layer, paint, mesh.matrix, 1.0f, 0.0f, out var pass, out var props); image.texture.filterMode = paint.filterMode; props.SetTexture(_texId, image.texture); props.SetInt(_texModeId, image.texture is RenderTexture || image.isDynamic ? 1 : 0); // pre alpha if RT else post alpha return(PictureFlusher.CmdDraw.create( mesh: mesh, pass: pass, material: mat, properties: props, image: image // keep a reference to avoid GC. )); }
public static uiMeshMesh create(uiRect rect) { uiMeshMesh newMesh = ObjectPool <uiMeshMesh> .alloc(); newMesh.vertices = ObjectPool <uiList <Vector3> > .alloc(); newMesh.vertices.Add(new Vector3(rect.right, rect.bottom)); newMesh.vertices.Add(new Vector3(rect.right, rect.top)); newMesh.vertices.Add(new Vector3(rect.left, rect.bottom)); newMesh.vertices.Add(new Vector3(rect.left, rect.top)); newMesh.triangles = ObjectPool <uiList <int> > .alloc(); newMesh.triangles.AddRange(_boundsTriangles); newMesh.rawBounds = rect; newMesh._bounds = newMesh.rawBounds; return(newMesh); }
void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { if (!this._applyClip(mesh.bounds)) { ObjectPool <uiMeshMesh> .release(mesh); return; } var layer = this._currentLayer; if (convex) { layer.draws.Add(CanvasShader.convexFill(layer, p, mesh)); } else { layer.draws.Add(CanvasShader.fill0(layer, mesh)); layer.draws.Add(CanvasShader.fill1(layer, p, mesh.boundsMesh)); } }
public void computeFillMesh(float fringe, out bool convex) { if (this._fillMesh != null && (fringe != 0.0f || this._strokeMesh != null) && this._fringe == fringe) { convex = this._fillConvex; return; } var verticesUV = this._expandFill(fringe); convex = this._fillConvex; var paths = this._paths; var cindices = 0; for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 2) { continue; } if (path.nfill > 0) { D.assert(path.nfill >= 2); cindices += (path.nfill - 2) * 3; } } var indices = ObjectPool <uiList <int> > .alloc(); indices.SetCapacity(cindices); for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 2) { continue; } if (path.nfill > 0) { for (var j = 2; j < path.nfill; j++) { indices.Add(path.ifill); indices.Add(path.ifill + j); indices.Add(path.ifill + j - 1); } } } D.assert(indices.Count == cindices); if (verticesUV.strokeVertices != null) { cindices = 0; for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 2) { continue; } if (path.nstroke > 0) { D.assert(path.nstroke >= 6); cindices += path.nstroke * 3; } } var strokeIndices = ObjectPool <uiList <int> > .alloc(); strokeIndices.SetCapacity(cindices); for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 2) { continue; } if (path.nstroke > 0) { strokeIndices.Add(path.istroke + path.nstroke - 1); strokeIndices.Add(path.istroke + path.nstroke - 2); strokeIndices.Add(path.istroke); strokeIndices.Add(path.istroke + path.nstroke - 1); strokeIndices.Add(path.istroke); strokeIndices.Add(path.istroke + 1); for (var j = 2; j < path.nstroke; j++) { if ((j & 1) == 0) { strokeIndices.Add(path.istroke + j - 1); strokeIndices.Add(path.istroke + j - 2); strokeIndices.Add(path.istroke + j); } else { strokeIndices.Add(path.istroke + j - 2); strokeIndices.Add(path.istroke + j - 1); strokeIndices.Add(path.istroke + j); } } } } D.assert(strokeIndices.Count == cindices); ObjectPool <uiMeshMesh> .release(this._strokeMesh); this._strokeMesh = uiMeshMesh.create(null, verticesUV.strokeVertices, strokeIndices, verticesUV.strokeUV); } var mesh = uiMeshMesh.create(null, verticesUV.fillVertices, indices, verticesUV.fillUV); this._fillMesh = mesh; this._fringe = fringe; }
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, uiPaint paint, uiMeshMesh mesh, Texture tex) { return(texAlpha(layer, paint, mesh, null, tex)); }
public static PictureFlusher.CmdDraw stencil1(PictureFlusher.RenderLayer layer, uiMeshMesh mesh) { Vector4 viewport = layer.viewport; var mat = _stencilMat; var pass = 2; var props = ObjectPool <MaterialPropertyBlockWrapper> .alloc(); props.SetVector(_viewportId, viewport); return(PictureFlusher.CmdDraw.create( mesh: mesh, pass: pass, material: mat, properties: props )); }
public static uiMeshMesh create(uiMatrix3?matrix, uiList <Vector3> vertices, uiList <int> triangles, uiList <Vector2> uv = null, uiRect?rawBounds = null) { D.assert(vertices != null); D.assert(vertices.Count >= 0); D.assert(triangles != null); D.assert(triangles.Count >= 0); D.assert(uv == null || uv.Count == vertices.Count); uiMeshMesh newMesh = ObjectPool <uiMeshMesh> .alloc(); newMesh.matrix = matrix; newMesh.vertices = vertices; newMesh.triangles = triangles; if (uv != null) { newMesh.uv = uv; } if (rawBounds == null) { if (vertices.Count > 0) { float minX = vertices[0].x; float maxX = vertices[0].x; float minY = vertices[0].y; float maxY = vertices[0].y; for (int i = 1; i < vertices.Count; i++) { var vertex = vertices[i]; if (vertex.x < minX) { minX = vertex.x; } if (vertex.x > maxX) { maxX = vertex.x; } if (vertex.y < minY) { minY = vertex.y; } if (vertex.y > maxY) { maxY = vertex.y; } } rawBounds = uiRectHelper.fromLTRB(minX, minY, maxX, maxY); } else { rawBounds = uiRectHelper.zero; } } newMesh.rawBounds = rawBounds.Value; return(newMesh); }
void _drawPathDrawMeshQuit(uiMeshMesh mesh, TextBlobMesh textMesh) { ObjectPool <uiMeshMesh> .release(mesh); ObjectPool <TextBlobMesh> .release(textMesh); }
public uiMeshMesh resolveMesh() { if (this._resolved) { return(this._mesh); } this._resolved = true; var style = this.textBlob.Value.style; var text = this.textBlob.Value.text; var key = MeshKey.create(this.textBlob.Value.instanceId, this.scale); var fontInfo = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle); var font = fontInfo.font; _meshes.TryGetValue(key, out var meshInfo); if (meshInfo != null && meshInfo.textureVersion == fontInfo.textureVersion) { ObjectPool <MeshKey> .release(key); meshInfo.touch(); this._mesh = meshInfo.mesh.transform(this.matrix); return(this._mesh); } // Handling Emoji char startingChar = text[this.textBlob.Value.textOffset]; if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) { var vert = ObjectPool <uiList <Vector3> > .alloc(); var tri = ObjectPool <uiList <int> > .alloc(); var uvCoord = ObjectPool <uiList <Vector2> > .alloc(); var metrics = FontMetrics.fromFont(font, style.UnityFontSize); var minMaxRect = EmojiUtils.getMinMaxRect(style.fontSize, metrics.ascent, metrics.descent); var minX = minMaxRect.left; var maxX = minMaxRect.right; var minY = minMaxRect.top; var maxY = minMaxRect.bottom; for (int i = 0; i < this.textBlob.Value.textSize; i++) { char a = text[this.textBlob.Value.textOffset + i]; int code = a; if (char.IsHighSurrogate(a)) { D.assert(i + 1 < this.textBlob.Value.textSize); D.assert(this.textBlob.Value.textOffset + i + 1 < this.textBlob.Value.text.Length); char b = text[this.textBlob.Value.textOffset + i + 1]; D.assert(char.IsLowSurrogate(b)); code = char.ConvertToUtf32(a, b); } else if (char.IsLowSurrogate(a) || EmojiUtils.isEmptyEmoji(a)) { continue; } var uvRect = EmojiUtils.getUVRect(code); var positionX = this.textBlob.Value.getPositionX(i); int baseIndex = vert.Count; vert.Add(new Vector3(positionX + minX, minY, 0)); vert.Add(new Vector3(positionX + maxX, minY, 0)); vert.Add(new Vector3(positionX + maxX, maxY, 0)); vert.Add(new Vector3(positionX + minX, maxY, 0)); tri.Add(baseIndex); tri.Add(baseIndex + 1); tri.Add(baseIndex + 2); tri.Add(baseIndex); tri.Add(baseIndex + 2); tri.Add(baseIndex + 3); uvCoord.Add(uvRect.bottomLeft.toVector()); uvCoord.Add(uvRect.bottomRight.toVector()); uvCoord.Add(uvRect.topRight.toVector()); uvCoord.Add(uvRect.topLeft.toVector()); if (char.IsHighSurrogate(a)) { i++; } } uiMeshMesh meshMesh = uiMeshMesh.create(null, vert, tri, uvCoord); if (_meshes.ContainsKey(key)) { ObjectPool <MeshInfo> .release(_meshes[key]); _meshes.Remove(key); } _meshes[key] = MeshInfo.create(key, meshMesh, 0); this._mesh = meshMesh.transform(this.matrix); return(this._mesh); } var length = this.textBlob.Value.textSize; var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * this.scale); var vertices = ObjectPool <uiList <Vector3> > .alloc(); vertices.SetCapacity(length * 4); var triangles = ObjectPool <uiList <int> > .alloc(); triangles.SetCapacity(length * 6); var uv = ObjectPool <uiList <Vector2> > .alloc(); uv.SetCapacity(length * 4); for (int charIndex = 0; charIndex < length; ++charIndex) { var ch = text[charIndex + this.textBlob.Value.textOffset]; // first char as origin for mesh position var positionX = this.textBlob.Value.getPositionX(charIndex); if (LayoutUtils.isWordSpace(ch) || LayoutUtils.isLineEndSpace(ch) || ch == '\t') { continue; } if (fontSizeToLoad == 0) { continue; } font.getGlyphInfo(ch, out var glyphInfo, fontSizeToLoad, style.UnityFontStyle); var minX = glyphInfo.minX / this.scale; var maxX = glyphInfo.maxX / this.scale; var minY = -glyphInfo.maxY / this.scale; var maxY = -glyphInfo.minY / this.scale; var baseIndex = vertices.Count; vertices.Add(new Vector3(positionX + minX, minY, 0)); vertices.Add(new Vector3(positionX + maxX, minY, 0)); vertices.Add(new Vector3(positionX + maxX, maxY, 0)); vertices.Add(new Vector3(positionX + minX, maxY, 0)); triangles.Add(baseIndex); triangles.Add(baseIndex + 1); triangles.Add(baseIndex + 2); triangles.Add(baseIndex); triangles.Add(baseIndex + 2); triangles.Add(baseIndex + 3); uv.Add(glyphInfo.uvTopLeft); uv.Add(glyphInfo.uvTopRight); uv.Add(glyphInfo.uvBottomRight); uv.Add(glyphInfo.uvBottomLeft); } if (vertices.Count == 0) { this._mesh = null; ObjectPool <uiList <Vector3> > .release(vertices); ObjectPool <uiList <Vector2> > .release(uv); ObjectPool <uiList <int> > .release(triangles); ObjectPool <MeshKey> .release(key); return(null); } uiMeshMesh mesh = vertices.Count > 0 ? uiMeshMesh.create(null, vertices, triangles, uv) : null; if (_meshes.ContainsKey(key)) { ObjectPool <MeshInfo> .release(_meshes[key]); _meshes.Remove(key); } _meshes[key] = MeshInfo.create(key, mesh, fontInfo.textureVersion); this._mesh = mesh.transform(this.matrix); return(this._mesh); }
public void computeStrokeMesh(float strokeWidth, float fringe, StrokeCap lineCap, StrokeJoin lineJoin, float miterLimit) { if (this._strokeMesh != null && this._fillMesh == null && // Ensure that the cached stroke mesh was not calculated in computeFillMesh this._strokeWidth == strokeWidth && this._fringe == fringe && this._lineCap == lineCap && this._lineJoin == lineJoin && this._miterLimit == miterLimit) { return; } var verticesUV = this._expandStroke(strokeWidth, fringe, lineCap, lineJoin, miterLimit); var paths = this._paths; var cindices = 0; for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } if (path.nstroke > 0) { D.assert(path.nstroke >= 2); cindices += (path.nstroke - 2) * 3; } } var indices = ObjectPool <uiList <int> > .alloc(); indices.SetCapacity(cindices); for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } if (path.nstroke > 0) { for (var j = 2; j < path.nstroke; j++) { if ((j & 1) == 0) { indices.Add(path.istroke + j - 1); indices.Add(path.istroke + j - 2); indices.Add(path.istroke + j); } else { indices.Add(path.istroke + j - 2); indices.Add(path.istroke + j - 1); indices.Add(path.istroke + j); } } } } D.assert(indices.Count == cindices); ObjectPool <uiMeshMesh> .release(this._strokeMesh); this._strokeMesh = uiMeshMesh.create(null, verticesUV.strokeVertices, indices, verticesUV.strokeUV); ObjectPool <uiMeshMesh> .release(this._fillMesh); this._fillMesh = null; this._strokeWidth = strokeWidth; this._fringe = fringe; this._lineCap = lineCap; this._lineJoin = lineJoin; this._miterLimit = miterLimit; return; }
public static PictureFlusher.CmdDraw maskFilter(PictureFlusher.RenderLayer layer, uiMeshMesh mesh, PictureFlusher.RenderLayer renderLayer, float radius, Vector2 imgInc, float[] kernel) { Vector4 viewport = layer.viewport; var mat = _filterMat; var pass = 0; var props = ObjectPool <MaterialPropertyBlockWrapper> .alloc(); props.SetVector(_viewportId, viewport); props.SetFloat(_mfRadiusId, radius); props.SetVector(_mfImgIncId, imgInc); props.SetFloatArray(_mfKernelId, kernel); return(PictureFlusher.CmdDraw.create( mesh: mesh, pass: pass, material: mat, properties: props, layerId: renderLayer.rtID )); }
public static PictureFlusher.CmdDraw fastShadow(PictureFlusher.RenderLayer layer, uiMeshMesh mesh, float sigma, bool isRect, bool isCircle, float corner, Vector4 bound, uiColor color) { Vector4 viewport = layer.viewport; var mat = _shadowBox; if (!isRect) { mat = _shadowRBox; } var props = ObjectPool <MaterialPropertyBlockWrapper> .alloc(); props.SetVector(_viewportId, viewport); props.SetFloat(_shadowSigmaId, sigma); props.SetVector(_shadowBoxId, bound); props.SetVector(_shadowColorId, _colorToVector4(color)); if (!isRect) { props.SetFloat(_shadowCornerId, corner); } return(PictureFlusher.CmdDraw.create( mesh: mesh, pass: 0, material: mat, properties: props )); }
void _drawLayer(RenderLayer layer, CommandBuffer cmdBuf) { bool toClear = true; foreach (var cmdObj in layer.draws) { switch (cmdObj) { case CmdLayer cmd: var subLayer = cmd.layer; var desc = new RenderTextureDescriptor( subLayer.width, subLayer.height, RenderTextureFormat.Default, 24) { useMipMap = false, autoGenerateMips = false }; cmdBuf.GetTemporaryRT(subLayer.rtID, desc, subLayer.filterMode); this._drawLayer(subLayer, cmdBuf); break; case CmdDraw cmd: this._setRenderTarget(cmdBuf, layer.rtID, ref toClear); if (cmd.layerId != null) { if (cmd.layerId == 0) { cmdBuf.SetGlobalTexture(CmdDraw.texId, this._renderTexture); } else { cmdBuf.SetGlobalTexture(CmdDraw.texId, cmd.layerId.Value); } } D.assert(cmd.meshObj == null); cmd.meshObj = this._meshPool.getMesh(); cmd.meshObjCreated = true; // clear triangles first in order to bypass validation in SetVertices. cmd.meshObj.SetTriangles((int[])null, 0, false); uiMeshMesh mesh = cmd.mesh; if (cmd.textMesh != null) { mesh = cmd.textMesh.resolveMesh(); } if (mesh == null) { continue; } if (mesh.matrix == null) { cmd.properties.SetFloatArray(CmdDraw.matId, CmdDraw.idMat3.fMat); } else { var mat = mesh.matrix.Value; this._drawLayer_matArray[0] = mat.kMScaleX; this._drawLayer_matArray[1] = mat.kMSkewX; this._drawLayer_matArray[2] = mat.kMTransX; this._drawLayer_matArray[3] = mat.kMSkewY; this._drawLayer_matArray[4] = mat.kMScaleY; this._drawLayer_matArray[5] = mat.kMTransY; this._drawLayer_matArray[6] = mat.kMPersp0; this._drawLayer_matArray[7] = mat.kMPersp1; this._drawLayer_matArray[8] = mat.kMPersp2; cmd.properties.SetFloatArray(CmdDraw.matId, this._drawLayer_matArray); } D.assert(mesh.vertices.Count > 0); if (CanvasShader.supportComputeBuffer) { this._addMeshToComputeBuffer(mesh.vertices?.data, mesh.uv?.data, mesh.triangles?.data); cmd.properties.SetBuffer(CmdDraw.vertexBufferId, _computeBuffer); cmd.properties.SetBuffer(CmdDraw.indexBufferId, _indexBuffer); cmd.properties.SetInt(CmdDraw.startIndexId, _startIndex); cmdBuf.DrawProcedural(Matrix4x4.identity, cmd.material, cmd.pass, MeshTopology.Triangles, mesh.triangles.Count, 1, cmd.properties.mpb); } else { cmd.meshObj.SetVertices(mesh.vertices?.data); cmd.meshObj.SetTriangles(mesh.triangles?.data, 0, false); cmd.meshObj.SetUVs(0, mesh.uv?.data); cmdBuf.DrawMesh(cmd.meshObj, CmdDraw.idMat, cmd.material, 0, cmd.pass, cmd.properties.mpb); } if (cmd.layerId != null) { cmdBuf.SetGlobalTexture(CmdDraw.texId, BuiltinRenderTextureType.None); } break; case CmdScissor cmd: this._setRenderTarget(cmdBuf, layer.rtID, ref toClear); if (cmd.deviceScissor == null) { cmdBuf.DisableScissorRect(); } else { cmdBuf.EnableScissorRect(uiRectHelper.toRect(cmd.deviceScissor.Value)); } break; } } if (toClear) { this._setRenderTarget(cmdBuf, layer.rtID, ref toClear); } D.assert(!toClear); foreach (var subLayer in layer.layers) { cmdBuf.ReleaseTemporaryRT(subLayer.rtID); } }