This commit is contained in:
Anish Bhobe 2024-07-09 15:42:19 +02:00
parent 63af9954d9
commit 31c09b0a35
2 changed files with 21 additions and 15 deletions

View File

@ -51,7 +51,6 @@ Pipeline CreatePipeline(const Device *device, const Swapchain *swapchain);
struct Vertex struct Vertex
{ {
vec3 m_Position; vec3 m_Position;
vec3 m_Color;
constexpr static vk::VertexInputBindingDescription constexpr static vk::VertexInputBindingDescription
GetBinding(const u32 binding) GetBinding(const u32 binding)
@ -59,7 +58,7 @@ struct Vertex
return {.binding = binding, .stride = sizeof(Vertex), .inputRate = vk::VertexInputRate::eVertex}; return {.binding = binding, .stride = sizeof(Vertex), .inputRate = vk::VertexInputRate::eVertex};
} }
constexpr static eastl::array<vk::VertexInputAttributeDescription, 2> constexpr static eastl::array<vk::VertexInputAttributeDescription, 1>
GetAttributes(const u32 binding) GetAttributes(const u32 binding)
{ {
return { return {
@ -69,12 +68,6 @@ struct Vertex
.format = vk::Format::eR32G32B32Sfloat, .format = vk::Format::eR32G32B32Sfloat,
.offset = offsetof(Vertex, m_Position), .offset = offsetof(Vertex, m_Position),
}, },
vk::VertexInputAttributeDescription{
.location = 1,
.binding = binding,
.format = vk::Format::eR32G32B32Sfloat,
.offset = offsetof(Vertex, m_Color),
},
}; };
} }
}; };
@ -121,7 +114,7 @@ main(int, char **)
Camera camera = { Camera camera = {
.m_Model = {1.0f}, .m_Model = {1.0f},
.m_View = glm::lookAt(vec3(-1.0f, 0.0f, 1.0f), vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)), .m_View = glm::lookAt(vec3(0.0f, 2.0f, 2.0f), vec3(0.0f), vec3(0.0f, 1.0f, 0.0f)),
.m_Perspective = glm::perspective( .m_Perspective = glm::perspective(
70_deg, Cast<f32>(swapchain.m_Extent.width) / Cast<f32>(swapchain.m_Extent.height), 0.1f, 100.0f), 70_deg, Cast<f32>(swapchain.m_Extent.width) / Cast<f32>(swapchain.m_Extent.height), 0.1f, 100.0f),
}; };
@ -166,10 +159,24 @@ main(int, char **)
// eastl::array<Vertex, 3> vertices{}; // eastl::array<Vertex, 3> vertices{};
eastl::array vertices = { eastl::array vertices = {
Vertex{.m_Position = {-0.5f, -0.5f, 0.0f}, .m_Color = {1.0f, 0.0f, 0.0f}}, vec3(-0.5f, -0.5f, -0.5f), vec3(0.5f, -0.5f, -0.5f), vec3(0.5f, 0.5f, -0.5f), vec3(0.5f, 0.5f, -0.5f),
Vertex{.m_Position = {0.5f, -0.5f, 0.0f}, .m_Color = {0.0f, 1.0f, 0.0f}}, vec3(-0.5f, 0.5f, -0.5f), vec3(-0.5f, -0.5f, -0.5f), vec3(-0.5f, -0.5f, 0.5f), vec3(0.5f, -0.5f, 0.5f),
Vertex{.m_Position = {0.0f, 0.5f, 0.0f}, .m_Color = {0.0f, 0.0f, 1.0f}}, vec3(0.5f, 0.5f, 0.5f), vec3(0.5f, 0.5f, 0.5f), vec3(-0.5f, 0.5f, 0.5f), vec3(-0.5f, -0.5f, 0.5f),
vec3(-0.5f, 0.5f, 0.5f), vec3(-0.5f, 0.5f, -0.5f), vec3(-0.5f, -0.5f, -0.5f), vec3(-0.5f, -0.5f, -0.5f),
vec3(-0.5f, -0.5f, 0.5f), vec3(-0.5f, 0.5f, 0.5f), vec3(0.5f, 0.5f, 0.5f), vec3(0.5f, 0.5f, -0.5f),
vec3(0.5f, -0.5f, -0.5f), vec3(0.5f, -0.5f, -0.5f), vec3(0.5f, -0.5f, 0.5f), vec3(0.5f, 0.5f, 0.5f),
vec3(-0.5f, -0.5f, -0.5f), vec3(0.5f, -0.5f, -0.5f), vec3(0.5f, -0.5f, 0.5f), vec3(0.5f, -0.5f, 0.5f),
vec3(-0.5f, -0.5f, 0.5f), vec3(-0.5f, -0.5f, -0.5f), vec3(-0.5f, 0.5f, -0.5f), vec3(0.5f, 0.5f, -0.5f),
vec3(0.5f, 0.5f, 0.5f), vec3(0.5f, 0.5f, 0.5f), vec3(-0.5f, 0.5f, 0.5f), vec3(-0.5f, 0.5f, -0.5f),
}; };
/*
* 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f
*/
VertexBuffer vbo; VertexBuffer vbo;
vbo.Init(&device, vertices.size() * sizeof vertices[0], "VBO"); vbo.Init(&device, vertices.size() * sizeof vertices[0], "VBO");
{ {
@ -348,7 +355,7 @@ main(int, char **)
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 0, 1, &descriptorSet, 0, nullptr); cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 0, 1, &descriptorSet, 0, nullptr);
usize offsets = 0; usize offsets = 0;
cmd.bindVertexBuffers(0, 1, &vbo.m_Buffer, &offsets); cmd.bindVertexBuffers(0, 1, &vbo.m_Buffer, &offsets);
cmd.draw(3, 1, 0, 0); cmd.draw(Cast<u32>(vertices.size()), 1, 0, 0);
cmd.endRendering(); cmd.endRendering();

View File

@ -2,7 +2,6 @@
#pragma shader_stage(vertex) #pragma shader_stage(vertex)
layout(location=0) in vec4 position; layout(location=0) in vec4 position;
layout(location=1) in vec4 color;
layout(location=0) out vec3 outColor; layout(location=0) out vec3 outColor;
@ -14,5 +13,5 @@ layout(binding=0) uniform Camera {
void main() { void main() {
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position.xyz, 1.0f); gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position.xyz, 1.0f);
outColor = vec3(color.rgb); outColor = vec3(0.5f, 0.3f, 0.1f);
} }