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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ libc = "0.2"
ndk-sys = "0.2"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
objc = "0.2"
objc = { package = "objc-rs", version = "0.2" }

[dev-dependencies]
glam = { version = "0.24", features = ["scalar-math"] }
Expand Down
1 change: 1 addition & 0 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ mod wasm {
use std::{cell::RefCell, collections::HashMap, thread_local};

thread_local! {
#[allow(clippy::type_complexity)]
static FILES: RefCell<HashMap<u32, Box<dyn Fn(Response)>>> = RefCell::new(HashMap::new());
}

Expand Down
61 changes: 30 additions & 31 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,13 @@ impl VertexFormat {
}
}

#[derive(Clone, Copy, PartialEq, Debug)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub enum VertexStep {
#[default]
PerVertex,
PerInstance,
}

impl Default for VertexStep {
fn default() -> VertexStep {
VertexStep::PerVertex
}
}

#[derive(Clone, Debug)]
pub struct BufferLayout {
pub stride: i32,
Expand Down Expand Up @@ -643,10 +638,11 @@ impl From<Comparison> for GLenum {

/// Specifies how incoming RGBA values (source) and the RGBA in framebuffer (destination)
/// are combined.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
pub enum Equation {
/// Adds source and destination. Source and destination are multiplied
/// by blending parameters before addition.
#[default]
Add,
/// Subtracts destination from source. Source and destination are
/// multiplied by blending parameters before subtraction.
Expand Down Expand Up @@ -675,12 +671,6 @@ pub enum BlendFactor {
SourceAlphaSaturate,
}

impl Default for Equation {
fn default() -> Equation {
Equation::Add
}
}

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum PrimitiveType {
Triangles,
Expand Down Expand Up @@ -882,6 +872,12 @@ pub struct ElapsedQuery {
gl_query: GLuint,
}

impl Default for ElapsedQuery {
fn default() -> Self {
Self::new()
}
}

impl ElapsedQuery {
pub fn new() -> ElapsedQuery {
ElapsedQuery { gl_query: 0 }
Expand Down Expand Up @@ -964,7 +960,7 @@ impl ElapsedQuery {
///
/// Implemented as `glDeleteQueries(...)` on OpenGL/WebGL platforms.
pub fn delete(&mut self) {
unsafe { glDeleteQueries(1, &mut self.gl_query) }
unsafe { glDeleteQueries(1, &self.gl_query) }
self.gl_query = 0;
}
}
Expand Down Expand Up @@ -1082,8 +1078,8 @@ pub struct ContextInfo {
/// allowing to see which glsl versions are actually supported.
/// Unfortunately, it only works on GL4.3+... and even there it is not quite correct.
///
/// miniquad will take a guess based on GL_VERSION_STRING, current platform and implementation details.
/// Would be all false on metal.
/// miniquad will take a guess based on GL_VERSION_STRING, current platform and implementation
/// details. Would be all false on metal.
pub glsl_support: GlslSupport,
/// List of platform-dependent features that miniquad failed to make cross-platforms
/// and therefore they might be missing.
Expand All @@ -1104,8 +1100,10 @@ impl ContextInfo {
pub trait RenderingBackend {
fn info(&self) -> ContextInfo;
/// For metal context's ShaderSource should contain MSL source string, for GL - glsl.
///
/// If in doubt, _most_ OpenGL contexts support "#version 100" glsl shaders.
/// So far miniquad never encountered where it can create a rendering context, but `version 100` shaders are not supported.
/// So far miniquad never encountered where it can create a rendering context,
/// but `version 100` shaders are not supported.
///
/// Typical `new_shader` invocation for an MSL and `glsl version 100` sources:
/// ```ignore
Expand Down Expand Up @@ -1239,13 +1237,14 @@ pub trait RenderingBackend {
/// is recommended instead.
fn render_pass_texture(&self, render_pass: RenderPass) -> TextureId {
let textures = self.render_pass_color_attachments(render_pass);
#[allow(clippy::len_zero)]
if textures.len() == 0 {
panic!("depth-only render pass");
}
if textures.len() != 1 {
panic!("multiple render target render pass");
}
return textures[0];
textures[0]
}
/// For depth-only render pass returns empty slice.
fn render_pass_color_attachments(&self, render_pass: RenderPass) -> &[TextureId];
Expand Down Expand Up @@ -1289,29 +1288,29 @@ pub trait RenderingBackend {

/// Delete GPU buffer, leaving handle unmodified.
///
/// More high-level code on top of miniquad probably is going to call this in Drop implementation of some
/// more RAII buffer object.
/// More high-level code on top of miniquad probably is going to call this in Drop
/// implementation of some more RAII buffer object.
///
/// There is no protection against using deleted buffers later. However its not an UB in OpenGl and thats why
/// this function is not marked as unsafe
/// There is no protection against using deleted buffers later. However its not an UB in OpenGl
/// and thats why this function is not marked as unsafe
fn delete_buffer(&mut self, buffer: BufferId);

/// Delete GPU texture, leaving handle unmodified.
///
/// More high-level code on top of miniquad probably is going to call this in Drop implementation of some
/// more RAII buffer object.
/// More high-level code on top of miniquad probably is going to call this in Drop
/// implementation of some more RAII buffer object.
///
/// There is no protection against using deleted textures later. However its not a CPU-level UB and thats why
/// this function is not marked as unsafe
/// There is no protection against using deleted textures later. However its not a CPU-level UB
/// and thats why this function is not marked as unsafe
fn delete_texture(&mut self, texture: TextureId);

/// Delete GPU program, leaving handle unmodified.
///
/// More high-level code on top of miniquad probably is going to call this in Drop implementation of some
/// more RAII buffer object.
/// More high-level code on top of miniquad probably is going to call this in Drop
/// implementation of some more RAII buffer object.
///
/// There is no protection against using deleted programs later. However its not a CPU-level Porgram and thats why
/// this function is not marked as unsafe
/// There is no protection against using deleted programs later. However its not a CPU-level
/// Porgram and thats why this function is not marked as unsafe
fn delete_shader(&mut self, program: ShaderId);

/// Set a new viewport rectangle.
Expand Down
41 changes: 20 additions & 21 deletions src/graphics/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,12 @@ pub struct GlContext {
pub(crate) info: ContextInfo,
}

impl Default for GlContext {
fn default() -> Self {
Self::new()
}
}

impl GlContext {
pub fn new() -> GlContext {
unsafe {
Expand Down Expand Up @@ -767,7 +773,7 @@ impl GlContext {
glStencilFuncSeparate(
GL_BACK,
back.test_func.into(),
back.test_ref.into(),
back.test_ref,
back.test_mask,
);
glStencilMaskSeparate(GL_BACK, back.write_mask);
Expand Down Expand Up @@ -810,6 +816,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 _) }
Expand All @@ -826,7 +833,6 @@ fn gl_info() -> ContextInfo {
let features = Features {
instancing: !gl2,
resolve_attachments: !webgl1 && !gl2,
..Default::default()
};

let mut glsl_support = GlslSupport::default();
Expand Down Expand Up @@ -862,17 +868,16 @@ fn gl_info() -> ContextInfo {
glsl_support.v150 = true; // MacOS is defaulting to 3.2 and GLSL 150
} else if gl_version_string.starts_with("4") || gl_version_string.starts_with("3.3") {
glsl_support.v330 = true;
} else
// gl 3.0, 3.1, 3.2 maps to 1.30, 1.40, 1.50 glsl versions
if gl_version_string.starts_with("3") {
} else if gl_version_string.starts_with("3") {
glsl_support.v130 = true;
}

ContextInfo {
backend: Backend::OpenGl,
gl_version_string,
glsl_support,
features: features,
features,
}
}

Expand Down Expand Up @@ -1005,11 +1010,8 @@ impl RenderingBackend for GlContext {
) {
let mut t = self.textures.get(texture);
t.resize(self, width, height, source);
match texture.0 {
TextureIdInner::Managed(tex_id) => {
self.textures.0[tex_id].params = t.params;
}
_ => {}
if let TextureIdInner::Managed(tex_id) = texture.0 {
self.textures.0[tex_id].params = t.params;
};
}
fn texture_read_pixels(&mut self, texture: TextureId, source: &mut [u8]) {
Expand Down Expand Up @@ -1455,8 +1457,7 @@ impl RenderingBackend for GlContext {
TextureOrRenderbuffer::Renderbuffer(id) => id,
};
unsafe {
self.cache
.bind_texture(n, texture.params.kind.into(), raw);
self.cache.bind_texture(n, texture.params.kind.into(), raw);
glUniform1i(gl_loc, n as i32);
}
}
Expand Down Expand Up @@ -1524,13 +1525,11 @@ impl RenderingBackend for GlContext {
gl_vbuf: vb.gl_buf,
});
}
} else {
if cached_attr.is_some() {
unsafe {
glDisableVertexAttribArray(attr_index as GLuint);
}
*cached_attr = None;
} else if cached_attr.is_some() {
unsafe {
glDisableVertexAttribArray(attr_index as GLuint);
}
*cached_attr = None;
}
}
}
Expand All @@ -1541,7 +1540,7 @@ impl RenderingBackend for GlContext {

let mut offset = 0;

for (_, uniform) in shader.uniforms.iter().enumerate() {
for uniform in shader.uniforms.iter() {
use UniformType::*;

assert!(
Expand All @@ -1550,8 +1549,8 @@ impl RenderingBackend for GlContext {
);

unsafe {
let data = (uniform_ptr as *const f32).offset(offset as isize);
let data_int = (uniform_ptr as *const i32).offset(offset as isize);
let data = (uniform_ptr as *const f32).add(offset);
let data_int = (uniform_ptr as *const i32).add(offset);

if let Some(gl_loc) = uniform.gl_loc {
match uniform.uniform_type {
Expand Down
12 changes: 4 additions & 8 deletions src/graphics/gl/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ impl GlCache {
self.bind_buffer(target, self.stored_vertex_buffer, None);
self.stored_vertex_buffer = 0;
}
} else {
if self.stored_index_buffer != 0 {
self.bind_buffer(target, self.stored_index_buffer, self.stored_index_type);
self.stored_index_buffer = 0;
}
} else if self.stored_index_buffer != 0 {
self.bind_buffer(target, self.stored_index_buffer, self.stored_index_type);
self.stored_index_buffer = 0;
}
}

Expand Down Expand Up @@ -135,9 +133,7 @@ impl GlCache {
let cached_attr = &mut self.attributes[attr_index];

if cached_attr.is_some() {
unsafe {
glDisableVertexAttribArray(attr_index as GLuint)
};
unsafe { glDisableVertexAttribArray(attr_index as GLuint) };
}
*cached_attr = None;
}
Expand Down
19 changes: 11 additions & 8 deletions src/graphics/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ pub struct MetalContext {
current_ub_offset: u64,
}

impl Default for MetalContext {
fn default() -> Self {
Self::new()
}
}

impl MetalContext {
pub fn new() -> MetalContext {
unsafe {
Expand Down Expand Up @@ -589,6 +595,7 @@ impl RenderingBackend for MetalContext {
BufferSource::Slice(data) => data.size,
BufferSource::Empty { size, .. } => *size,
};
#[allow(clippy::needless_range_loop)]
for i in 0..BUFFERS_IN_ROTATION {
let buffer: ObjcId = if let BufferSource::Slice(data) = &data {
debug_assert!(data.is_slice);
Expand Down Expand Up @@ -619,7 +626,7 @@ impl RenderingBackend for MetalContext {
}
let buffer = Buffer {
raw,
size: size as usize,
size,
value: 0,
next_value: 0,
};
Expand Down Expand Up @@ -804,8 +811,8 @@ impl RenderingBackend for MetalContext {
let raw_texture = self.textures.get(texture).texture;
let region = MTLRegion {
origin: MTLOrigin {
x: 0 as u64,
y: 0 as u64,
x: 0_u64,
y: 0_u64,
z: 0,
},
size: MTLSize {
Expand Down Expand Up @@ -1155,11 +1162,7 @@ impl RenderingBackend for MetalContext {
None => {
let (screen_width, screen_height) = crate::window::screen_size();
(
{
let a = msg_send_![self.view, currentRenderPassDescriptor];
//msg_send_![a, retain];
a
},
msg_send_![self.view, currentRenderPassDescriptor],
screen_width as f64,
screen_height as f64,
)
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#![doc = include_str!("../README.md")]
#![allow(
clippy::collapsible_if,
clippy::collapsible_else_if,
clippy::unused_unit,
clippy::identity_op,
clippy::missing_safety_doc
)]

pub mod conf;
mod event;
pub mod fs;
Expand Down
Loading
Loading