OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Instancing.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.instancing;
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 Instancing extends Activity
32 {
33  private static android.content.Context applicationContext = null;
34  private static String assetsDirectory = null;
35  private static String LOGTAG = "Instancing";
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 
51  /* [onCreateNew] */
52  setContentView(tutorialView);
53  }
54  @Override protected void onPause()
55  {
56  super.onPause();
57  tutorialView.onPause();
58  }
59  @Override protected void onResume()
60  {
61  super.onResume();
62  tutorialView.onResume();
63  }
64  @Override protected void onDestroy()
65  {
66  super.onDestroy();
67  }
68 
69  private void extractAsset(String assetName)
70  {
71  File file = new File(assetsDirectory + assetName);
72 
73  if(file.exists()) {
74  Log.d(LOGTAG, assetName + " already exists. No extraction needed.\n");
75  } else {
76  Log.d(LOGTAG, assetName + " doesn't exist. Extraction needed. \n");
77 
78  try {
79  RandomAccessFile randomAccessFile = new RandomAccessFile(assetsDirectory + assetName,"rw");
80  AssetManager assetManager = applicationContext.getResources().getAssets();
81  InputStream inputStream = assetManager.open(assetName);
82 
83  byte buffer[] = new byte[1024];
84  int count = inputStream.read(buffer, 0, 1024);
85 
86  while (count > 0) {
87  randomAccessFile.write(buffer, 0, count);
88 
89  count = inputStream.read(buffer, 0, 1024);
90  }
91 
92  randomAccessFile.close();
93  inputStream.close();
94  } catch(Exception e) {
95  Log.e(LOGTAG, "Failure in extractAssets(): " + e.toString() + " " + assetsDirectory + assetName);
96  }
97 
98  if(file.exists()) {
99  Log.d(LOGTAG,"File extracted successfully");
100  }
101  }
102  }
103 }
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
GLenum GLuint buffer
Definition: gl2ext.h:628