简体   繁体   English

OSX-将GLSL'InOut'转换为金属

[英]OSX - Convert GLSL 'InOut' to Metal

I am trying to convert the GLSL function below: 我正在尝试转换下面的GLSL函数:

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 用于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 ? 什么是InOut in Metal的等效限定符?

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM