Question

I am trying to pass an array of Float2 variables to Renderscript using the copyfrom method using Android Studio with the following code. The first example for an integer is accepted by the IDE, but the next two for either a float or a float2 are not. The IDE returns the following errors:

Cannot resolve method 'copyFrom(java.lang.Float[])'

and

Cannot resolve method 'copyFrom(java.lang.Float2[])'

Any suggestions on the correct method or syntax is appreciated.

    mRS = RenderScript.create(this);

    int[] inputData1 = new int[10];
    Float[] inputData2 = new Float[10];
    Float2[] inputData3 = new Float2[10];      

    inputData1[0] = 1;

    inputData2[0] = 1.0f;

    inputData3[0].x = 1.0f;
    inputData3[0].y = 1.0f;


    Allocation mInAlloc1 = Allocation.createSized(mRS, Element.I32(mRS), 10, Allocation.USAGE_SCRIPT);
    mInAlloc1.copyFrom(inputData1);

    Allocation mInAlloc2 = Allocation.createSized(mRS, Element.F32(mRS), 10, Allocation.USAGE_SCRIPT);
    mInAlloc2.copyFrom(inputData2);

    Allocation mInAlloc3 = Allocation.createSized(mRS, Element.F32_2(mRS), 10, Allocation.USAGE_SCRIPT);
    mInAlloc3.copyFrom(inputData3);

Edit:

I have tried the same code in Eclipse and get a slightly different error:

The method copyFrom(BaseObj[]) in the type Allocation is not applicable for the arguments (Float[])

with the suggestion that I change the type to BaseObj[], but in doing so the IDE then complains that I should change (back) to Float, which seems a bit recursive?

Was it helpful?

Solution

The RenderScript types that don't have native representations in Java code are slightly more difficult. The best way to deal with the vector types is "copyFromUnchecked". So if you have an allocation with 10x, float2, you would create a 20 element java float array. The addressing would be [element*2 + component]

The "unchecked" variants of the copy routines do fewer type checks to allow these copies. Its far more efficient than using an array of objects as you would have with an array of Float2.

I realized re-reading your code, the problem is Float vs float. The RenderScript copy commands are designed to work on the primitive arrays, not object arrays.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top