Search code examples
macosglslmetalanguage

OSX - Convert GLSL 'InOut' to Metal


I am trying to convert the GLSL function below:

float pMod1(inout float p, float size) {
    float halfsize = size*0.5;
    float c = floor((p + halfsize)/size);
    p = mod(p + halfsize, size) - halfsize;
    return c;
}

to use in Metal

static float pMod1( thread float &p, float size) {
    float halfsize = size*0.5;
    float c = floor((p + halfsize)/size);
    p = mod(p + halfsize, size) - halfsize;
    return c;
}

Then use it:

static float map( float3 p )
{
    p.x = pMod1(p.x,10);
    ...
}

and I got an error:

Non-cont reference cannot bind to vector element

  1. How to resolve this issue?
  2. What is the equivalent qualifier for InOut in Metal?

Solution

  • I found the solution:

    first you have to define it:

    #define _inout(T) T
    

    Then use it in your function:

    static float somefunction( _inout(float) p)