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