Skip to content

Commit 152b966

Browse files
author
Matthew Russo
committed
adds cgmath
1 parent 120af82 commit 152b966

File tree

2 files changed

+48
-36
lines changed

2 files changed

+48
-36
lines changed

src/bin/28_generating_mipmaps.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern crate vulkano_win;
44
extern crate winit;
55
extern crate image;
66
extern crate tobj;
7+
extern crate cgmath;
78

89
use std::sync::{Arc, Mutex};
910
use std::collections::HashSet;
@@ -88,8 +89,17 @@ use vulkano::sampler::{
8889
MipmapMode,
8990
SamplerAddressMode,
9091
};
92+
9193
use image::GenericImageView;
9294

95+
use cgmath::{
96+
Rad,
97+
Deg,
98+
Matrix4,
99+
Vector3,
100+
Point3
101+
};
102+
93103
const WIDTH: u32 = 800;
94104
const HEIGHT: u32 = 600;
95105

@@ -143,9 +153,9 @@ impl_vertex!(Vertex, pos, color, tex);
143153
#[allow(dead_code)]
144154
#[derive(Copy, Clone)]
145155
struct UniformBufferObject {
146-
model: glm::Mat4,
147-
view: glm::Mat4,
148-
proj: glm::Mat4,
156+
model: Matrix4<f32>,
157+
view: Matrix4<f32>,
158+
proj: Matrix4<f32>,
149159
}
150160

151161
type DescriptorSetUBO = PersistentDescriptorSetBuf<Arc<CpuAccessibleBuffer<UniformBufferObject>>>;
@@ -937,28 +947,22 @@ impl HelloTriangleApplication {
937947
let duration = Instant::now().duration_since(start_time);
938948
let elapsed = (duration.as_secs() * 1000) + u64::from(duration.subsec_millis());
939949

940-
let identity_matrix = glm::mat4(
941-
1.0, 0.0, 0.0, 0.0,
942-
0.0, 1.0, 0.0, 0.0,
943-
0.0, 0.0, 1.0, 0.0,
944-
0.0, 0.0, 0.0, 1.0,
945-
);
946-
947-
let model = glm::ext::rotate(&identity_matrix, (elapsed as f32) * glm::radians(0.180), glm::vec3(0.0, 0.0, 1.00));
950+
let model = Matrix4::from_angle_z(Rad::from(Deg(elapsed as f32 * 0.180)));
948951

949-
let view = glm::ext::look_at(
950-
glm::vec3(2.0, 2.0, 2.0),
951-
glm::vec3(0.0, 0.0, 0.0),
952-
glm::vec3(0.0, 0.0, 1.0)
952+
let view = Matrix4::look_at(
953+
Point3::new(2.0, 2.0, 2.0),
954+
Point3::new(0.0, 0.0, 0.0),
955+
Vector3::new(0.0, 0.0, 1.0)
953956
);
954-
let mut proj = glm::ext::perspective(
955-
glm::radians(45.0,),
957+
958+
let mut proj = cgmath::perspective(
959+
Rad::from(Deg(45.0)),
956960
dimensions[0] as f32 / dimensions[1] as f32,
957961
0.1,
958962
10.0
959963
);
960964

961-
proj.c1.y *= -1.0;
965+
proj.y.y *= -1.0;
962966

963967
UniformBufferObject { model, view, proj }
964968
}

src/bin/28_generating_mipmaps.rs.diff

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- a/27_model_loading.rs
22
+++ b/28_generating_mipmaps.rs
3-
@@ -36,12 +36,20 @@ use vulkano::swapchain::{
3+
@@ -37,12 +37,20 @@ use vulkano::swapchain::{
44
use vulkano::format::{Format, ClearValue};
55
use vulkano::image::{
66
ImageUsage,
@@ -24,29 +24,31 @@
2424
use vulkano::pipeline::{
2525
GraphicsPipeline,
2626
GraphicsPipelineAbstract,
27-
@@ -58,6 +66,7 @@ use vulkano::command_buffer::{
27+
@@ -59,6 +67,7 @@ use vulkano::command_buffer::{
2828
AutoCommandBuffer,
2929
AutoCommandBufferBuilder,
3030
DynamicState,
3131
+ CommandBuffer,
3232
};
3333
use vulkano::buffer::{
3434
immutable::ImmutableBuffer,
35-
@@ -73,7 +82,12 @@ use vulkano::descriptor::descriptor_set::{
35+
@@ -74,9 +83,14 @@ use vulkano::descriptor::descriptor_set::{
3636
PersistentDescriptorSetImg,
3737
PersistentDescriptorSetSampler,
3838
};
39-
-use vulkano::sampler::Sampler;
4039
+use vulkano::sampler::{
4140
+ Sampler,
4241
+ Filter,
4342
+ MipmapMode,
4443
+ SamplerAddressMode,
4544
+};
45+
4646
use image::GenericImageView;
47+
-use vulkano::sampler::Sampler;
4748

48-
const WIDTH: u32 = 800;
49-
@@ -539,28 +553,108 @@ impl HelloTriangleApplication {
49+
use cgmath::{
50+
Rad,
51+
@@ -549,28 +563,114 @@ impl HelloTriangleApplication {
5052
).collect::<Vec<_>>()
5153
}
5254

@@ -149,19 +151,25 @@
149151

150152
fn create_image_sampler(device: &Arc<Device>) -> Arc<Sampler> {
151153
- Sampler::simple_repeat_linear(device.clone())
154+
+ // This is the standard sampler but for this section we are using a custom sampler to show the work we have done
152155
+ // Sampler::simple_repeat_linear(device.clone())
153-
+ Sampler::new(device.clone(),
154-
+ Filter::Linear,
155-
+ Filter::Linear,
156-
+ MipmapMode::Linear,
157-
+ SamplerAddressMode::Repeat,
158-
+ SamplerAddressMode::Repeat,
159-
+ SamplerAddressMode::Repeat,
160-
+ 0.0,
161-
+ 1.0,
162-
+ 6.0,
163-
+ 1_000.0)
164-
+ .unwrap()
156+
+
157+
+ let min_lod = 6.0;
158+
+ // This custom sampler used a min_lod of 6 to display the work we have done in this section
159+
+ // changing the above variable will change which mipmap is used.
160+
+ Sampler::new(
161+
+ device.clone(),
162+
+ Filter::Linear,
163+
+ Filter::Linear,
164+
+ MipmapMode::Linear,
165+
+ SamplerAddressMode::Repeat,
166+
+ SamplerAddressMode::Repeat,
167+
+ SamplerAddressMode::Repeat,
168+
+ 0.0,
169+
+ 1.0,
170+
+ min_lod,
171+
+ 1_000.0
172+
+ ).unwrap()
165173
}
166174

167175
fn load_model() -> (Vec<Vertex>, Vec<u32>) {

0 commit comments

Comments
 (0)