MCPcopy Create free account
hub / github.com/SFML/SFML / setupPipeline

Method setupPipeline

examples/vulkan/Vulkan.cpp:1094–1228  ·  view source on GitHub ↗

Set up rendering pipeline

Source from the content-addressed store, hash-verified

1092
1093 // Set up rendering pipeline
1094 void setupPipeline()
1095 {
1096 // Set up how the vertex shader pulls data out of our vertex buffer
1097 VkVertexInputBindingDescription vertexInputBindingDescription = VkVertexInputBindingDescription();
1098 vertexInputBindingDescription.binding = 0;
1099 vertexInputBindingDescription.stride = sizeof(float) * 9;
1100 vertexInputBindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
1101
1102 // Set up how the vertex buffer data is interpreted as attributes by the vertex shader
1103 std::array<VkVertexInputAttributeDescription, 3> vertexInputAttributeDescriptions{};
1104
1105 // Position attribute
1106 vertexInputAttributeDescriptions[0] = VkVertexInputAttributeDescription();
1107 vertexInputAttributeDescriptions[0].binding = 0;
1108 vertexInputAttributeDescriptions[0].location = 0;
1109 vertexInputAttributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
1110 vertexInputAttributeDescriptions[0].offset = sizeof(float) * 0;
1111
1112 // Color attribute
1113 vertexInputAttributeDescriptions[1] = VkVertexInputAttributeDescription();
1114 vertexInputAttributeDescriptions[1].binding = 0;
1115 vertexInputAttributeDescriptions[1].location = 1;
1116 vertexInputAttributeDescriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
1117 vertexInputAttributeDescriptions[1].offset = sizeof(float) * 3;
1118
1119 // Texture coordinate attribute
1120 vertexInputAttributeDescriptions[2] = VkVertexInputAttributeDescription();
1121 vertexInputAttributeDescriptions[2].binding = 0;
1122 vertexInputAttributeDescriptions[2].location = 2;
1123 vertexInputAttributeDescriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
1124 vertexInputAttributeDescriptions[2].offset = sizeof(float) * 7;
1125
1126 VkPipelineVertexInputStateCreateInfo vertexInputStateCreateInfo = VkPipelineVertexInputStateCreateInfo();
1127 vertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
1128 vertexInputStateCreateInfo.vertexBindingDescriptionCount = 1;
1129 vertexInputStateCreateInfo.pVertexBindingDescriptions = &vertexInputBindingDescription;
1130 vertexInputStateCreateInfo.vertexAttributeDescriptionCount = static_cast<std::uint32_t>(
1131 vertexInputAttributeDescriptions.size());
1132 vertexInputStateCreateInfo.pVertexAttributeDescriptions = vertexInputAttributeDescriptions.data();
1133
1134 // We want to generate a triangle list with our vertex data
1135 VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo = VkPipelineInputAssemblyStateCreateInfo();
1136 inputAssemblyStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
1137 inputAssemblyStateCreateInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
1138 inputAssemblyStateCreateInfo.primitiveRestartEnable = VK_FALSE;
1139
1140 // Set up the viewport
1141 VkViewport viewport = VkViewport();
1142 viewport.x = 0.0f;
1143 viewport.y = 0.0f;
1144 viewport.width = static_cast<float>(swapchainExtent.width);
1145 viewport.height = static_cast<float>(swapchainExtent.height);
1146 viewport.minDepth = 0.0f;
1147 viewport.maxDepth = 1.f;
1148
1149 // Set up the scissor region
1150 VkRect2D scissor = VkRect2D();
1151 scissor.offset.x = 0;

Callers

nothing calls this directly

Tested by

no test coverage detected