完成顶点缓冲区输入描述创建
							parent
							
								
									c6d688a055
								
							
						
					
					
						commit
						7e7f530f3f
					
				| 
						 | 
					@ -954,12 +954,16 @@ void HelloTriangleApplication::createGraphicPipeline()
 | 
				
			||||||
	VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo,fragShaderStageInfo };
 | 
						VkPipelineShaderStageCreateInfo shaderStages[] = { vertShaderStageInfo,fragShaderStageInfo };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//顶点输入
 | 
						//顶点输入
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						auto bindingDescription = Vertex::getBindingDescription();
 | 
				
			||||||
 | 
						auto attributeDescriptions = Vertex::getAttributeDescriptions();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
 | 
						VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
 | 
				
			||||||
	vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
 | 
						vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
 | 
				
			||||||
	vertexInputInfo.vertexBindingDescriptionCount = 0;
 | 
						vertexInputInfo.vertexBindingDescriptionCount = 1;
 | 
				
			||||||
	vertexInputInfo.pVertexBindingDescriptions = nullptr;
 | 
						vertexInputInfo.pVertexBindingDescriptions = &bindingDescription;
 | 
				
			||||||
	vertexInputInfo.vertexAttributeDescriptionCount = 0;
 | 
						vertexInputInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescriptions.size());
 | 
				
			||||||
	vertexInputInfo.pVertexAttributeDescriptions = nullptr;
 | 
						vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//使用动态状态并保留视口和剪刀裁剪状态
 | 
						//使用动态状态并保留视口和剪刀裁剪状态
 | 
				
			||||||
| 
						 | 
					@ -1177,4 +1181,27 @@ int main()
 | 
				
			||||||
	return EXIT_SUCCESS;
 | 
						return EXIT_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					VkVertexInputBindingDescription HelloTriangleApplication::Vertex::getBindingDescription()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						VkVertexInputBindingDescription bindingDescription{};
 | 
				
			||||||
 | 
						bindingDescription.binding = 0;
 | 
				
			||||||
 | 
						bindingDescription.stride = sizeof(Vertex);
 | 
				
			||||||
 | 
						bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return bindingDescription;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					std::array<VkVertexInputAttributeDescription,2> HelloTriangleApplication::Vertex::getAttributeDescriptions()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						std::array<VkVertexInputAttributeDescription,2> attributeDescriptions{};
 | 
				
			||||||
 | 
						attributeDescriptions[0].binding = 0;
 | 
				
			||||||
 | 
						attributeDescriptions[0].location = 0;
 | 
				
			||||||
 | 
						attributeDescriptions[0].format = VK_FORMAT_R32G32_SFLOAT;
 | 
				
			||||||
 | 
						attributeDescriptions[0].offset = offsetof(Vertex, pos);
 | 
				
			||||||
 | 
						attributeDescriptions[1].binding = 0;
 | 
				
			||||||
 | 
						attributeDescriptions[1].location = 1;
 | 
				
			||||||
 | 
						attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
 | 
				
			||||||
 | 
						attributeDescriptions[1].offset = offsetof(Vertex, color);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return attributeDescriptions;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@
 | 
				
			||||||
#include<GLFW/glfw3.h>
 | 
					#include<GLFW/glfw3.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include<vulkan/vulkan.h>
 | 
					#include<vulkan/vulkan.h>
 | 
				
			||||||
 | 
					#include<glm/glm.hpp>
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include <optional>
 | 
					#include <optional>
 | 
				
			||||||
#include <stdexcept>
 | 
					#include <stdexcept>
 | 
				
			||||||
| 
						 | 
					@ -18,6 +19,7 @@
 | 
				
			||||||
#include <cstdint>
 | 
					#include <cstdint>
 | 
				
			||||||
#include <limits>
 | 
					#include <limits>
 | 
				
			||||||
#include <algorithm>
 | 
					#include <algorithm>
 | 
				
			||||||
 | 
					#include <array>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <fstream>
 | 
					#include <fstream>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -101,6 +103,20 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool framebufferResized = false;
 | 
						bool framebufferResized = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct Vertex
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							glm::vec2 pos;
 | 
				
			||||||
 | 
							glm::vec3 color;
 | 
				
			||||||
 | 
							static VkVertexInputBindingDescription getBindingDescription();
 | 
				
			||||||
 | 
							static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescriptions();
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const std::vector<Vertex> vertices = {
 | 
				
			||||||
 | 
						{{0.0f, -0.5f}, {1.0f, 0.0f, 0.0f}},
 | 
				
			||||||
 | 
						{{0.5f, 0.5f}, {0.0f, 1.0f, 0.0f}},
 | 
				
			||||||
 | 
						{{-0.5f, 0.5f}, {0.0f, 0.0f, 1.0f}}
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void initWindow(int Width, int Height);
 | 
						void initWindow(int Width, int Height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void createInstance();
 | 
						void createInstance();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,20 +1,13 @@
 | 
				
			||||||
#version 450
 | 
					#version 450
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					layout(location = 0) in vec2 inPosition;
 | 
				
			||||||
 | 
					layout(location = 1) in vec3 inColor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
layout(location = 0) out vec3 fragColor;
 | 
					layout(location = 0) out vec3 fragColor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vec2 positions[3] = vec2[](
 | 
					 | 
				
			||||||
    vec2(0.0f, -0.5f),
 | 
					 | 
				
			||||||
    vec2(0.5f, 0.5f),
 | 
					 | 
				
			||||||
    vec2(-0.5f, 0.5f)
 | 
					 | 
				
			||||||
);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
vec3 colors[3] = vec3[](
 | 
					 | 
				
			||||||
    vec3(1.0,0.0,0.0),
 | 
					 | 
				
			||||||
    vec3(0.0,1.0,0.0),
 | 
					 | 
				
			||||||
    vec3(0.0,0.0,1.0)
 | 
					 | 
				
			||||||
);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void main(){
 | 
					void main(){
 | 
				
			||||||
    gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
 | 
					    gl_Position = vec4(inPosition, 0.0, 1.0);
 | 
				
			||||||
    fragColor = colors[gl_VertexIndex];
 | 
					    fragColor = inColor;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in New Issue