浏览代码

Merge pull request #97 from UnityTech/kgdev

refine canvas.
/main
GitHub 6 年前
当前提交
9634fe27
共有 3 个文件被更改,包括 48 次插入34 次删除
  1. 4
      Runtime/foundation/node.mixin.gen.cs
  2. 4
      Runtime/foundation/node.mixin.njk
  3. 74
      Runtime/ui/painting/canvas_impl.cs

4
Runtime/foundation/node.mixin.gen.cs


static readonly Dictionary<_DependencyList, WeakReference> _canonicalObjects =
new Dictionary<_DependencyList, WeakReference>();
public bool pure { get; set; } // pure = false, if canonicalEquals should not be used.
public bool pureWidget { get; set; } // pure = false, if canonicalEquals should not be used.
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {

return false;
}
if (!this.pure) {
if (!this.pureWidget) {
return ReferenceEquals(this, obj);
} else {
return ReferenceEquals(this._getCanonical(), ((CanonicalMixinDiagnosticableTree) obj)._getCanonical());

4
Runtime/foundation/node.mixin.njk


static readonly Dictionary<_DependencyList, WeakReference> _canonicalObjects =
new Dictionary<_DependencyList, WeakReference>();
public bool alwaysUpdate { get; set; } // if canonicalEquals should not be used.
public bool pureWidget { get; set; } // if canonicalEquals should not be used.
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {

return false;
}
if (!this.pure) {
if (!this.pureWidget) {
return ReferenceEquals(this, obj);
} else {
return ReferenceEquals(this._getCanonical(), ((CanonicalMixin{{with}}) obj)._getCanonical());

74
Runtime/ui/painting/canvas_impl.cs


height = textureHeight,
layerBounds = maskBounds,
filterMode = FilterMode.Bilinear,
noMSAA = true,
};
parentLayer.addLayer(maskLayer);

height = textureHeight,
layerBounds = maskLayer.layerBounds,
filterMode = FilterMode.Bilinear,
noMSAA = true,
};
parentLayer.addLayer(blurXLayer);

height = textureHeight,
layerBounds = maskLayer.layerBounds,
filterMode = FilterMode.Bilinear,
noMSAA = true,
};
parentLayer.addLayer(blurYLayer);

public void flush(Picture picture) {
this._reset();
D.assert(this._layers.Count == 1);
D.assert(this._layers[0].states.Count == 1);

using (var cmdBuf = new CommandBuffer()) {
cmdBuf.name = "CommandBufferCanvas";
this._lastRtID = -1;
// this is necessary for webgl2. not sure why... just to be safe to disable the scissor.
cmdBuf.DisableScissorRect();
void _drawLayer(RenderLayer layer, CommandBuffer cmdBuf) {
if (layer.rtID == 0) {
cmdBuf.SetRenderTarget(this._renderTexture);
cmdBuf.ClearRenderTarget(true, true, UnityEngine.Color.clear);
}
else {
cmdBuf.SetRenderTarget(layer.rtID);
cmdBuf.ClearRenderTarget(true, true, UnityEngine.Color.clear);
}
int _lastRtID;
void _setRenderTarget(CommandBuffer cmdBuf, int rtID, ref bool toClear) {
if (this._lastRtID == rtID) {
return;
}
this._lastRtID = rtID;
if (rtID == 0) {
cmdBuf.SetRenderTarget(this._renderTexture);
} else {
cmdBuf.SetRenderTarget(rtID);
}
if (toClear) {
cmdBuf.ClearRenderTarget(true, true, UnityEngine.Color.clear);
toClear = false;
}
}
void _drawLayer(RenderLayer layer, CommandBuffer cmdBuf) {
bool toClear = true;
foreach (var cmdObj in layer.draws) {
foreach (var cmdObj in layer.draws) {
switch (cmdObj) {
case CmdLayer cmd:
var subLayer = cmd.layer;

useMipMap = false,
autoGenerateMips = false,
};
if (this._renderTexture.antiAliasing != 0) {
if (this._renderTexture.antiAliasing != 0 && !subLayer.noMSAA) {
if (layer.rtID == 0) {
cmdBuf.SetRenderTarget(this._renderTexture);
}
else {
cmdBuf.SetRenderTarget(layer.rtID);
}
this._setRenderTarget(cmdBuf, layer.rtID, ref toClear);
if (cmd.layer != null) {
if (cmd.layer.rtID == 0) {
cmdBuf.SetGlobalTexture(CmdDraw.texId, this._renderTexture);

if (mesh == null) {
continue;
}
D.assert(mesh.vertices.Count > 0);
D.assert(mesh.vertices.Count > 0);
cmd.meshObj.SetVertices(mesh.vertices);
cmd.meshObj.SetTriangles(mesh.triangles, 0, false);
cmd.meshObj.SetUVs(0, mesh.uv);

foreach (var subLayer in layer.layers) {
cmdBuf.ReleaseTemporaryRT(subLayer.rtID);
}
if (layer.rtID == 0) {
// this is necessary for webgl2. not sure why... just to be safe to disable the scissor.
cmdBuf.DisableScissorRect();
}
}
void _clearLayer(RenderLayer layer) {

public int width;
public int height;
public FilterMode filterMode = FilterMode.Point;
public bool noMSAA = false;
public Rect layerBounds;
public Paint layerPaint;
public readonly List<object> draws = new List<object>();

正在加载...
取消
保存