diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de4465e..b5dde26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,6 +54,10 @@ jobs: - run: cargo build --verbose --target wasm32-unknown-unknown env: RUSTFLAGS: --cfg=web_sys_unstable_apis + - run: cargo build --verbose --no-default-features + - run: cargo build --verbose --target wasm32-unknown-unknown --no-default-features + env: + RUSTFLAGS: --cfg=web_sys_unstable_apis - run: cargo test --verbose - run: (cd examples/hello && cargo build --features glutin) - run: (cd examples/hello && cargo build --target wasm32-unknown-unknown) diff --git a/Cargo.toml b/Cargo.toml index 5482564..35f8e5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,11 +27,15 @@ name = "glow" path = "src/lib.rs" [dependencies] +ahash = { version = "0.8.3", default-features = false } +hashbrown = { version = "0.14.0", default-features = false } log = { version = "0.4.16", optional = true } [features] +default = ["std"] debug_trace_calls = [] debug_automatic_glGetError = [] +std = ["ahash/std"] [target.'cfg(target_arch = "wasm32")'.dependencies] js-sys = "~0.3" diff --git a/src/lib.rs b/src/lib.rs index 525323d..54e381a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,10 +4,14 @@ #![allow(clippy::unreadable_literal)] #![allow(clippy::missing_safety_doc)] #![allow(clippy::pedantic)] // For anyone using pedantic and a source dep, this is needed +#![no_std] +extern crate alloc; + +use alloc::string::String; +use alloc::vec::Vec; use core::fmt::Debug; use core::hash::Hash; -use std::collections::HashSet; mod version; pub use version::Version; @@ -95,7 +99,7 @@ pub trait HasContext { type TransformFeedback: Copy + Clone + Debug + Eq + Hash + Ord + PartialEq + PartialOrd; type UniformLocation: Clone + Debug; - fn supported_extensions(&self) -> &HashSet; + fn supports_extension(&self, extension: &str) -> bool; fn supports_debug(&self) -> bool; diff --git a/src/native.rs b/src/native.rs index 98a0298..937279d 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1,8 +1,17 @@ use super::*; use crate::{gl46 as native_gl, version::Version}; -use std::ffi::CStr; -use std::ptr; -use std::{collections::HashSet, ffi::CString, num::NonZeroU32}; + +use alloc::borrow::ToOwned; +use alloc::ffi::CString; +use alloc::string::{String, ToString}; +use alloc::vec; + +use core::ffi::CStr; +use core::fmt; +use core::num::NonZeroU32; +use core::ptr; + +type HashSet = hashbrown::HashSet; #[derive(Default)] struct Constants { @@ -19,13 +28,12 @@ pub struct Context { impl Context { pub unsafe fn from_loader_function_cstr(mut loader_function: F) -> Self where - F: FnMut(&CStr) -> *const std::os::raw::c_void, + F: FnMut(&CStr) -> *const core::ffi::c_void, { - let raw: native_gl::GlFns = - native_gl::GlFns::load_with(|p: *const std::os::raw::c_char| { - let c_str = std::ffi::CStr::from_ptr(p); - loader_function(c_str) as *mut std::os::raw::c_void - }); + let raw: native_gl::GlFns = native_gl::GlFns::load_with(|p: *const core::ffi::c_char| { + let c_str = CStr::from_ptr(p); + loader_function(c_str) as *mut core::ffi::c_void + }); // Retrieve and parse `GL_VERSION` let raw_string = raw.GetString(VERSION); @@ -34,7 +42,7 @@ impl Context { panic!("Reading GL_VERSION failed. Make sure there is a valid GL context currently active.") } - let raw_version = std::ffi::CStr::from_ptr(raw_string as *const native_gl::GLchar) + let raw_version = CStr::from_ptr(raw_string as *const native_gl::GLchar) .to_str() .unwrap() .to_owned(); @@ -43,7 +51,7 @@ impl Context { // Setup extensions and constants after the context has been built let mut context = Self { raw, - extensions: HashSet::new(), + extensions: HashSet::with_hasher(ahash::RandomState::new()), constants: Constants::default(), version, }; @@ -80,7 +88,7 @@ impl Context { pub unsafe fn from_loader_function(mut loader_function: F) -> Self where - F: FnMut(&str) -> *const std::os::raw::c_void, + F: FnMut(&str) -> *const core::ffi::c_void, { Self::from_loader_function_cstr(move |name| loader_function(name.to_str().unwrap())) } @@ -104,8 +112,8 @@ impl Context { } } -impl std::fmt::Debug for Context { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for Context { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Native_GL_Context") } } @@ -164,8 +172,8 @@ impl HasContext for Context { type UniformLocation = NativeUniformLocation; type TransformFeedback = NativeTransformFeedback; - fn supported_extensions(&self) -> &HashSet { - &self.extensions + fn supports_extension(&self, extension: &str) -> bool { + self.extensions.contains(extension) } fn supports_debug(&self) -> bool { @@ -294,7 +302,7 @@ impl HasContext for Context { gl.GetShaderiv(shader.0.get(), INFO_LOG_LENGTH, &mut length); if length > 0 { let mut log = String::with_capacity(length as usize); - log.extend(std::iter::repeat('\0').take(length as usize)); + log.extend(core::iter::repeat('\0').take(length as usize)); gl.GetShaderInfoLog( shader.0.get(), length, @@ -323,8 +331,8 @@ impl HasContext for Context { format, ty, match pixels { - PixelPackData::BufferOffset(offset) => offset as *mut std::ffi::c_void, - PixelPackData::Slice(data) => data.as_mut_ptr() as *mut std::ffi::c_void, + PixelPackData::BufferOffset(offset) => offset as *mut core::ffi::c_void, + PixelPackData::Slice(data) => data.as_mut_ptr() as *mut core::ffi::c_void, }, ); } @@ -379,7 +387,7 @@ impl HasContext for Context { gl.GetProgramiv(program.0.get(), INFO_LOG_LENGTH, &mut length); if length > 0 { let mut log = String::with_capacity(length as usize); - log.extend(std::iter::repeat('\0').take(length as usize)); + log.extend(core::iter::repeat('\0').take(length as usize)); gl.GetProgramInfoLog( program.0.get(), length, @@ -449,7 +457,7 @@ impl HasContext for Context { ); let mut name = String::with_capacity(uniform_max_size as usize); - name.extend(std::iter::repeat('\0').take(uniform_max_size as usize)); + name.extend(core::iter::repeat('\0').take(uniform_max_size as usize)); let mut length = 0; let mut size = 0; let mut utype = 0; @@ -642,7 +650,7 @@ impl HasContext for Context { unsafe fn buffer_data_size(&self, target: u32, size: i32, usage: u32) { let gl = &self.raw; - gl.BufferData(target, size as isize, std::ptr::null(), usage); + gl.BufferData(target, size as isize, core::ptr::null(), usage); } unsafe fn buffer_data_u8_slice(&self, target: u32, data: &[u8], usage: u32) { @@ -650,7 +658,7 @@ impl HasContext for Context { gl.BufferData( target, data.len() as isize, - data.as_ptr() as *const std::ffi::c_void, + data.as_ptr() as *const core::ffi::c_void, usage, ); } @@ -660,7 +668,7 @@ impl HasContext for Context { gl.NamedBufferData( buffer.0.get(), data.len() as isize, - data.as_ptr() as *const std::ffi::c_void, + data.as_ptr() as *const core::ffi::c_void, usage, ); } @@ -671,7 +679,7 @@ impl HasContext for Context { target, offset as isize, src_data.len() as isize, - src_data.as_ptr() as *const std::ffi::c_void, + src_data.as_ptr() as *const core::ffi::c_void, ); } @@ -681,14 +689,15 @@ impl HasContext for Context { target, offset as isize, dst_data.len() as isize, - dst_data.as_mut_ptr() as *mut std::ffi::c_void, + dst_data.as_mut_ptr() as *mut core::ffi::c_void, ); } unsafe fn buffer_storage(&self, target: u32, size: i32, data: Option<&[u8]>, flags: u32) { let gl = &self.raw; let size = size as isize; - let data = data.map(|p| p.as_ptr()).unwrap_or(std::ptr::null()) as *const std::ffi::c_void; + let data = + data.map(|p| p.as_ptr()).unwrap_or(core::ptr::null()) as *const core::ffi::c_void; if gl.BufferStorage_is_loaded() { gl.BufferStorage(target, size, data, flags); } else { @@ -931,7 +940,7 @@ impl HasContext for Context { unsafe fn draw_arrays_indirect_offset(&self, mode: u32, offset: i32) { let gl = &self.raw; - gl.DrawArraysIndirect(mode, offset as *const std::ffi::c_void); + gl.DrawArraysIndirect(mode, offset as *const core::ffi::c_void); } unsafe fn draw_buffer(&self, draw_buffer: u32) { @@ -950,7 +959,7 @@ impl HasContext for Context { mode as u32, count, element_type as u32, - offset as *const std::ffi::c_void, + offset as *const core::ffi::c_void, ); } @@ -967,7 +976,7 @@ impl HasContext for Context { mode as u32, count, element_type as u32, - offset as *const std::ffi::c_void, + offset as *const core::ffi::c_void, base_vertex, ); } @@ -985,7 +994,7 @@ impl HasContext for Context { mode as u32, count, element_type as u32, - offset as *const std::ffi::c_void, + offset as *const core::ffi::c_void, instance_count, ); } @@ -1004,7 +1013,7 @@ impl HasContext for Context { mode as u32, count, element_type as u32, - offset as *const std::ffi::c_void, + offset as *const core::ffi::c_void, instance_count, base_vertex, ); @@ -1025,7 +1034,7 @@ impl HasContext for Context { mode as u32, count, element_type as u32, - offset as *const std::ffi::c_void, + offset as *const core::ffi::c_void, instance_count, base_vertex, base_instance, @@ -1034,7 +1043,7 @@ impl HasContext for Context { unsafe fn draw_elements_indirect_offset(&self, mode: u32, element_type: u32, offset: i32) { let gl = &self.raw; - gl.DrawElementsIndirect(mode, element_type, offset as *const std::ffi::c_void); + gl.DrawElementsIndirect(mode, element_type, offset as *const core::ffi::c_void); } unsafe fn enable(&self, parameter: u32) { @@ -1213,7 +1222,7 @@ impl HasContext for Context { unsafe fn get_parameter_indexed_string(&self, parameter: u32, index: u32) -> String { let gl = &self.raw; let raw_ptr = gl.GetStringi(parameter, index); - std::ffi::CStr::from_ptr(raw_ptr as *const native_gl::GLchar) + core::ffi::CStr::from_ptr(raw_ptr as *const native_gl::GLchar) .to_str() .unwrap() .to_owned() @@ -1228,7 +1237,7 @@ impl HasContext for Context { parameter ) } - std::ffi::CStr::from_ptr(raw_ptr as *const native_gl::GLchar) + core::ffi::CStr::from_ptr(raw_ptr as *const native_gl::GLchar) .to_str() .unwrap() .to_owned() @@ -1292,7 +1301,7 @@ impl HasContext for Context { &mut attribute_max_size, ); let mut name = String::with_capacity(attribute_max_size as usize); - name.extend(std::iter::repeat('\0').take(attribute_max_size as usize)); + name.extend(core::iter::repeat('\0').take(attribute_max_size as usize)); let mut length = 0; let mut size = 0; let mut atype = 0; @@ -1398,7 +1407,7 @@ impl HasContext for Context { border, format, ty, - pixels.map(|p| p.as_ptr()).unwrap_or(std::ptr::null()) as *const std::ffi::c_void, + pixels.map(|p| p.as_ptr()).unwrap_or(core::ptr::null()) as *const core::ffi::c_void, ); } @@ -1420,7 +1429,7 @@ impl HasContext for Context { width, border, image_size, - pixels.as_ptr() as *const std::ffi::c_void, + pixels.as_ptr() as *const core::ffi::c_void, ); } @@ -1446,7 +1455,7 @@ impl HasContext for Context { border, format, ty, - pixels.map(|p| p.as_ptr()).unwrap_or(std::ptr::null()) as *const std::ffi::c_void, + pixels.map(|p| p.as_ptr()).unwrap_or(core::ptr::null()) as *const core::ffi::c_void, ); } @@ -1490,7 +1499,7 @@ impl HasContext for Context { height, border, image_size, - pixels.as_ptr() as *const std::ffi::c_void, + pixels.as_ptr() as *const core::ffi::c_void, ); } @@ -1518,7 +1527,7 @@ impl HasContext for Context { border, format, ty, - pixels.map(|p| p.as_ptr()).unwrap_or(std::ptr::null()) as *const std::ffi::c_void, + pixels.map(|p| p.as_ptr()).unwrap_or(core::ptr::null()) as *const core::ffi::c_void, ); } @@ -1544,7 +1553,7 @@ impl HasContext for Context { depth, border, image_size, - pixels.as_ptr() as *const std::ffi::c_void, + pixels.as_ptr() as *const core::ffi::c_void, ); } @@ -2055,8 +2064,8 @@ impl HasContext for Context { format, ty, match pixels { - PixelUnpackData::BufferOffset(offset) => offset as *const std::ffi::c_void, - PixelUnpackData::Slice(data) => data.as_ptr() as *const std::ffi::c_void, + PixelUnpackData::BufferOffset(offset) => offset as *const core::ffi::c_void, + PixelUnpackData::Slice(data) => data.as_ptr() as *const core::ffi::c_void, }, ); } @@ -2075,11 +2084,11 @@ impl HasContext for Context { let gl = &self.raw; let (data, image_size) = match pixels { CompressedPixelUnpackData::BufferRange(ref range) => ( - range.start as *const std::ffi::c_void, + range.start as *const core::ffi::c_void, (range.end - range.start) as i32, ), CompressedPixelUnpackData::Slice(data) => { - (data.as_ptr() as *const std::ffi::c_void, data.len() as i32) + (data.as_ptr() as *const core::ffi::c_void, data.len() as i32) } }; @@ -2115,8 +2124,8 @@ impl HasContext for Context { format, ty, match pixels { - PixelUnpackData::BufferOffset(offset) => offset as *const std::ffi::c_void, - PixelUnpackData::Slice(data) => data.as_ptr() as *const std::ffi::c_void, + PixelUnpackData::BufferOffset(offset) => offset as *const core::ffi::c_void, + PixelUnpackData::Slice(data) => data.as_ptr() as *const core::ffi::c_void, }, ); } @@ -2148,8 +2157,8 @@ impl HasContext for Context { format, ty, match pixels { - PixelUnpackData::BufferOffset(offset) => offset as *const std::ffi::c_void, - PixelUnpackData::Slice(data) => data.as_ptr() as *const std::ffi::c_void, + PixelUnpackData::BufferOffset(offset) => offset as *const core::ffi::c_void, + PixelUnpackData::Slice(data) => data.as_ptr() as *const core::ffi::c_void, }, ); } @@ -2170,11 +2179,11 @@ impl HasContext for Context { let gl = &self.raw; let (data, image_size) = match pixels { CompressedPixelUnpackData::BufferRange(ref range) => ( - range.start as *const std::ffi::c_void, + range.start as *const core::ffi::c_void, (range.end - range.start) as i32, ), CompressedPixelUnpackData::Slice(data) => { - (data.as_ptr() as *const std::ffi::c_void, data.len() as i32) + (data.as_ptr() as *const core::ffi::c_void, data.len() as i32) } }; @@ -2304,7 +2313,7 @@ impl HasContext for Context { data_type, normalized as u8, stride, - offset as *const std::ffi::c_void, + offset as *const core::ffi::c_void, ); } @@ -2322,7 +2331,7 @@ impl HasContext for Context { size, data_type, stride, - offset as *const std::ffi::c_void, + offset as *const core::ffi::c_void, ); } @@ -2340,7 +2349,7 @@ impl HasContext for Context { size, data_type, stride, - offset as *const std::ffi::c_void, + offset as *const core::ffi::c_void, ); } @@ -2542,7 +2551,7 @@ impl HasContext for Context { let gl = &self.raw; let ids_ptr = if ids.is_empty() { - std::ptr::null() + core::ptr::null() } else { ids.as_ptr() }; @@ -2589,13 +2598,13 @@ impl HasContext for Context { if gl.DebugMessageCallback_is_loaded() { gl.DebugMessageCallback( Some(raw_debug_message_callback::), - &mut callback as *mut _ as *mut std::ffi::c_void, + &mut callback as *mut _ as *mut core::ffi::c_void, ); } else { // Fallback to extension gl.DebugMessageCallbackKHR( Some(raw_debug_message_callback::), - &mut callback as *mut _ as *mut std::ffi::c_void, + &mut callback as *mut _ as *mut core::ffi::c_void, ); } } @@ -2633,7 +2642,7 @@ impl HasContext for Context { let mut offset = 0; for i in 0..received { let message = - std::ffi::CStr::from_ptr(message_log[offset..].as_ptr()).to_string_lossy(); + core::ffi::CStr::from_ptr(message_log[offset..].as_ptr()).to_string_lossy(); offset += lengths[i] as usize; entries.push(DebugMessageLogEntry { source: sources[i], @@ -2679,7 +2688,7 @@ impl HasContext for Context { lbl.as_ptr() as *const native_gl::GLchar, ); } - None => gl.ObjectLabel(identifier, name, 0, std::ptr::null()), + None => gl.ObjectLabel(identifier, name, 0, core::ptr::null()), } } @@ -2695,7 +2704,7 @@ impl HasContext for Context { label_buf.as_mut_ptr(), ); label_buf.set_len(len as usize); - std::ffi::CStr::from_ptr(label_buf.as_ptr()) + core::ffi::CStr::from_ptr(label_buf.as_ptr()) .to_str() .unwrap() .to_owned() @@ -2712,12 +2721,12 @@ impl HasContext for Context { let lbl = l.as_ref().as_bytes(); let length = lbl.len() as i32; gl.ObjectPtrLabel( - sync.0 as *mut std::ffi::c_void, + sync.0 as *mut core::ffi::c_void, length, lbl.as_ptr() as *const native_gl::GLchar, ); } - None => gl.ObjectPtrLabel(sync.0 as *mut std::ffi::c_void, 0, std::ptr::null()), + None => gl.ObjectPtrLabel(sync.0 as *mut core::ffi::c_void, 0, core::ptr::null()), } } @@ -2726,13 +2735,13 @@ impl HasContext for Context { let mut len = 0; let mut label_buf = Vec::with_capacity(self.constants.max_label_length as usize); gl.GetObjectPtrLabel( - sync.0 as *mut std::ffi::c_void, + sync.0 as *mut core::ffi::c_void, self.constants.max_label_length, &mut len, label_buf.as_mut_ptr(), ); label_buf.set_len(len as usize); - std::ffi::CStr::from_ptr(label_buf.as_ptr()) + core::ffi::CStr::from_ptr(label_buf.as_ptr()) .to_str() .unwrap() .to_owned() @@ -2804,8 +2813,8 @@ impl HasContext for Context { format, gltype, match pixels { - PixelPackData::BufferOffset(offset) => offset as *mut std::ffi::c_void, - PixelPackData::Slice(data) => data.as_mut_ptr() as *mut std::ffi::c_void, + PixelPackData::BufferOffset(offset) => offset as *mut core::ffi::c_void, + PixelPackData::Slice(data) => data.as_mut_ptr() as *mut core::ffi::c_void, }, ); } @@ -2911,7 +2920,7 @@ impl HasContext for Context { program.0.get(), index, buf_size as i32, - std::ptr::null_mut(), + core::ptr::null_mut(), size as *mut i32, tftype as *mut u32, c_name_buf, @@ -3014,18 +3023,18 @@ impl HasContext for Context { if length > 0 { assert_eq!( - std::mem::size_of::(), - std::mem::size_of::(), + core::mem::size_of::(), + core::mem::size_of::(), "This operation is only safe in systems in which the length of \ a GLchar is the same as that of an u8" ); assert_eq!( - std::mem::align_of::(), - std::mem::align_of::(), + core::mem::align_of::(), + core::mem::align_of::(), "This operation is only safe in systems in which the alignment \ of a GLchar is the same as that of an u8" ); - let buffer = std::slice::from_raw_parts( + let buffer = core::slice::from_raw_parts( buffer.as_ptr() as *const u8, (length as usize + 1).min(buffer.len()), ); @@ -3059,15 +3068,45 @@ extern "system" fn raw_debug_message_callback( severity: u32, length: i32, message: *const native_gl::GLchar, - user_param: *mut std::ffi::c_void, + user_param: *mut core::ffi::c_void, ) where F: FnMut(u32, u32, u32, u32, &str), { - std::panic::catch_unwind(move || unsafe { + catch_unwind(move || unsafe { let callback: &mut F = &mut *(user_param as *mut _); - let slice = std::slice::from_raw_parts(message as *const u8, length as usize); - let msg = std::str::from_utf8(slice).unwrap(); + let slice = core::slice::from_raw_parts(message as *const u8, length as usize); + let msg = core::str::from_utf8(slice).unwrap(); (callback)(source, gltype, id, severity, msg); - }) - .ok(); + }); +} + +#[cfg(feature = "std")] +fn catch_unwind(f: F) { + extern crate std; + std::panic::catch_unwind(f).ok(); +} + +#[cfg(not(feature = "std"))] +fn catch_unwind(f: F) { + // No real option here, just abort by panicking while panicking. + struct PanicOnDrop; + + impl Drop for PanicOnDrop { + fn drop(&mut self) { + panic!("Panic while panicking"); + } + } + + struct AbortOnDrop; + + impl Drop for AbortOnDrop { + fn drop(&mut self) { + let _bomb = PanicOnDrop; + panic!("Panic while panicking"); + } + } + + let _bomb = AbortOnDrop; + f(); + core::mem::forget(_bomb); } diff --git a/src/version.rs b/src/version.rs index b96961b..3a75258 100644 --- a/src/version.rs +++ b/src/version.rs @@ -1,3 +1,6 @@ +use alloc::string::{String, ToString}; +use core::fmt; + /// A version number for a specific component of an OpenGL implementation #[derive(Clone, Eq, Ord, PartialEq, PartialOrd)] pub struct Version { @@ -121,8 +124,8 @@ impl Version { } } -impl std::fmt::Debug for Version { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl fmt::Debug for Version { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match ( self.major, self.minor, @@ -142,6 +145,7 @@ impl std::fmt::Debug for Version { #[cfg(test)] mod tests { use super::Version; + use alloc::string::{String, ToString}; #[test] fn test_version_parse() { diff --git a/src/web_sys.rs b/src/web_sys.rs index 165c014..90729eb 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -1,8 +1,8 @@ use super::*; +use core::cell::RefCell; use js_sys::{self, Array}; use slotmap::{new_key_type, SlotMap}; -use std::cell::RefCell; use web_sys::{ self, HtmlCanvasElement, HtmlImageElement, HtmlVideoElement, ImageBitmap, WebGl2RenderingContext, WebGlBuffer, WebGlFramebuffer, WebGlProgram, WebGlQuery, @@ -10,6 +10,8 @@ use web_sys::{ WebGlTransformFeedback, WebGlUniformLocation, WebGlVertexArrayObject, }; +type HashSet = hashbrown::HashSet; + #[cfg(web_sys_unstable_apis)] use web_sys::VideoFrame; @@ -237,12 +239,14 @@ macro_rules! build_extensions { ), }; - let supported_extensions = $context - .get_supported_extensions() - .unwrap() - .iter() - .map(|val| val.as_string().unwrap()) - .collect::>(); + let mut supported_extensions = HashSet::with_hasher(ahash::RandomState::new()); + supported_extensions.extend( + $context + .get_supported_extensions() + .unwrap() + .iter() + .map(|val| val.as_string().unwrap()), + ); (extensions, supported_extensions) }}; @@ -1356,8 +1360,8 @@ impl HasContext for Context { type UniformLocation = WebGlUniformLocation; type TransformFeedback = WebTransformFeedbackKey; - fn supported_extensions(&self) -> &HashSet { - &self.supported_extensions + fn supports_extension(&self, extension: &str) -> bool { + self.supported_extensions.contains(extension) } fn supports_debug(&self) -> bool { @@ -4781,8 +4785,8 @@ impl HasContext for Context { /// This function reinterprets the byte data into the correct type for the texture. /// The lookup is generated from this table: https://www.khronos.org/registry/webgl/specs/latest/2.0/#TEXTURE_PIXELS_TYPE_TABLE unsafe fn texture_data_view(ty: u32, bytes: &[u8]) -> js_sys::Object { - use std::mem::size_of; - use std::slice::from_raw_parts; + use core::mem::size_of; + use core::slice::from_raw_parts; match ty { BYTE => {