diff --git a/examples/triangle_color4b.rs b/examples/triangle_color4b.rs index f06a302a..e01a3c36 100644 --- a/examples/triangle_color4b.rs +++ b/examples/triangle_color4b.rs @@ -60,7 +60,10 @@ impl Stage { &[BufferLayout::default()], &[ VertexAttribute::new("in_pos", VertexFormat::Float2), - VertexAttribute::new("in_color", VertexFormat::Byte4), + VertexAttribute { + gl_pass_as_float: false, + ..VertexAttribute::new("in_color", VertexFormat::Byte4) + }, ], shader, PipelineParams::default(), diff --git a/src/graphics.rs b/src/graphics.rs index e9e8e2bc..8b737375 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -236,6 +236,15 @@ pub struct VertexAttribute { pub name: &'static str, pub format: VertexFormat, pub buffer_index: usize, + /// This flag affects integer VertexFormats, Byte*, Short*, Int* + /// Taking Byte4 as an example: + /// On Metal, it might be received as either `float4` or `uint4` + /// On OpenGl and `gl_pass_as_float = true` shaders should receive it as `vec4` + /// With `gl_pass_as_float = false`, as `uvec4` + /// + /// Note that `uvec4` requires at least `150` glsl version + /// Before setting `gl_pass_as_float` to false, better check `context.info().has_integer_attributes()` and double check that shaders are at least `150` + pub gl_pass_as_float: bool, } impl VertexAttribute { @@ -252,6 +261,7 @@ impl VertexAttribute { name, format, buffer_index, + gl_pass_as_float: true, } } } diff --git a/src/graphics/gl.rs b/src/graphics/gl.rs index 9bfe01e4..18ab1970 100644 --- a/src/graphics/gl.rs +++ b/src/graphics/gl.rs @@ -1070,6 +1070,7 @@ impl RenderingBackend for GlContext { name, format, buffer_index, + gl_pass_as_float, } in attributes { let buffer_data = &mut buffer_cache @@ -1105,6 +1106,7 @@ impl RenderingBackend for GlContext { stride: buffer_data.stride, buffer_index: *buffer_index, divisor, + gl_pass_as_float: *gl_pass_as_float, }; assert!( @@ -1332,7 +1334,9 @@ impl RenderingBackend for GlContext { unsafe { match attribute.type_ { GL_INT | GL_UNSIGNED_INT | GL_SHORT | GL_UNSIGNED_SHORT - | GL_UNSIGNED_BYTE | GL_BYTE => { + | GL_UNSIGNED_BYTE | GL_BYTE + if !attribute.gl_pass_as_float => + { assert!(self.has_integer_attributes()); glVertexAttribIPointer( attr_index as GLuint, diff --git a/src/graphics/gl/cache.rs b/src/graphics/gl/cache.rs index 6dd548e0..3e252d92 100644 --- a/src/graphics/gl/cache.rs +++ b/src/graphics/gl/cache.rs @@ -9,6 +9,7 @@ pub struct VertexAttributeInternal { pub stride: i32, pub buffer_index: usize, pub divisor: i32, + pub gl_pass_as_float: bool, } #[derive(Default, Copy, Clone)] diff --git a/src/native/ios.rs b/src/native/ios.rs index 84d721a1..ad1fcfbf 100644 --- a/src/native/ios.rs +++ b/src/native/ios.rs @@ -340,7 +340,10 @@ pub fn define_glk_or_mtk_view_dlg(superclass: &Class) -> *const Class { d.screen_width = screen_width; d.screen_height = screen_height; } - send_message(Message::Resize { width: screen_width, height: screen_height }); + send_message(Message::Resize { + width: screen_width, + height: screen_height, + }); } if let Some(ref mut event_handler) = payload.event_handler { @@ -648,8 +651,7 @@ pub fn define_app_delegate() -> *const Class { // I hope it will work the same on the real device. if conf.platform.blocking_event_loop { msg_send_![&*view, performSelectorOnMainThread:sel!(setNeedsDisplay) withObject:nil waitUntilDone:NO]; - } - else { + } else { msg_send_![&*view, performSelectorOnMainThread:sel!(display) withObject:nil waitUntilDone:YES]; } } diff --git a/src/native/linux_x11/keycodes.rs b/src/native/linux_x11/keycodes.rs index c0133dd2..f8ee3e17 100644 --- a/src/native/linux_x11/keycodes.rs +++ b/src/native/linux_x11/keycodes.rs @@ -165,6 +165,9 @@ pub unsafe fn translate_mouse_button(button: i32) -> MouseButton { }; } -pub unsafe extern "C" fn keysym_to_unicode(libxkbcommon: &mut LibXkbCommon, keysym: super::libx11::KeySym) -> i32 { - return (libxkbcommon.xkb_keysym_to_utf32)(keysym as u32) as i32 +pub unsafe extern "C" fn keysym_to_unicode( + libxkbcommon: &mut LibXkbCommon, + keysym: super::libx11::KeySym, +) -> i32 { + return (libxkbcommon.xkb_keysym_to_utf32)(keysym as u32) as i32; }