Adding examples (#1256)

* Derive PartialEq for DescriptorDesc and added examples
This commit is contained in:
Antonino Siena 2019-10-27 23:27:38 +01:00 committed by Austin Johnson
parent 212c5f6622
commit e5d6c2cb1a
2 changed files with 76 additions and 4 deletions

View File

@ -57,7 +57,7 @@ use vk;
/// > will be checked when you create a pipeline layout, a descriptor set, or when you try to bind
/// > a descriptor set.
// TODO: add example
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct DescriptorDesc {
/// Describes the content and layout of each array element of a descriptor.
pub ty: DescriptorDescTy,
@ -78,7 +78,33 @@ impl DescriptorDesc {
///
/// Returns true if `self` is the same descriptor as `other`, or if `self` is the same as
/// `other` but with a larger array elements count and/or more shader stages.
// TODO: add example
///
///# Example
///```
///use vulkano::descriptor::descriptor::DescriptorDesc;
///use vulkano::descriptor::descriptor::DescriptorDescTy::*;
///use vulkano::descriptor::descriptor::ShaderStages;
///
///let desc_super = DescriptorDesc{ ty: Sampler, array_count: 2, stages: ShaderStages{
/// vertex: true,
/// tessellation_control: true,
/// tessellation_evaluation: true,
/// geometry: true,
/// fragment: true,
/// compute: true
///}, readonly: false };
///let desc_sub = DescriptorDesc{ ty: Sampler, array_count: 1, stages: ShaderStages{
/// vertex: true,
/// tessellation_control: false,
/// tessellation_evaluation: false,
/// geometry: false,
/// fragment: true,
/// compute: false
///}, readonly: true };
///
///assert_eq!(desc_super.is_superset_of(&desc_sub).unwrap(), ());
///
///```
#[inline]
pub fn is_superset_of(&self, other: &DescriptorDesc)
-> Result<(), DescriptorDescSupersetError> {
@ -102,8 +128,43 @@ impl DescriptorDesc {
/// Builds a `DescriptorDesc` that is the union of `self` and `other`, if possible.
///
/// The returned value will be a superset of both `self` and `other`.
///
///# Example
///```
///use vulkano::descriptor::descriptor::DescriptorDesc;
///use vulkano::descriptor::descriptor::DescriptorDescTy::*;
///use vulkano::descriptor::descriptor::ShaderStages;
///
///let desc_part1 = DescriptorDesc{ ty: Sampler, array_count: 2, stages: ShaderStages{
/// vertex: true,
/// tessellation_control: true,
/// tessellation_evaluation: false,
/// geometry: true,
/// fragment: false,
/// compute: true
///}, readonly: false };
///
///let desc_part2 = DescriptorDesc{ ty: Sampler, array_count: 1, stages: ShaderStages{
/// vertex: true,
/// tessellation_control: false,
/// tessellation_evaluation: true,
/// geometry: false,
/// fragment: true,
/// compute: true
///}, readonly: true };
///
///let desc_union = DescriptorDesc{ ty: Sampler, array_count: 2, stages: ShaderStages{
/// vertex: true,
/// tessellation_control: true,
/// tessellation_evaluation: true,
/// geometry: true,
/// fragment: true,
/// compute: true
///}, readonly: false };
///
///assert_eq!(desc_part1.union(&desc_part2), Some(desc_union));
///```
// TODO: Result instead of Option
// TODO: add example
#[inline]
pub fn union(&self, other: &DescriptorDesc) -> Option<DescriptorDesc> {
if self.ty != other.ty {

View File

@ -10,7 +10,18 @@
use pipeline::vertex::VertexMemberTy;
/// Implements the `Vertex` trait on a struct.
// TODO: add example
///# Example
///
///```
///#[derive(Default, Copy, Clone)]
///struct Vertex{
/// position: [f32; 3],
/// color: [f32; 4]
///}
///
///vulkano::impl_vertex!(Vertex, position, color);
///
///```
#[macro_export]
macro_rules! impl_vertex {
($out:ty $(, $member:ident)*) => (