whatever
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
#version 450
|
#version 450
|
||||||
#extension GL_ARB_separate_shader_objects : enable
|
#extension GL_ARB_separate_shader_objects : enable
|
||||||
|
|
||||||
|
layout(binding = 1) uniform sampler2D tex;
|
||||||
|
|
||||||
layout(location = 0) in vec2 tex_coords;
|
layout(location = 0) in vec2 tex_coords;
|
||||||
|
|
||||||
layout(location = 0) out vec4 out_color;
|
layout(location = 0) out vec4 out_color;
|
||||||
|
|
||||||
//layout(binding = 1) uniform sampler2D tex;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
out_color = vec4(1.0, 0.0, 0.0, 1.0);// texture(tex, tex_coords);
|
out_color = texture(tex, tex_coords);
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,10 @@ layout(push_constant) uniform PushConstants {
|
|||||||
mat4 model;
|
mat4 model;
|
||||||
} push;
|
} push;
|
||||||
|
|
||||||
|
out gl_PerVertex {
|
||||||
|
vec4 gl_Position;
|
||||||
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = ubo.projection * ubo.view * push.model * vec4(position, 1.0);
|
gl_Position = ubo.projection * ubo.view * push.model * vec4(position, 1.0);
|
||||||
tex_coords = uv;
|
tex_coords = uv;
|
||||||
|
|||||||
@@ -75,8 +75,9 @@ pub struct GameObject {
|
|||||||
pub(crate) type GameObjectHandle = usize;
|
pub(crate) type GameObjectHandle = usize;
|
||||||
pub(crate) type MeshHandle = usize;
|
pub(crate) type MeshHandle = usize;
|
||||||
|
|
||||||
type FixedGraphicsDescriptorSet = Arc<FixedSizeDescriptorSet<Arc<dyn GraphicsPipelineAbstract + Send + Sync>, ((), PersistentDescriptorSetBuf<Arc<vulkano::buffer::cpu_access::CpuAccessibleBuffer<vs::ty::UniformBufferObject>>>)>>;
|
//type FixedGraphicsDescriptorSet = Arc<FixedSizeDescriptorSet<Arc<dyn GraphicsPipelineAbstract + Send + Sync>, ((), PersistentDescriptorSetBuf<Arc<vulkano::buffer::cpu_access::CpuAccessibleBuffer<vs::ty::UniformBufferObject>>>)>>;
|
||||||
//type FixedGraphicsDescriptorSet = Arc<FixedSizeDescriptorSet<Arc<dyn GraphicsPipelineAbstract + Send + Sync>, ((((), PersistentDescriptorSetBuf<Arc<CpuAccessibleBuffer<vs::ty::UniformBufferObject>>>), PersistentDescriptorSetImg<Arc<ImmutableImage<Format>>>), PersistentDescriptorSetSampler)>>;
|
//type FixedGraphicsDescriptorSet = Arc<FixedSizeDescriptorSet<Arc<dyn GraphicsPipelineAbstract + Send + Sync>, (((), PersistentDescriptorSetBuf<Arc<CpuAccessibleBuffer<vs::ty::UniformBufferObject>>>), PersistentDescriptorSetImg<Arc<ImmutableImage<Format>>>)>>;
|
||||||
|
type FixedGraphicsDescriptorSet = Arc<FixedSizeDescriptorSet<Arc<dyn GraphicsPipelineAbstract + Send + Sync>, ((((), PersistentDescriptorSetBuf<Arc<CpuAccessibleBuffer<vs::ty::UniformBufferObject>>>), PersistentDescriptorSetImg<Arc<ImmutableImage<Format>>>), PersistentDescriptorSetSampler)>>;
|
||||||
|
|
||||||
pub struct GameData {
|
pub struct GameData {
|
||||||
pub start_time: SystemTime,
|
pub start_time: SystemTime,
|
||||||
@@ -268,20 +269,22 @@ impl VulkanRenderer {
|
|||||||
let line_pipeline: Arc<GraphicsPipelineAbstract + Send + Sync> =
|
let line_pipeline: Arc<GraphicsPipelineAbstract + Send + Sync> =
|
||||||
create_pipeline::<LinePoint>(device.clone(), render_pass.clone(), "shaders/line.vert", "shaders/line.frag", true).unwrap();
|
create_pipeline::<LinePoint>(device.clone(), render_pass.clone(), "shaders/line.vert", "shaders/line.frag", true).unwrap();
|
||||||
|
|
||||||
let (default_tex, default_tex_future) = {
|
let default_tex = {
|
||||||
let image = image::load_from_memory_with_format(include_bytes!("../models/missing-texture.jpg"),
|
let image = image::load_from_memory_with_format(include_bytes!("../models/missing-texture.jpg"),
|
||||||
ImageFormat::JPEG).unwrap().to_rgba();
|
ImageFormat::JPEG).unwrap().to_rgba();
|
||||||
let image_data = image.into_raw().clone();
|
let image_data = image.into_raw().clone();
|
||||||
|
|
||||||
ImmutableImage::from_iter(
|
let (image_view, future) = ImmutableImage::from_iter(
|
||||||
image_data.iter().cloned(),
|
image_data.iter().cloned(),
|
||||||
Dimensions::Dim2d { width: 128, height: 128 },
|
Dimensions::Dim2d { width: 128, height: 128 },
|
||||||
Format::R8G8B8A8Unorm,
|
Format::R8G8B8A8Unorm,
|
||||||
queue.clone(),
|
queue.clone(),
|
||||||
).unwrap()
|
).unwrap();
|
||||||
};
|
|
||||||
|
|
||||||
default_tex_future.flush().unwrap();
|
future.flush().unwrap();
|
||||||
|
|
||||||
|
image_view
|
||||||
|
};
|
||||||
|
|
||||||
// Dynamic viewports allow us to recreate just the viewport when the window is resized
|
// Dynamic viewports allow us to recreate just the viewport when the window is resized
|
||||||
// Otherwise we would have to recreate the whole pipeline.
|
// Otherwise we would have to recreate the whole pipeline.
|
||||||
@@ -310,7 +313,7 @@ impl VulkanRenderer {
|
|||||||
descriptor_set_pool
|
descriptor_set_pool
|
||||||
.lock().unwrap().next()
|
.lock().unwrap().next()
|
||||||
.add_buffer(uniform_buffer.clone()).unwrap()
|
.add_buffer(uniform_buffer.clone()).unwrap()
|
||||||
// .add_sampled_image(default_tex.clone(), sampler.clone()).unwrap()
|
.add_sampled_image(default_tex.clone(), sampler.clone()).unwrap()
|
||||||
.build().unwrap())
|
.build().unwrap())
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@@ -419,13 +422,23 @@ impl VulkanRenderer {
|
|||||||
|
|
||||||
let command_buffer = self.create_command_buffer(fb_index, new_ubo).clone();
|
let command_buffer = self.create_command_buffer(fb_index, new_ubo).clone();
|
||||||
|
|
||||||
let future = self.previous_frame_end.take().unwrap().join(acquire_future)
|
let future = self.previous_frame_end.take().unwrap()
|
||||||
|
.join(acquire_future)
|
||||||
.then_execute(self.queue.clone(), command_buffer).unwrap()
|
.then_execute(self.queue.clone(), command_buffer).unwrap()
|
||||||
.then_swapchain_present(self.queue.clone(), self.swapchain.clone(), fb_index)
|
.then_swapchain_present(self.queue.clone(), self.swapchain.clone(), fb_index)
|
||||||
.then_signal_fence_and_flush();
|
.then_signal_fence_and_flush();
|
||||||
|
|
||||||
match future {
|
match future {
|
||||||
Ok(future) => {
|
Ok(future) => {
|
||||||
|
// we're joining on the previous future but the CPU is running faster than the GPU so
|
||||||
|
// eventually it stutters, and jumps ahead to the newer frames.
|
||||||
|
//
|
||||||
|
// See vulkano issue 1135: https://github.com/vulkano-rs/vulkano/issues/1135
|
||||||
|
// This makes sure the CPU stays in sync with the GPU in situations when the CPU is
|
||||||
|
// running "too fast"
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
future.wait(None).unwrap();
|
||||||
|
|
||||||
self.previous_frame_end = Some(Box::new(future) as Box<_>);
|
self.previous_frame_end = Some(Box::new(future) as Box<_>);
|
||||||
},
|
},
|
||||||
Err(FlushError::OutOfDate) => {
|
Err(FlushError::OutOfDate) => {
|
||||||
@@ -585,8 +598,8 @@ fn create_pipeline<V: vulkano::pipeline::vertex::Vertex>(device: Arc<Device>, re
|
|||||||
.vertex_shader(vertex_shader_entry.clone(), ())
|
.vertex_shader(vertex_shader_entry.clone(), ())
|
||||||
.triangle_list()
|
.triangle_list()
|
||||||
.viewports_dynamic_scissors_irrelevant(1)
|
.viewports_dynamic_scissors_irrelevant(1)
|
||||||
.fragment_shader(fragment_shader_entry.clone(), ())
|
|
||||||
.depth_stencil_simple_depth()
|
.depth_stencil_simple_depth()
|
||||||
|
.fragment_shader(fragment_shader_entry.clone(), ())
|
||||||
.blend_alpha_blending()
|
.blend_alpha_blending()
|
||||||
.cull_mode_back()
|
.cull_mode_back()
|
||||||
.render_pass(sub_pass.clone())
|
.render_pass(sub_pass.clone())
|
||||||
|
|||||||
Reference in New Issue
Block a user