2018-11-07 07:20:52 -05:00
|
|
|
#include "skypass.h"
|
|
|
|
|
2018-11-08 14:14:11 -05:00
|
|
|
#include <array>
|
|
|
|
|
2018-11-07 07:20:52 -05:00
|
|
|
#include "renderer.h"
|
|
|
|
|
|
|
|
SkyPass::SkyPass(Renderer& renderer) : renderer_(renderer) {
|
|
|
|
createPipeline();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkyPass::~SkyPass() {
|
|
|
|
vkDestroyPipeline(renderer_.getDevice(), pipeline_, nullptr);
|
|
|
|
vkDestroyPipelineLayout(renderer_.getDevice(), pipelineLayout_, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkyPass::render(VkCommandBuffer commandBuffer) {
|
|
|
|
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
|
|
|
vkCmdDraw(commandBuffer, 3, 1, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkyPass::createPipeline() {
|
|
|
|
VkShaderModule vertShaderModule = renderer_.createShader("shaders/sky.vert.spv");
|
|
|
|
VkShaderModule fragShaderModule = renderer_.createShader("shaders/sky.frag.spv");
|
|
|
|
|
|
|
|
VkPipelineShaderStageCreateInfo vertShaderStageInfo = {};
|
|
|
|
vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
|
|
|
vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
|
|
|
|
vertShaderStageInfo.module = vertShaderModule;
|
|
|
|
vertShaderStageInfo.pName = "main";
|
|
|
|
|
|
|
|
VkPipelineShaderStageCreateInfo fragShaderStageInfo = {};
|
|
|
|
fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
|
|
|
fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
|
|
|
fragShaderStageInfo.module = fragShaderModule;
|
|
|
|
fragShaderStageInfo.pName = "main";
|
|
|
|
|
|
|
|
const std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages = {vertShaderStageInfo, fragShaderStageInfo};
|
|
|
|
|
|
|
|
VkPipelineVertexInputStateCreateInfo vertexInputInfo = {};
|
|
|
|
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
|
|
|
|
|
|
|
VkPipelineInputAssemblyStateCreateInfo inputAssembly = {};
|
|
|
|
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
|
|
|
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
|
|
|
|
|
|
|
VkPipelineViewportStateCreateInfo viewportState = {};
|
|
|
|
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
|
|
|
viewportState.viewportCount = 1;
|
|
|
|
viewportState.scissorCount = 1;
|
|
|
|
|
|
|
|
VkPipelineRasterizationStateCreateInfo rasterizer = {};
|
|
|
|
rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
|
|
|
|
rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
|
|
|
|
rasterizer.cullMode = VK_CULL_MODE_NONE;
|
|
|
|
rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
|
|
|
rasterizer.lineWidth = 1.0f;
|
|
|
|
|
|
|
|
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
|
|
|
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
|
|
|
multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
|
|
|
|
VkPipelineColorBlendAttachmentState colorBlendAttachment = {};
|
|
|
|
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
|
|
|
|
|
|
|
VkPipelineColorBlendStateCreateInfo colorBlending = {};
|
|
|
|
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
|
|
|
colorBlending.attachmentCount = 1;
|
|
|
|
colorBlending.pAttachments = &colorBlendAttachment;
|
|
|
|
|
|
|
|
VkPipelineDepthStencilStateCreateInfo depthState = {};
|
|
|
|
depthState.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
|
|
|
depthState.depthTestEnable = VK_TRUE;
|
|
|
|
depthState.depthWriteEnable = VK_FALSE;
|
|
|
|
depthState.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
|
|
|
|
|
|
|
|
const std::array<VkDynamicState, 2> dynamicStates = {
|
|
|
|
VK_DYNAMIC_STATE_VIEWPORT,
|
|
|
|
VK_DYNAMIC_STATE_SCISSOR
|
|
|
|
};
|
|
|
|
|
|
|
|
VkPipelineDynamicStateCreateInfo dynamicState = {};
|
|
|
|
dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
|
|
|
|
dynamicState.dynamicStateCount = dynamicStates.size();
|
|
|
|
dynamicState.pDynamicStates = dynamicStates.data();
|
|
|
|
|
|
|
|
VkPipelineLayoutCreateInfo pipelineLayoutInfo = {};
|
|
|
|
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
|
|
|
|
|
|
|
vkCreatePipelineLayout(renderer_.getDevice(), &pipelineLayoutInfo, nullptr, &pipelineLayout_);
|
|
|
|
|
|
|
|
VkGraphicsPipelineCreateInfo pipelineInfo = {};
|
|
|
|
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
|
|
|
pipelineInfo.stageCount = shaderStages.size();
|
|
|
|
pipelineInfo.pStages = shaderStages.data();
|
|
|
|
pipelineInfo.pVertexInputState = &vertexInputInfo;
|
|
|
|
pipelineInfo.pInputAssemblyState = &inputAssembly;
|
|
|
|
pipelineInfo.pViewportState = &viewportState;
|
|
|
|
pipelineInfo.pRasterizationState = &rasterizer;
|
|
|
|
pipelineInfo.pMultisampleState = &multisampling;
|
|
|
|
pipelineInfo.pColorBlendState = &colorBlending;
|
|
|
|
pipelineInfo.pDepthStencilState = &depthState;
|
|
|
|
pipelineInfo.pDynamicState = &dynamicState;
|
|
|
|
pipelineInfo.layout = pipelineLayout_;
|
|
|
|
pipelineInfo.renderPass = renderer_.getWorldPass().getRenderPass();
|
|
|
|
|
|
|
|
vkCreateGraphicsPipelines(renderer_.getDevice(), nullptr, 1, &pipelineInfo, nullptr, &pipeline_);
|
|
|
|
|
|
|
|
vkDestroyShaderModule(renderer_.getDevice(), fragShaderModule, nullptr);
|
|
|
|
vkDestroyShaderModule(renderer_.getDevice(), vertShaderModule, nullptr);
|
|
|
|
}
|