Created a vertex input description
This commit is contained in:
parent
a769169aa6
commit
85fd25f59a
2 changed files with 57 additions and 18 deletions
|
|
@ -1,20 +1,12 @@
|
||||||
#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.0, -0.5),
|
|
||||||
vec2(0.5, 0.5),
|
|
||||||
vec2(-0.5, 0.5)
|
|
||||||
);
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#define GLFW_INCLUDE_VULKAN
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include <cglm/cglm.h>
|
||||||
|
#include <cglm/types.h>
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
const bool enableValidationLayers = false;
|
const bool enableValidationLayers = false;
|
||||||
#else
|
#else
|
||||||
|
|
@ -648,6 +651,43 @@ VkShaderModule createShaderModule(VkDevice device, ShaderBuffer code) {
|
||||||
return shaderModule;
|
return shaderModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
vec2 pos;
|
||||||
|
vec3 colour;
|
||||||
|
} Vertex;
|
||||||
|
|
||||||
|
const 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}}};
|
||||||
|
|
||||||
|
static VkVertexInputBindingDescription getBindingDescription() {
|
||||||
|
VkVertexInputBindingDescription bindingDescription = {0};
|
||||||
|
|
||||||
|
bindingDescription.binding = 0;
|
||||||
|
bindingDescription.stride = sizeof(Vertex);
|
||||||
|
bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||||
|
|
||||||
|
return bindingDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currently this is for an array of 2
|
||||||
|
static VkVertexInputAttributeDescription *populateAttributeDescriptions(
|
||||||
|
VkVertexInputAttributeDescription *attributeDescriptions) {
|
||||||
|
// location 0
|
||||||
|
attributeDescriptions[0].binding = 0;
|
||||||
|
attributeDescriptions[0].location = 0;
|
||||||
|
attributeDescriptions[0].format = VK_FORMAT_R32G32_SFLOAT;
|
||||||
|
attributeDescriptions[0].offset = offsetof(Vertex, pos);
|
||||||
|
|
||||||
|
// location 1
|
||||||
|
attributeDescriptions[1].binding = 0;
|
||||||
|
attributeDescriptions[1].location = 1;
|
||||||
|
attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||||
|
attributeDescriptions[1].offset = offsetof(Vertex, colour);
|
||||||
|
|
||||||
|
return attributeDescriptions;
|
||||||
|
}
|
||||||
|
|
||||||
void createGraphicsPipeline(VulkanApp *app) {
|
void createGraphicsPipeline(VulkanApp *app) {
|
||||||
ShaderBuffer vertShaderCode = loadShaderIntoBuffer("shaders/shader.vert.spv");
|
ShaderBuffer vertShaderCode = loadShaderIntoBuffer("shaders/shader.vert.spv");
|
||||||
ShaderBuffer fragShaderCode = loadShaderIntoBuffer("shaders/shader.frag.spv");
|
ShaderBuffer fragShaderCode = loadShaderIntoBuffer("shaders/shader.frag.spv");
|
||||||
|
|
@ -690,10 +730,17 @@ void createGraphicsPipeline(VulkanApp *app) {
|
||||||
VkPipelineVertexInputStateCreateInfo vertexInputInfo = {0};
|
VkPipelineVertexInputStateCreateInfo vertexInputInfo = {0};
|
||||||
vertexInputInfo.sType =
|
vertexInputInfo.sType =
|
||||||
VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||||
vertexInputInfo.vertexBindingDescriptionCount = 0;
|
|
||||||
vertexInputInfo.pVertexBindingDescriptions = NULL; // Optional
|
VkVertexInputBindingDescription bindingDescription = getBindingDescription();
|
||||||
vertexInputInfo.vertexAttributeDescriptionCount = 0;
|
#define attributeDescriptionsCount 2
|
||||||
vertexInputInfo.pVertexAttributeDescriptions = NULL; // Optional
|
VkVertexInputAttributeDescription attributeDescriptions[attributeDescriptionsCount] = {0};
|
||||||
|
populateAttributeDescriptions(
|
||||||
|
(VkVertexInputAttributeDescription *)&attributeDescriptions);
|
||||||
|
|
||||||
|
vertexInputInfo.vertexBindingDescriptionCount = 1;
|
||||||
|
vertexInputInfo.pVertexBindingDescriptions = &bindingDescription;
|
||||||
|
vertexInputInfo.vertexAttributeDescriptionCount = attributeDescriptionsCount;
|
||||||
|
vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions;
|
||||||
|
|
||||||
VkPipelineInputAssemblyStateCreateInfo inputAssembly = {0};
|
VkPipelineInputAssemblyStateCreateInfo inputAssembly = {0};
|
||||||
inputAssembly.sType =
|
inputAssembly.sType =
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue