2017-04-22 8 views
1

structを使用してバッファ値を取得するにはどうすればよいですか?たとえば:金属シェーディング言語 - 構造体を使用してバッファ値を取得する

struct mouseInput 
{ 
float x; 
float y; 
}; 

kernel void compute(texture2d<float, access::write> output [[texture(0)]], 
        constant float &time [[buffer(0)]], 
        constant mouseInput.x &mouseX [[buffer(1)]],///<--mouseX from swift 
        constant mouseInput.y &mouseY [[buffer(2)]],///<--mouseY from swift 
        uint2 gid [[thread_position_in_grid]]) { 
... 
} 

それから私はMetalにそうどこかmouseInput.xにアクセスすることができます。一番近いのはthis threadですが、それを私の使い方にどのように変換するのかは分かりません。

答えて

2

マウスポジションの2つのコンポーネントに別々のバッファを使用すると、私にとっては愚かで無駄に見えます。

両方を含む単一のバッファを作成します。

struct params 
{ 
    float time; 
    float2 mouse; 
}; 

kernel void compute(texture2d<float, access::write> output [[texture(0)]], 
        constant params &params [[buffer(0)]], 
        uint2 gid [[thread_position_in_grid]]) { 
... 
// use params.time to get the time value. 
// Use params.mouse.x and params.mouse.y to get the mouse position. 
} 
:実際には

struct mouseInput 
{ 
float x; 
float y; 
}; 

kernel void compute(texture2d<float, access::write> output [[texture(0)]], 
        constant float &time [[buffer(0)]], 
        constant mouseInput &mouse [[buffer(1)]], 
        uint2 gid [[thread_position_in_grid]]) { 
... 
} 

は、あなたのアプリケーションの残りの部分に応じて、それはおそらく、マウスの位置と時間を結合することは理にかなって:その後のようなシグネチャを使用して計算関数を書きます

関連する問題