public void LimitVertexBuffers(int vertexCount) { // Is it possible for the draw to fetch outside the bounds of any vertex buffer currently bound? if (vertexCount <= _minVertexCount) { return; } // If the draw can fetch out of bounds, let's ensure that it will only fetch zeros rather than memory garbage. int currentTempVbOffset = 0; uint buffersInUse = _vertexBuffersInUse; while (buffersInUse != 0) { int vbIndex = BitOperations.TrailingZeroCount(buffersInUse); ref var vb = ref _vertexBuffers[vbIndex]; int requiredSize = vertexCount * vb.Stride; if (vb.Buffer.Size < requiredSize) { BufferHandle tempVertexBuffer = EnsureTempVertexBufferSize(currentTempVbOffset + requiredSize); Buffer.Copy(vb.Buffer.Handle, tempVertexBuffer, vb.Buffer.Offset, currentTempVbOffset, vb.Buffer.Size); Buffer.Clear(tempVertexBuffer, currentTempVbOffset + vb.Buffer.Size, requiredSize - vb.Buffer.Size, 0); GL.BindVertexBuffer(vbIndex, tempVertexBuffer.ToInt32(), (IntPtr)currentTempVbOffset, vb.Stride); currentTempVbOffset += requiredSize; _vertexBuffersLimited |= 1u << vbIndex; } buffersInUse &= ~(1u << vbIndex); }
public void ClearBuffer(BufferHandle destination, int offset, int size, uint value) { Buffer.Clear(destination, offset, size, value); }