Programming guide of DebugRenderer
[platform/core/uifw/dali-toolkit.git] / docs / content / shared-javascript-and-cpp-documentation / texture-compression.md
1 <!--
2 /**-->
3
4 # Texture Compression {#texturecompression}
5
6
7 Using compressing the textures will:
8
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.
14
15 DALi supports the KTX file format.
16
17 You load the compressed texture just like you would any other image.
18
19 ~~~{.cpp}
20 // C++
21 ResourceImage image = ResourceImage::New("my_compressed_file.ktx");
22 ~~~
23 ~~~{.js}
24 // JavaScript
25 var image = new dali.ResourceImage( { url:"my_compressed_file.ktx"});
26
27 ~~~
28
29 ### ARMS texture compression tool
30
31 http://malideveloper.arm.com/develop-for-mali/tools/asset-creation/mali-gpu-texture-compression-tool/
32
33 Here is an example of using the ARM compression tool.
34
35 ![ ](../assets/img/texture-atlas/compression-options.jpg)
36 ![ ](compression-options.jpg)
37
38 ![ ](../assets/img/texture-atlas/compression-example.jpg)
39 ![ ](compression-example.jpg)
40
41
42 As shown above the ETC-1 compression format does not support alpha.
43
44 As a work around the tool will export the alpha as a separate compressed image.
45
46 In order to combine both the images you need to use a custom shader.
47 Here is an example shader:
48
49 ~~~{.cpp}
50 // C++ Code
51   const char* const COMPRESSED_RGB_PLUS_SEPARATE_ALPHA_FRAGMENT_SOURCE =
52     "\n"
53     "void main()\n"
54     "{\n"
55     "    vec4 v4Color  = (texture2D(sTexture, vTexCoord) * uColor);\n"
56     "    v4Color.a =  texture2D(sEffect, vTexCoord ).r;\n"
57     "   gl_FragColor = v4Color;"
58     "}\n";
59
60
61   mShaderEffect = ShaderEffect::New( "", COMPRESSED_RGB_PLUS_SEPARATE_ALPHA_FRAGMENT_SOURCE);
62
63   mAtlasImageRGB = ResourceImage::New( ATLAS_RGB_FILENAME.KTX);
64
65   mAtlasImageAlpha = ResourceImage::New( ATLAS_ALPHA_FILENAME.KTX );
66
67   mShaderEffect.SetEffectImage( mAtlasImageAlpha );
68
69
70
71   // to create Image Actor
72   ImageActor  imageActor = ImageActor::New( mAtlasImageRGB, GetImagePosition( info) );
73
74   imageActor.SetShaderEffect( mShaderEffect );
75
76   imageActor.SetBlendMode(BlendingMode::ON);
77 ~~~
78
79 ~~~{.js}
80 // JavaScript code
81 var fragSource = "  \
82 void main()                                                   \
83 {                                                             \
84     vec4 v4Color  = (texture2D(sTexture, vTexCoord) * uColor); \
85     v4Color.a =  texture2D(sEffect, vTexCoord ).r;             \
86    gl_FragColor = v4Color;                                     \
87 }";
88
89 var shaderEffect = new dali.ShaderEffect( "", fragSource);
90
91 var atlasImageRGB = new dali.ResourceImage( { url:"ATLAS_RGB_FILENAME.KTX"} );
92
93 var atlasImageAlpha = new dali.ResourceImage( { url:"ATLAS_ALPHA_FILENAME.KTX"} );
94
95 shaderEffect.setEffectImage( atlasImageAlpha );
96
97 // to create Image Actor
98 ImageActor  imageActor = ImageActor::New( mAtlasImageRGB, GetImagePosition( info) );
99
100 imageActor.setShaderEffect( shaderEffect );
101
102 imageActor.setBlendMode( dali.BLENDING_ON );
103 ~~~
104
105 @class _Guide_Texture_compression
106
107
108 */