Skip to content

Allow users to provide image dimensions type/layers count in ImageLoaderSettings #17145

@MatrixDev

Description

@MatrixDev

What problem does this solve or what need does it fill?

Makes the usage of stacked 2D array (and similar) textures much much easier and less error prone.

What solution would you like?

Adding enum specifying texture type during asset loading to ImageLoaderSettings:

enum ImageDimensions {
    D1,
    D2,
    D2Array(u32),
}

struct ImageLoaderSettings {
    // ...
    dimensions: ImageDimensions,
}

So it can be used after:

#[derive(Asset, AsBindGroup, Reflect, Debug, Default, Clone)]
struct MyMaterial {
    #[texture(0, dimension = "2d_array")]
    #[sampler(1)]
    pub textures: Handle<Image>,
}

let textures = assets.load_with_settings("assets/2d_array.png", |s: &mut ImageLoaderSettings| {
    s.dimentions = ImageDimensions::D2Array(3);
});

commands.spawn((
    Mesh3d(mesh),
    MeshMaterial3d(materials.add(MyMaterial { textures })),
));

What alternative(s) have you considered?

The only alternative so far is to track when the image was loaded and call reinterpret_stacked_2d_as_array manually. But this requires a lot of boiler plate code and feels like a workaround. Also if there is any delay in calling reinterpret_stacked_2d_as_array, program will crash because shader expects 2d-array texture, but receives 2d texture.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsA-RenderingDrawing game state to the screenC-FeatureA new feature, making something new possibleD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions