main
noah metz 2024-11-04 00:44:21 -07:00
parent 75b834a0f7
commit 1d85024a6a
3 changed files with 16 additions and 67 deletions

@ -44,7 +44,6 @@ typedef struct HexContextStruct {
VmaAllocation context_memory; VmaAllocation context_memory;
GraphicsPipeline graphics; GraphicsPipeline graphics;
ComputePipeline compute;
HexRegion regions[MAX_LOADED_REGIONS]; HexRegion regions[MAX_LOADED_REGIONS];

@ -9,48 +9,10 @@ VkResult create_hex_context(
HexContext* context) { HexContext* context) {
VkResult result; VkResult result;
// Compute Pipeline
VkShaderModule compute_shader = load_shader_file("shader/hex.comp.spv", gpu->device);
if(compute_shader == VK_NULL_HANDLE) {
return VK_ERROR_UNKNOWN;
}
VkPipelineShaderStageCreateInfo compute_shader_stage = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_COMPUTE_BIT,
.pName = "main",
.module = compute_shader,
};
VkPushConstantRange compute_push = {
.size = sizeof(HexPushConstant),
.offset = 0,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
};
VkPipelineLayoutCreateInfo compute_layout_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.pPushConstantRanges = &compute_push,
.pushConstantRangeCount = 1,
};
VK_RESULT(vkCreatePipelineLayout(gpu->device, &compute_layout_info, NULL, &context->compute.layout));
VkComputePipelineCreateInfo compute_pipeline_info = {
.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
.stage = compute_shader_stage,
.layout = context->compute.layout,
};
VK_RESULT(vkCreateComputePipelines(gpu->device, VK_NULL_HANDLE, 1, &compute_pipeline_info, NULL, &context->compute.pipeline));
// Graphics Pipeline
VkShaderModule vert_shader = load_shader_file("shader/hex.vert.spv", gpu->device); VkShaderModule vert_shader = load_shader_file("shader/hex.vert.spv", gpu->device);
VkShaderModule frag_shader = load_shader_file("shader/hex.frag.spv", gpu->device); VkShaderModule frag_shader = load_shader_file("shader/hex.frag.spv", gpu->device);
VkPipelineShaderStageCreateInfo graphics_stages[] = { VkPipelineShaderStageCreateInfo stages[] = {
{ {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_VERTEX_BIT, .stage = VK_SHADER_STAGE_VERTEX_BIT,
@ -65,19 +27,19 @@ VkResult create_hex_context(
}, },
}; };
VkPushConstantRange graphics_push = { VkPushConstantRange push = {
.size = sizeof(HexPushConstant), .size = sizeof(HexPushConstant),
.offset = 0, .offset = 0,
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT, .stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
}; };
VkPipelineLayoutCreateInfo graphics_layout_info = { VkPipelineLayoutCreateInfo layout_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.pPushConstantRanges = &graphics_push, .pPushConstantRanges = &push,
.pushConstantRangeCount = 1, .pushConstantRangeCount = 1,
}; };
VK_RESULT(vkCreatePipelineLayout(gpu->device, &graphics_layout_info, NULL, &context->graphics.layout)); VK_RESULT(vkCreatePipelineLayout(gpu->device, &layout_info, NULL, &context->graphics.layout));
VkPipelineVertexInputStateCreateInfo vertex_info = { VkPipelineVertexInputStateCreateInfo vertex_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
@ -177,8 +139,8 @@ VkResult create_hex_context(
VkGraphicsPipelineCreateInfo graphics_pipeline_info = { VkGraphicsPipelineCreateInfo graphics_pipeline_info = {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.layout = context->graphics.layout, .layout = context->graphics.layout,
.stageCount = sizeof(graphics_stages)/sizeof(VkPipelineShaderStageCreateInfo), .stageCount = sizeof(stages)/sizeof(VkPipelineShaderStageCreateInfo),
.pStages = graphics_stages, .pStages = stages,
.pVertexInputState = &vertex_info, .pVertexInputState = &vertex_info,
.pInputAssemblyState = &input_info, .pInputAssemblyState = &input_info,
.pViewportState = &viewport_info, .pViewportState = &viewport_info,

@ -117,26 +117,6 @@ VkResult main_thread(ClientContext* context) {
} }
} }
context->position[0] = 0;
context->position[1] = 0;
context->position[2] = 0;
context->rotation[0] = 3*M_PI/2;
context->rotation[1] = M_PI/4;
context->cur_spin[0] = 0;
context->cur_spin[1] = 0;
context->key_spin[0] = 0;
context->key_spin[1] = 0;
context->cur_spin[0] = 0;
context->cur_spin[1] = 0;
context->distance = 25;
context->zoom = 0;
context->camera_mode = false;
context->key_spin_speed = 1.0;
context->cur_spin_speed = 1.0;
context->zoom_speed = 1.0;
// //
uint32_t* mapped_codes = context->ui->containers[0].layers[0].codes_buffer; uint32_t* mapped_codes = context->ui->containers[0].layers[0].codes_buffer;
GPUString* mapped_string = context->ui->containers[0].layers[0].strings_buffer; GPUString* mapped_string = context->ui->containers[0].layers[0].strings_buffer;
@ -148,6 +128,7 @@ VkResult main_thread(ClientContext* context) {
double frame_time = glfwGetTime(); double frame_time = glfwGetTime();
double delta_time = (frame_time - last_frame_time); double delta_time = (frame_time - last_frame_time);
// Reset callback variables
context->clicked_element = 0x00000000; context->clicked_element = 0x00000000;
context->clicked_container = 0x00000000; context->clicked_container = 0x00000000;
context->clicked_hex[0] = 0; context->clicked_hex[0] = 0;
@ -395,6 +376,13 @@ int main() {
.ui = malloc(sizeof(UIContext)), .ui = malloc(sizeof(UIContext)),
.hex = malloc(sizeof(HexContext)), .hex = malloc(sizeof(HexContext)),
.window = init_window(), .window = init_window(),
.position = {0, 0, 0},
.rotation = {3*M_PI/2, M_PI/4},
.distance = 25,
.key_spin_speed = 1.0,
.cur_spin_speed = 1.0,
.zoom_speed = 1.0,
}; };
if(context.window == NULL || context.render == NULL || context.ui == NULL || context.hex == NULL) { if(context.window == NULL || context.render == NULL || context.ui == NULL || context.hex == NULL) {
return VK_ERROR_OUT_OF_HOST_MEMORY; return VK_ERROR_OUT_OF_HOST_MEMORY;