comparison semiconginev2/rendering/renderer.nim @ 1240:42eeb59f3a43

add: more tests, line and point rendering
author sam <sam@basx.dev>
date Mon, 22 Jul 2024 12:42:35 +0700
parents 69489a678141
children c15770761865
comparison
equal deleted inserted replaced
1239:69489a678141 1240:42eeb59f3a43
302 302
303 proc AllocateGPUData( 303 proc AllocateGPUData(
304 renderdata: var RenderData, 304 renderdata: var RenderData,
305 bufferType: BufferType, 305 bufferType: BufferType,
306 size: uint64, 306 size: uint64,
307 needsFrameInFlight = -1
308 ): (Buffer, uint64) = 307 ): (Buffer, uint64) =
309 308
310 # find buffer that has space 309 # find buffer that has space
311 var selectedBufferI = -1 310 var selectedBufferI = -1
312 311
313 for i in 0 ..< renderData.buffers[bufferType].len: 312 for i in 0 ..< renderData.buffers[bufferType].len:
314 let buffer = renderData.buffers[bufferType][i] 313 let buffer = renderData.buffers[bufferType][i]
315 if needsFrameInFlight == -1 or buffer.useForFrameInFlight == needsFrameInFlight: 314 if buffer.size - alignedTo(buffer.offsetNextFree, BUFFER_ALIGNMENT) >= size:
316 if buffer.size - alignedTo(buffer.offsetNextFree, BUFFER_ALIGNMENT) >= size: 315 selectedBufferI = i
317 selectedBufferI = i
318 316
319 # otherwise create new buffer 317 # otherwise create new buffer
320 if selectedBufferI < 0: 318 if selectedBufferI < 0:
321 selectedBufferI = renderdata.buffers[bufferType].len 319 selectedBufferI = renderdata.buffers[bufferType].len
322 renderdata.buffers[bufferType].add renderdata.AllocateNewBuffer( 320 renderdata.buffers[bufferType].add renderdata.AllocateNewBuffer(
323 size = max(size, BUFFER_ALLOCATION_SIZE), 321 size = max(size, BUFFER_ALLOCATION_SIZE),
324 bufferType = bufferType, 322 bufferType = bufferType,
325 ) 323 )
326 if needsFrameInFlight >= 0:
327 renderdata.buffers[bufferType][selectedBufferI].useForFrameInFlight = needsFrameInFlight
328 324
329 # assigne value 325 # assigne value
330 let selectedBuffer = renderdata.buffers[bufferType][selectedBufferI] 326 let selectedBuffer = renderdata.buffers[bufferType][selectedBufferI]
331 renderdata.buffers[bufferType][selectedBufferI].offsetNextFree = alignedTo( 327 renderdata.buffers[bufferType][selectedBufferI].offsetNextFree = alignedTo(
332 selectedBuffer.offsetNextFree, 328 selectedBuffer.offsetNextFree,