what is standard process to load assets from C++?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

what is standard process to load assets from C++?

Phil Dougherty
Using the NDK to develop a native oculus quest appplication: 

I'm finding conflicting and outdated information, and would love to be pointed in the right direction.

On PC, for example, I have a simple folder structure:
- resources
- - images
- - - blah0.png
- - - blah1.png  
- - - ...
- - shaders
- - - blah0.spv
- - - blah1.spv
- - - ...

All I have to do is put my resources folder in the running directory of the .exe and I have easy direct access to them.

For android, I'm getting the idea that things aren't so simple.

my build.gradle uses the following snippet:

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      assets.srcDirs 'build/cmake/release/arm64-v8a/resources'
    }
  }

(the srcDirs string is the resources directory which CMake creates)

What alterations do I need to make to my C++ code which loads those files essentially as simply as "fopen("resources/images/blah0.png",...);"?

I would love to be pointed to any up-to-date resources that 1. would reassure me that my resources folder is in fact going to the right place in the apk, and 2. would show me how to load these files in C++.

Thanks!

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/181ba0cb-2e13-4523-9469-2675510cafc9n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: what is standard process to load assets from C++?

Dan Albert

On Mon, Aug 17, 2020 at 6:35 PM Phil Dougherty <[hidden email]> wrote:
Using the NDK to develop a native oculus quest appplication: 

I'm finding conflicting and outdated information, and would love to be pointed in the right direction.

On PC, for example, I have a simple folder structure:
- resources
- - images
- - - blah0.png
- - - blah1.png  
- - - ...
- - shaders
- - - blah0.spv
- - - blah1.spv
- - - ...

All I have to do is put my resources folder in the running directory of the .exe and I have easy direct access to them.

For android, I'm getting the idea that things aren't so simple.

my build.gradle uses the following snippet:

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      assets.srcDirs 'build/cmake/release/arm64-v8a/resources'
    }
  }

(the srcDirs string is the resources directory which CMake creates)

What alterations do I need to make to my C++ code which loads those files essentially as simply as "fopen("resources/images/blah0.png",...);"?

I would love to be pointed to any up-to-date resources that 1. would reassure me that my resources folder is in fact going to the right place in the apk, and 2. would show me how to load these files in C++.

Thanks!

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/181ba0cb-2e13-4523-9469-2675510cafc9n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAFVaGhu7QikgLOiBHh53nnHChYiWRJQGKRdqz1QLs2jpS9t4tw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: what is standard process to load assets from C++?

Phil Dougherty
Ok that's a great start!

I've been experimenting, and when I change my gradle snippet from before to

assets.srcDirs 'some/random/directory/on/my/hd'

then, when I enumerate the root assets directory via 

  AAssetDir *rootAssets = AAssetManager_openDir(aassman, "");
  const char *f = AAssetDir_getNextFileName(rootAssets);
  while(f)
  {
    log(f);
    f = AAssetDir_getNextFileName(rootAssets);
  }
  AAssetDir_close(rootAssets);

I get all of the files that were in that directory, but none of the directories.
This would explain why, when I have my gradle assets.srcDirs set to what it was before ('build/cmake/release/arm64-v8a/resources'), the enumeration prints nothing.

Is it not possible to simply plop my resources directory hierarchy into my apk?
I'm unsure which possibility is occurring:
1. the resources hierarchy is present in the .apk, but "getNextFileName" bypasses directories, and my AAssetManager_open calls to that hierarchy ("resources/images/blah0.png") is inexplicably failing for some other reason
2. the resources hierarchy isn't present, because gradle's assets.srcDirs only copies files and not directories
3. there is some restriction on using gradle, or AAsset, or both which forbids hierarchies altogether?
4. ????

What I want is simply the ability to tell gradle "please put the resources folder and its contents where it is accessible in the .apk". I feel like this is an extremely standard and not-niche request, yet am having a ton of trouble finding any documentation showing just that.

The examples you linked seem to point to a flat resources folder, and then access their content by enumerating the files from that folder (rather than any "hardcoded" relative filepaths).
Another concern of mine is- if I'm pointing to my "resources" folder via gradle, will that copy its contents, but not the folder itself? so if I want the folder itself copied, I should put the resources folder in another folder where it is the sole entry, and instead point to that?

Please excuse my verbosity here- I appreciate your help and want to be clear that what I want is something I would expect should be quite simple!

On Monday, August 17, 2020 at 10:19:59 PM UTC-5 Dan Albert wrote:

