Add textures

Textures supported
This commit is contained in:
Piotr Krygier committed 2023-10-03 09:00:02 +02:00
1 parent 4fcda01ba2
commit 548ed57969
11 files changed
+183 -76

No files matched your search

+50 -38
View File
@@ -5,6 +5,7 @@
#include "utilities/logger.h"
#include "vulkan_errors.h"
#include "mesh_controller.h"
#include "rse_vulkan_image.h"
#include "vulkan/vulkan.h"
@@ -72,24 +73,24 @@ static VkVertexInputBindingDescription get_binding_description()
static VkVertexInputAttributeDescription* get_attribute_descriptions()
{
static VkVertexInputAttributeDescription attributeDescriptions[3];
static VkVertexInputAttributeDescription attribute_descriptions[3];
attributeDescriptions[0].binding = 0;
attributeDescriptions[0].location = 0; /* inPosition in shader.vert */
attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[0].offset = offsetof(struct rse_vertex_t, pos);
attribute_descriptions[0].binding = 0;
attribute_descriptions[0].location = 0; /* inPosition in shader.vert */
attribute_descriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
attribute_descriptions[0].offset = offsetof(struct rse_vertex_t, pos);
attributeDescriptions[1].binding = 0;
attributeDescriptions[1].location = 1; /* inColor in shader.vert */
attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[1].offset = offsetof(struct rse_vertex_t, color);
attribute_descriptions[1].binding = 0;
attribute_descriptions[1].location = 1; /* inColor in shader.vert */
attribute_descriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
attribute_descriptions[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);
attribute_descriptions[2].binding = 0;
attribute_descriptions[2].location = 2; /* inTexCoords in shader.vert */
attribute_descriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
attribute_descriptions[2].offset = offsetof(struct rse_vertex_t, tex_coords);
return attributeDescriptions;
return attribute_descriptions;
}
/**
@@ -266,6 +267,7 @@ uint8_t create_descriptor_set_layout()
VkDescriptorSetLayoutBinding bindings[2];
VkDescriptorSetLayoutBinding ubo_layout_binding = {};
VkDescriptorSetLayoutBinding sampler_layout_binding = {};
// VkDescriptorSetLayoutBinding textures_layout_binding = {};
ubo_layout_binding.binding = 0;
ubo_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
@@ -275,12 +277,13 @@ uint8_t create_descriptor_set_layout()
sampler_layout_binding.binding = 1;
sampler_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
sampler_layout_binding.descriptorCount = 1;
sampler_layout_binding.descriptorCount = get_textures_count();
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;
@@ -549,45 +552,54 @@ void free_dynamic_pipeline_state_info(VkPipelineDynamicStateCreateInfo* dynamic_
*/
void fill_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_input_info)
{
const size_t binding_descriptions_count = 2;
const size_t attribute_descriptions_count = 7;
/* This is clusterfuck with some magic numbers here and there and unneeded malloc and memcpy stuff. Change,
* so you won't feel ashamed. */
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) * 6);
VkVertexInputBindingDescription* binding_descriptions = malloc(sizeof(VkVertexInputBindingDescription)
* binding_descriptions_count);
VkVertexInputAttributeDescription* attribute_descriptions = malloc(sizeof(VkVertexInputAttributeDescription)
* attribute_descriptions_count);
bindingDescriptions[0] = vertex_binding_description;
binding_descriptions[0] = vertex_binding_description;
bindingDescriptions[1].binding = 1;
bindingDescriptions[1].stride = sizeof(struct rse_instance_data_t); //TODO: change
bindingDescriptions[1].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
binding_descriptions[1].binding = 1;
binding_descriptions[1].stride = sizeof(struct rse_instance_data_t); //TODO: change
binding_descriptions[1].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
memcpy(attributeDescriptions, vertex_attribute_descriptions, sizeof(VkVertexInputAttributeDescription) * 3);
memcpy(attribute_descriptions, 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, pos);
attribute_descriptions[3].binding = 1;
attribute_descriptions[3].location = 3;
attribute_descriptions[3].format = VK_FORMAT_R32G32B32_SFLOAT;
attribute_descriptions[3].offset = offsetof(struct rse_instance_data_t, pos);
attributeDescriptions[4].binding = 1;
attributeDescriptions[4].location = 4;
attributeDescriptions[4].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[4].offset = offsetof(struct rse_instance_data_t, rot);
attribute_descriptions[4].binding = 1;
attribute_descriptions[4].location = 4;
attribute_descriptions[4].format = VK_FORMAT_R32G32B32_SFLOAT;
attribute_descriptions[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);
attribute_descriptions[5].binding = 1;
attribute_descriptions[5].location = 5;
attribute_descriptions[5].format = VK_FORMAT_R32_SFLOAT;
attribute_descriptions[5].offset = offsetof(struct rse_instance_data_t, scale);
attribute_descriptions[6].binding = 1;
attribute_descriptions[6].location = 6;
attribute_descriptions[6].format = VK_FORMAT_R8_UINT;
attribute_descriptions[6].offset = offsetof(struct rse_instance_data_t, texture_id);
// ************************
vertex_input_info->sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertex_input_info->pNext = NULL;
vertex_input_info->flags = 0U;
vertex_input_info->vertexBindingDescriptionCount = 2U;
vertex_input_info->pVertexBindingDescriptions = bindingDescriptions;
vertex_input_info->vertexAttributeDescriptionCount = 6U;
vertex_input_info->pVertexAttributeDescriptions = attributeDescriptions;
vertex_input_info->vertexBindingDescriptionCount = binding_descriptions_count;
vertex_input_info->pVertexBindingDescriptions = binding_descriptions;
vertex_input_info->vertexAttributeDescriptionCount = attribute_descriptions_count;
vertex_input_info->pVertexAttributeDescriptions = attribute_descriptions;
}
/**