Implement Utah teapot model loading
This commit is contained in:
1 parent
f546f27a42
commit
620cf7606b
8 files changed
+303
-48
No files matched your search
@@ -144,7 +144,7 @@ static void load_buffer(
|
||||
vkFreeCommandBuffers(ctx->dev, cmd_pool, 1, &cmd_buf);
|
||||
}
|
||||
|
||||
void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config)
|
||||
void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
|
||||
{
|
||||
// Initialise Vulkan instance.
|
||||
const VkApplicationInfo app_info = {
|
||||
@@ -428,7 +428,7 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config)
|
||||
.binding = 0,
|
||||
.location = 1,
|
||||
.format = VK_FORMAT_R32G32B32_SFLOAT,
|
||||
.offset = offsetof(vertex_t, colour),
|
||||
.offset = offsetof(vertex_t, normal),
|
||||
},
|
||||
};
|
||||
const VkPipelineVertexInputStateCreateInfo vertex_input_config = {
|
||||
@@ -658,23 +658,24 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config)
|
||||
assert(result == VK_SUCCESS);
|
||||
|
||||
// Set up staging, vertex and index buffers
|
||||
ctx->index_count = config->index_data_size / sizeof(*config->index_data);
|
||||
const size_t vertex_data_size = model.vertex_count * sizeof(vertex_t);
|
||||
const size_t index_data_size = model.index_count * sizeof(vertex_t);
|
||||
ctx->index_count = model.index_count;
|
||||
VkBuffer staging_buf;
|
||||
VkDeviceMemory staging_buf_mem;
|
||||
const size_t staging_buf_size
|
||||
= MAX(config->vertex_data_size, config->index_data_size);
|
||||
const size_t staging_buf_size = MAX(vertex_data_size, index_data_size);
|
||||
create_buffer(
|
||||
ctx, staging_buf_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
||||
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||
&staging_buf, &staging_buf_mem);
|
||||
create_buffer(
|
||||
ctx, config->vertex_data_size,
|
||||
ctx, vertex_data_size,
|
||||
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &ctx->vertex_buf,
|
||||
&ctx->vertex_buf_mem);
|
||||
create_buffer(
|
||||
ctx, config->index_data_size,
|
||||
ctx, index_data_size,
|
||||
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &ctx->index_buf,
|
||||
&ctx->index_buf_mem);
|
||||
@@ -692,11 +693,11 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config)
|
||||
|
||||
// Load vertex and index data
|
||||
load_buffer(
|
||||
ctx, ctx->vertex_buf, config->vertex_data, config->vertex_data_size,
|
||||
staging_buf, staging_buf_mem, transient_cmd_pool);
|
||||
ctx, ctx->vertex_buf, model.vertices, vertex_data_size, staging_buf,
|
||||
staging_buf_mem, transient_cmd_pool);
|
||||
load_buffer(
|
||||
ctx, ctx->index_buf, config->index_data, config->index_data_size,
|
||||
staging_buf, staging_buf_mem, transient_cmd_pool);
|
||||
ctx, ctx->index_buf, model.indices, index_data_size, staging_buf,
|
||||
staging_buf_mem, transient_cmd_pool);
|
||||
|
||||
// Clean up staging buffer and transient command pool
|
||||
vkDestroyCommandPool(ctx->dev, transient_cmd_pool, nullptr);
|
||||
|
||||
Reference in new issue
Block a user