Changeset 771b33a in opengl-game
- Timestamp:
- Oct 4, 2019, 8:39:46 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- b794178
- Parents:
- 0b1b52d
- Files:
-
- 5 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); -
graphics-pipeline_vulkan.hpp
r0b1b52d r771b33a 4 4 #include "graphics-pipeline.hpp" 5 5 6 #include <vector> 7 6 8 #include <vulkan/vulkan.h> 7 8 #include <vector>9 9 10 10 class GraphicsPipeline_Vulkan : public GraphicsPipeline { 11 11 public: 12 GraphicsPipeline_Vulkan(VkDevice device );12 GraphicsPipeline_Vulkan(VkDevice device, Viewport viewport, int vertexSize); 13 13 ~GraphicsPipeline_Vulkan(); 14 14 15 void addAttribute(VkFormat format, size_t offset); 15 16 void createPipeline(string vertShaderFile, string fragShaderFile); 16 17 17 18 private: 18 19 VkDevice device; 20 VkVertexInputBindingDescription bindingDescription; 21 vector<VkVertexInputAttributeDescription> attributeDescriptions; 19 22 20 23 VkShaderModule createShaderModule(const vector<char>& code); -
vulkan-game.cpp
r0b1b52d r771b33a 8 8 #include "logger.hpp" 9 9 10 #include "utils.hpp" 10 11 #include "vulkan-utils.hpp" 11 12 … … 106 107 createCommandPool(); 107 108 108 graphicsPipelines.push_back(GraphicsPipeline_Vulkan(device)); 109 graphicsPipelines.push_back(GraphicsPipeline_Vulkan(device, viewport, sizeof(Vertex))); 110 111 graphicsPipelines.back().addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&Vertex::pos)); 112 graphicsPipelines.back().addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&Vertex::color)); 113 graphicsPipelines.back().addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&Vertex::texCoord)); 114 109 115 graphicsPipelines.back().createPipeline("shaders/scene-vert.spv", "shaders/scene-frag.spv"); 110 116 111 graphicsPipelines.push_back(GraphicsPipeline_Vulkan(device)); 117 graphicsPipelines.push_back(GraphicsPipeline_Vulkan(device, viewport, sizeof(OverlayVertex))); 118 119 graphicsPipelines.back().addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&OverlayVertex::pos)); 120 graphicsPipelines.back().addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&OverlayVertex::texCoord)); 121 112 122 graphicsPipelines.back().createPipeline("shaders/overlay-vert.spv", "shaders/overlay-frag.spv"); 113 123 … … 427 437 428 438 swapChainImageFormat = surfaceFormat.format; 429 swapChainExtent = extent;439 viewport = { 0, 0, (int)extent.width, (int)extent.height }; 430 440 } 431 441 -
vulkan-game.hpp
r0b1b52d r771b33a 1 1 #ifndef _VULKAN_GAME_H 2 2 #define _VULKAN_GAME_H 3 4 #include <glm/glm.hpp> 3 5 4 6 #include "game-gui-sdl.hpp" … … 11 13 #endif 12 14 15 // TODO: Figure out if these structs should be defined in the VulkanGame class 16 17 struct Vertex { 18 glm::vec3 pos; 19 glm::vec3 color; 20 glm::vec2 texCoord; 21 }; 22 23 struct OverlayVertex { 24 glm::vec3 pos; 25 glm::vec2 texCoord; 26 }; 27 13 28 class VulkanGame { 14 29 public: … … 20 35 private: 21 36 GameGui* gui; 37 Viewport viewport; 22 38 23 39 vector<GraphicsPipeline_Vulkan> graphicsPipelines; … … 39 55 vector<VkImage> swapChainImages; 40 56 VkFormat swapChainImageFormat; 41 VkExtent2D swapChainExtent;42 57 vector<VkImageView> swapChainImageViews; 43 58 -
vulkan-ref.cpp
r0b1b52d r771b33a 175 175 VkFormat swapChainImageFormat; 176 176 /*** END OF REFACTORED CODE ***/ 177 VkExtent2D swapChainExtent; // (This was taken out of vulkan-game for now and replaced with Viewport) 177 // (This was taken out of vulkan-game for now and replaced with Viewport) 178 // It will definitely be needed when creating render passes and I could use it in a few other places 179 VkExtent2D swapChainExtent; 178 180 /*** START OF REFACTORED CODE ***/ 179 181 vector<VkImageView> swapChainImageViews;
Note:
See TracChangeset
for help on using the changeset viewer.