@@ -58,7 +58,7 @@ typedef struct _plAppData
58
58
// buffers
59
59
plBufferHandle tStagingBuffer ;
60
60
plBufferHandle tIndexBuffer ;
61
- plBufferHandle tVertexBuffer ;
61
+ plBufferHandle atVertexBuffer [ 2 ] ;
62
62
63
63
// textures
64
64
plTextureHandle tTexture ;
@@ -192,33 +192,49 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
192
192
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~vertex buffer~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193
193
194
194
// vertex buffer data
195
- const float atVertexData [] = { // x, y, u, v
196
- -0.5f , -0.5f , 0.0f , 0.0f ,
197
- -0.5f , 0.5f , 0.0f , 1.0f ,
198
- 0.5f , 0.5f , 1.0f , 1.0f ,
199
- 0.5f , -0.5f , 1.0f , 0.0f
195
+ const float atVertexData0 [] = { // x, y
196
+ -0.5f , -0.5f ,
197
+ -0.5f , 0.5f ,
198
+ 0.5f , 0.5f ,
199
+ 0.5f , -0.5f
200
+ };
201
+
202
+ const float atVertexData1 [] = { // u, v
203
+ 0.0f , 0.0f ,
204
+ 0.0f , 1.0f ,
205
+ 1.0f , 1.0f ,
206
+ 1.0f , 0.0f
200
207
};
201
208
202
209
// create vertex buffer
203
210
const plBufferDesc tVertexBufferDesc = {
204
211
.tUsage = PL_BUFFER_USAGE_VERTEX ,
205
- .szByteSize = sizeof (float ) * PL_ARRAYSIZE (atVertexData ),
212
+ .szByteSize = sizeof (float ) * PL_ARRAYSIZE (atVertexData0 ),
206
213
.pcDebugName = "vertex buffer"
207
214
};
208
- ptAppData -> tVertexBuffer = gptGfx -> create_buffer (ptDevice , & tVertexBufferDesc , NULL );
215
+ ptAppData -> atVertexBuffer [0 ] = gptGfx -> create_buffer (ptDevice , & tVertexBufferDesc , NULL );
216
+ ptAppData -> atVertexBuffer [1 ] = gptGfx -> create_buffer (ptDevice , & tVertexBufferDesc , NULL );
209
217
210
218
// retrieve buffer to get memory allocation requirements (do not store buffer pointer)
211
- plBuffer * ptVertexBuffer = gptGfx -> get_buffer (ptDevice , ptAppData -> tVertexBuffer );
219
+ plBuffer * ptVertexBuffer0 = gptGfx -> get_buffer (ptDevice , ptAppData -> atVertexBuffer [0 ]);
220
+ plBuffer * ptVertexBuffer1 = gptGfx -> get_buffer (ptDevice , ptAppData -> atVertexBuffer [1 ]);
212
221
213
222
// allocate memory for the vertex buffer
214
- const plDeviceMemoryAllocation tVertexBufferAllocation = gptGfx -> allocate_memory (ptDevice ,
215
- ptVertexBuffer -> tMemoryRequirements .ulSize ,
223
+ const plDeviceMemoryAllocation tVertexBufferAllocation0 = gptGfx -> allocate_memory (ptDevice ,
224
+ ptVertexBuffer0 -> tMemoryRequirements .ulSize ,
225
+ PL_MEMORY_FLAGS_DEVICE_LOCAL ,
226
+ ptVertexBuffer0 -> tMemoryRequirements .uMemoryTypeBits ,
227
+ "vertex buffer memory" );
228
+
229
+ const plDeviceMemoryAllocation tVertexBufferAllocation1 = gptGfx -> allocate_memory (ptDevice ,
230
+ ptVertexBuffer1 -> tMemoryRequirements .ulSize ,
216
231
PL_MEMORY_FLAGS_DEVICE_LOCAL ,
217
- ptVertexBuffer -> tMemoryRequirements .uMemoryTypeBits ,
232
+ ptVertexBuffer1 -> tMemoryRequirements .uMemoryTypeBits ,
218
233
"vertex buffer memory" );
219
234
220
235
// bind the buffer to the new memory allocation
221
- gptGfx -> bind_buffer_to_memory (ptDevice , ptAppData -> tVertexBuffer , & tVertexBufferAllocation );
236
+ gptGfx -> bind_buffer_to_memory (ptDevice , ptAppData -> atVertexBuffer [0 ], & tVertexBufferAllocation0 );
237
+ gptGfx -> bind_buffer_to_memory (ptDevice , ptAppData -> atVertexBuffer [1 ], & tVertexBufferAllocation1 );
222
238
223
239
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~index buffer~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
224
240
@@ -274,11 +290,13 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
274
290
275
291
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~transfers~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
276
292
277
- memcpy (ptStagingBuffer -> tMemoryAllocation .pHostMapped , atVertexData , sizeof (float ) * PL_ARRAYSIZE (atVertexData ));
293
+ memcpy (ptStagingBuffer -> tMemoryAllocation .pHostMapped , atVertexData0 , sizeof (float ) * PL_ARRAYSIZE (atVertexData0 ));
294
+ memcpy (& ptStagingBuffer -> tMemoryAllocation .pHostMapped [512 ], atVertexData1 , sizeof (float ) * PL_ARRAYSIZE (atVertexData1 ));
278
295
memcpy (& ptStagingBuffer -> tMemoryAllocation .pHostMapped [1024 ], atIndexData , sizeof (uint32_t ) * PL_ARRAYSIZE (atIndexData ));
279
296
280
297
plBlitEncoder * ptEncoder = gptStarter -> get_blit_encoder ();
281
- gptGfx -> copy_buffer (ptEncoder , ptAppData -> tStagingBuffer , ptAppData -> tVertexBuffer , 0 , 0 , sizeof (float ) * PL_ARRAYSIZE (atVertexData ));
298
+ gptGfx -> copy_buffer (ptEncoder , ptAppData -> tStagingBuffer , ptAppData -> atVertexBuffer [0 ], 0 , 0 , sizeof (float ) * PL_ARRAYSIZE (atVertexData0 ));
299
+ gptGfx -> copy_buffer (ptEncoder , ptAppData -> tStagingBuffer , ptAppData -> atVertexBuffer [1 ], 512 , 0 , sizeof (float ) * PL_ARRAYSIZE (atVertexData1 ));
282
300
gptGfx -> copy_buffer (ptEncoder , ptAppData -> tStagingBuffer , ptAppData -> tIndexBuffer , 1024 , 0 , sizeof (uint32_t ) * PL_ARRAYSIZE (atIndexData ));
283
301
284
302
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~textures~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -431,10 +449,17 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
431
449
},
432
450
.atVertexBufferLayouts = {
433
451
{
434
- .uByteStride = sizeof (float ) * 4 ,
452
+ .bExplicitLocation = true,
453
+ .uByteStride = sizeof (float ) * 2 ,
454
+ .atAttributes = {
455
+ {.uByteOffset = 0 , .tFormat = PL_VERTEX_FORMAT_FLOAT2 }
456
+ }
457
+ },
458
+ {
459
+ .bExplicitLocation = true,
460
+ .uByteStride = sizeof (float ) * 2 ,
435
461
.atAttributes = {
436
- {.uByteOffset = 0 , .tFormat = PL_VERTEX_FORMAT_FLOAT2 },
437
- {.uByteOffset = sizeof (float ) * 2 , .tFormat = PL_VERTEX_FORMAT_FLOAT2 },
462
+ {.uLocation = 3 , .uByteOffset = 0 , .tFormat = PL_VERTEX_FORMAT_FLOAT2 }
438
463
}
439
464
}
440
465
},
@@ -474,7 +499,8 @@ pl_app_shutdown(plAppData* ptAppData)
474
499
gptGfx -> flush_device (ptDevice );
475
500
476
501
// cleanup our resources
477
- gptGfx -> destroy_buffer (ptDevice , ptAppData -> tVertexBuffer );
502
+ gptGfx -> destroy_buffer (ptDevice , ptAppData -> atVertexBuffer [0 ]);
503
+ gptGfx -> destroy_buffer (ptDevice , ptAppData -> atVertexBuffer [1 ]);
478
504
gptGfx -> destroy_buffer (ptDevice , ptAppData -> tIndexBuffer );
479
505
gptGfx -> destroy_buffer (ptDevice , ptAppData -> tStagingBuffer );
480
506
gptGfx -> destroy_texture (ptDevice , ptAppData -> tTexture );
@@ -513,7 +539,7 @@ pl_app_update(plAppData* ptAppData)
513
539
514
540
// submit nonindexed draw using basic API
515
541
gptGfx -> bind_shader (ptEncoder , ptAppData -> tShader );
516
- gptGfx -> bind_vertex_buffer (ptEncoder , ptAppData -> tVertexBuffer );
542
+ gptGfx -> bind_vertex_buffers (ptEncoder , 0 , 2 , ptAppData -> atVertexBuffer , NULL );
517
543
518
544
// retrieve dynamic binding data
519
545
// NOTE: This system is meant frequently updated shader data. Underneath its just simple
0 commit comments