three-rs 0.3.0

A port of three.js core and its WebGPURenderer to Rust on wgpu, graded against three.js's own end-to-end pixel comparison.
Documentation
//! Ports of `three.js/src/textures`.

use std::cell::Cell;

mod compressed_texture;
mod cube_depth_texture;
mod cube_texture;
mod data3d_texture;
mod data_array_texture;
mod data_texture;
mod depth_texture;
mod texture;

pub use cube_depth_texture::{CubeDepthTexture, CubeDepthTextureInner};
pub use cube_texture::{CubeTexture, CubeTextureInner, Image, Mapping};
pub use data3d_texture::{Data3DTexture, Data3DTextureInner};
pub use data_array_texture::{DataArrayTexture, DataArrayTextureInner};
pub use data_texture::{DataTexture, DataTextureData, DataTextureInner};
pub use depth_texture::{DepthTexture, DepthTextureInner, TextureFilter, TextureType};
pub use texture::{MinFilter, Mipmap, Texture, TextureInner, Wrapping};

/// `Texture.id` — three.js' `_textureId ++`, shared by every texture class the
/// port has, the way `Source`/`Texture` ids are one counter upstream.
///
/// A texture is a *handle* (`Rc<RefCell<Inner>>`), so a clone is the same
/// texture and keeps the same id; only a `new` mints one. The id used to be
/// `Rc::as_ptr( &inner )`, and the renderer keeps its uploaded `wgpu::Texture`s
/// under it — so a texture dropped and another allocated at its address was
/// served the dead one's pixels, the same freed-address bug as issue #58's
/// geometry cache. A never-reused counter cannot do that.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub(crate) struct TextureId(usize);

/// A `Weak` on a texture handle's shared state, of whichever texture class:
/// what the renderer keeps beside a GPU resource it made for that texture, so
/// it can let the resource go once the consumer has dropped every handle.
///
/// three.js frees a texture's GPU side on `texture.dispose()`, whose `dispose`
/// event `Textures` listens for. A handle here is an `Rc`, so the strong count
/// reaching zero is the same signal with no event and no call (issue #158; the
/// geometry cache's #58 is the same idea). Only
/// [`strong_count`](std::rc::Weak::strong_count) is ever read, so the class is
/// erased.
pub(crate) type TextureOwner = std::rc::Weak<dyn std::any::Any>;

impl TextureId {
    pub fn next() -> Self {
        thread_local! {
            static TEXTURE_ID: Cell<usize> = const { Cell::new(0) };
        }
        TEXTURE_ID.with(|id| {
            let next = id.get();
            id.set(next + 1);
            TextureId(next)
        })
    }

    /// The number itself, for keying on.
    pub fn get(&self) -> usize {
        self.0
    }
}