diff --git a/graphics/shaders/shader.frag b/graphics/shaders/shader.frag new file mode 100644 index 0000000..13009da --- /dev/null +++ b/graphics/shaders/shader.frag @@ -0,0 +1,9 @@ +#version 450 + +layout(location = 0) in vec3 fragColor; + +layout(location = 0) out vec4 outColor; + +void main() { + outColor = vec4(fragColor, 1.0); +} \ No newline at end of file diff --git a/graphics/shaders/shader.vert b/graphics/shaders/shader.vert new file mode 100644 index 0000000..f5b2f8d --- /dev/null +++ b/graphics/shaders/shader.vert @@ -0,0 +1,20 @@ +#version 450 + +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() { + gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); + fragColor = colors[gl_VertexIndex]; +} diff --git a/graphics/src/detail/vertex_layout.h b/graphics/src/detail/vertex_layout.h new file mode 100644 index 0000000..499bdf1 --- /dev/null +++ b/graphics/src/detail/vertex_layout.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include +#include + +namespace derith { + namespace graphics { + struct StaticMeshVertex { + glm::vec3 position; + glm::vec3 normal; + }; + + enum class VertexLayout : uint8_t { + StaticMesh = 0 + }; + + extern VkPipelineVertexInputStateCreateInfo static_mesh_vertex_input_state; + + void create_vulkan_vertex_inputs(); + } // namespace graphics +} // namespace derith \ No newline at end of file diff --git a/graphics/src/vulkan_graphics_pipeline.cpp b/graphics/src/vulkan_graphics_pipeline.cpp index 671a26b..a8e5590 100644 --- a/graphics/src/vulkan_graphics_pipeline.cpp +++ b/graphics/src/vulkan_graphics_pipeline.cpp @@ -1,4 +1,5 @@ #include "detail/graphics.h" +#include "detail/vertex_layout.h" #include diff --git a/graphics/src/vulkan_vertex_layouts.cpp b/graphics/src/vulkan_vertex_layouts.cpp new file mode 100644 index 0000000..3ff1711 --- /dev/null +++ b/graphics/src/vulkan_vertex_layouts.cpp @@ -0,0 +1,44 @@ +#include "detail/vertex_layout.h" + +#include + +namespace derith { + namespace graphics { + void create_vulkan_static_mesh_vertex_input_state(); + + VkPipelineVertexInputStateCreateInfo static_mesh_vertex_input_state; + VkVertexInputBindingDescription static_mesh_binding_description; + std::array static_mesh_attribute_descriptors; + + } // namespace graphics + + void graphics::create_vulkan_vertex_inputs() { + create_vulkan_static_mesh_vertex_input_state(); + } + + void graphics::create_vulkan_static_mesh_vertex_input_state() { + VkVertexInputBindingDescription bindingDescription{}; + bindingDescription.binding = 0; + bindingDescription.stride = sizeof(StaticMeshVertex); + bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; + + static_mesh_attribute_descriptors[0] = {}; + static_mesh_attribute_descriptors[0].binding = 0; + static_mesh_attribute_descriptors[0].location = 0; + static_mesh_attribute_descriptors[0].format = VK_FORMAT_R32G32B32_SFLOAT; + static_mesh_attribute_descriptors[0].offset = offsetof(StaticMeshVertex, position); + + static_mesh_attribute_descriptors[1] = {}; + static_mesh_attribute_descriptors[1].binding = 0; + static_mesh_attribute_descriptors[1].location = 1; + static_mesh_attribute_descriptors[1].format = VK_FORMAT_R32G32B32_SFLOAT; + static_mesh_attribute_descriptors[1].offset = offsetof(StaticMeshVertex, normal); + + static_mesh_vertex_input_state = {}; + static_mesh_vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + static_mesh_vertex_input_state.vertexBindingDescriptionCount = 1; + static_mesh_vertex_input_state.pVertexBindingDescriptions = &static_mesh_binding_description; + static_mesh_vertex_input_state.vertexAttributeDescriptionCount = static_cast(static_mesh_attribute_descriptors.size()); + static_mesh_vertex_input_state.pVertexAttributeDescriptions = static_mesh_attribute_descriptors.data(); + } +} // namespace derith \ No newline at end of file