简体   繁体   English

无法运行简单的renderscript数学函数

[英]Cannot get simple renderscript maths function to run

I am trying to get a simple renderscript function to take two numnbers, add them and return the result, however I have not managed to find an example project to do that smoothly. 我试图获得一个简单的renderscript函数来获取两个数字,将它们相加并返回结果,但是我没有设法找到一个示例项目来顺利地做到这一点。 I keep getting a weird error when I try to load the file: 尝试加载文件时,我总是收到奇怪的错误消息:

ScriptC_myexamplescript myScript;
RenderScript rs = RenderScript.create(this);

I get the error: 我得到错误:

Symbol not found: .rs.dtor  on the next line:
myScript = new ScriptC_myexamplescript(rs, getResources(), R.raw.myexamplescript);

My .rs file is just something simple: 我的.rs文件很简单:

#pragma version(1)
#pragma rs java_package_name(com.exercise.<my pacakge name>);

void init(){

}

void root(const float *v_in, float *v_out) {

   const float *data = v_in;
   float *outData = v_out;
   *outData = *data;    

}

Does anyone know what this means, or if there is a simple project I can download for Android ICS and later that does maths, not actual rendering that just works? 有谁知道这意味着什么,或者是否有一个我可以为Android ICS下载的简单项目,以后可以进行数学运算,而不是实际的渲染?

(I can get a rendering script file to work, but that isn't what I want. I don't want any graphics in it) (我可以使一个渲染脚本文件起作用,但这不是我想要的。我不需要其中的任何图形)

EDIT Today I have tried to make it run, and get the following problem: 今天,我尝试使其运行,并得到以下问题:

Allocation mInAllocation = null;
Allocation mOutAllocation;

float[] A = new float[1];
for (int i = 0; i < 1; i++) {
A[i] = 2;
}



Allocation inFloatPointer = Allocation.createSized(rs, Element.F32(rs), A.length, Allocation.USAGE_SCRIPT);
Allocation outFloatPointer = Allocation.createSized(rs, Element.F32(rs), A.length, Allocation.USAGE_SCRIPT);  
inFloatPointer.copyFrom(A); // copies from an array of floats (random numbers in this test case).
mScript.forEach_root(inFloatPointer, outFloatPointer);            

I get the error message: the method forEach_root is undedifed for type ScriptC_RenderScript There is no function forEach_root in the .java file and even after I clean the project it still is not there. 我收到错误消息:ScriptC_RenderScript类型的forEach_root方法未定义。在.java文件中没有forEach_root函数,即使在我清理项目后,它仍然不存在。

Is there a simple project I can download with just a maths function I can download? 是否有一个我可以下载的简单函数,仅需一个数学函数即可下载?

Are you sure that there is indeed an error here? 您确定这里确实存在错误吗? I believe you are just seeing extra verbose logging information. 我相信您会看到更多详细的日志记录信息。 Can you post the exact logcat (or Java exception trace)? 您可以发布确切的logcat(或Java异常跟踪)吗? Note that if you actually want to execute your function, you will need to create an input and output allocation and then call "myScript.forEach_root(input, output);" 请注意,如果您实际上要执行函数,则需要创建输入和输出分配,然后调用“ myScript.forEach_root(input,output);”。 in order to have it execute the root() function on each cell of input/output. 为了使它在输入/输出的每个单元上执行root()函数。 When that is done, you can read the results back from the output allocation and use them from Java. 完成后,您可以从输出分配中读取结果并从Java中使用它们。

Add to the manifest, before <application> , the line 将行添加到清单中<application>之前

<uses-sdk android:minSdkVersion="14" />

Any value under 14 throws the error you mentioned after ant clean debug 小于14的任何值都会在您执行ant clean debug后引发您提到的错误

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

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