project-aster/samples/03_model_render/pipeline_utils.h

52 lines
1.5 KiB
C++

// =============================================
// Aster: pipeline_utils.h
// Copyright (c) 2020-2024 Anish Bhobe
// =============================================
#pragma once
#include "pipeline.h"
#include <EASTL/array.h>
struct RenderResourceManager;
struct Swapchain;
struct Device;
constexpr auto VERTEX_SHADER_FILE = "shader/model.vert.glsl.spv";
constexpr auto FRAGMENT_SHADER_FILE = "shader/model.frag.glsl.spv";
struct Vertex
{
vec3 m_Position;
vec2 m_UV0;
constexpr static vk::VertexInputBindingDescription
GetBinding(const u32 binding)
{
return {.binding = binding, .stride = sizeof(Vertex), .inputRate = vk::VertexInputRate::eVertex};
}
constexpr static eastl::array<vk::VertexInputAttributeDescription, 2>
GetAttributes(const u32 binding)
{
return {
vk::VertexInputAttributeDescription{
.location = 0,
.binding = binding,
.format = vk::Format::eR32G32B32Sfloat,
.offset = offsetof(Vertex, m_Position),
},
vk::VertexInputAttributeDescription{
.location = 1,
.binding = binding,
.format = vk::Format::eR32G32Sfloat,
.offset = offsetof(Vertex, m_UV0),
},
};
}
};
vk::ShaderModule CreateShader(const Device *device, cstr shaderFile);
Pipeline CreatePipeline(const Device *device, const Swapchain *swapchain, const RenderResourceManager *resourceManager);