public void Update(DX11RenderContext context) { if (this.spreadmax == 0) { return; } if (this.FInvalidate || !this.FOutput[0].Contains(context)) { int count = this.ffixed ? this.FCount.IOObject[0] : this.FInData.SliceCount; if (this.FOutput[0].Contains(context)) { if (this.FOutput[0][context].ElementCount != count || this.bufferType != this.FBufferType[0] || this.FOutput[0][context] is DX11ImmutableStructuredBuffer <T> ) { this.FOutput[0].Dispose(context); } } if (this.tempbuffer.Length != count) { Array.Resize <T>(ref this.tempbuffer, count); } //If fixed or if size is the same, we can do a direct copy bool needconvert = ((this.ffixed && count != this.FInData.SliceCount)) || this.NeedConvert; T[] bufferToCopy = this.FInData.Stream.Buffer; int bufferElementCount = this.FInData.SliceCount; if (needconvert) { this.WriteArray(count); bufferToCopy = this.tempbuffer; bufferElementCount = this.tempbuffer.Length; } if (!this.FOutput[0].Contains(context)) { if (count > 0) { if (this.FBufferType[0] == DX11BufferUploadType.Dynamic) { this.FOutput[0][context] = new DX11DynamicStructuredBuffer <T>(context, count); } else if (this.FBufferType[0] == DX11BufferUploadType.Default) { this.FOutput[0][context] = new DX11CopyDestStructuredBuffer <T>(context, count); } else { this.FOutput[0][context] = new DX11ImmutableStructuredBuffer <T>(context.Device, bufferToCopy, bufferToCopy.Length); } this.FValid[0] = true; this.bufferType = this.FBufferType[0]; } else { this.FValid[0] = false; return; } } bool needContextCopy = this.FBufferType[0] != DX11BufferUploadType.Immutable; if (needContextCopy) { try { if (this.FBufferType[0] == DX11BufferUploadType.Dynamic) { DX11DynamicStructuredBuffer <T> b = (DX11DynamicStructuredBuffer <T>) this.FOutput[0][context]; b.WriteData(bufferToCopy, 0, b.ElementCount); } else if (this.FBufferType[0] == DX11BufferUploadType.Default) { DX11CopyDestStructuredBuffer <T> b = (DX11CopyDestStructuredBuffer <T>) this.FOutput[0][context]; b.WriteData(bufferToCopy, 0, b.ElementCount); } } catch (Exception ex) { this.iofactory.PluginHost.Log(TLogType.Error, ex.Message); } } } }
public void Update(DX11RenderContext context) { if (this.FLayerInSpreadMax == 0) { return; } var newContext = !this.FTransformOutput[0].Contains(context); if (this.FInvalidate || newContext) { var bufferTypeChanged = this.currentBufferType != this.FBufferType[0]; //refresh buffers? CheckBufferDispose <Matrix>(context, this.FTransformOutput[0], FTotalTransformCount, bufferTypeChanged); CheckBufferDispose <Color4>(context, this.FColorOutput[0], FTotalColorCount, bufferTypeChanged); CheckBufferDispose <Vector3>(context, this.FSpritesPositionOutput[0], FTotalSpritesPositionCount, bufferTypeChanged); CheckBufferDispose <Vector2>(context, this.FSpritesSizeOutput[0], FTotalSpritesSizeCount, bufferTypeChanged); CheckBufferDispose <Color4>(context, this.FSpritesColorOutput[0], FTotalSpritesColorCount, bufferTypeChanged); PrepareLocalGeometryBufferData(context); PrepareLocalSpriteBufferData(context); //make new buffers? CreateBuffer <Matrix>(FTransformOutput[0], context, FTotalTransformCount, FBufferTrans); CreateBuffer <Color4>(FColorOutput[0], context, FTotalColorCount, FBufferColor); CreateBuffer <Vector3>(FSpritesPositionOutput[0], context, FTotalSpritesPositionCount, FBufferSpritesPosition); CreateBuffer <Vector2>(FSpritesSizeOutput[0], context, FTotalSpritesSizeCount, FBufferSpritesSize); CreateBuffer <Color4>(FSpritesColorOutput[0], context, FTotalSpritesColorCount, FBufferSpritesColor); //if (FTotalTransformCount < 0 || FTotalColorCount < 0) //{ // this.FValid[0] = false; //} } this.FValid[0] = true; this.currentBufferType = this.FBufferType[0]; //write to buffers bool needContextCopy = this.FBufferType[0] != DX11BufferUploadType.Immutable; if (needContextCopy) { try { WriteToBuffer(FTransformOutput[0], context, FBufferTrans, FTotalTransformCount); WriteToBuffer(FColorOutput[0], context, FBufferColor, FTotalColorCount); WriteToBuffer(FSpritesPositionOutput[0], context, FBufferSpritesPosition, FTotalSpritesPositionCount); WriteToBuffer(FSpritesSizeOutput[0], context, FBufferSpritesSize, FTotalSpritesSizeCount); WriteToBuffer(FSpritesColorOutput[0], context, FBufferSpritesColor, FTotalSpritesColorCount); } catch (Exception ex) { this.pluginHost.Log(TLogType.Error, ex.Message); } } }