-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update windowing chapter #17
Changes from all commits
b0bad89
8ad20d2
5a43845
9ec9810
f81cc59
59cf9ce
d9d9f65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -55,12 +55,30 @@ let event_loop = EventLoop::new(); // ignore this for now | |||||||||||||||||||||
let surface = WindowBuilder::new() | ||||||||||||||||||||||
.build_vk_surface(&event_loop, instance.clone()) | ||||||||||||||||||||||
.unwrap(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
let window = surface | ||||||||||||||||||||||
.object() | ||||||||||||||||||||||
.unwrap() | ||||||||||||||||||||||
.clone() | ||||||||||||||||||||||
.downcast::<Window>() | ||||||||||||||||||||||
.unwrap(); | ||||||||||||||||||||||
Comment on lines
+58
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated since it also appears below. I like that put a separate version of this together with the explanation, so I think it's best if you stick only with the below one and remove this one.
Suggested change
|
||||||||||||||||||||||
``` | ||||||||||||||||||||||
|
||||||||||||||||||||||
As you can see, we created a new object, called *surface*. | ||||||||||||||||||||||
|
||||||||||||||||||||||
The *surface* is a cross-platform abstraction over the actual window object, that vulkano can use | ||||||||||||||||||||||
for rendering. As for the window itself, it can be retrieved by calling `surface.window()`, which | ||||||||||||||||||||||
for rendering. As for the window itself, it can be retrieved this way: | ||||||||||||||||||||||
|
||||||||||||||||||||||
```rust | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
let window = surface | ||||||||||||||||||||||
.object() | ||||||||||||||||||||||
.unwrap() | ||||||||||||||||||||||
.clone() | ||||||||||||||||||||||
.downcast::<Window>() | ||||||||||||||||||||||
.unwrap(); | ||||||||||||||||||||||
Comment on lines
+74
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fmt
Suggested change
|
||||||||||||||||||||||
``` | ||||||||||||||||||||||
|
||||||||||||||||||||||
which | ||||||||||||||||||||||
you can use to manipulate and change its default properties. | ||||||||||||||||||||||
Comment on lines
+80
to
82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This continues a sentence from above the code block, which is generally a no-no as it can be a bit hard to read. More importantly however, ideally users wouldn't use this procedure every time they need to access the window. This is something users seem to be doing and so I would like to make this distinction clearer. I'm not sure what the best phrasing is myself (feel free to comment). All in all, maybe it's best to remove this entirely.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: the issue has just been resolved upstream. Therefore there is no further clarification needed, as this way of creating the surface is going to be deprecated in the next release. |
||||||||||||||||||||||
|
||||||||||||||||||||||
After you made the change, running the program should now open a window, then immediately | ||||||||||||||||||||||
|
@@ -98,6 +116,7 @@ makes our closure set the `control_flow` to `ControlFlow::Exit` which signals to | |||||||||||||||||||||
an exit. | ||||||||||||||||||||||
|
||||||||||||||||||||||
<!-- todo: is this correct? --> | ||||||||||||||||||||||
|
||||||||||||||||||||||
<!-- > **Note**: Since there is nothing to stop it, the window will try to update as quickly as it can, | ||||||||||||||||||||||
> likely using all the power it can get from one of your cores. | ||||||||||||||||||||||
> We will change that, however, in the incoming chapters. --> | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -10,7 +10,7 @@ invalid format errors: | |||||||
```rust | ||||||||
use vulkano::render_pass::RenderPass; | ||||||||
|
||||||||
fn get_render_pass(device: Arc<Device>, swapchain: &Arc<Swapchain<Window>>) -> Arc<RenderPass> { | ||||||||
fn get_render_pass(device: Arc<Device>, swapchain: &Arc<Swapchain>) -> Arc<RenderPass> { | ||||||||
vulkano::single_pass_renderpass!( | ||||||||
device, | ||||||||
attachments: { | ||||||||
|
@@ -42,7 +42,7 @@ use vulkano::image::SwapchainImage; | |||||||
use vulkano::render_pass::{Framebuffer, FramebufferCreateInfo}; | ||||||||
|
||||||||
fn get_framebuffers( | ||||||||
images: &[Arc<SwapchainImage<Window>>], | ||||||||
images: &[Arc<SwapchainImage>], | ||||||||
render_pass: &Arc<RenderPass>, | ||||||||
) -> Vec<Arc<Framebuffer>> { | ||||||||
images | ||||||||
|
@@ -149,7 +149,6 @@ As for the pipeline, let's initialize the viewport with our window dimensions: | |||||||
|
||||||||
```rust | ||||||||
use vulkano::pipeline::graphics::input_assembly::InputAssemblyState; | ||||||||
use vulkano::pipeline::graphics::vertex_input::BuffersDefinition; | ||||||||
use vulkano::pipeline::graphics::viewport::{Viewport, ViewportState}; | ||||||||
use vulkano::pipeline::GraphicsPipeline; | ||||||||
use vulkano::render_pass::Subpass; | ||||||||
|
@@ -163,7 +162,7 @@ fn get_pipeline( | |||||||
viewport: Viewport, | ||||||||
) -> Arc<GraphicsPipeline> { | ||||||||
GraphicsPipeline::start() | ||||||||
.vertex_input_state(BuffersDefinition::new().vertex::<Vertex>()) | ||||||||
.vertex_input_state(MyVertex::per_vertex()) | ||||||||
.vertex_shader(vs.entry_point("main").unwrap(), ()) | ||||||||
.input_assembly_state(InputAssemblyState::new()) | ||||||||
.viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([viewport])) | ||||||||
|
@@ -178,7 +177,7 @@ fn main() { | |||||||
|
||||||||
let mut viewport = Viewport { | ||||||||
origin: [0.0, 0.0], | ||||||||
dimensions: surface.window().inner_size().into(), | ||||||||
dimensions: window.inner_size().into(), | ||||||||
depth_range: 0.0..1.0, | ||||||||
}; | ||||||||
|
||||||||
|
@@ -206,7 +205,7 @@ also have multiple framebuffers, we will have multiple command buffers as well, | |||||||
framebuffer. Let's put everything nicely into a function: | ||||||||
|
||||||||
```rust | ||||||||
use vulkano::buffer::TypedBufferAccess; | ||||||||
use vulkano::buffer::subbuffer::Subbuffer; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would personally prefer importing the re-exported one from the
Suggested change
|
||||||||
use vulkano::command_buffer::{ | ||||||||
AutoCommandBufferBuilder, CommandBufferUsage, PrimaryAutoCommandBuffer, SubpassContents, | ||||||||
RenderPassBeginInfo, | ||||||||
|
@@ -215,17 +214,17 @@ use vulkano::command_buffer::{ | |||||||
use vulkano::device::Queue; | ||||||||
|
||||||||
fn get_command_buffers( | ||||||||
device: &Arc<Device>, | ||||||||
command_buffer_allocator: &StandardCommandBufferAllocator, | ||||||||
queue: &Arc<Queue>, | ||||||||
pipeline: &Arc<GraphicsPipeline>, | ||||||||
framebuffers: &Vec<Arc<Framebuffer>>, | ||||||||
vertex_buffer: &Arc<CpuAccessibleBuffer<[MyVertex]>>, | ||||||||
vertex_buffer: &Subbuffer<[MyVertex]>, | ||||||||
) -> Vec<Arc<PrimaryAutoCommandBuffer>> { | ||||||||
framebuffers | ||||||||
.iter() | ||||||||
.map(|framebuffer| { | ||||||||
let mut builder = AutoCommandBufferBuilder::primary( | ||||||||
device.clone(), | ||||||||
command_buffer_allocator, | ||||||||
queue.queue_family_index(), | ||||||||
CommandBufferUsage::MultipleSubmit, // don't forget to write the correct buffer usage | ||||||||
) | ||||||||
|
@@ -254,7 +253,7 @@ fn get_command_buffers( | |||||||
|
||||||||
// main() | ||||||||
let mut command_buffers = get_command_buffers( | ||||||||
&device, | ||||||||
&command_buffer_allocator, | ||||||||
&queue, | ||||||||
&pipeline, | ||||||||
&framebuffers, | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt