开发者

Problem Overloading Functions in Android Renderscript

I have been writing some helper functions in Android 3.0's renderscript, and have come across a problem when I try to overload a built in function (even one declared as overloadable), or try to declare a function which takes a pointer.

File: *graphics_helper.rsh*

typedef st开发者_Python百科ruct color4_s {
    float red;
    float blue;
    float green;
    float alpha;
} color;

extern void __attribute__((overloadable))
    rsgClearColor(color c);

File: *graphics_helper.rs*

inline void __attribute__((overloadable)) rsgClearColor(color c) {
    rsgClearColor(c.red,c.green,c.blue,c.alpha);
}

When trying to compile as above, I get the error

error: invalid function name prefix, "rs" is reserved: 'rsgClearColor'

In order to make the function compile I have to change it's name (to e.g. gClearColor). Furthermore, the Android tools seem to complain if I try to prototype a function which takes a pointer to a struct. So, for example (using the same struct as above),

extern void __attribute__((overloadable))
    gClearColor(color* c);

Produces the error

Failed to export the function _Z11gClearColorP8color4_s. There's at least one parameter whose type is not supported by the reflectionRSContext::processExport : failed to export func 'gClearColor'

Based on the clang documentation I should be able to both (a) overload the builtin function names and (b) write overloaded functions which take pointers, but neither seems to be working.


Renderscript tries to make a Java wrapper for this function so it is callable from Java. There is no pointer type in Java, so the function is not exportable. The solution here is to make the function static.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