@@ -38,7 +38,7 @@ public abstract class Buffer<T>(BufferTarget target, BufferUsageHint usageHint,
3838 public int Count { get ; private set ; }
3939 public int Capacity { get ; private set ; }
4040
41- private bool _bInitialized ;
41+ protected bool IsAllocated ;
4242 private readonly Dictionary < int , BufferAllocationMetadata > _allocations = new ( ) ;
4343 private readonly SortedSet < FreeBlock > _freeBlocks = new ( Comparer < FreeBlock > . Create ( ( a , b ) =>
4444 {
@@ -52,12 +52,12 @@ public abstract class Buffer<T>(BufferTarget target, BufferUsageHint usageHint,
5252
5353 public override void Generate ( )
5454 {
55- if ( _bInitialized )
55+ if ( IsAllocated )
5656 throw new InvalidOperationException ( "Buffer is already initialized." ) ;
5757
5858 GL . CreateBuffers ( 1 , out uint handle ) ;
5959 Handle = handle ;
60- _bInitialized = false ;
60+ IsAllocated = false ;
6161 }
6262
6363 public void Bind ( )
@@ -78,11 +78,11 @@ private void ResizeIfNeeded(int newSize, double factor = 1.5, bool copy = false)
7878 var oldCapacity = Capacity ;
7979 Capacity = ( int ) Math . Max ( Capacity * factor , newSize ) ;
8080
81- if ( _bInitialized )
81+ if ( IsAllocated )
8282 {
8383 Log . Warning ( "Resizing buffer {0} ({1}) from {2} to {3} (asked: {4}) (initialized!!!!!!)" , Handle , PName , oldCapacity , Capacity , newSize ) ;
8484
85- _bInitialized = false ;
85+ IsAllocated = false ;
8686 if ( copy )
8787 {
8888 var oldBuffer = Handle ;
@@ -109,15 +109,15 @@ private void ResizeIfNeeded(int newSize, double factor = 1.5, bool copy = false)
109109
110110 public void Reallocate ( int size )
111111 {
112- _bInitialized = false ;
112+ IsAllocated = false ;
113113 Allocate ( size ) ;
114114 }
115115
116116 public void Allocate ( uint size ) => Allocate ( ( int ) size ) ;
117117 public void Allocate ( int size )
118118 {
119119 ArgumentOutOfRangeException . ThrowIfNegativeOrZero ( size ) ;
120- if ( _bInitialized )
120+ if ( IsAllocated )
121121 throw new InvalidOperationException ( "Buffer is already initialized. Use Update method to modify data." ) ;
122122
123123 if ( size > Capacity )
@@ -133,7 +133,7 @@ public void Allocate(int size)
133133 // _allocationIdCounter = 0;
134134 // _allocations.Clear();
135135 // _freeBlocks.Clear();
136- _bInitialized = true ;
136+ IsAllocated = true ;
137137 }
138138
139139 public BufferAllocation Add ( T data ) => AddInternal ( [ data ] ) ;
@@ -143,7 +143,7 @@ private BufferAllocation AddInternal(T[] data)
143143 var length = data . Length ;
144144 ArgumentOutOfRangeException . ThrowIfNegativeOrZero ( length ) ;
145145
146- if ( ! _bInitialized )
146+ if ( ! IsAllocated )
147147 {
148148 Allocate ( length ) ;
149149 }
@@ -176,7 +176,7 @@ private void UpsertInternal(int index, T[] data)
176176 ArgumentOutOfRangeException . ThrowIfNegativeOrZero ( length ) ;
177177 ArgumentOutOfRangeException . ThrowIfNegative ( index ) ;
178178
179- if ( ! _bInitialized )
179+ if ( ! IsAllocated )
180180 {
181181 Allocate ( index + length ) ;
182182 }
@@ -196,7 +196,7 @@ private void UpsertInternal(int index, T[] data)
196196 public void Update ( int allocationId , T [ ] data ) => UpdateInternal ( allocationId , data ) ;
197197 private void UpdateInternal ( int allocationId , T [ ] data , bool batched = false )
198198 {
199- if ( ! _bInitialized )
199+ if ( ! IsAllocated )
200200 throw new InvalidOperationException ( "Buffer is not initialized. Use Add method to initialize it." ) ;
201201
202202 if ( ! _allocations . TryGetValue ( allocationId , out var metadata ) )
@@ -215,7 +215,7 @@ private void UpdateInternal(int allocationId, T[] data, bool batched = false)
215215 public void UpdateCustom < TCustom > ( BufferAllocation allocation , TCustom data , int offset ) where TCustom : unmanaged => UpdateCustomInternal ( allocation . AllocationId , data , offset ) ;
216216 private void UpdateCustomInternal < TCustom > ( int allocationId , TCustom data , int offset ) where TCustom : unmanaged
217217 {
218- if ( ! _bInitialized )
218+ if ( ! IsAllocated )
219219 throw new InvalidOperationException ( "Buffer is not initialized. Use Add method to initialize it." ) ;
220220
221221 if ( ! _allocations . TryGetValue ( allocationId , out var metadata ) )
@@ -304,7 +304,7 @@ public BufferAllocation CopyFrom(Buffer<T> sourceBuffer, BufferAllocation source
304304 var length = sourceAllocation . Length ;
305305 ArgumentOutOfRangeException . ThrowIfNegativeOrZero ( length ) ;
306306
307- if ( ! _bInitialized )
307+ if ( ! IsAllocated )
308308 {
309309 Allocate ( length ) ;
310310 }
@@ -326,7 +326,7 @@ public BufferAllocation CopyFrom(Buffer<T> sourceBuffer, BufferAllocation source
326326
327327 public void Clear ( )
328328 {
329- if ( ! _bInitialized )
329+ if ( ! IsAllocated )
330330 throw new InvalidOperationException ( "Cannot clear a buffer that is not initialized." ) ;
331331
332332 ClearStorage ( 0 , TotalElements * Stride ) ;
0 commit comments