pub trait Geometry {
    // Required methods
    fn draw(
        &self,
        camera: &Camera,
        program: &Program,
        render_states: RenderStates,
        attributes: FragmentAttributes
    );
    fn vertex_shader_source(
        &self,
        required_attributes: FragmentAttributes
    ) -> String;
    fn id(&self, required_attributes: FragmentAttributes) -> u16;
    fn render_with_material(
        &self,
        material: &dyn Material,
        camera: &Camera,
        lights: &[&dyn Light]
    );
    fn render_with_effect(
        &self,
        material: &dyn Effect,
        camera: &Camera,
        lights: &[&dyn Light],
        color_texture: Option<ColorTexture<'_>>,
        depth_texture: Option<DepthTexture<'_>>
    );
    fn aabb(&self) -> AxisAlignedBoundingBox;

    // Provided method
    fn animate(&mut self, _time: f32) { ... }
}
Expand description

Represents a 3D geometry that, together with a material, can be rendered using Geometry::render_with_material. Alternatively, a geometry and a material can be combined in a Gm, thereby creating an Object which can be used in a render call, for example RenderTarget::render.

If requested by the material, the geometry has to support the following attributes in the vertex shader source code.

  • position: out vec3 pos; (must be in world space)
  • normal: out vec3 nor;
  • tangent: out vec3 tang;
  • bitangent: out vec3 bitang;
  • uv coordinates: out vec2 uvs; (must be flipped in v compared to standard uv coordinates, ie. do uvs = vec2(uvs.x, 1.0 - uvs.y); in the vertex shader or do the flip before constructing the uv coordinates vertex buffer)
  • color: out vec4 col;

Required Methods§

source

fn draw( &self, camera: &Camera, program: &Program, render_states: RenderStates, attributes: FragmentAttributes )

Draw this geometry.

source

fn vertex_shader_source( &self, required_attributes: FragmentAttributes ) -> String

Returns the vertex shader source for this geometry given that the fragment shader needs the given vertex attributes.

source

fn id(&self, required_attributes: FragmentAttributes) -> u16

Returns a unique ID for each variation of the shader source returned from Geometry::vertex_shader_source.

Note: The last bit is reserved to internally implemented geometries, so if implementing the Geometry trait outside of this crate, always return an id that is smaller than 0b1u16 << 15.

source

fn render_with_material( &self, material: &dyn Material, camera: &Camera, lights: &[&dyn Light] )

Render the geometry with the given Material. Must be called in the callback given as input to a RenderTarget, ColorTarget or DepthTarget write method. Use an empty array for the lights argument, if the material does not require lights to be rendered.

source

fn render_with_effect( &self, material: &dyn Effect, camera: &Camera, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>> )

Render the geometry with the given Effect. Must be called in the callback given as input to a RenderTarget, ColorTarget or DepthTarget write method. Use an empty array for the lights argument, if the material does not require lights to be rendered.

source

fn aabb(&self) -> AxisAlignedBoundingBox

Returns the AxisAlignedBoundingBox for this geometry in the global coordinate system.

Provided Methods§

source

fn animate(&mut self, _time: f32)

For updating the animation of this geometry if it is animated, if not, this method does nothing. The time parameter should be some continious time, for example the time since start.

Implementations on Foreign Types§

source§

impl<T: Geometry + ?Sized> Geometry for &T

source§

fn draw( &self, camera: &Camera, program: &Program, render_states: RenderStates, attributes: FragmentAttributes )

source§

fn vertex_shader_source( &self, required_attributes: FragmentAttributes ) -> String

source§

fn id(&self, required_attributes: FragmentAttributes) -> u16

source§

fn render_with_material( &self, material: &dyn Material, camera: &Camera, lights: &[&dyn Light] )

source§

fn render_with_effect( &self, material: &dyn Effect, camera: &Camera, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>> )

source§

fn aabb(&self) -> AxisAlignedBoundingBox

source§

impl<T: Geometry + ?Sized> Geometry for &mut T

source§

