从另一个脚本设置一个renderscript全局

时间:2014-10-07 17:37:37

标签: android renderscript

是否有可能在Android renderscript A中设置另一个renderscript B中的字段?我知道您可以使用rsForEach()调用另一个脚本的内核,但是如何设置全局变量或绑定分配?

示例:

我有一个(当然会有多个)奴隶脚本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结构,避免从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引擎可以直接从ndk使用。

1 个答案:

答案 0 :(得分:0)

不,没有办法直接调用其他脚本的功能或将分配从一个脚本绑定到另一个脚本。但是,您可以使用ScriptGroup创建一个脚本链,与一个脚本的输出一起运行,输出另一个脚本甚至是另一个域的输入。