Skip to content

Commit f62ab45

Browse files
WIP
1 parent ce76b68 commit f62ab45

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

examples/example_gfx_2.c

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef struct _plAppData
5858
// buffers
5959
plBufferHandle tStagingBuffer;
6060
plBufferHandle tIndexBuffer;
61-
plBufferHandle tVertexBuffer;
61+
plBufferHandle atVertexBuffer[2];
6262

6363
// textures
6464
plTextureHandle tTexture;
@@ -192,33 +192,49 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
192192
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~vertex buffer~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193193

194194
// 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
200207
};
201208

202209
// create vertex buffer
203210
const plBufferDesc tVertexBufferDesc = {
204211
.tUsage = PL_BUFFER_USAGE_VERTEX,
205-
.szByteSize = sizeof(float) * PL_ARRAYSIZE(atVertexData),
212+
.szByteSize = sizeof(float) * PL_ARRAYSIZE(atVertexData0),
206213
.pcDebugName = "vertex buffer"
207214
};
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);
209217

210218
// 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]);
212221

213222
// 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,
216231
PL_MEMORY_FLAGS_DEVICE_LOCAL,
217-
ptVertexBuffer->tMemoryRequirements.uMemoryTypeBits,
232+
ptVertexBuffer1->tMemoryRequirements.uMemoryTypeBits,
218233
"vertex buffer memory");
219234

220235
// 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);
222238

223239
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~index buffer~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
224240

@@ -274,11 +290,13 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
274290

275291
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~transfers~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
276292

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));
278295
memcpy(&ptStagingBuffer->tMemoryAllocation.pHostMapped[1024], atIndexData, sizeof(uint32_t) * PL_ARRAYSIZE(atIndexData));
279296

280297
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));
282300
gptGfx->copy_buffer(ptEncoder, ptAppData->tStagingBuffer, ptAppData->tIndexBuffer, 1024, 0, sizeof(uint32_t) * PL_ARRAYSIZE(atIndexData));
283301

284302
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~textures~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -431,10 +449,17 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
431449
},
432450
.atVertexBufferLayouts = {
433451
{
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,
435461
.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}
438463
}
439464
}
440465
},
@@ -474,7 +499,8 @@ pl_app_shutdown(plAppData* ptAppData)
474499
gptGfx->flush_device(ptDevice);
475500

476501
// 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]);
478504
gptGfx->destroy_buffer(ptDevice, ptAppData->tIndexBuffer);
479505
gptGfx->destroy_buffer(ptDevice, ptAppData->tStagingBuffer);
480506
gptGfx->destroy_texture(ptDevice, ptAppData->tTexture);
@@ -513,7 +539,7 @@ pl_app_update(plAppData* ptAppData)
513539

514540
// submit nonindexed draw using basic API
515541
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);
517543

518544
// retrieve dynamic binding data
519545
// NOTE: This system is meant frequently updated shader data. Underneath its just simple

examples/shaders/example_gfx_2.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// input
55
layout(location = 0) in vec2 inPos;
6-
layout(location = 1) in vec2 inUV;
6+
layout(location = 3) in vec2 inUV;
77

88
// output
99
layout(location = 0) out struct plShaderOut {

0 commit comments

Comments
 (0)