fn coordinate_components(
        &mut self,
        ctx: &mut Context,
        image: Handle<Expression>,
        coord: Handle<Expression>,
        extra: Option<Handle<Expression>>,
        meta: Span,
        body: &mut Block,
    ) -> Result<CoordComponents> {
        if let TypeInner::Image {
            dim,
            arrayed,
            class,
        } = *self.resolve_type(ctx, image, meta)?
        {
            let image_size = match dim {
                Dim::D1 => None,
                Dim::D2 => Some(VectorSize::Bi),
                Dim::D3 => Some(VectorSize::Tri),
                Dim::Cube => Some(VectorSize::Tri),
            };
            let coord_size = match *self.resolve_type(ctx, coord, meta)? {
                TypeInner::Vector { size, .. } => Some(size),
                _ => None,
            };
            let (shadow, storage) = match class {
                ImageClass::Depth { .. } => (true, false),
                ImageClass::Storage { .. } => (false, true),
                _ => (false, false),
            };

            let coordinate = match (image_size, coord_size) {
                (Some(size), Some(coord_s)) if size != coord_s => {
                    ctx.vector_resize(size, coord, Span::default(), body)
                }
                (None, Some(_)) => ctx.add_expression(
                    Expression::AccessIndex {
                        base: coord,
                        index: 0,
                    },
                    Span::default(),
                    body,
                ),
                _ => coord,
            };

            let mut coord_index = image_size.map_or(1, |s| s as u32);

            let array_index = if arrayed && !(storage && dim == Dim::Cube) {
                let index = coord_index;
                coord_index += 1;

                Some(ctx.add_expression(
                    Expression::AccessIndex { base: coord, index },
                    Span::default(),
                    body,
                ))
            } else {
                None
            };
            let mut used_extra = false;
            let depth_ref = match shadow {
                true => {
                    let index = coord_index;

                    if index == 4 {
                        used_extra = true;
                        extra
                    } else {
                        Some(ctx.add_expression(
                            Expression::AccessIndex { base: coord, index },
                            Span::default(),
                            body,
                        ))
                    }
                }
                false => None,
            };

            Ok(CoordComponents {
                coordinate,
                depth_ref,
                array_index,
                used_extra,
            })
        } else {
            self.errors.push(Error {
                kind: ErrorKind::SemanticError("Type is not an image".into()),
                meta,
            });

            Ok(CoordComponents {
                coordinate: coord,
                depth_ref: None,
                array_index: None,
                used_extra: false,
            })
        }
    }
/// Helper function for texture calls, splits the vector argument into it's components
Helper function for texture calls, splits the vector argument into it's components
Helper function for texture calls splits the vector argument into it ' s components
fn coordinate_components(
        &mut self,
        ctx: &mut Context,
        image: Handle<Expression>,
        coord: Handle<Expression>,
        extra: Option<Handle<Expression>>,
        meta: Span,
        body: &mut Block,
    ) -> Result<CoordComponents> {
        if let TypeInner::Image {
            dim,
            arrayed,
            class,
        } = *self.resolve_type(ctx, image, meta)?
        {
            let image_size = match dim {
                Dim::D1 => None,
                Dim::D2 => Some(VectorSize::Bi),
                Dim::D3 => Some(VectorSize::Tri),
                Dim::Cube => Some(VectorSize::Tri),
            };
            let coord_size = match *self.resolve_type(ctx, coord, meta)? {
                TypeInner::Vector { size, .. } => Some(size),
                _ => None,
            };
            let (shadow, storage) = match class {
                ImageClass::Depth { .. } => (true, false),
                ImageClass::Storage { .. } => (false, true),
                _ => (false, false),
            };
            let coordinate = match (image_size, coord_size) {
                (Some(size), Some(coord_s)) if size != coord_s => {
                    ctx.vector_resize(size, coord, Span::default(), body)
                }
                (None, Some(_)) => ctx.add_expression(
                    Expression::AccessIndex {
                        base: coord,
                        index: 0,
                    },
                    Span::default(),
                    body,
                ),
                _ => coord,
            };
            let mut coord_index = image_size.map_or(1, |s| s as u32);
            let array_index = if arrayed && !(storage && dim == Dim::Cube) {
                let index = coord_index;
                coord_index += 1;
                Some(ctx.add_expression(
                    Expression::AccessIndex { base: coord, index },
                    Span::default(),
                    body,
                ))
            } else {
                None
            };
            let mut used_extra = false;
            let depth_ref = match shadow {
                true => {
                    let index = coord_index;
                    if index == 4 {
                        used_extra = true;
                        extra
                    } else {
                        Some(ctx.add_expression(
                            Expression::AccessIndex { base: coord, index },
                            Span::default(),
                            body,
                        ))
                    }
                }
                false => None,
            };
            Ok(CoordComponents {
                coordinate,
                depth_ref,
                array_index,
                used_extra,
            })
        } else {
            self.errors.push(Error {
                kind: ErrorKind::SemanticError("Type is not an image".into()),
                meta,
            });
            Ok(CoordComponents {
                coordinate: coord,
                depth_ref: None,
                array_index: None,
                used_extra: false,
            })
        }
    }
