Add colours to the mesh
This commit is contained in:
parent
2ec8a315c6
commit
f2535de9a9
4 changed files with 26 additions and 12 deletions
|
@ -1,8 +1,10 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
|
layout(location = 0) in vec3 fragCol;
|
||||||
|
|
||||||
// Final output output (must also have location)
|
// Final output output (must also have location)
|
||||||
layout(location = 0) out vec4 outColour;
|
layout(location = 0) out vec4 outColour;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
outColour = vec4(1.0, 0.0, 0.0, 1.0);
|
outColour = vec4(fragCol, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout(location = 0) in vec3 pos;
|
layout(location = 0) in vec3 pos;
|
||||||
|
layout(location = 1) in vec3 col;
|
||||||
|
|
||||||
|
layout(location = 0) out vec3 fragCol;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(pos, 1.0);
|
gl_Position = vec4(pos, 1.0);
|
||||||
// fragColour = colours[gl_VertexIndex];
|
fragCol = col;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,13 @@ const vk = @import("vulkan");
|
||||||
|
|
||||||
pub const device_extensions = [_][*:0]const u8{vk.extensions.khr_swapchain.name};
|
pub const device_extensions = [_][*:0]const u8{vk.extensions.khr_swapchain.name};
|
||||||
|
|
||||||
|
pub const Vector3 = @Vector(3, f32);
|
||||||
|
|
||||||
// Vertex data representation
|
// Vertex data representation
|
||||||
pub const Vertex = struct {
|
pub const Vertex = struct {
|
||||||
// Vertex position (x, y, z)
|
// Vertex position (x, y, z)
|
||||||
pos: @Vector(3, f32),
|
pos: Vector3,
|
||||||
|
col: Vector3,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const QueueFamilyIndices = struct {
|
pub const QueueFamilyIndices = struct {
|
||||||
|
|
|
@ -104,9 +104,12 @@ pub const VulkanRenderer = struct {
|
||||||
|
|
||||||
// Create mesh
|
// Create mesh
|
||||||
var mesh_vertices = [_]Vertex{
|
var mesh_vertices = [_]Vertex{
|
||||||
.{ .pos = .{ 0.0, -0.4, 0.0 } },
|
.{ .pos = .{ -0.5, -0.5, 0.0 }, .col = .{ 1.0, 0.0, 0.0 } },
|
||||||
.{ .pos = .{ 0.4, 0.4, 0.0 } },
|
.{ .pos = .{ 0.5, -0.5, 0.0 }, .col = .{ 0.0, 1.0, 0.0 } },
|
||||||
.{ .pos = .{ -0.4, 0.4, 0.0 } },
|
.{ .pos = .{ 0.5, 0.5, 0.0 }, .col = .{ 0.0, 0.0, 1.0 } },
|
||||||
|
.{ .pos = .{ 0.5, 0.5, 0.0 }, .col = .{ 0.0, 0.0, 1.0 } },
|
||||||
|
.{ .pos = .{ -0.5, 0.5, 0.0 }, .col = .{ 0.0, 1.0, 0.0 } },
|
||||||
|
.{ .pos = .{ -0.5, -0.5, 0.0 }, .col = .{ 1.0, 0.0, 0.0 } },
|
||||||
};
|
};
|
||||||
|
|
||||||
self.first_mesh = try Mesh.new(self.instance, self.physical_device, self.device, &mesh_vertices);
|
self.first_mesh = try Mesh.new(self.instance, self.physical_device, self.device, &mesh_vertices);
|
||||||
|
@ -154,7 +157,6 @@ pub const VulkanRenderer = struct {
|
||||||
|
|
||||||
// Submit command buffer to queue
|
// Submit command buffer to queue
|
||||||
try self.device.queueSubmit(self.graphics_queue.handle, 1, @ptrCast(&submit_info), self.draw_fences[self.current_frame]);
|
try self.device.queueSubmit(self.graphics_queue.handle, 1, @ptrCast(&submit_info), self.draw_fences[self.current_frame]);
|
||||||
// try self.device.queueSubmit(self.graphics_queue.handle, 1, @ptrCast(&submit_info), self.frame_fence);
|
|
||||||
|
|
||||||
// -- Present rendered image to screen
|
// -- Present rendered image to screen
|
||||||
const present_info: vk.PresentInfoKHR = .{
|
const present_info: vk.PresentInfoKHR = .{
|
||||||
|
@ -506,6 +508,13 @@ pub const VulkanRenderer = struct {
|
||||||
.format = vk.Format.r32g32b32_sfloat, // Format the data will take (also helps define size of data)
|
.format = vk.Format.r32g32b32_sfloat, // Format the data will take (also helps define size of data)
|
||||||
.offset = @offsetOf(Vertex, "pos"), // Where this attribute is defined in data for a single vertex
|
.offset = @offsetOf(Vertex, "pos"), // Where this attribute is defined in data for a single vertex
|
||||||
},
|
},
|
||||||
|
// Colour attribute
|
||||||
|
.{
|
||||||
|
.binding = 0,
|
||||||
|
.location = 1,
|
||||||
|
.format = vk.Format.r32g32b32_sfloat,
|
||||||
|
.offset = @offsetOf(Vertex, "col"),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// -- Vertex input --
|
// -- Vertex input --
|
||||||
|
@ -1044,16 +1053,13 @@ fn getDebugUtilsCreateInfo() vk.DebugUtilsMessengerCreateInfoEXT {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// message_severity: vk.DebugUtilsMessageSeverityFlagsEXT,
|
|
||||||
// message_types: vk.DebugUtilsMessageTypeFlagsEXT,
|
|
||||||
// p_callback_data: ?*const vk.DebugUtilsMessengerCallbackDataEXT,
|
|
||||||
// p_user_data: ?*anyopaque,
|
|
||||||
fn debugCallback(
|
fn debugCallback(
|
||||||
message_severity: vk.DebugUtilsMessageSeverityFlagsEXT,
|
message_severity: vk.DebugUtilsMessageSeverityFlagsEXT,
|
||||||
message_types: vk.DebugUtilsMessageTypeFlagsEXT,
|
message_types: vk.DebugUtilsMessageTypeFlagsEXT,
|
||||||
p_callback_data: ?*const vk.DebugUtilsMessengerCallbackDataEXT,
|
p_callback_data: ?*const vk.DebugUtilsMessengerCallbackDataEXT,
|
||||||
_: ?*anyopaque,
|
p_user_data: ?*anyopaque,
|
||||||
) callconv(vk.vulkan_call_conv) vk.Bool32 {
|
) callconv(vk.vulkan_call_conv) vk.Bool32 {
|
||||||
|
_ = p_user_data;
|
||||||
const severity = getMessageSeverityLabel(message_severity);
|
const severity = getMessageSeverityLabel(message_severity);
|
||||||
const message_type = getMessageTypeLabel(message_types);
|
const message_type = getMessageTypeLabel(message_types);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue