OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EtcTexture.java
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 package com.arm.malideveloper.openglessdk.etcTexture;
22 
23 import java.io.File;
24 import java.io.InputStream;
25 import java.io.RandomAccessFile;
26 import android.os.Bundle;
27 import android.app.Activity;
28 import android.content.res.AssetManager;
29 import android.util.Log;
30 
31 public class EtcTexture extends Activity
32 {
33  private static android.content.Context applicationContext = null;
34  private static String assetsDirectory = null;
35  private static String LOGTAG = "EtcTexture";
36  protected TutorialView tutorialView;
37 
38  @Override protected void onCreate(Bundle savedInstanceState)
39  {
40  super.onCreate(savedInstanceState);
41 
42  tutorialView = new TutorialView(getApplication());
43 
44  /* [onCreateNew] */
45  applicationContext = getApplicationContext();
46  assetsDirectory = applicationContext.getFilesDir().getPath() + "/";
47 
48  extractAsset("fragment_shader_source.frag");
49  extractAsset("vertex_shader_source.vert");
50  extractAsset("font.frag");
51  extractAsset("font.vert");
52  extractAsset("font.raw");
53  extractAsset("BinaryAlpha.pkm");
54  extractAsset("BumpMap.pkm");
55  extractAsset("BumpMapSigned.pkm");
56  extractAsset("HeightMap.pkm");
57  extractAsset("HeightMapSigned.pkm");
58  extractAsset("SemiAlpha.pkm");
59  extractAsset("Texture.pkm");
60 
61  /* [onCreateNew] */
62  setContentView(tutorialView);
63  }
64  @Override protected void onPause()
65  {
66  super.onPause();
67  tutorialView.onPause();
68  }
69  @Override protected void onResume()
70  {
71  super.onResume();
72  tutorialView.onResume();
73  }
74  @Override protected void onDestroy()
75  {
76  super.onDestroy();
77  }
78 
79  private void extractAsset(String assetName)
80  {
81  File file = new File(assetsDirectory + assetName);
82 
83  if(file.exists()) {
84  Log.d(LOGTAG, assetName + " already exists. No extraction needed.\n");
85  } else {
86  Log.d(LOGTAG, assetName + " doesn't exist. Extraction needed. \n");
87 
88  try {
89  RandomAccessFile randomAccessFile = new RandomAccessFile(assetsDirectory + assetName,"rw");
90  AssetManager assetManager = applicationContext.getResources().getAssets();
91  InputStream inputStream = assetManager.open(assetName);
92 
93  byte buffer[] = new byte[1024];
94  int count = inputStream.read(buffer, 0, 1024);
95 
96  while (count > 0) {
97  randomAccessFile.write(buffer, 0, count);
98 
99  count = inputStream.read(buffer, 0, 1024);
100  }
101 
102  randomAccessFile.close();
103  inputStream.close();
104  } catch(Exception e) {
105  Log.e(LOGTAG, "Failure in extractAssets(): " + e.toString() + " " + assetsDirectory + assetName);
106  }
107 
108  if(file.exists()) {
109  Log.d(LOGTAG,"File extracted successfully");
110  }
111  }
112  }
113 }
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
GLenum GLuint buffer
Definition: gl2ext.h:628