protected override void WriteBlock(DrawState state, TVertexType[] data, int startIndex, int start, int length, object target) { VertexBuffer buffer = (VertexBuffer)target; state.UnbindBuffer(buffer); #if DEBUG state.Context.PerformanceMonitor.IncreaseCounter(DeviceCounters.VertexBufferByesCopied, Stride * length); #endif DataStream stream = buffer.Lock(startIndex * Stride, length * Stride, LockFlags.None); stream.WriteRange(data); buffer.Unlock(); }
protected override void WriteBlock(DrawState state, TIndexType[] data, int startIndex, int start, int length, object target) { IndexBuffer buffer = (IndexBuffer)target; state.UnbindBuffer(buffer); if (start == 0 && length == ((IndexBuffer)target).Description.Size) { min = default(TIndexType); max = default(TIndexType); } processor(data, length, this); #if DEBUG state.Context.PerformanceMonitor.IncreaseCounter(DeviceCounters.IndexBufferBytesCopied, Stride * length); #endif DataStream stream = buffer.Lock(startIndex * Stride, length * Stride, LockFlags.None); stream.WriteRange(data); buffer.Unlock(); }
protected override void WriteBlock(DrawState state, VertexType[] data, int startIndex, int start, int length, object target, object parent) { state.UnbindBuffer((VertexBuffer)target); if (target is DynamicVertexBuffer) { #if DEBUG state.Application.currentFrame.DynamicVertexBufferByesCopied += Stride * length; #endif SetDataOptions setOp = SetDataOptions.None; #if !XBOX360 if (sequentialWriteFlag) { if (start == 0) { setOp = SetDataOptions.Discard; } else { setOp = SetDataOptions.NoOverwrite; #if DEBUG if (start < previousCopyEnd) { throw new InvalidOperationException("ResourceUsage.DynamicSequential data overwrite detected"); } #endif } #if DEBUG previousCopyEnd = start + length * Stride; #endif } else if (start == 0 && length * Stride == ((DynamicVertexBuffer)target).SizeInBytes) { setOp = SetDataOptions.Discard; } #endif if (IsRawDataVertices) // raw data buffer { ((DynamicVertexBuffer)target).SetData(start, data, startIndex * Stride, length * Stride, 1, setOp); } else { ((DynamicVertexBuffer)target).SetData(start, data, startIndex, length, Stride, setOp); } } else { #if DEBUG state.Application.currentFrame.VertexBufferByesCopied += Stride * length; #endif if (IsRawDataVertices && typeof(VertexType) == typeof(byte)) // raw data buffer { ((VertexBuffer)target).SetData(start, data, startIndex * Stride, length * Stride, 1); } else { ((VertexBuffer)target).SetData(start, data, startIndex, length, Stride); } } }
protected override void WriteBlock(DrawState state, IndexType[] data, int startIndex, int start, int length, object target, object parent) { state.UnbindBuffer((IndexBuffer)target); if (start == 0 && length == ((IndexBuffer)target).SizeInBytes) { min = default(IndexType); max = default(IndexType); } processor(data, length, this); #if !XBOX360 if (target is DynamicIndexBuffer) { #if DEBUG state.Application.currentFrame.DynamicIndexBufferByesCopied += Stride * length; #endif SetDataOptions setOp = SetDataOptions.None; if (sequentialWriteFlag) { if (start == 0) { setOp = SetDataOptions.Discard; } else { setOp = SetDataOptions.NoOverwrite; #if DEBUG if (start < previousCopyEnd) { throw new InvalidOperationException("ResourceUsage.DynamicSequential data overwrite detected"); } #endif } #if DEBUG previousCopyEnd = start + length * Stride; #endif } else if (start == 0 && length * Stride == ((DynamicIndexBuffer)target).SizeInBytes) { setOp = SetDataOptions.Discard; } ((DynamicIndexBuffer)target).SetData(start, data, startIndex, length, setOp); } else #endif { #if DEBUG #if XBOX360 if (target is DynamicIndexBuffer) { state.Application.currentFrame.DynamicIndexBufferByesCopied += Stride * length; } else #endif state.Application.currentFrame.IndexBufferByesCopied += Stride * length; #endif #if XBOX360 int instancingCount = Math.Max(this.instancingCount, 1); //instancing requires data is duplicated over the index buffer multiple times, with an offset //added to each duplication if (instancingCount >= 1 && !convertToInt) { ((IndexBuffer)target).SetData(start, data, startIndex, length); } if (instancingCount > 1) { int max = this.i_max; IndexBufferProcessor.Update(this, out i_min, out i_max); if (max == 0) { if (start != 0 || length * Stride != ((IndexBuffer)target).SizeInBytes / instancingCount / (convertToInt ? 2 : 1)) { throw new ArgumentException("XBOX Instancing error: Instancing requires the first index buffer write to copy the entire buffer"); } } else { if (this.i_max > max) { throw new ArgumentException("XBOX Instancing error: Max index in the index buffer has increased from the first write"); } } //copy in multiple versions of the same indices if (convertToInt) { uint[] buffer = null; try { uint increment = (uint)(this.i_max + 1); buffer = IndexBufferProcessor.BeginLock <uint>(length); //foreach instance copy, make a copy of the data. for (int i = 0; i < instancingCount; i++) { IndexBufferProcessor.CopyIncrementToInt(data, buffer, length, (uint)(increment * i)); ((IndexBuffer)target).SetData(start + length * 4 * i, buffer, startIndex, length); } } finally { IndexBufferProcessor.EndLock <uint>(buffer); } } else { IndexType[] buffer = null; try { uint increment = (uint)(this.i_max + 1); buffer = IndexBufferProcessor.BeginLock <IndexType>(length); //foreach instance copy, make a copy of the data. for (int i = 1; i < instancingCount; i++) { IndexBufferProcessor.CopyIncrement(data, buffer, length, (uint)(increment * i)); ((IndexBuffer)target).SetData(start + length * Stride * i, buffer, startIndex, length); } } finally { IndexBufferProcessor.EndLock <IndexType>(buffer); } } IndexType[] da = new IndexType[((IndexBuffer)target).SizeInBytes / Stride]; ((IndexBuffer)target).GetData(da); da = null; } #else ((IndexBuffer)target).SetData(start, data, startIndex, length); #endif } }