Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ on:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUSTFLAGS: "-Dwarnings"

jobs:
desktop:
name: Check Desktop
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
Expand All @@ -41,16 +43,22 @@ jobs:
command: check
args: --examples --all-features

- name: Rustfmt
- name: Formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
args: --all -- --check

- name: Clippy
uses: actions-rs/cargo@v1
with:
command: clippy

web:
name: Check Web
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
Expand Down
4 changes: 1 addition & 3 deletions examples/headless/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ fn main() {
// Render three frames
for frame_index in 0..3 {
// Set the current transformation of the triangle
model.set_transformation(Mat4::from_angle_y(radians(
(frame_index as f32 * 0.6) as f32,
)));
model.set_transformation(Mat4::from_angle_y(radians(frame_index as f32 * 0.6)));

// Create a render target (a combination of a color and a depth texture) to write into
let pixels = RenderTarget::new(
Expand Down
10 changes: 4 additions & 6 deletions examples/lighting/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,10 @@ pub async fn run() {
ui.add(Slider::new(&mut spot0.intensity, 0.0..=10.0).text("Spot intensity"));
ui.add(Slider::new(&mut point0.intensity, 0.0..=1.0).text("Point 0 intensity"));
ui.add(Slider::new(&mut point1.intensity, 0.0..=1.0).text("Point 1 intensity"));
if ui.checkbox(&mut shadows_enabled, "Shadows").clicked() {
if !shadows_enabled {
spot0.clear_shadow_map();
directional0.clear_shadow_map();
directional1.clear_shadow_map();
}
if ui.checkbox(&mut shadows_enabled, "Shadows").clicked() && !shadows_enabled {
spot0.clear_shadow_map();
directional0.clear_shadow_map();
directional1.clear_shadow_map();
}

ui.label("Lighting model");
Expand Down
2 changes: 1 addition & 1 deletion examples/lights/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl Glow {
);
Self {
aabb,
light: PointLight::new(&context, 1.0, Srgba::WHITE, pos, Attenuation::default()),
light: PointLight::new(context, 1.0, Srgba::WHITE, pos, Attenuation::default()),
velocity: vec3(
rng.gen::<f32>() * 2.0 - 1.0,
rng.gen::<f32>() * 2.0 - 1.0,
Expand Down
2 changes: 1 addition & 1 deletion examples/logo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Material for LogoMaterial<'_> {
}

fn use_uniforms(&self, program: &Program, _viewer: &dyn Viewer, _lights: &[&dyn Light]) {
program.use_texture("image", &self.image);
program.use_texture("image", self.image);
}

fn render_states(&self) -> RenderStates {
Expand Down
2 changes: 1 addition & 1 deletion examples/shapes2d/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn main() {
.screen()
.clear(ClearState::color_and_depth(0.8, 0.8, 0.8, 1.0, 1.0))
.render(
&Camera::new_2d(frame_input.viewport),
Camera::new_2d(frame_input.viewport),
line.into_iter().chain(&rectangle).chain(&circle),
&[],
);
Expand Down
2 changes: 1 addition & 1 deletion examples/text/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn main() {
frame_input
.screen()
.clear(ClearState::color_and_depth(1.0, 1.0, 1.0, 1.0, 1.0))
.render(&camera, &[&text0, &text1, &text2], &[]);
.render(&camera, [&text0, &text1, &text2], &[]);
FrameOutput::default()
});
}
7 changes: 1 addition & 6 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ pub(crate) fn full_screen_vertex_shader_source() -> &'static str {
mod data_type;
use data_type::DataType;
fn to_byte_slice<T: DataType>(data: &[T]) -> &[u8] {
unsafe {
std::slice::from_raw_parts(
data.as_ptr() as *const _,
data.len() * std::mem::size_of::<T>(),
)
}
unsafe { std::slice::from_raw_parts(data.as_ptr() as *const _, std::mem::size_of_val(data)) }
}

fn from_byte_slice<T: DataType>(data: &[u8]) -> &[T] {
Expand Down
2 changes: 1 addition & 1 deletion src/core/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<T: BufferDataType> Buffer<T> {
);
self.context.bind_buffer(crate::context::ARRAY_BUFFER, None);
}
self.attribute_count = (offset as u32 + data.len() as u32).max(self.attribute_count);
self.attribute_count = (offset + data.len() as u32).max(self.attribute_count);
}

pub fn attribute_count(&self) -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion src/core/buffer/element_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<T: ElementBufferDataType> ElementBuffer<T> {
self.context
.bind_buffer(crate::context::ELEMENT_ARRAY_BUFFER, None);
}
self.count = (offset as u32 + indices.len() as u32).max(self.count);
self.count = (offset + indices.len() as u32).max(self.count);
}

///
Expand Down
2 changes: 1 addition & 1 deletion src/core/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub trait DataType: std::fmt::Debug + Clone {
fn send_uniform(context: &Context, location: &UniformLocation, data: &[Self]);
}

impl<T: DataType + ?Sized> DataType for &T {
impl<T: DataType> DataType for &T {
fn internal_format() -> u32 {
T::internal_format()
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ impl Program {
viewport,
element_buffer,
0,
element_buffer.count() as u32,
element_buffer.count(),
)
}

Expand Down Expand Up @@ -561,7 +561,7 @@ impl Program {
viewport,
element_buffer,
0,
element_buffer.count() as u32,
element_buffer.count(),
instance_count,
)
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/texture/texture2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ impl Texture2D {
/// using low-level context calls inside the callback.
/// This function binds the texture and sets the parameters before calling the callback and generates mip maps afterwards.
///
/// **Note:** This function is unsafe and should only be used in special cases,
/// # Safety
///
/// This function is unsafe and should only be used in special cases,
/// for example when you have an uncommon source of data or the data is in a special format like sRGB.
///
pub unsafe fn new_unchecked<T: TextureDataType>(
Expand Down
6 changes: 4 additions & 2 deletions src/core/texture/texture2d_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Texture2DArray {
///
pub fn new(context: &Context, cpu_textures: &[&CpuTexture]) -> Self {
let cpu_texture = cpu_textures
.get(0)
.first()
.expect("Expect at least one texture in a texture array");
match &cpu_texture.data {
TextureData::RU8(_) => Self::new_with_data(
Expand Down Expand Up @@ -304,7 +304,9 @@ impl Texture2DArray {
/// using low-level context calls inside the callback.
/// This function binds the texture and sets the parameters before calling the callback and generates mip maps afterwards.
///
/// **Note:** This function is unsafe and should only be used in special cases,
/// # Safety
///
/// This function is unsafe and should only be used in special cases,
/// for example when you have an uncommon source of data or the data is in a special format like sRGB.
///
pub unsafe fn new_unchecked<T: TextureDataType>(
Expand Down
4 changes: 3 additions & 1 deletion src/core/texture/texture3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ impl Texture3D {
/// using low-level context calls inside the callback.
/// This function binds the texture and sets the parameters before calling the callback and generates mip maps afterwards.
///
/// **Note:** This function is unsafe and should only be used in special cases,
/// # Safety
///
/// This function is unsafe and should only be used in special cases,
/// for example when you have an uncommon source of data or the data is in a special format like sRGB.
///
pub unsafe fn new_unchecked<T: TextureDataType>(
Expand Down
6 changes: 4 additions & 2 deletions src/core/texture/texture_cube_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ impl TextureCubeMap {
let program = Program::from_source(
context,
full_screen_vertex_shader_source(),
&fragment_shader_source,
fragment_shader_source,
)
.expect("Failed compiling shader");

Expand Down Expand Up @@ -558,7 +558,9 @@ impl TextureCubeMap {
/// using low-level context calls inside the callback.
/// This function binds the texture and sets the parameters before calling the callback and generates mip maps afterwards.
///
/// **Note:** This function is unsafe and should only be used in special cases,
/// # Safety
///
/// This function is unsafe and should only be used in special cases,
/// for example when you have an uncommon source of data or the data is in a special format like sRGB.
///
pub unsafe fn new_unchecked<T: TextureDataType>(
Expand Down
2 changes: 1 addition & 1 deletion src/core/uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ impl<T: UniformDataType + PrimitiveDataType> UniformDataType for Matrix2<T> {}
impl<T: UniformDataType + PrimitiveDataType> UniformDataType for Matrix3<T> {}
impl<T: UniformDataType + PrimitiveDataType> UniformDataType for Matrix4<T> {}

impl<T: UniformDataType + ?Sized> UniformDataType for &T {}
impl<T: UniformDataType> UniformDataType for &T {}
32 changes: 14 additions & 18 deletions src/gui/egui_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,19 @@ impl GUI {
device_pixel_ratio: f32,
callback: impl FnOnce(&egui::Context),
) -> bool {
self.egui_context
.set_pixels_per_point(device_pixel_ratio as f32);
self.egui_context.set_pixels_per_point(device_pixel_ratio);
self.viewport = viewport;
let egui_input = egui::RawInput {
screen_rect: Some(egui::Rect {
min: egui::Pos2 {
x: viewport.x as f32 / device_pixel_ratio as f32,
y: viewport.y as f32 / device_pixel_ratio as f32,
x: viewport.x as f32 / device_pixel_ratio,
y: viewport.y as f32 / device_pixel_ratio,
},
max: egui::Pos2 {
x: viewport.x as f32 / device_pixel_ratio as f32
+ viewport.width as f32 / device_pixel_ratio as f32,
y: viewport.y as f32 / device_pixel_ratio as f32
+ viewport.height as f32 / device_pixel_ratio as f32,
x: viewport.x as f32 / device_pixel_ratio
+ viewport.width as f32 / device_pixel_ratio,
y: viewport.y as f32 / device_pixel_ratio
+ viewport.height as f32 / device_pixel_ratio,
},
}),
time: Some(accumulated_time_in_ms * 0.001),
Expand Down Expand Up @@ -123,9 +122,8 @@ impl GUI {
if !handled {
Some(egui::Event::PointerButton {
pos: egui::Pos2 {
x: position.x / device_pixel_ratio as f32,
y: (viewport.height as f32 - position.y)
/ device_pixel_ratio as f32,
x: position.x / device_pixel_ratio,
y: (viewport.height as f32 - position.y) / device_pixel_ratio,
},
button: button.into(),
pressed: true,
Expand All @@ -144,9 +142,8 @@ impl GUI {
if !handled {
Some(egui::Event::PointerButton {
pos: egui::Pos2 {
x: position.x / device_pixel_ratio as f32,
y: (viewport.height as f32 - position.y)
/ device_pixel_ratio as f32,
x: position.x / device_pixel_ratio,
y: (viewport.height as f32 - position.y) / device_pixel_ratio,
},
button: button.into(),
pressed: false,
Expand All @@ -161,9 +158,8 @@ impl GUI {
} => {
if !handled {
Some(egui::Event::PointerMoved(egui::Pos2 {
x: position.x / device_pixel_ratio as f32,
y: (viewport.height as f32 - position.y)
/ device_pixel_ratio as f32,
x: position.x / device_pixel_ratio,
y: (viewport.height as f32 - position.y) / device_pixel_ratio,
}))
} else {
None
Expand All @@ -179,7 +175,7 @@ impl GUI {
} => {
if !handled {
Some(egui::Event::MouseWheel {
delta: egui::Vec2::new(delta.0 as f32, delta.1 as f32),
delta: egui::Vec2::new(delta.0, delta.1),
unit: egui::MouseWheelUnit::Point,
modifiers: modifiers.into(),
})
Expand Down
2 changes: 1 addition & 1 deletion src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ fn combine_ids(
let mut id = geometry.0.to_le_bytes().to_vec();
id.extend(effect_material.0.to_le_bytes());
id.extend(lights.map(|l| l.0));
return id;
id
}

///
Expand Down
6 changes: 2 additions & 4 deletions src/renderer/control/control2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ impl Control2D {
handled,
..
} => {
if !*handled && delta.0.abs() + delta.1.abs() > std::f32::EPSILON {
if delta.0.abs() < std::f32::EPSILON
&& delta.1.fract().abs() > std::f32::EPSILON
{
if !*handled && delta.0.abs() + delta.1.abs() > f32::EPSILON {
if delta.0.abs() < f32::EPSILON && delta.1.fract().abs() > f32::EPSILON {
self.zoom(camera, delta.1, *position, 0.005);
} else {
self.pan(camera, *delta, device_pixel_ratio);
Expand Down
12 changes: 5 additions & 7 deletions src/renderer/control/first_person_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ impl FirstPersonControl {
handled,
..
} => {
if !*handled {
if Some(MouseButton::Left) == *button {
camera.yaw(radians(delta.0 * std::f32::consts::PI / 1800.0));
camera.pitch(radians(delta.1 * std::f32::consts::PI / 1800.0));
*handled = true;
change = true;
}
if !*handled && Some(MouseButton::Left) == *button {
camera.yaw(radians(delta.0 * std::f32::consts::PI / 1800.0));
camera.pitch(radians(delta.1 * std::f32::consts::PI / 1800.0));
*handled = true;
change = true;
}
}
Event::MouseWheel { delta, handled, .. } => {
Expand Down
12 changes: 5 additions & 7 deletions src/renderer/control/free_orbit_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ impl FreeOrbitControl {
handled,
..
} => {
if !*handled {
if Some(MouseButton::Left) == *button {
let speed = 0.01 * self.target.distance(camera.position()) + 0.001;
camera.rotate_around(self.target, speed * delta.0, speed * delta.1);
*handled = true;
change = true;
}
if !*handled && Some(MouseButton::Left) == *button {
let speed = 0.01 * self.target.distance(camera.position()) + 0.001;
camera.rotate_around(self.target, speed * delta.0, speed * delta.1);
*handled = true;
change = true;
}
}
Event::MouseWheel { delta, handled, .. } => {
Expand Down
20 changes: 9 additions & 11 deletions src/renderer/control/orbit_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,15 @@ impl OrbitControl {
handled,
..
} => {
if !*handled {
if Some(MouseButton::Left) == *button {
let speed = 0.01;
camera.rotate_around_with_fixed_up(
self.target,
speed * delta.0,
speed * delta.1,
);
*handled = true;
change = true;
}
if !*handled && Some(MouseButton::Left) == *button {
let speed = 0.01;
camera.rotate_around_with_fixed_up(
self.target,
speed * delta.0,
speed * delta.1,
);
*handled = true;
change = true;
}
}
Event::MouseWheel { delta, handled, .. } => {
Expand Down
Loading
Loading