for Mao to write this
Originally felt like this problem, is unable to classify, because different projects have different needs, but today because of the quick forum in a technical question affixed, hooked up I organized this article interest http://www.cocoachina.com/bbs/read.php?tid=214811
So, I decided to try to describe the texture format selection problem, one is to play a role in science, because there is no very complete to say this aspect of the article. The second is to tidy up their own ideas.
Of course, these things are definitely not my own out of the box, I also reference a lot of articles, but also from the project summed up some problems. Here is a list of some links, sneak peek
Mobile platform GPU Compression Arts Encyclopedia
ETC1 texture compression Using the Mali official tool
Ericsson Texture Compression
iOS and Android game texture optimization and memory optimization (COCOS2D-X)
Optimize your mobile game (no delay, is healthy)
Some summary of Cocos2d-x texture optimization scheme
Mobile game development Texture Picture optimization experience
Mobile game development, how to select and optimize the picture material
Well, I think it's enough, and maybe you don't have the patience to read all the links. At least I didn't ...
GPU Textures vs. non-GPU textures
Many small partners have not understood the difference between GPU texture and non-GPU texture, so that I hit nearly 1000 words, he did not understand why JPG can not save memory.
A common JPG format is a file compression format that allows you to store image pixel values using a lossy compression method so that the volume of the image becomes very small.
The GPU texture format that we often mention, such as PVRTC,ETC, is a kind of GPU compression format, this compression format, the file size is larger than JPG, but it is read into the memory, will not be decompressed, but directly to the video card. The video card does not align the decompression, but instead accesses and requests the content of the corresponding pixel value when performing a tex2d texture sampling instruction. This will save memory and RAM. PVRTC, etc, can be compressed, but also provide random access (that is, in the case of not all decompression, access to the specified UV coordinates of the pixel value) ability, so much larger than JPG
Introduction to Picture format
PVRTC
PVRTC has two formats, one is PVRTC 2bp and the other is pvrtc4bp. There is no essential difference between the two, the main difference is that the 2bp means that each pixel uses 2 bit to store, 4BP uses 4bit to store. This is, of course, a theoretical value, since PVRTC also needs to store additional information to ensure that the pixel values are restored, as well as providing random access capabilities. So, the actual PVRTC format of the file will not be 1/8 and 1/16 so small. When the PVRTC format is read into memory, it is not decompressed, but is sent directly to the GPU. The GPU also does not decompress, which guarantees memory and graphics savings. Tex2d is able to sample the textures in this format directly.
In addition, PVRTC currently has two large versions, PVRTC1 and PVRTC2,PVRTC2 have made significant improvements to the compression algorithm. However, the new GPU is supported, so if you want to use the PVRTC2 version of the PVRTC texture, remember to check the extended markup of OpenGL ES.
PVRTC is recommended only for iOS platforms, as this is a dedicated texture format for power VR graphics.
etc
ETC currently has two formats, ETC1/ETC2. ETC1 is the hardware format that the OpenGL ES 1.x and OpenGL ES 2.0 provide must support, with the only drawback being that the alpha channel is not supported. The ETC2 is supported by OpenGL ES 3.0 and increases the alpha channel capability.
Due to the current prevalence of Opengles 3.0 devices is not high, the current (when writing this article is July 18, 2014) recommend the use of ETC1 format
It is recommended that the ETC1 format be used on Android platforms.
PNG24/32
Png24 and 32 are actually the same, and 24 means that the alpha channel is not used, so this is a RGBA8888 texture format that does not compress anything and completely preserves the original pixel values. can provide high quality, but this texture occupies a large amount of disk space. (equivalent to its memory footprint), you can simply calculate the size by a long x wide x4. For example, 1024x1024 's PNG24/32 texture takes up disk space and memory to 4MB.
Png8
Png8 is very complex, because PNG8 is more meaningful.
8-bit PNG with alpha channel only: This is typically used to provide a separate alpha channel capability, and OpenGL D3D supports this 8-bit alpha texture.
256-color palette of PNG: This is usually seen in the site icon, etc., it only one of the alpha, that is, the hollow effect. and is not suitable for occasions where there is a need for rich and high saturation.
Compressed PNG obtained by some compression methods, such as grunt-png8,tinypng, these tools, using a high compression technique, so that the PNG24/32 Rgba can be saved in the 8-bit channel. And can provide a higher degree of reduction. Like PNG, each pixel still accounts for 4BYTES after it is read into memory.
jpg
JPG is a format that allows the original image to be stored in very small files by means of a lossy compression algorithm. This is very similar to the Png8 mentioned above, but JPG does not support alpha channels. Although the alpha channel is not supported, the memory footprint is still 4BYTES per pixel after it is read into memory.
There are some dds,tga and so on, because I personally in mobile game development involved in this aspect less (the end of the use of TGA and DDS more), not discussed here.
How to choose a texture format
The reason why life is tangled up is that there are many things you can choose
---Tangled Emperor Kylin Zi · Alex
The above texture format, in the same case, may be a variety of suitable, then how to choose it. We still depend on the circumstances.
1. Scene, background, full screen picture
2D mobile games, most of them have such a picture, as a background, especially in some SLG, horizontal version of the clearance game. This image does not require alpha, and, at the same time, only one sheet appears (if multiple stitching does not exceed the screen size too much), memory will not be a key point. So, in this case, we can choose JPG boldly.
2. Scene foreground, ornament, movable object
This depends on the size, if the size is small, the type is not much. or type although many, but at the same time appear in the scene of the type is not much, then we can choose to compress the way PNG8, it supports the alpha channel, the file is small.
If the same screen may appear in a variety of this, you need to consider using PVRTC on iOS, using Etc1+alpha_mask on Android
3. UI
The background of the UI, you can prioritize the use of compression PNG8, if you do not reach the accuracy requirements, then use PNG32. For small elements of the UI, you might consider using compression PNG8.
For UI icons, pvrtc/etc + A common alpha mask graph with no alpha, with a double-layered blend for rounded edges. Because the icon may appear larger than the same screen. If the icon can be controlled within a certain range, because the icon is 48x48, such as size, a large picture of 1024x1024, you can put 400 icons. Swapping with JPG also has a 4MB overhead, and if this is acceptable, you can also use the Jpg+alpha_mask method.
Written here only to find, in fact, only need the following sentence can be done.
If this type of picture will appear at the same time, when the memory overhead is unacceptable, if it is not acceptable, then use the GPU texture, otherwise, priority Jpg,jpg+alpha, or PNG8
That is, to reduce the size of the installation package first, if there is unacceptable situation, you need to use GPU texture optimization. When we are optimizing, it is best to treat a certain kind of picture uniformly. For example, if you decide to use JPG, the exclusively JPG will be the image of the scene.
drawing and processing of textures
So many formats, if you let the art out of the picture, not to toss the dead.
Therefore, only need to stipulate that the art out of the picture only to PNG (some may be TGA) can, the rest of the matter, the program to write their own scripts to solve. This can guarantee the standard of art drawing, and also avoids the problem of re-drawing caused by changing the texture format during the process of optimization.
PS:PVRTC and etc can be converted using Pvrtex tool, etc conversion can also use Mali tools to see everyone's hobbies. The PVR tool, whether it's downloading or viewing a document, needs to be registered and not linked ....
End
Perhaps you will say, Jjyy half a day, not with some practical.
This is really ironic, but I'm really going to end, one is what I want to say, that's it, and two, I'm not going to write an article on how to use a variety of textures on a mobile platform.
I hope this article will bring inspiration to the confused brothers.