3

I am working with OpenGL ES 3.0 and using Eclipse NDK for rendering volume data with Google Nexus. I am using AssetManager for loading the volume data which is a raw file of 16 MB to the real device but it's not working. I stored the resource in the Asset folder included headers too but still i am receiving the same error in logcat __load_uniform_float:802>:GL_INVALID_OPERATION I tried to Google some related examples but couldn't find any.

Here is my code:

int LoadVolume()
{
    GLubyte *pdata;
    const unsigned int BUFFER_SIZE = XDIM*YDIM*ZDIM;
    GLubyte buffer[BUFFER_SIZE];
    AAssetManager*mgr;
    AAsset* asset=AAssetManager_open(mgr,"Engine256.raw",AASSET_MODE_BUFFER);
    if(!asset)
    {
    __android_log_print(ANDROID_LOG_ERROR, "TAG", "_ASSET_NOT_FOUND_");
     return 0;
    }
    pdata=(GLubyte*)AAsset_read(asset,buffer,BUFFER_SIZE);

    AAsset_close(asset);

   glGenTextures ( 1,&textureId );
   glBindTexture ( GL_TEXTURE_3D,textureId );
   glTexImage3D ( GL_TEXTURE_3D, 0, GL_RED,XDIM, YDIM, ZDIM, 0,
                  GL_RED, GL_UNSIGNED_BYTE,pdata);

   glTexParameteri ( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
   glTexParameteri ( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
   glTexParameteri ( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
   glTexParameteri ( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE );
   glTexParameteri ( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

   glBindTexture ( GL_TEXTURE_3D, 0 );
   return 1;
}
Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
user3492894
  • 43
  • 1
  • 6

1 Answers1

8

If you look at these two lines:

AAssetManager*mgr;
AAsset* asset=AAssetManager_open(mgr,"Engine256.raw",AASSET_MODE_BUFFER);

You're declaring mgr as a pointer variable, but you don't assign a value to it. Then you use it on the next line, while it's uninitialized.

You need to pass an AssetManager object from your Java code into the native code through your JNI interface, and then obtain the AAssetManager by using this call, where assetManager is the Java object passed in, which comes into the native code as a jobject type parameter.

AAssetManager *mgr = AAssetManager_fromJava(env, assetManager);

This question/answer show in some more detail how to pass the Java object to the native code: Can't access AAssetManager in native code passed from Java in WallpaperService.

Community
  • 1
  • 1
Reto Koradi
  • 53,228
  • 8
  • 93
  • 133