fn coordinate_components ( & mut self , ctx : & mut Context , image : Handle < Expression > , coord : Handle < Expression > , extra : Option < Handle < Expression > > , meta : Span , body : & mut Block , ) -> Result < CoordComponents > { if let TypeInner :: Image { dim , arrayed , class , } = * self . resolve_type ( ctx , image , meta ) ? { let image_size = match dim { Dim :: D1 => None , Dim :: D2 => Some ( VectorSize :: Bi ) , Dim :: D3 => Some ( VectorSize :: Tri ) , Dim :: Cube => Some ( VectorSize :: Tri ) , } ; let coord_size = match * self . resolve_type ( ctx , coord , meta ) ? { TypeInner :: Vector { size , .. } => Some ( size ) , _ => None , } ; let ( shadow , storage ) = match class { ImageClass :: Depth { .. } => ( true , false ) , ImageClass :: Storage { .. } => ( false , true ) , _ => ( false , false ) , } ; let coordinate = match ( image_size , coord_size ) { ( Some ( size ) , Some ( coord_s ) ) if size != coord_s => { ctx . vector_resize ( size , coord , Span :: default ( ) , body ) } ( None , Some ( _ ) ) => ctx . add_expression ( Expression :: AccessIndex { base : coord , index : 0 , } , Span :: default ( ) , body , ) , _ => coord , } ; let mut coord_index = image_size . map_or ( 1 , | s | s as u32 ) ; let array_index = if arrayed && ! ( storage && dim == Dim :: Cube ) { let index = coord_index ; coord_index += 1 ; Some ( ctx . add_expression ( Expression :: AccessIndex { base : coord , index } , Span :: default ( ) , body , ) ) } else { None } ; let mut used_extra = false ; let depth_ref = match shadow { true => { let index = coord_index ; if index == 4 { used_extra = true ; extra } else { Some ( ctx . add_expression ( Expression :: AccessIndex { base : coord , index } , Span :: default ( ) , body , ) ) } } false => None , } ; Ok ( CoordComponents { coordinate , depth_ref , array_index , used_extra , } ) } else { self . errors . push ( Error { kind : ErrorKind :: SemanticError ( " " . into ( ) ) , meta , } ) ; Ok ( CoordComponents { coordinate : coord , depth_ref : None , array_index : None , used_extra : false , } ) } }
Helper function for texture calls, splits the vector argument into it's components
Helper function for texture calls splits the vector argument into it ' s components
&mut self
ctx
&mut Context
image
Handle<Expression>
coord
Handle<Expression>
extra
Option<Handle<Expression>>
meta
Span
body
&mut Block
&mut self
ctx
&mut Context
image
Handle<Expression>
coord
Handle<Expression>
extra
Option<Handle<Expression>>
meta
Span
body
&mut Block