Changeset 771b33a in opengl-game for graphics-pipeline_vulkan.cpp
- Timestamp:
- Oct 4, 2019, 8:39:46 PM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- b794178
- Parents:
- 0b1b52d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
graphics-pipeline_vulkan.cpp
r0b1b52d r771b33a 4 4 #include <stdexcept> 5 5 6 GraphicsPipeline_Vulkan::GraphicsPipeline_Vulkan(VkDevice device ) {6 GraphicsPipeline_Vulkan::GraphicsPipeline_Vulkan(VkDevice device, Viewport viewport, int vertexSize) { 7 7 this->device = device; 8 this->viewport = viewport; 9 10 this->bindingDescription.binding = 0; 11 this->bindingDescription.stride = vertexSize; 12 this->bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; 8 13 } 9 14 10 15 GraphicsPipeline_Vulkan::~GraphicsPipeline_Vulkan() { 16 } 17 18 void GraphicsPipeline_Vulkan::addAttribute(VkFormat format, size_t offset) { 19 VkVertexInputAttributeDescription attributeDesc = {}; 20 21 attributeDesc.binding = 0; 22 attributeDesc.location = this->attributeDescriptions.size(); 23 attributeDesc.format = format; 24 attributeDesc.offset = offset; 25 26 this->attributeDescriptions.push_back(attributeDesc); 11 27 } 12 28 … … 34 50 VkPipelineVertexInputStateCreateInfo vertexInputInfo = {}; 35 51 vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; 52 53 vertexInputInfo.vertexBindingDescriptionCount = 1; 54 vertexInputInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(this->attributeDescriptions.size()); 55 vertexInputInfo.pVertexBindingDescriptions = &this->bindingDescription; 56 vertexInputInfo.pVertexAttributeDescriptions = this->attributeDescriptions.data(); 57 58 VkPipelineInputAssemblyStateCreateInfo inputAssembly = {}; 59 inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; 60 inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; 61 inputAssembly.primitiveRestartEnable = VK_FALSE; 62 63 VkViewport viewport = {}; 64 viewport.x = (float)this->viewport.x; 65 viewport.y = (float)this->viewport.y; 66 viewport.width = (float)this->viewport.width; 67 viewport.height = (float)this->viewport.height; 68 viewport.minDepth = 0.0f; 69 viewport.maxDepth = 1.0f; 70 71 VkRect2D scissor = {}; 72 scissor.offset = { 0, 0 }; 73 scissor.extent = { (uint32_t)this->viewport.width, (uint32_t)this->viewport.height }; 74 75 VkPipelineViewportStateCreateInfo viewportState = {}; 76 viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; 77 viewportState.viewportCount = 1; 78 viewportState.pViewports = &viewport; 79 viewportState.scissorCount = 1; 80 viewportState.pScissors = &scissor; 81 82 VkPipelineRasterizationStateCreateInfo rasterizer = {}; 83 rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; 84 rasterizer.depthClampEnable = VK_FALSE; 85 rasterizer.rasterizerDiscardEnable = VK_FALSE; 86 rasterizer.polygonMode = VK_POLYGON_MODE_FILL; 87 rasterizer.lineWidth = 1.0f; 88 rasterizer.cullMode = VK_CULL_MODE_BACK_BIT; 89 rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; 90 rasterizer.depthBiasEnable = VK_FALSE; 91 92 VkPipelineMultisampleStateCreateInfo multisampling = {}; 93 multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; 94 multisampling.sampleShadingEnable = VK_FALSE; 95 multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; 96 97 VkPipelineColorBlendAttachmentState colorBlendAttachment = {}; 98 colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; 99 colorBlendAttachment.blendEnable = VK_TRUE; 100 colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; 101 colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; 102 colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; 103 colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; 104 colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; 105 colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; 106 107 VkPipelineColorBlendStateCreateInfo colorBlending = {}; 108 colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; 109 colorBlending.logicOpEnable = VK_FALSE; 110 colorBlending.logicOp = VK_LOGIC_OP_COPY; 111 colorBlending.attachmentCount = 1; 112 colorBlending.pAttachments = &colorBlendAttachment; 113 colorBlending.blendConstants[0] = 0.0f; 114 colorBlending.blendConstants[1] = 0.0f; 115 colorBlending.blendConstants[2] = 0.0f; 116 colorBlending.blendConstants[3] = 0.0f; 117 118 VkPipelineDepthStencilStateCreateInfo depthStencil = {}; 119 depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; 120 depthStencil.depthTestEnable = VK_TRUE; 121 depthStencil.depthWriteEnable = VK_TRUE; 122 depthStencil.depthCompareOp = VK_COMPARE_OP_LESS; 123 depthStencil.depthBoundsTestEnable = VK_FALSE; 124 depthStencil.minDepthBounds = 0.0f; 125 depthStencil.maxDepthBounds = 1.0f; 126 depthStencil.stencilTestEnable = VK_FALSE; 127 depthStencil.front = {}; 128 depthStencil.back = {}; 129 130 VkPipelineLayoutCreateInfo pipelineLayoutInfo = {}; 131 pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; 132 pipelineLayoutInfo.setLayoutCount = 1; 36 133 37 134 vkDestroyShaderModule(device, vertShaderModule, nullptr);
Note:
See TracChangeset
for help on using the changeset viewer.