Skip to content
2 changes: 1 addition & 1 deletion examples/instancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl EventHandler for Stage {

fn draw(&mut self) {
// by default glam-rs can vec3 as u128 or #[reprc(C)](f32, f32, f32). need to ensure that the second option was used
assert_eq!(std::mem::size_of::<Vec3>(), 12);
assert_eq!(core::mem::size_of::<Vec3>(), 12);

self.ctx.buffer_update(
self.bindings.vertex_buffers[1],
Expand Down
4 changes: 2 additions & 2 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ impl Icon {
}
// Printing 64x64 array with a default formatter is not meaningfull,
// so debug will skip the data fields of an Icon
impl std::fmt::Debug for Icon {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Debug for Icon {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Icon").finish()
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ impl From<std::io::Error> for Error {
}
}

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Self::IOError(e) => write!(f, "I/O error: {e}"),
Self::DownloadFailed => write!(f, "Download failed"),
Expand Down Expand Up @@ -54,15 +54,15 @@ fn load_file_android<F: Fn(Response)>(path: &str, on_loaded: F) {
fn load_file_sync(path: &str) -> Response {
use crate::native;

let filename = std::ffi::CString::new(path).unwrap();
let filename = alloc::ffi::CString::new(path).unwrap();

let mut data: native::android_asset = unsafe { std::mem::zeroed() };
let mut data: native::android_asset = unsafe { core::mem::zeroed() };

unsafe { native::android::load_asset(filename.as_ptr(), &mut data as _) };

if data.content.is_null() == false {
let slice =
unsafe { std::slice::from_raw_parts(data.content, data.content_length as _) };
unsafe { core::slice::from_raw_parts(data.content, data.content_length as _) };
let response = slice.iter().map(|c| *c as _).collect::<Vec<_>>();
Ok(response)
} else {
Expand Down Expand Up @@ -110,8 +110,8 @@ mod wasm {
}

pub fn load_file<F: Fn(Response) + 'static>(path: &str, on_loaded: F) {
use alloc::ffi::CString;
use native::wasm::fs;
use std::ffi::CString;

let url = CString::new(path).unwrap();
let file_id = unsafe { fs::fs_load_file(url.as_ptr(), url.as_bytes().len() as u32) };
Expand Down
35 changes: 18 additions & 17 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use crate::native::gl::*;

use std::{error::Error, fmt::Display};
use core::fmt::Display;
use std::error::Error;

//pub use texture::{FilterMode, TextureAccess, TextureFormat, TextureParams, TextureWrap};

Expand Down Expand Up @@ -274,7 +275,7 @@ pub enum ShaderType {
}

impl Display for ShaderType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Vertex => write!(f, "Vertex"),
Self::Fragment => write!(f, "Fragment"),
Expand All @@ -290,17 +291,17 @@ pub enum ShaderError {
},
LinkError(String),
/// Shader strings should never contains \00 in the middle
FFINulError(std::ffi::NulError),
FFINulError(alloc::ffi::NulError),
}

impl From<std::ffi::NulError> for ShaderError {
fn from(e: std::ffi::NulError) -> ShaderError {
impl From<alloc::ffi::NulError> for ShaderError {
fn from(e: alloc::ffi::NulError) -> ShaderError {
ShaderError::FFINulError(e)
}
}

impl Display for ShaderError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::CompilationError {
shader_type,
Expand Down Expand Up @@ -969,11 +970,11 @@ impl ElapsedQuery {
/// Basically, the same thing as `fn f<U>(a: &U)`, but
/// trait-object friendly.
pub struct Arg<'a> {
ptr: *const std::ffi::c_void,
ptr: *const core::ffi::c_void,
element_size: usize,
size: usize,
is_slice: bool,
_phantom: std::marker::PhantomData<&'a ()>,
_phantom: core::marker::PhantomData<&'a ()>,
}

pub enum TextureSource<'a> {
Expand All @@ -997,20 +998,20 @@ impl<'a> BufferSource<'a> {
///
/// For vertex buffers it is OK to use `empty::<u8>(byte_size);`
pub fn empty<T>(size: usize) -> BufferSource<'a> {
let element_size = std::mem::size_of::<T>();
let element_size = core::mem::size_of::<T>();
BufferSource::Empty {
size: size * std::mem::size_of::<T>(),
size: size * core::mem::size_of::<T>(),
element_size,
}
}

pub fn slice<T>(data: &'a [T]) -> BufferSource<'a> {
BufferSource::Slice(Arg {
ptr: data.as_ptr() as _,
size: std::mem::size_of_val(data),
element_size: std::mem::size_of::<T>(),
size: core::mem::size_of_val(data),
element_size: core::mem::size_of::<T>(),
is_slice: true,
_phantom: std::marker::PhantomData,
_phantom: core::marker::PhantomData,
})
}

Expand All @@ -1020,7 +1021,7 @@ impl<'a> BufferSource<'a> {
size,
element_size,
is_slice: true,
_phantom: std::marker::PhantomData,
_phantom: core::marker::PhantomData,
})
}
}
Expand All @@ -1030,10 +1031,10 @@ impl<'a> UniformsSource<'a> {
pub fn table<T>(data: &'a T) -> UniformsSource<'a> {
Self(Arg {
ptr: data as *const T as _,
size: std::mem::size_of_val(data),
element_size: std::mem::size_of::<T>(),
size: core::mem::size_of_val(data),
element_size: core::mem::size_of::<T>(),
is_slice: false,
_phantom: std::marker::PhantomData,
_phantom: core::marker::PhantomData,
})
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/graphics/gl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ffi::CString;
use alloc::ffi::CString;

use crate::{window, ResourceManager};

Expand Down Expand Up @@ -245,7 +245,7 @@ impl Texture {
0,
format,
pixel_type,
std::ptr::null() as _,
core::ptr::null() as _,
);
}
TextureSource::Bytes(source) => {
Expand Down Expand Up @@ -347,7 +347,7 @@ impl Texture {
pixel_type,
match source {
Some(source) => source.as_ptr() as *const _,
Option::None => std::ptr::null(),
Option::None => core::ptr::null(),
},
);
}
Expand Down Expand Up @@ -613,7 +613,7 @@ fn load_shader_internal(
);
assert!(max_length >= 1);
let error_message =
std::string::String::from_utf8_lossy(&error_message[0..max_length as usize - 1]);
alloc::string::String::from_utf8_lossy(&error_message[0..max_length as usize - 1]);
return Err(ShaderError::LinkError(error_message.to_string()));
}

Expand Down Expand Up @@ -650,7 +650,7 @@ pub fn load_shader(shader_type: GLenum, source: &str) -> Result<GLuint, ShaderEr

let cstring = CString::new(source)?;
let csource = [cstring];
glShaderSource(shader, 1, csource.as_ptr() as *const _, std::ptr::null());
glShaderSource(shader, 1, csource.as_ptr() as *const _, core::ptr::null());
glCompileShader(shader);

let mut is_compiled = 0;
Expand All @@ -669,7 +669,7 @@ pub fn load_shader(shader_type: GLenum, source: &str) -> Result<GLuint, ShaderEr

assert!(max_length >= 1);
let mut error_message =
std::string::String::from_utf8_lossy(&error_message[0..max_length as usize - 1])
alloc::string::String::from_utf8_lossy(&error_message[0..max_length as usize - 1])
.into_owned();

// On Wasm + Chrome, for unknown reason, string with zero-terminator is returned. On Firefox there is no zero-terminators in JavaScript string.
Expand Down Expand Up @@ -819,7 +819,7 @@ impl GlContext {
#[allow(clippy::field_reassign_with_default)]
fn gl_info() -> ContextInfo {
let version_string = unsafe { glGetString(super::gl::GL_VERSION) };
let gl_version_string = unsafe { std::ffi::CStr::from_ptr(version_string as _) }
let gl_version_string = unsafe { core::ffi::CStr::from_ptr(version_string as _) }
.to_str()
.unwrap()
.to_string();
Expand Down Expand Up @@ -1365,7 +1365,12 @@ impl RenderingBackend for GlContext {
self.cache.store_buffer_binding(gl_target);
self.cache.bind_buffer(gl_target, gl_buf, index_type);

glBufferData(gl_target, size as _, std::ptr::null() as *const _, gl_usage);
glBufferData(
gl_target,
size as _,
core::ptr::null() as *const _,
gl_usage,
);
if let BufferSource::Slice(data) = data {
debug_assert!(data.is_slice);
glBufferSubData(gl_target, 0, size as _, data.ptr as _);
Expand Down
8 changes: 4 additions & 4 deletions src/graphics/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ impl RenderingBackend for MetalContext {
assert!(data.size <= buffer.size);

unsafe {
let dest: *mut std::ffi::c_void = msg_send![buffer.raw[buffer.next_value], contents];
std::ptr::copy(data.ptr, dest, data.size);
let dest: *mut core::ffi::c_void = msg_send![buffer.raw[buffer.next_value], contents];
core::ptr::copy(data.ptr, dest, data.size);

#[cfg(target_os = "macos")]
msg_send_![buffer.raw[buffer.next_value], didModifyRange:NSRange::new(0, data.size as u64)];
Expand Down Expand Up @@ -1126,8 +1126,8 @@ impl RenderingBackend for MetalContext {

let buffer = self.uniform_buffers[self.current_frame_index];
unsafe {
let dest: *mut std::ffi::c_void = msg_send![buffer, contents];
std::ptr::copy(
let dest: *mut core::ffi::c_void = msg_send![buffer, contents];
core::ptr::copy(
uniform_ptr as _,
dest.add(self.current_ub_offset as usize),
size,
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
clippy::missing_safety_doc
)]

extern crate alloc;

pub mod conf;
mod event;
pub mod fs;
pub mod graphics;
pub mod native;
use core::ops::{Index, IndexMut};
use std::collections::HashMap;
use std::ops::{Index, IndexMut};

#[cfg(feature = "log-impl")]
pub mod log;
Expand Down
6 changes: 3 additions & 3 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// Will send log calls like debug!(), warn!() and error!() to appropriate console_* call on wasm
/// and just println! on PC.
/// If you need better control of log messages - just dont use "log-impl" feature and use appropriate loggers from log-rs
use std::cmp;
use core::cmp;

#[repr(usize)]
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn __private_api_log_lit(
&(_target, _module_path, _file, _line): &(&str, &'static str, &'static str, u32),
) {
use crate::native::wasm;
use std::ffi::CString;
use alloc::ffi::CString;

let log_fn = match level {
Level::Debug => wasm::console_debug,
Expand All @@ -214,7 +214,7 @@ pub fn __private_api_log_lit(
level: Level,
&(_target, _module_path, _file, _line): &(&str, &'static str, &'static str, u32),
) {
use std::ffi::CString;
use alloc::ffi::CString;

let log_fn = match level {
Level::Debug => crate::native::android::console_debug,
Expand Down
4 changes: 2 additions & 2 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ impl NativeDisplayData {
#[cfg(target_vendor = "apple")]
gfx_api: crate::conf::AppleGfxApi::OpenGl,
#[cfg(target_vendor = "apple")]
view: std::ptr::null_mut(),
view: core::ptr::null_mut(),
#[cfg(target_os = "ios")]
view_ctrl: std::ptr::null_mut(),
view_ctrl: core::ptr::null_mut(),
}
}
}
Expand Down
Loading
Loading