On Mon, Aug 17, 2020 at 6:35 PM Phil Dougherty <[hidden email]> wrote:
Using the NDK to develop a native oculus quest appplication: 

I'm finding conflicting and outdated information, and would love to be pointed in the right direction.

On PC, for example, I have a simple folder structure:
- resources
- - images
- - - blah0.png
- - - blah1.png  
- - - ...
- - shaders
- - - blah0.spv
- - - blah1.spv
- - - ...

All I have to do is put my resources folder in the running directory of the .exe and I have easy direct access to them.

For android, I'm getting the idea that things aren't so simple.

my build.gradle uses the following snippet:

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      assets.srcDirs 'build/cmake/release/arm64-v8a/resources'
    }
  }

(the srcDirs string is the resources directory which CMake creates)

What alterations do I need to make to my C++ code which loads those files essentially as simply as "fopen("resources/images/blah0.png",...);"?

I would love to be pointed to any up-to-date resources that 1. would reassure me that my resources folder is in fact going to the right place in the apk, and 2. would show me how to load these files in C++.

Thanks!

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/181ba0cb-2e13-4523-9469-2675510cafc9n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/5255877d-a5e3-4b52-beb4-4904820eee55n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: what is standard process to load assets from C++?

Phil Dougherty
I've articulated the problem perhaps more concisely (and certainly with better formatting) here:  https://stackoverflow.com/questions/63471752/how-can-i-add-resources-images-sound-files-shaders-etc-to-an-ndk-project
I do think this google groups forum is the only active ndk community I can find, so please don't assume that because it's on stackoverflow I don't need your help!

As always, thank you all for your time and expertise!
On Monday, August 17, 2020 at 11:04:33 PM UTC-5 Phil Dougherty wrote:
Ok that's a great start!

I've been experimenting, and when I change my gradle snippet from before to

assets.srcDirs 'some/random/directory/on/my/hd'

then, when I enumerate the root assets directory via 

  AAssetDir *rootAssets = AAssetManager_openDir(aassman, "");
  const char *f = AAssetDir_getNextFileName(rootAssets);
  while(f)
  {
    log(f);
    f = AAssetDir_getNextFileName(rootAssets);
  }
  AAssetDir_close(rootAssets);

I get all of the files that were in that directory, but none of the directories.
This would explain why, when I have my gradle assets.srcDirs set to what it was before ('build/cmake/release/arm64-v8a/resources'), the enumeration prints nothing.

Is it not possible to simply plop my resources directory hierarchy into my apk?
I'm unsure which possibility is occurring:
1. the resources hierarchy is present in the .apk, but "getNextFileName" bypasses directories, and my AAssetManager_open calls to that hierarchy ("resources/images/blah0.png") is inexplicably failing for some other reason
2. the resources hierarchy isn't present, because gradle's assets.srcDirs only copies files and not directories
3. there is some restriction on using gradle, or AAsset, or both which forbids hierarchies altogether?
4. ????

What I want is simply the ability to tell gradle "please put the resources folder and its contents where it is accessible in the .apk". I feel like this is an extremely standard and not-niche request, yet am having a ton of trouble finding any documentation showing just that.

The examples you linked seem to point to a flat resources folder, and then access their content by enumerating the files from that folder (rather than any "hardcoded" relative filepaths).
Another concern of mine is- if I'm pointing to my "resources" folder via gradle, will that copy its contents, but not the folder itself? so if I want the folder itself copied, I should put the resources folder in another folder where it is the sole entry, and instead point to that?

Please excuse my verbosity here- I appreciate your help and want to be clear that what I want is something I would expect should be quite simple!

On Monday, August 17, 2020 at 10:19:59 PM UTC-5 Dan Albert wrote:

On Mon, Aug 17, 2020 at 6:35 PM Phil Dougherty <[hidden email]> wrote:
Using the NDK to develop a native oculus quest appplication: 

I'm finding conflicting and outdated information, and would love to be pointed in the right direction.

On PC, for example, I have a simple folder structure:
- resources
- - images
- - - blah0.png
- - - blah1.png  
- - - ...
- - shaders
- - - blah0.spv
- - - blah1.spv
- - - ...

All I have to do is put my resources folder in the running directory of the .exe and I have easy direct access to them.

For android, I'm getting the idea that things aren't so simple.

my build.gradle uses the following snippet:

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      assets.srcDirs 'build/cmake/release/arm64-v8a/resources'
    }
  }

(the srcDirs string is the resources directory which CMake creates)