fn draw( &self, camera: &Camera, program: &Program, render_states: RenderStates, attributes: FragmentAttributes )

source§

fn vertex_shader_source( &self, required_attributes: FragmentAttributes ) -> String

source§

fn id(&self, required_attributes: FragmentAttributes) -> u16

source§

fn render_with_material( &self, material: &dyn Material, camera: &Camera, lights: &[&dyn Light] )

source§

fn render_with_effect( &self, material: &dyn Effect, camera: &Camera, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>> )

source§

fn aabb(&self) -> AxisAlignedBoundingBox

source§

fn animate(&mut self, time: f32)

source§

impl<T: Geometry> Geometry for Box<T>

source§

fn draw( &self, camera: &Camera, program: &Program, render_states: RenderStates, attributes: FragmentAttributes )

source§

fn vertex_shader_source( &self, required_attributes: FragmentAttributes ) -> String

source§

fn id(&self, required_attributes: FragmentAttributes) -> u16

source§

fn render_with_material( &self, material: &dyn Material, camera: &Camera, lights: &[&dyn Light] )

source§

fn render_with_effect( &self, material: &dyn Effect, camera: &Camera, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>> )

source§

fn aabb(&self) -> AxisAlignedBoundingBox

source§

impl<T: Geometry> Geometry for Rc<T>

source§

fn draw( &self, camera: &Camera, program: &Program, render_states: RenderStates, attributes: FragmentAttributes )

source§

fn vertex_shader_source( &self, required_attributes: FragmentAttributes ) -> String

source§

fn id(&self, required_attributes: FragmentAttributes) -> u16

source§

fn render_with_material( &self, material: &dyn Material, camera: &Camera, lights: &[&dyn Light] )

source§

fn render_with_effect( &self, material: &dyn Effect, camera: &Camera, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>> )

source§

fn aabb(&self) -> AxisAlignedBoundingBox

source§

impl<T: Geometry> Geometry for Arc<T>

source§

fn draw( &self, camera: &Camera, program: &Program, render_states: RenderStates, attributes: FragmentAttributes )

source§

fn vertex_shader_source( &self, required_attributes: FragmentAttributes ) -> String

source§

fn id(&self, required_attributes: FragmentAttributes) -> u16

source§

fn render_with_material( &self, material: &dyn Material, camera: &Camera, lights: &[&dyn Light] )

source§

fn render_with_effect( &self, material: &dyn Effect, camera: &Camera, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>> )

source§

fn aabb(&self) -> AxisAlignedBoundingBox

source§

impl<T: Geometry> Geometry for RefCell<T>

source§

fn draw( &self, camera: &Camera, program: &Program, render_states: RenderStates, attributes: FragmentAttributes )

source§

fn vertex_shader_source( &self, required_attributes: FragmentAttributes ) -> String

source§

fn id(&self, required_attributes: FragmentAttributes) -> u16

source§

fn render_with_material( &self, material: &dyn Material, camera: &Camera, lights: &[&dyn Light] )

source§

fn render_with_effect( &self, material: &dyn Effect, camera: &Camera, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>> )

source§

fn aabb(&self) -> AxisAlignedBoundingBox

source§

fn animate(&mut self, time: f32)

source§

impl<T: Geometry> Geometry for RwLock<T>

source§

fn draw( &self, camera: &Camera, program: &Program, render_states: RenderStates, attributes: FragmentAttributes )

source§

fn vertex_shader_source( &self, required_attributes: FragmentAttributes ) -> String

source§

fn id(&self, required_attributes: FragmentAttributes) -> u16

source§

fn render_with_material( &self, material: &dyn Material, camera: &Camera, lights: &[&dyn Light] )

source§

fn render_with_effect( &self, material: &dyn Effect, camera: &Camera, lights: &[&dyn Light], color_texture: Option<ColorTexture<'_>>, depth_texture: Option<DepthTexture<'_>> )

source§

fn aabb(&self) -> AxisAlignedBoundingBox

source§

fn animate(&mut self, time: f32)

Implementors§