2014-10-07 33 views
0

是否有可能在另一個renderscript B中設置Android renderscript A中的一個字段?我知道你可以調用另一個腳本的內核,使用rsForEach(),但如何設置全局變量或綁定分配?從另一個腳本中設置一個renderscript global

例子:

我有一個(當然會有多個)從腳本slave.rs

// just two example allocations 
rs_allocation gImg1; 
rs_allocation gImg2; 

/** merge the two images element wise - just an example */ 
float2 __attribute__((kernel)) root(uint32_t x, uint32_t y) { 
    float2 merged = 0; 
    merged.x = rsGetElementAt_float(gImg1, x, y); 
    merged.y = rsGetElementAt_float(gImg2, x, y); 
    return merged; 
} 

,我想從我的master.rs腳本中調用:

// my globals (which will be set from java) 
rs_allocation gI0; 
rs_allocation gI1; 
rs_allocation gMerged; 

rs_script mSlave; 

/** 
* This function is called from Java and should delegate some of its work 
* to the kernel function of the slave - script 
*/ 
void myFunction(){ 
    // do some stuff 

    // now bind the allocations to the slave sript 
    rsBind(mSlave, "gImg1", gI0); // ??? does there exists something like that? 
    rsBind(mSlave, "gImg2", gI1); // ??? 

    // and invoke the kernel 
    rsForEach(mSlave, 0 , gMerged); 
} 

當然這只是一個玩具的例子,但我希望能夠實現一些更復雜的renderscript構造,避免太多的上下文切換f從Java到renderscript。

也在另一個問題評論提供了有關多個腳本時的一些信息: https://stackoverflow.com/a/18926003/4118132

同樣在的renderScript功能的概述這裏提供: https://stuff.mit.edu/afs/sipb/project/android/docs/guide/topics/renderscript/reference.html

我知道的是,在開始Android 4.4,renderscript-engine可以直接在ndk中使用。

回答

0

不,沒有辦法直接調用其他腳本的函數或將腳本的分配綁定到另一個腳本。但是,您可以使用ScriptGroup創建一個腳本鏈,以便一起輸入另一個腳本的輸入,或者輸入另一個腳本的輸入。

+0

這就是我害怕的:)但謝謝你把它寫成白色! – Alex 2014-10-08 05:58:10

相關問題