What alterations do I need to make to my C++ code which loads those files essentially as simply as "fopen("resources/images/blah0.png",...);"?

I would love to be pointed to any up-to-date resources that 1. would reassure me that my resources folder is in fact going to the right place in the apk, and 2. would show me how to load these files in C++.

Thanks!

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/181ba0cb-2e13-4523-9469-2675510cafc9n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/6b4660e7-4bc9-4e55-b927-99fdda5e9966n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: what is standard process to load assets from C++?

Phil Dougherty
I've figured it out- see the stackoverflow link for details (tl;dr: I was pointing to a directory that gradle itself was responsible for building, and so the asset packaging was occurring at unreliable times, among other things).

Thanks for your help!

On Tuesday, August 18, 2020 at 10:48:40 AM UTC-5 Phil Dougherty wrote:
I've articulated the problem perhaps more concisely (and certainly with better formatting) here:  https://stackoverflow.com/questions/63471752/how-can-i-add-resources-images-sound-files-shaders-etc-to-an-ndk-project
I do think this google groups forum is the only active ndk community I can find, so please don't assume that because it's on stackoverflow I don't need your help!

As always, thank you all for your time and expertise!
On Monday, August 17, 2020 at 11:04:33 PM UTC-5 Phil Dougherty wrote:
Ok that's a great start!

I've been experimenting, and when I change my gradle snippet from before to

assets.srcDirs 'some/random/directory/on/my/hd'

then, when I enumerate the root assets directory via 

  AAssetDir *rootAssets = AAssetManager_openDir(aassman, "");
  const char *f = AAssetDir_getNextFileName(rootAssets);
  while(f)
  {
    log(f);
    f = AAssetDir_getNextFileName(rootAssets);
  }
  AAssetDir_close(rootAssets);

I get all of the files that were in that directory, but none of the directories.
This would explain why, when I have my gradle assets.srcDirs set to what it was before ('build/cmake/release/arm64-v8a/resources'), the enumeration prints nothing.

Is it not possible to simply plop my resources directory hierarchy into my apk?
I'm unsure which possibility is occurring:
1. the resources hierarchy is present in the .apk, but "getNextFileName" bypasses directories, and my AAssetManager_open calls to that hierarchy ("resources/images/blah0.png") is inexplicably failing for some other reason
2. the resources hierarchy isn't present, because gradle's assets.srcDirs only copies files and not directories
3. there is some restriction on using gradle, or AAsset, or both which forbids hierarchies altogether?
4. ????

What I want is simply the ability to tell gradle "please put the resources folder and its contents where it is accessible in the .apk". I feel like this is an extremely standard and not-niche request, yet am having a ton of trouble finding any documentation showing just that.

The examples you linked seem to point to a flat resources folder, and then access their content by enumerating the files from that folder (rather than any "hardcoded" relative filepaths).
Another concern of mine is- if I'm pointing to my "resources" folder via gradle, will that copy its contents, but not the folder itself? so if I want the folder itself copied, I should put the resources folder in another folder where it is the sole entry, and instead point to that?

Please excuse my verbosity here- I appreciate your help and want to be clear that what I want is something I would expect should be quite simple!

On Monday, August 17, 2020 at 10:19:59 PM UTC-5 Dan Albert wrote:

On Mon, Aug 17, 2020 at 6:35 PM Phil Dougherty <[hidden email]> wrote:
Using the NDK to develop a native oculus quest appplication: 

I'm finding conflicting and outdated information, and would love to be pointed in the right direction.

On PC, for example, I have a simple folder structure:
- resources
- - images
- - - blah0.png
- - - blah1.png  
- - - ...
- - shaders
- - - blah0.spv
- - - blah1.spv
- - - ...

All I have to do is put my resources folder in the running directory of the .exe and I have easy direct access to them.

For android, I'm getting the idea that things aren't so simple.

my build.gradle uses the following snippet:

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      assets.srcDirs 'build/cmake/release/arm64-v8a/resources'
    }
  }

(the srcDirs string is the resources directory which CMake creates)

What alterations do I need to make to my C++ code which loads those files essentially as simply as "fopen("resources/images/blah0.png",...);"?

I would love to be pointed to any up-to-date resources that 1. would reassure me that my resources folder is in fact going to the right place in the apk, and 2. would show me how to load these files in C++.

Thanks!

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/181ba0cb-2e13-4523-9469-2675510cafc9n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/a9f34a3b-21ea-4b60-87e6-ad904357f1f4n%40googlegroups.com.