OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AstcTextures.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.astctextures;
22 
23 import java.io.File;
24 import java.io.InputStream;
25 import java.io.RandomAccessFile;
26 
27 import android.os.Bundle;
28 import android.app.Activity;
29 import android.content.res.AssetManager;
30 import android.util.Log;
31 
32 public class AstcTextures extends Activity
33 {
34  /* [classMembers] */
35  private static String LOGTAG = "AstcTextures";
36  private static String assetDirectory = null;
37  protected TutorialView graphicsView;
38 
39  private static android.content.Context applicationContext = null;
40  /* [classMembers] */
41  @Override
42  protected void onCreate(Bundle savedInstanceState)
43  {
44  super.onCreate(savedInstanceState);
45  graphicsView = new TutorialView(getApplication());
46 
47  /* [onCreateNew] */
48  applicationContext = getApplicationContext();
49  assetDirectory = applicationContext.getFilesDir().getPath() + "/";
50 
51  extractAsset("font.raw");
52  extractAsset("font.png");
53  extractAsset("font.vert");
54  extractAsset("font.frag");
55  extractAsset("shader.vert");
56  extractAsset("shader.frag");
57  extractAsset("CloudAndGloss4x4.astc");
58  extractAsset("CloudAndGloss5x4.astc");
59  extractAsset("CloudAndGloss5x5.astc");
60  extractAsset("CloudAndGloss6x5.astc");
61  extractAsset("CloudAndGloss6x6.astc");
62  extractAsset("CloudAndGloss8x5.astc");
63  extractAsset("CloudAndGloss8x6.astc");
64  extractAsset("CloudAndGloss8x8.astc");
65  extractAsset("CloudAndGloss10x5.astc");
66  extractAsset("CloudAndGloss10x6.astc");
67  extractAsset("CloudAndGloss10x8.astc");
68  extractAsset("CloudAndGloss10x10.astc");
69  extractAsset("CloudAndGloss12x10.astc");
70  extractAsset("CloudAndGloss12x12.astc");
71  extractAsset("Earth-Color4x4.astc");
72  extractAsset("Earth-Color5x4.astc");
73  extractAsset("Earth-Color5x5.astc");
74  extractAsset("Earth-Color6x5.astc");
75  extractAsset("Earth-Color6x6.astc");
76  extractAsset("Earth-Color8x5.astc");
77  extractAsset("Earth-Color8x6.astc");
78  extractAsset("Earth-Color8x8.astc");
79  extractAsset("Earth-Color10x5.astc");
80  extractAsset("Earth-Color10x6.astc");
81  extractAsset("Earth-Color10x8.astc");
82  extractAsset("Earth-Color10x10.astc");
83  extractAsset("Earth-Color12x10.astc");
84  extractAsset("Earth-Color12x12.astc");
85  extractAsset("Earth-Night4x4.astc");
86  extractAsset("Earth-Night5x4.astc");
87  extractAsset("Earth-Night5x5.astc");
88  extractAsset("Earth-Night6x5.astc");
89  extractAsset("Earth-Night6x6.astc");
90  extractAsset("Earth-Night8x5.astc");
91  extractAsset("Earth-Night8x6.astc");
92  extractAsset("Earth-Night8x8.astc");
93  extractAsset("Earth-Night10x5.astc");
94  extractAsset("Earth-Night10x6.astc");
95  extractAsset("Earth-Night10x8.astc");
96  extractAsset("Earth-Night10x10.astc");
97  extractAsset("Earth-Night12x10.astc");
98  extractAsset("Earth-Night12x12.astc");
99 
100  /* [onCreateNew] */
101  setContentView(graphicsView);
102  }
103  @Override protected void onPause()
104  {
105  super.onPause();
106  graphicsView.onPause();
107  }
108  @Override protected void onResume()
109  {
110  super.onResume();
111  graphicsView.onResume();
112  }
113  @Override protected void onDestroy()
114  {
115  super.onDestroy();
116  }
117  /* [extractAssetBeginning] */
118  private void extractAsset(String assetName)
119  {
120  File fileTest = new File(assetDirectory + assetName);
121 
122  if(fileTest.exists())
123  {
124  Log.d(LOGTAG,assetName + " already exists. No extraction needed.\n");
125  }
126  else
127  {
128  Log.d(LOGTAG, assetName + " doesn't exist. Extraction needed. \n");
129  /* [extractAssetBeginning] */
130  /* [tryCatch extractAsset] */
131  try
132  {
133  RandomAccessFile out = new RandomAccessFile(assetDirectory + assetName,"rw");
134  AssetManager am = applicationContext.getResources().getAssets();
135  /* [tryCatch extractAsset] */
136  /* [readWriteFile] */
137  InputStream inputStream = am.open(assetName);
138  byte buffer[] = new byte[1024];
139  int count = inputStream.read(buffer, 0, 1024);
140 
141  while (count > 0)
142  {
143  out.write(buffer, 0, count);
144  count = inputStream.read(buffer, 0, 1024);
145  }
146  out.close();
147  inputStream.close();
148  }
149  catch(Exception e)
150  {
151  Log.e(LOGTAG, "Failure in extractAssets(): " + e.toString() + " " + assetDirectory+assetName);
152  }
153  if(fileTest.exists())
154  {
155  Log.d(LOGTAG,"File extracted successfully");
156  /* [readWriteFile] */
157  }
158  }
159  }
160 }
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
GLenum GLuint buffer
Definition: gl2ext.h:628