Skip to content

Commit 394c8d2

Browse files
committed
Update HowTo_PackageTextures_On_Android.md
1 parent c044754 commit 394c8d2

File tree

1 file changed

+87
-2
lines changed

1 file changed

+87
-2
lines changed

articles/getting_to_know/howto/content_pipeline/HowTo_PackageTextures_On_Android.md

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,92 @@ Android needs to have some special attention when shipping your game.
66

77
## Texture Compression
88

9-
As stated in [Texture Compress.md] you need to be aware of the performance limitations on mobile devices.
9+
As stated in "[Why use the Content Pipeline](https://docs.monogame.net/articles/getting_started/content_pipeline/why_content_pipeline.html)" you need to be aware of the performance limitations on mobile devices.
1010
The graphics cards on mobile phones do not have the same kind of capabilities as those on the PC or Consoles.
1111
They regularly have less memory and less power. So you need to make use of what you have in a more efficient way.
12-
One of these ways is to use Texture Compression. As stated in [Texture Compress.md] this allows you to fit more
12+
One of these ways is to use Texture Compression. As stated in "[Why use the Content Pipeline](https://docs.monogame.net/articles/getting_started/content_pipeline/why_content_pipeline.html)" this allows you to fit more
1313
textures on the graphics card than you could if you just used raw RGBA textures.
1414

15+
## How Android deals with textures
16+
17+
Fortunately the Android engineers recognised that supporting all of these texture compresison formats
18+
was not an easy task. So with the introduction of the `.aab` file format they added the ability to
19+
add multiple texture format files to the package. The way the `.aab` works is that it is not the final
20+
`.apk`. The final `.apk` will be built from the `.aab` when the game is delivered to the end user device.
21+
As a result not all of the file in the `.aab` will make it to the device. It will filter out things like
22+
`.so` files for other cpu types, and yes, texture formats.
23+
24+
The `.aab` supports the following directory suffixes for texture compresison
25+
26+
| Texture Format | Suffix |
27+
| -------------- | ------ |
28+
| PVRTC | #tcf_pvrtc |
29+
| ATC | #tcf_atc |
30+
| ASTC| #tcf_astc |
31+
| S3TC | #tcf_s3tc |
32+
| DXT1 | #tcf_dxt1 |
33+
| ETC1 | #tcf_etc1 |
34+
| ETC2 | #tcf_etc2 |
35+
36+
see https://developer.android.com/guide/playcore/asset-delivery/texture-compression
37+
38+
MonoGame has its own [TextureProcessorOutputFormat](https://docs.monogame.net/api/Microsoft.Xna.Framework.Content.Pipeline.Processors.TextureProcessorOutputFormat.html) enumeration which describes the type of Texture Compression
39+
you use when processing an image. This following table shows you how to map that to the Suffix
40+
41+
| TextureProcessorOutputFormat | Suffix |
42+
| -------------- | ------ |
43+
| PvrCompressed | #tcf_pvrtc |
44+
| AtcCompressed | #tcf_atc |
45+
| AstcCompressed| #tcf_astc |
46+
| DxtCompressed | #tcf_s3tc |
47+
| Etc1Compressed | #tcf_etc1 |
48+
| EtcCompressed | #tcf_etc2 |
49+
| Compressed | No Suffix |
50+
51+
## Adding Texture Compression Suffixes
52+
53+
With the latest MonoGame we added support for being able to have one texture with multiple outputs.
54+
Previously it would only build the last item, but this has been fixed.
55+
56+
In the Content Editor
57+
58+
1. Add a new folder for your desired Suffix. This is usually in the form of `Textures<suffix>`.
59+
2. Right click on the new folder and Add an Existing File.
60+
3. Select the file you want to use for this Suffix and Add it
61+
4. In the Properties of the new file change the TextureFormat to be the one which matches the desired Suffix.
62+
63+
In the `.mgcb` file directly you can do the following
64+
65+
```bash
66+
/processorParam:TextureFormat=PvrCompressed
67+
/build:Textures/LogoOnly_64px.png;Textures#tcf_pvrtc/LogoOnly_64px
68+
```
69+
70+
As documented the [/build](https://docs.monogame.net/articles/getting_started/tools/mgcb.html#build-content-file) command takes
71+
an optional `<destination_filepath>` after the `<content_filepath>`. We can use this to provide the target folder for our output.
72+
So in the example above, the `LogoOnly_64px.png` file will be compressed using `PvrCompressed` and then the output will end up in `Textures#tcf_pvrtc`.
73+
74+
> !Important
75+
> Some texture formats have specific size requirements. For example PVRTC Compressed Textures MUST be a Power of 2 and Square (e.g 1024x1024).
76+
> Many others need to be Power of 2. It is recommended that you make all your textures Power of 2
77+
78+
79+
## Sample `.mgcb`
80+
81+
```bash
82+
#begin Textures/LogoOnly_64px.png
83+
/importer:TextureImporter
84+
/processor:TextureProcessor
85+
/processorParam:ColorKeyColor=255,0,255,255
86+
/processorParam:ColorKeyEnabled=True
87+
/processorParam:GenerateMipmaps=False
88+
/processorParam:PremultiplyAlpha=True
89+
/processorParam:ResizeToPowerOfTwo=True
90+
/processorParam:MakeSquare=False
91+
/processorParam:TextureFormat=PvrCompressed
92+
/build:Textures/LogoOnly_64px.png;Textures#tcf_pvrtc/LogoOnly_64px
93+
```
94+
1595
```bash
1696
#----------------------------- Global Properties ----------------------------#
1797

@@ -82,3 +162,8 @@ textures on the graphics card than you could if you just used raw RGBA textures.
82162
/processorParam:TextureFormat=AtscCompressed
83163
/build:Textures/LogoOnly_64px.png;Textures#tcf_atsc/LogoOnly_64px
84164
```
165+
166+
## Also see
167+
168+
[MGCB File Format](https://docs.monogame.net/articles/getting_started/tools/mgcb.html#build-content-file)
169+
[Why use the Content Pipeline](https://docs.monogame.net/articles/getting_started/content_pipeline/why_content_pipeline.html)

0 commit comments

Comments
 (0)