4 # Texture Compression {#texturecompression}
7 Using compressing the textures will:
9 - Reduce memory bandwidth in rendering due to less texture data being transferred per frame.
10 - Reduces power consumption.
11 - Speeds up rendering.
12 - Reduce texture memory usage.
13 - Speed up load times. There is no CPU decoding step in loading: the file data can be copied directly to GPU memory.
15 DALi supports the KTX file format.
17 You load the compressed texture just like you would any other image.
21 ResourceImage image = ResourceImage::New("my_compressed_file.ktx");
25 var image = new dali.ResourceImage( { url:"my_compressed_file.ktx"});
29 ### ARMS texture compression tool
31 http://malideveloper.arm.com/develop-for-mali/tools/asset-creation/mali-gpu-texture-compression-tool/
33 Here is an example of using the ARM compression tool.
35 ![ ](../assets/img/texture-atlas/compression-options.jpg)
36 ![ ](compression-options.jpg)
38 ![ ](../assets/img/texture-atlas/compression-example.jpg)
39 ![ ](compression-example.jpg)
42 As shown above the ETC-1 compression format does not support alpha.
44 As a work around the tool will export the alpha as a separate compressed image.
46 In order to combine both the images you need to use a custom shader.
47 Here is an example shader:
51 const char* const COMPRESSED_RGB_PLUS_SEPARATE_ALPHA_FRAGMENT_SOURCE =
55 " vec4 v4Color = (texture2D(sTexture, vTexCoord) * uColor);\n"
56 " v4Color.a = texture2D(sEffect, vTexCoord ).r;\n"
57 " gl_FragColor = v4Color;"
61 mShaderEffect = ShaderEffect::New( "", COMPRESSED_RGB_PLUS_SEPARATE_ALPHA_FRAGMENT_SOURCE);
63 mAtlasImageRGB = ResourceImage::New( ATLAS_RGB_FILENAME.KTX);
65 mAtlasImageAlpha = ResourceImage::New( ATLAS_ALPHA_FILENAME.KTX );
67 mShaderEffect.SetEffectImage( mAtlasImageAlpha );
71 // to create Image Actor
72 ImageActor imageActor = ImageActor::New( mAtlasImageRGB, GetImagePosition( info) );
74 imageActor.SetShaderEffect( mShaderEffect );
76 imageActor.SetBlendMode(BlendingMode::ON);
84 vec4 v4Color = (texture2D(sTexture, vTexCoord) * uColor); \
85 v4Color.a = texture2D(sEffect, vTexCoord ).r; \
86 gl_FragColor = v4Color; \
89 var shaderEffect = new dali.ShaderEffect( "", fragSource);
91 var atlasImageRGB = new dali.ResourceImage( { url:"ATLAS_RGB_FILENAME.KTX"} );
93 var atlasImageAlpha = new dali.ResourceImage( { url:"ATLAS_ALPHA_FILENAME.KTX"} );
95 shaderEffect.setEffectImage( atlasImageAlpha );
97 // to create Image Actor
98 ImageActor imageActor = ImageActor::New( mAtlasImageRGB, GetImagePosition( info) );
100 imageActor.setShaderEffect( shaderEffect );
102 imageActor.setBlendMode( dali.BLENDING_ON );
105 @class _Guide_Texture_compression