Skip to content

Commit 3b646e6

Browse files
committed
Move examples to glam
1 parent bdacba9 commit 3b646e6

File tree

9 files changed

+29
-634
lines changed

9 files changed

+29
-634
lines changed

crates/optix/examples/ex03_window/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ anyhow = "1.0.44"
1313
glfw = "0.42.0"
1414
gl = "0.14.0"
1515
num-traits = "0.2.14"
16+
glam = { version = "0.30", features = ["bytemuck"] }

crates/optix/examples/ex03_window/src/gl_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use gl;
22
use gl::types::{GLchar, GLenum, GLint, GLsizeiptr, GLuint, GLvoid};
33
use std::ffi::{CStr, CString};
44

5-
use crate::vector::*;
5+
use glam::Vec4;
66

77
pub struct Shader {
88
id: GLuint,
@@ -516,7 +516,7 @@ impl FullscreenQuad {
516516
self.vertex_array.unbind();
517517
}
518518

519-
pub fn update_texture(&self, data: &[V4f32]) {
519+
pub fn update_texture(&self, data: &[Vec4]) {
520520
unsafe {
521521
gl::BindTexture(gl::TEXTURE_2D, self.texture_id);
522522
gl::TexSubImage2D(

crates/optix/examples/ex03_window/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
mod renderer;
44
use renderer::Renderer;
55

6-
mod vector;
7-
pub use vector::*;
6+
use glam::{IVec2, Vec4};
87
mod gl_util;
98
use gl_util::FullscreenQuad;
109
use glfw::{Action, Context, Key};
@@ -42,7 +41,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4241

4342
let mut fsq = FullscreenQuad::new(width, height).unwrap();
4443

45-
let mut image_data = vec![v4f32(0.0, 0.0, 0.0, 0.0); (width * height) as usize];
44+
let mut image_data = vec![Vec4::new(0.0, 0.0, 0.0, 0.0); (width * height) as usize];
4645

4746
unsafe {
4847
gl::Viewport(0, 0, fb_width, fb_height);
@@ -62,7 +61,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6261
renderer.resize(w, h)?;
6362
width = w;
6463
height = h;
65-
image_data.resize((width * height) as usize, v4f32(0.0, 0.0, 0.0, 0.0));
64+
image_data.resize((width * height) as usize, Vec4::new(0.0, 0.0, 0.0, 0.0));
6665
}
6766

6867
renderer.render()?;

crates/optix/examples/ex03_window/src/renderer.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use optix::{
1414
shader_binding_table::{SbtRecord, ShaderBindingTable},
1515
};
1616

17-
use crate::vector::V4f32;
17+
use glam::{IVec2, Vec4};
1818

1919
pub struct Renderer {
2020
launch_params: DeviceVariable<LaunchParams>,
@@ -23,7 +23,7 @@ pub struct Renderer {
2323
buf_hitgroup: DeviceBuffer<HitgroupRecord>,
2424
buf_miss: DeviceBuffer<MissRecord>,
2525
pipeline: Pipeline,
26-
color_buffer: DeviceBuffer<V4f32>,
26+
color_buffer: DeviceBuffer<Vec4>,
2727
ctx: DeviceContext,
2828
stream: Stream,
2929
cuda_context: CuContext,
@@ -144,10 +144,7 @@ impl Renderer {
144144
let launch_params = DeviceVariable::new(LaunchParams {
145145
frame_id: 0,
146146
color_buffer: color_buffer.as_device_ptr(),
147-
fb_size: Point2i {
148-
x: width as i32,
149-
y: height as i32,
150-
},
147+
fb_size: IVec2::new(width as i32, height as i32),
151148
})?;
152149

153150
Ok(Renderer {
@@ -193,24 +190,17 @@ impl Renderer {
193190
Ok(())
194191
}
195192

196-
pub fn download_pixels(&self, slice: &mut [V4f32]) -> Result<(), Box<dyn std::error::Error>> {
193+
pub fn download_pixels(&self, slice: &mut [Vec4]) -> Result<(), Box<dyn std::error::Error>> {
197194
self.color_buffer.copy_to(slice)?;
198195
Ok(())
199196
}
200197
}
201198

202-
#[repr(C)]
203-
#[derive(Copy, Clone, DeviceCopy)]
204-
struct Point2i {
205-
pub x: i32,
206-
pub y: i32,
207-
}
208-
209199
#[repr(C)]
210200
#[derive(Copy, Clone, DeviceCopy)]
211201
struct LaunchParams {
212-
pub color_buffer: DevicePointer<V4f32>,
213-
pub fb_size: Point2i,
202+
pub color_buffer: DevicePointer<Vec4>,
203+
pub fb_size: IVec2,
214204
pub frame_id: i32,
215205
}
216206

0 commit comments

Comments
 (0)