Issue
I have shaders kept in assets folder. name of the shader (file name) : "vertex.vs" path : assets/shaders/vertex.vs
I want to access this file from a C++ file from NDK without calling Java or JNI whatever it is. From reading various resources I managed to understand that i have to use the header
#include <android/asset_manager.h>
After that I create pointers and open it.
const char* mPath = "shaders/vertex.vs";
AAssetManager* mAssetManager;
AAsset* mAsset;
mAsset = AAssetManager_open(mAssetManager, mPath,AASSET_MODE_UNKNOWN);
int foo = AAsset_getLength(mAsset);
LOGD( "This is a number: %d", foo );
AAsset_close(mAsset);
But it doesn't do anything. And what's with this read function.
AAsset_read(mAsset,pBuffer,bytesToRead);
Where is the data read? How to define the pBuffer ? Can someone share a simple example on how to read the data from a raw file and how to access it(Like showing it in logcat)?
Solution
You must initialize mAssetManager to begin with, we usually get it from Java via a JNI call, see e.g. this answer. You can obtain this Java object in your C++ code like this, but this still needs JNIEnv.
If you really really want to extract an asset from your APK with no JNI interaction, it not impossible. The trick is to find your APK file and trust that it is a ZIP file under the hood.
Answered By - Alex Cohn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.