2

I did some searching but came up dry... where is the appropriate location to store my shader files? Assets, the raw folder of resources, or somewhere else entirely?

Thank you

xtraorange
  • 1,456
  • 1
  • 16
  • 37

3 Answers3

4

I've used both methods in the past, and both work fine.

One thing to consider is if you are going to use this code in a Library Project at any point in time. If you are, I would recommend using the res/raw directory, as assets has limitations with Library Projects.

From the documentation:

Library projects cannot include raw assets

The tools do not support the use of raw asset files (saved in the assets/ directory) in a library project. Any asset resources used by an application must be stored in the assets/ directory of the application project itself. However, resource files saved in the res/ directory are supported.

Grimmace
  • 4,021
  • 1
  • 31
  • 25
1

Honestly, I would do neither. Storing them in your code itself is probably the safest and most secure method of doing it. (Making them public static final String variables in some class, that is.) I'd probably build them using StringBuilder when the app starts or when the class is initialized.

If you feel more comfortable with storing the files themselves, use assets. Using res/raw has restrictions on filenames, and you cannot use subdirectories in raw.

Cat
  • 66,919
  • 24
  • 133
  • 141
  • I know this comes down to personal preference and some laziness, but I just don't like how shaders look when you plug them into java strings. I also feel like my code becomes more tangled that way, but again, I know that's just personal preference. – xtraorange Dec 08 '12 at 04:47
  • @xtraorange Yes, I sometimes feel that way, as well. It can feel strange to put something you "include" within code itself, so I get what you're after. Just keep in mind the second paragraph, in that case. – Cat Dec 08 '12 at 04:48
  • Well noted then, I had read somewhere that assets were slower and more resource intensive, so I wasn't sure if that was worth the exchange for sub-directories. Good to know. I know there are several ways to make use of assets, what would be the best way to read them for shaders? – xtraorange Dec 08 '12 at 04:50
  • 1
    If you're using the NDK, check out [this thread](http://stackoverflow.com/questions/13317387/how-to-get-file-in-assets-from-android-ndk). Otherwise, [this blog post](http://xjaphx.wordpress.com/2011/10/02/store-and-use-files-in-assets/) should do the trick. In either event, you end up with a usable string-like object that you can use as the shader. – Cat Dec 08 '12 at 05:18
0

store the shader files in assets folder

brux
  • 3,197
  • 10
  • 44
  • 78