Load bone matrices for each frame
This commit is contained in:
1 parent
74309be52c
commit
8bd595989d
3 files changed
+13
-5
No files matched your search
@@ -145,6 +145,9 @@ static void load_buffer(
|
|||||||
|
|
||||||
void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
|
void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
|
||||||
{
|
{
|
||||||
|
ctx->index_count = model.index_count;
|
||||||
|
ctx->bone_count = model.bone_count;
|
||||||
|
|
||||||
// Initialise Vulkan instance.
|
// Initialise Vulkan instance.
|
||||||
const VkApplicationInfo app_info = {
|
const VkApplicationInfo app_info = {
|
||||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||||
@@ -776,7 +779,6 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
|
|||||||
// Set up staging, vertex and index buffers
|
// Set up staging, vertex and index buffers
|
||||||
const size_t vertex_data_size = model.vertex_count * sizeof(vertex_t);
|
const size_t vertex_data_size = model.vertex_count * sizeof(vertex_t);
|
||||||
const size_t index_data_size = model.index_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;
|
VkBuffer staging_buf;
|
||||||
VkDeviceMemory staging_buf_mem;
|
VkDeviceMemory staging_buf_mem;
|
||||||
const size_t staging_buf_size = MAX(vertex_data_size, index_data_size);
|
const size_t staging_buf_size = MAX(vertex_data_size, index_data_size);
|
||||||
@@ -869,7 +871,8 @@ void gpu_cleanup(const gpu_ctx_t *ctx)
|
|||||||
vkDestroyInstance(ctx->inst, nullptr);
|
vkDestroyInstance(ctx->inst, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpu_render(const gpu_ctx_t *ctx, const mvp_t *mvp)
|
void gpu_render(
|
||||||
|
const gpu_ctx_t *ctx, const mvp_t *mvp, const mat4_t *bone_matrices)
|
||||||
{
|
{
|
||||||
VkResult result;
|
VkResult result;
|
||||||
|
|
||||||
@@ -884,8 +887,11 @@ void gpu_render(const gpu_ctx_t *ctx, const mvp_t *mvp)
|
|||||||
&img_index);
|
&img_index);
|
||||||
assert(result == VK_SUCCESS);
|
assert(result == VK_SUCCESS);
|
||||||
|
|
||||||
// Copy MVP matricies into uniform buffer for this image
|
// Copy MVP and bone matricies into uniform buffer for this image
|
||||||
memcpy(ctx->mvps + img_index, mvp, sizeof(mvp_t));
|
memcpy(ctx->mvps + img_index, mvp, sizeof(mvp_t));
|
||||||
|
memcpy(
|
||||||
|
ctx->bone_matrices + (ctx->bone_count * img_index), bone_matrices,
|
||||||
|
ctx->bone_count * sizeof(mat4_t));
|
||||||
|
|
||||||
// Reset command buffer, then begin writing
|
// Reset command buffer, then begin writing
|
||||||
vkResetCommandBuffer(ctx->cmd_buf, 0);
|
vkResetCommandBuffer(ctx->cmd_buf, 0);
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ typedef struct {
|
|||||||
VkBuffer index_buf;
|
VkBuffer index_buf;
|
||||||
VkDeviceMemory index_buf_mem;
|
VkDeviceMemory index_buf_mem;
|
||||||
size_t index_count;
|
size_t index_count;
|
||||||
|
size_t bone_count;
|
||||||
} gpu_ctx_t;
|
} gpu_ctx_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -62,6 +63,7 @@ typedef struct {
|
|||||||
|
|
||||||
void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model);
|
void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model);
|
||||||
void gpu_cleanup(const gpu_ctx_t *ctx);
|
void gpu_cleanup(const gpu_ctx_t *ctx);
|
||||||
void gpu_render(const gpu_ctx_t *ctx, const mvp_t *mvp);
|
void gpu_render(
|
||||||
|
const gpu_ctx_t *ctx, const mvp_t *mvp, const mat4_t *bone_matrices);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in new issue
Block a user