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. douvs = 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§
sourcefn draw(
&self,
camera: &Camera,
program: &Program,
render_states: RenderStates,
attributes: FragmentAttributes
)
fn draw( &self, camera: &Camera, program: &Program, render_states: RenderStates, attributes: FragmentAttributes )
Draw this geometry.
sourcefn vertex_shader_source(
&self,
required_attributes: FragmentAttributes
) -> String
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.
sourcefn id(&self, required_attributes: FragmentAttributes) -> u16
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
.
sourcefn render_with_material(
&self,
material: &dyn Material,
camera: &Camera,
lights: &[&dyn Light]
)
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.
sourcefn render_with_effect(
&self,
material: &dyn Effect,
camera: &Camera,
lights: &[&dyn Light],
color_texture: Option<ColorTexture<'_>>,
depth_texture: Option<DepthTexture<'_>>
)
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.
sourcefn aabb(&self) -> AxisAlignedBoundingBox
fn aabb(&self) -> AxisAlignedBoundingBox
Returns the AxisAlignedBoundingBox for this geometry in the global coordinate system.