|
|
|
|
|
|
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>(); |
|
|
|