Add texture handler
Added functionality to load images as textures and bind them to meshes.
This commit is contained in:
1 parent
0e040dd0d5
commit
4fcda01ba2
24 files changed
+897
-200
No files matched your search
@@ -72,7 +72,7 @@ static VkVertexInputBindingDescription get_binding_description()
|
||||
|
||||
static VkVertexInputAttributeDescription* get_attribute_descriptions()
|
||||
{
|
||||
static VkVertexInputAttributeDescription attributeDescriptions[2];
|
||||
static VkVertexInputAttributeDescription attributeDescriptions[3];
|
||||
|
||||
attributeDescriptions[0].binding = 0;
|
||||
attributeDescriptions[0].location = 0; /* inPosition in shader.vert */
|
||||
@@ -84,6 +84,11 @@ static VkVertexInputAttributeDescription* get_attribute_descriptions()
|
||||
attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
attributeDescriptions[1].offset = offsetof(struct rse_vertex_t, color);
|
||||
|
||||
attributeDescriptions[2].binding = 0;
|
||||
attributeDescriptions[2].location = 2; /* inTexCoords in shader.vert */
|
||||
attributeDescriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
|
||||
attributeDescriptions[2].offset = offsetof(struct rse_vertex_t, tex_coords);
|
||||
|
||||
return attributeDescriptions;
|
||||
}
|
||||
|
||||
@@ -258,7 +263,9 @@ uint8_t create_render_pass()
|
||||
uint8_t create_descriptor_set_layout()
|
||||
{
|
||||
VkDescriptorSetLayoutCreateInfo layout_info = {};
|
||||
VkDescriptorSetLayoutBinding bindings[2];
|
||||
VkDescriptorSetLayoutBinding ubo_layout_binding = {};
|
||||
VkDescriptorSetLayoutBinding sampler_layout_binding = {};
|
||||
|
||||
ubo_layout_binding.binding = 0;
|
||||
ubo_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
@@ -266,11 +273,19 @@ uint8_t create_descriptor_set_layout()
|
||||
ubo_layout_binding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
ubo_layout_binding.pImmutableSamplers = NULL;
|
||||
|
||||
sampler_layout_binding.binding = 1;
|
||||
sampler_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
sampler_layout_binding.descriptorCount = 1;
|
||||
sampler_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
sampler_layout_binding.pImmutableSamplers = NULL;
|
||||
|
||||
bindings[0] = ubo_layout_binding;
|
||||
bindings[1] = sampler_layout_binding;
|
||||
layout_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||
layout_info.pNext = NULL;
|
||||
layout_info.flags = 0U;
|
||||
layout_info.bindingCount = 1U;
|
||||
layout_info.pBindings = &ubo_layout_binding;
|
||||
layout_info.bindingCount = 2U;
|
||||
layout_info.pBindings = bindings;
|
||||
|
||||
if (vkCreateDescriptorSetLayout(g_vulkan_state.device, &layout_info, NULL, &g_vulkan_state.descriptor_set_layout) != VK_SUCCESS) {
|
||||
LOGF(vulkan_error_messages[VULKAN_DESCRIPTORSETLAYOUT_CREATION_FAILED]);
|
||||
@@ -440,22 +455,22 @@ void cleanup_swapchain()
|
||||
static uint8_t fill_shader_stages(VkPipelineShaderStageCreateInfo* shader_stages)
|
||||
{
|
||||
char* buffer;
|
||||
size_t buffer_size;
|
||||
long buffer_size;
|
||||
VkShaderModule vertex_shader_module;
|
||||
VkShaderModule fragments_shader_module;
|
||||
VkPipelineShaderStageCreateInfo vert_shader_stage_info = {};
|
||||
VkPipelineShaderStageCreateInfo frag_shader_stage_info = {};
|
||||
|
||||
read_file(g_shader_paths[VERTEX], &buffer_size, NULL);
|
||||
rse_read_file(g_shader_paths[VERTEX], &buffer_size, NULL);
|
||||
buffer = malloc(buffer_size);
|
||||
read_file(g_shader_paths[VERTEX], &buffer_size, buffer);
|
||||
rse_read_file(g_shader_paths[VERTEX], &buffer_size, buffer);
|
||||
|
||||
vertex_shader_module = create_shader_module(buffer, buffer_size);
|
||||
free(buffer);
|
||||
|
||||
read_file(g_shader_paths[FRAGMENTS], &buffer_size, NULL);
|
||||
rse_read_file(g_shader_paths[FRAGMENTS], &buffer_size, NULL);
|
||||
buffer = malloc(buffer_size);
|
||||
read_file(g_shader_paths[FRAGMENTS], &buffer_size, buffer);
|
||||
rse_read_file(g_shader_paths[FRAGMENTS], &buffer_size, buffer);
|
||||
|
||||
fragments_shader_module = create_shader_module(buffer, buffer_size);
|
||||
free(buffer);
|
||||
@@ -539,7 +554,7 @@ void fill_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_input_i
|
||||
VkVertexInputBindingDescription vertex_binding_description = get_binding_description();
|
||||
VkVertexInputAttributeDescription* vertex_attribute_descriptions = get_attribute_descriptions();
|
||||
VkVertexInputBindingDescription* bindingDescriptions = malloc(sizeof(VkVertexInputBindingDescription) * 2);
|
||||
VkVertexInputAttributeDescription* attributeDescriptions = malloc(sizeof(VkVertexInputAttributeDescription) * 5);
|
||||
VkVertexInputAttributeDescription* attributeDescriptions = malloc(sizeof(VkVertexInputAttributeDescription) * 6);
|
||||
|
||||
bindingDescriptions[0] = vertex_binding_description;
|
||||
|
||||
@@ -547,22 +562,22 @@ void fill_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_input_i
|
||||
bindingDescriptions[1].stride = sizeof(struct rse_instance_data_t); //TODO: change
|
||||
bindingDescriptions[1].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
|
||||
|
||||
memcpy(attributeDescriptions, vertex_attribute_descriptions, sizeof(VkVertexInputAttributeDescription) * 2);
|
||||
|
||||
attributeDescriptions[2].binding = 1;
|
||||
attributeDescriptions[2].location = 2;
|
||||
attributeDescriptions[2].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
attributeDescriptions[2].offset = offsetof(struct rse_instance_data_t, pos);
|
||||
memcpy(attributeDescriptions, vertex_attribute_descriptions, sizeof(VkVertexInputAttributeDescription) * 3);
|
||||
|
||||
attributeDescriptions[3].binding = 1;
|
||||
attributeDescriptions[3].location = 3;
|
||||
attributeDescriptions[3].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
attributeDescriptions[3].offset = offsetof(struct rse_instance_data_t, rot);
|
||||
attributeDescriptions[3].offset = offsetof(struct rse_instance_data_t, pos);
|
||||
|
||||
attributeDescriptions[4].binding = 1;
|
||||
attributeDescriptions[4].location = 4;
|
||||
attributeDescriptions[4].format = VK_FORMAT_R32_SFLOAT;
|
||||
attributeDescriptions[4].offset = offsetof(struct rse_instance_data_t, scale);
|
||||
attributeDescriptions[4].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
attributeDescriptions[4].offset = offsetof(struct rse_instance_data_t, rot);
|
||||
|
||||
attributeDescriptions[5].binding = 1;
|
||||
attributeDescriptions[5].location = 5;
|
||||
attributeDescriptions[5].format = VK_FORMAT_R32_SFLOAT;
|
||||
attributeDescriptions[5].offset = offsetof(struct rse_instance_data_t, scale);
|
||||
// ************************
|
||||
|
||||
vertex_input_info->sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||
@@ -571,7 +586,7 @@ void fill_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_input_i
|
||||
|
||||
vertex_input_info->vertexBindingDescriptionCount = 2U;
|
||||
vertex_input_info->pVertexBindingDescriptions = bindingDescriptions;
|
||||
vertex_input_info->vertexAttributeDescriptionCount = 5U;
|
||||
vertex_input_info->vertexAttributeDescriptionCount = 6U;
|
||||
vertex_input_info->pVertexAttributeDescriptions = attributeDescriptions;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user