Multi color triangle

This commit is contained in:
maik klein 2016-12-09 01:11:26 +01:00
parent 87ef22419f
commit 46f93779a0
5 changed files with 42 additions and 26 deletions

Binary file not shown.

View file

@ -54,10 +54,8 @@ pub fn find_memorytype_index(memory_req: &vk::MemoryRequirements,
} }
#[derive(Clone, Debug, Copy)] #[derive(Clone, Debug, Copy)]
struct Vertex { struct Vertex {
x: f32, pos: [f32; 4],
y: f32, color: [f32; 4],
z: f32,
w: f32,
} }
fn main() { fn main() {
@ -119,7 +117,6 @@ fn main() {
p_user_data: ptr::null_mut(), p_user_data: ptr::null_mut(),
}; };
let debug_call_back = instance.create_debug_report_callback_ext(&debug_info).unwrap(); let debug_call_back = instance.create_debug_report_callback_ext(&debug_info).unwrap();
// println!("{:?}", instance);
let x11_display = window.glfw.get_x11_display(); let x11_display = window.glfw.get_x11_display();
let x11_window = window.get_x11_window(); let x11_window = window.get_x11_window();
let x11_create_info = vk::XlibSurfaceCreateInfoKHR { let x11_create_info = vk::XlibSurfaceCreateInfoKHR {
@ -226,7 +223,7 @@ fn main() {
let present_mode = present_modes.iter() let present_mode = present_modes.iter()
.cloned() .cloned()
.find(|&mode| mode == vk::PresentModeKHR::Mailbox) .find(|&mode| mode == vk::PresentModeKHR::Mailbox)
.unwrap_or(vk::PresentModeKHR::Immediate); .unwrap_or(vk::PresentModeKHR::Fifo);
let swapchain_create_info = vk::SwapchainCreateInfoKHR { let swapchain_create_info = vk::SwapchainCreateInfoKHR {
s_type: vk::StructureType::SwapchainCreateInfoKhr, s_type: vk::StructureType::SwapchainCreateInfoKhr,
p_next: ptr::null(), p_next: ptr::null(),
@ -346,7 +343,6 @@ fn main() {
let layout_transition_barrier = vk::ImageMemoryBarrier { let layout_transition_barrier = vk::ImageMemoryBarrier {
s_type: vk::StructureType::ImageMemoryBarrier, s_type: vk::StructureType::ImageMemoryBarrier,
p_next: ptr::null(), p_next: ptr::null(),
// TODO Is this correct?
src_access_mask: Default::default(), src_access_mask: Default::default(),
dst_access_mask: vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | dst_access_mask: vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
@ -444,14 +440,15 @@ fn main() {
attachment: 1, attachment: 1,
layout: vk::ImageLayout::DepthStencilAttachmentOptimal, layout: vk::ImageLayout::DepthStencilAttachmentOptimal,
}; };
let dependency = vk::SubpassDependency{ let dependency = vk::SubpassDependency {
dependency_flags: Default::default(), dependency_flags: Default::default(),
src_subpass: vk::VK_SUBPASS_EXTERNAL, src_subpass: vk::VK_SUBPASS_EXTERNAL,
dst_subpass: Default::default(), dst_subpass: Default::default(),
src_stage_mask: vk::PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, src_stage_mask: vk::PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
src_access_mask: Default::default(), src_access_mask: Default::default(),
dst_access_mask: vk::ACCESS_COLOR_ATTACHMENT_READ_BIT | vk::ACCESS_COLOR_ATTACHMENT_WRITE_BIT, dst_access_mask: vk::ACCESS_COLOR_ATTACHMENT_READ_BIT |
dst_stage_mask: vk::PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT vk::ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
dst_stage_mask: vk::PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
}; };
let subpass = vk::SubpassDescription { let subpass = vk::SubpassDescription {
color_attachment_count: 1, color_attachment_count: 1,
@ -526,22 +523,16 @@ fn main() {
vk::MemoryMapFlags::empty()) vk::MemoryMapFlags::empty())
.unwrap(); .unwrap();
let vertices = [Vertex { let vertices = [Vertex {
x: -1.0, pos: [-1.0, 1.0, 0.0, 1.0],
y: 1.0, color: [0.0, 1.0, 0.0, 1.0],
z: 0.0,
w: 1.0,
}, },
Vertex { Vertex {
x: 1.0, pos: [1.0, 1.0, 0.0, 1.0],
y: 1.0, color: [0.0, 0.0, 1.0, 1.0],
z: 0.0,
w: 1.0,
}, },
Vertex { Vertex {
x: 0.0, pos: [0.0, -1.0, 0.0, 1.0],
y: -1.0, color: [1.0, 0.0, 0.0, 1.0],
z: 0.0,
w: 1.0,
}]; }];
slice.copy_from_slice(&vertices); slice.copy_from_slice(&vertices);
@ -613,6 +604,12 @@ fn main() {
binding: 0, binding: 0,
format: vk::Format::R32g32b32a32Sfloat, format: vk::Format::R32g32b32a32Sfloat,
offset: 0, offset: 0,
},
vk::VertexInputAttributeDescription {
location: 1,
binding: 0,
format: vk::Format::R32g32b32a32Sfloat,
offset: mem::size_of::<[f32; 4]>() as u32,
}]; }];
let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo { let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo {
s_type: vk::StructureType::PipelineVertexInputStateCreateInfo, s_type: vk::StructureType::PipelineVertexInputStateCreateInfo,
@ -765,7 +762,6 @@ fn main() {
let present_complete_semaphore = device.create_semaphore(&semaphore_create_info).unwrap(); let present_complete_semaphore = device.create_semaphore(&semaphore_create_info).unwrap();
let rendering_complete_semaphore = device.create_semaphore(&semaphore_create_info).unwrap(); let rendering_complete_semaphore = device.create_semaphore(&semaphore_create_info).unwrap();
/// / println!("{:?}", present_image_views.len());
let mut current = time::precise_time_ns(); let mut current = time::precise_time_ns();
let mut last = current; let mut last = current;
device.reset_fences(&[submit_fence]).unwrap(); device.reset_fences(&[submit_fence]).unwrap();
@ -779,7 +775,6 @@ fn main() {
current = time::precise_time_ns(); current = time::precise_time_ns();
let dt = current - last; let dt = current - last;
last = current; last = current;
println!("dt: {}ms", dt/1000000);
let present_index = device.acquire_next_image_khr(swapchain, let present_index = device.acquire_next_image_khr(swapchain,
std::u64::MAX, std::u64::MAX,
present_complete_semaphore, present_complete_semaphore,
@ -833,7 +828,6 @@ fn main() {
}; };
device.queue_submit(present_queue, &[submit_info], draw_fence) device.queue_submit(present_queue, &[submit_info], draw_fence)
.unwrap(); .unwrap();
let mut present_info_err = unsafe { mem::uninitialized() }; let mut present_info_err = unsafe { mem::uninitialized() };
let present_info = vk::PresentInfoKHR { let present_info = vk::PresentInfoKHR {
s_type: vk::StructureType::PresentInfoKhr, s_type: vk::StructureType::PresentInfoKhr,
@ -849,7 +843,6 @@ fn main() {
device.wait_for_fences(&[draw_fence], true, std::u64::MAX) device.wait_for_fences(&[draw_fence], true, std::u64::MAX)
.unwrap(); .unwrap();
device.reset_fences(&[draw_fence]).unwrap(); device.reset_fences(&[draw_fence]).unwrap();
// device.queue_wait_idle(present_queue).unwrap();
} }
device.device_wait_idle().unwrap(); device.device_wait_idle().unwrap();

10
examples/triangle.frag Normal file
View file

@ -0,0 +1,10 @@
#version 400
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec4 o_color;
layout (location = 0) out vec4 uFragColor;
void main() {
uFragColor = o_color;
}

13
examples/triangle.vert Normal file
View file

@ -0,0 +1,13 @@
#version 400
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec4 pos;
layout (location = 1) in vec4 color;
layout (location = 0) out vec4 o_color;
void main() {
o_color = color;
gl_Position = pos;
}

Binary file not shown.