Missing Mesh class on RenderScript support library

走远了吗. 提交于 2019-12-24 12:22:53

问题


I'm following this sample in order to learn about RenderScript. I added the following at project.properties:

renderscript.target=19
renderscript.support.mode=true
sdk.buildtools=23.0.2

I wrote my .rs file, the ScriptC_myfilename was generated at gen folder but the android.support.v8.renderscript could not be resolved to a type, so I added the renderscript-v8.jar located at sdk/build-tools/android-4.4W/renderscript/lib as a library (configure Build Path >> Libraries >> add External JARs) and the problem was fixed.

After codding, I couldn't compile the code due to this error, found on ScriptC_filename.java at gen folder:

Mesh cannot be resolved to a Type

I search about the issue, trying to find the missing class and, I don't know, maybe manually implement this class as a part of my project, so Eclipse would be allowed to import it and fix the error, but I'm a bit confused since the Mesh class isn't cited even on android docs.

I also tried to import the renderscript-v8.jar at sdk\build-tools\android-4.4.2\renderscript\lib, as well as add import android.support.v8.renderscript.Mesh but with no success.

I don't know if this would help, but this is my ScriptC_Snow.java file (everything here was generated, I didn't edit it), The comments is the error showed on Eclipse

    public class ScriptC_Snow extends ScriptC {
    private static final String __rs_resource_name = "snow";

    public  ScriptC_Snow(RenderScript rs) {
        this(rs,
             rs.getApplicationContext().getResources(),
             rs.getApplicationContext().getResources().getIdentifier(
                 __rs_resource_name, "raw",
                 rs.getApplicationContext().getPackageName()));
    }

    public  ScriptC_Snow(RenderScript rs, Resources resources, int id) {
        super(rs, resources, id);
        __MESH = Element.MESH(rs); //the method MESH(RenderScript) is undefined for the type Element
        __F32_2 = Element.F32_2(rs);
    }

    private Element __F32_2;
    private Element __MESH;
    private FieldPacker __rs_fp_F32_2;
    private FieldPacker __rs_fp_MESH;
    private final static int mExportVarIdx_snowMesh = 0;
    private Mesh mExportVar_snowMesh; // Mesh cannot be resolved to a type
    public synchronized void set_snowMesh(Mesh v) { // Mesh cannot be resolved to a type
        setVar(mExportVarIdx_snowMesh, v);
        mExportVar_snowMesh = v; // Mesh cannot be resolved to a type
    }

    public Mesh get_snowMesh() { // Mesh cannot be resolved to a type
        return mExportVar_snowMesh; // Mesh cannot be resolved to a type
    }

    public Script.FieldID getFieldID_snowMesh() {
        return createFieldID(mExportVarIdx_snowMesh, null);
    }

    private final static int mExportVarIdx_snow = 1;
    private ScriptField_Snow mExportVar_snow;
    public void bind_snow(ScriptField_Snow v) {
        mExportVar_snow = v;
        if (v == null) bindAllocation(null, mExportVarIdx_snow);
        else bindAllocation(v.getAllocation(), mExportVarIdx_snow);
    }

    public ScriptField_Snow get_snow() {
        return mExportVar_snow;
    }

    private final static int mExportVarIdx_wind = 2;
    private Float2 mExportVar_wind;
    public synchronized void set_wind(Float2 v) {
        mExportVar_wind = v;
        FieldPacker fp = new FieldPacker(8);
        fp.addF32(v);
        int []__dimArr = new int[1];
        __dimArr[0] = 4;
        setVar(mExportVarIdx_wind, fp, __F32_2, __dimArr);
    }

    public Float2 get_wind() {
        return mExportVar_wind;
    }

    public Script.FieldID getFieldID_wind() {
        return createFieldID(mExportVarIdx_wind, null);
    }

    private final static int mExportVarIdx_grav = 3;
    private Float2 mExportVar_grav;
    public synchronized void set_grav(Float2 v) {
        mExportVar_grav = v;
        FieldPacker fp = new FieldPacker(8);
        fp.addF32(v);
        int []__dimArr = new int[1];
        __dimArr[0] = 4;
        setVar(mExportVarIdx_grav, fp, __F32_2, __dimArr);
    }

    public Float2 get_grav() {
        return mExportVar_grav;
    }

    public Script.FieldID getFieldID_grav() {
        return createFieldID(mExportVarIdx_grav, null);
    }

    private final static int mExportFuncIdx_initSnow = 0;
    public void invoke_initSnow() {
        invoke(mExportFuncIdx_initSnow);
    }

}

This is my renderscript code (.rs file):

#pragma version(1)

#pragma rs java_package_name(com.mypackage.script)

#include "rs_graphics.rsh"

rs_mesh snowMesh;

typedef struct __attribute__((packed, aligned(4))) Snow {
enter code here
    float2 velocity;
    float2 position;
    uchar4 color;
enter code here
} Snow_t;

Snow_t *snow;

float2 wind;
float2 grav;

int root() {

    rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    rsgDrawMesh(snowMesh);
    return 0;

}

void init() {

    grav.x = 0;
    grav.y = 18;
    wind.x = rsRand(50)+20;
    wind.y = rsRand(4) - 2;

}

void initSnow() {
enter code here
    const float w = rsgGetWidth();
    const float h = rsgGetHeight();

    int snowCount = rsAllocationGetDimX(rsGetAllocation(snow));

    Snow_t *pSnow = snow;
    for (int i=0; i < snowCount; i++) {
        pSnow->position.x = rsRand(w);
        pSnow->position.y = rsRand(h);

        pSnow->velocity.y = rsRand(60);
        pSnow->velocity.x = rsRand(100);
        pSnow->velocity.x -= 50;

        uchar4 c = rsPackColorTo8888(255, 255, 255);
        pSnow->color = c;
        pSnow++;

    }

}

I only used the SDK Manager to obtain the files, is there anything I'm missing? Anyone can give me a link to donwload the latest version of renderscript-v8.jar? Is there any link that I could use to see the missing class, in order to implement it in my project, so Eclipse'd be allowed to import and use it?

Thanks in advance.


回答1:


You can't use the support library with rs_graphics.rsh. It doesn't support objects like rs_mesh, rs_font, or rs_program*. The support library is only for accessing RenderScript compute.



来源:https://stackoverflow.com/questions/24560313/missing-mesh-class-on-renderscript-support-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!