简体   繁体   English

从另一个脚本全局设置一个渲染脚本

[英]set a renderscript global from another script

Is there a possibility to set a field in the Android renderscript A out of another renderscript B? 是否可以在Android渲染脚本A中设置另一个渲染脚本B中的字段? I know that you can call a kernel of another Script, using rsForEach() , but how to set globals or bind allocations? 我知道您可以使用rsForEach()调用另一个脚本的内核,但是如何设置全局变量或绑定分配?

Example: 例:

I have a (of course there will be multiple) slave script slave.rs : 我有一个(当然会有多个)从属脚本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;
}

which i would like to call from my master.rs script: 我想从我的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 );
}

Of course this is just a toy example, but I was hoping to realize some more complex renderscript constructs with avoiding too many context switches from Java to renderscript. 当然,这只是一个玩具示例,但我希望通过避免从Java到renderscript的上下文切换过多来实现一些更复杂的renderscript结构。

Some information about multiple Scripts are also provided in a comment to another question: https://stackoverflow.com/a/18926003/4118132 另一个问题的注释中也提供了有关多个脚本的一些信息: https : //stackoverflow.com/a/18926003/4118132

Also an overview on the renderscript functions are provided here: https://stuff.mit.edu/afs/sipb/project/android/docs/guide/topics/renderscript/reference.html 此处还提供了有关renderscript函数的概述: https : //stuff.mit.edu/afs/sipb/project/android/docs/guide/topics/renderscript/reference.html

I'm aware that, starting in Android 4.4, the renderscript - engine can be used directly from the ndk. 我知道,从Android 4.4开始,可以直接从ndk使用renderscript-引擎。

No, there's no way to directly call functions of other scripts or bind allocations from one script to another. 不,无法直接调用其他脚本的功能或将一个脚本的分配绑定到另一个脚本。 However, you can use a ScriptGroup to create a chain of scripts to be run together with output of one feeding the input of another, or even a field of another. 但是,您可以使用ScriptGroup创建一个脚本链,这些脚本链与一个脚本的输出一起运行,从而为另一个脚本的输入甚至另一个字段提供输入。

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

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