RenderScript:不匹配函数rsGetElementAt_uchar4

时间:2017-09-06 11:26:51

标签: android renderscript android-renderscript

我写了很短的RS,但是在Gradle同步后Android Studio给了我错误

  

错误:(8,34)错误:没有匹配的调用函数   ' rsGetElementAt_uchar4'

脚本:

#pragma version(1)
#pragma rs java_package_name(xx.xxx.xxxxxxx)

uchar4 road = 0;
const uchar4 nothing = 0;

void init() {
    road.a = 0xff;
}

uchar4 __attribute__((kernel)) kernel(uchar4 original, uint32_t x, uint32_t y) {
    uchar4 masked = rsGetElementAt_uchar4(extra_alloc, x, y));
    if (original.r != masked.r || original.g != masked.g || original.b != masked.b) {
        return road;
    } else {
        return nothing;
    }
}

在build.gradle中:

defaultConfig {
    applicationId "xx.xxx.xxxxxxx"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    renderscriptTargetApi 24 // I've tried almost every possible value
    renderscriptSupportModeEnabled true
}

相同的代码,但使用API​​ 23有效:

#pragma version(1)
#pragma rs java_package_name(gl.kid.maptilt)

uchar4 road = 0; // I don't know, how to declare uchar4, any advice?
const uchar4 nothing = 0;

void init() {
    road.a = 0xff;
}

uchar4 __attribute__((kernel)) root(uchar4 original, uchar4 masked, uint32_t x, uint32_t y) {
    if (original.r != masked.r || original.g != masked.g || original.b != masked.b) {
        return road;
    } else {
        return nothing;
    }
}

1 个答案:

答案 0 :(得分:2)

我将从免责声明开始,我对RenderScript了解不多。也就是说,我认为您遵循的代码类似于this question,但您错过了这一行:

rs_allocation extra_alloc;

注意Java中设置它的位:

script.set_extra_alloc(inAllocationExtra);