pub struct Shader {
    pub build_geom: Option<fn() -> Geometry>,
    pub code_to_concatenate: &'static [CodeFragment],
    pub shader_id: AtomicUsize,
}
Expand description

Contains all information necessary to build a shader. Define a new shader.

Pass in a Geometry which gets used for instancing (e.g. a quad or a cube).

The different CodeFragments are appended together (but preserving their filename/line/column information for error messages). They are split out into base_code_fragments and main_code_fragment purely for convenience. (We could instead have used a single slice but they are annoying to get through concatenation..)

TODO(JP): Would be good to instead compile shaders beforehand, ie. during compile time. Should look into that at some point.

Fields

build_geom: Option<fn() -> Geometry>

The Geometry that we will draw with, if any. Can be overridden using [DrawCallProps::gpu_geometry].

code_to_concatenate: &'static [CodeFragment]

A bunch of CodeFragments that will get concatenated.

shader_id: AtomicUsize

The id of the shader (index into Cx::shaders), or Shader::UNCOMPILED_SHADER_ID if uninitialized. You should never read or modify this manually (see TODO below).

TODO(JP): This shouldn’t be public, but right now that’s necessary for using Shader::DEFAULT. We might want to switch to a define_shader helper function once we can pass function pointers to const functions (see https://github.com/rust-lang/rust/issues/63997 and https://github.com/rust-lang/rust/issues/57563).

Implementations

TODO(JP): We might want to switch to a define_shader helper function once we can pass function pointers to const functions (see https://github.com/rust-lang/rust/issues/63997 and https://github.com/rust-lang/rust/issues/57563).

We suppress clippy::declare_interior_mutable_const here since we don’t actually want shader_id in this constant to be editable.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.