OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InstancedTessellation.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.instancedTessellation;
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 InstancedTessellation extends Activity
33 {
34  /* [classMembers] */
35  private static String LOGTAG = "InstancedTessellation";
36  private static String assetDirectory = null;
37  private static android.content.Context applicationContext = null;
38  protected TutorialView graphicsView;
39  /* [classMembers] */
40  @Override
41  protected void onCreate(Bundle savedInstanceState)
42  {
43  super.onCreate(savedInstanceState);
44 
45  graphicsView = new TutorialView(getApplication());
46 
47  /* [onCreateNew] */
48  applicationContext = getApplicationContext();
49  assetDirectory = applicationContext.getFilesDir().getPath() + "/";
50 
51  extractAsset("Instanced_Tessellation_Instanced_shader.frag");
52  extractAsset("Instanced_Tessellation_Instanced_shader.vert");
53  extractAsset("Instanced_Tessellation_Wireframe_shader.frag");
54  extractAsset("Instanced_Tessellation_Wireframe_shader.vert");
55 
56  /* [onCreateNew] */
57  setContentView(graphicsView);
58  }
59  @Override protected void onPause()
60  {
61  super.onPause();
62  graphicsView.onPause();
63  }
64  @Override protected void onResume()
65  {
66  super.onResume();
67  graphicsView.onResume();
68  }
69  @Override protected void onDestroy()
70  {
71  super.onDestroy();
72  }
73  /* [extractAssetBeginning] */
74  private void extractAsset(String assetName)
75  {
76  File fileTest = new File(assetDirectory + assetName);
77 
78  if(fileTest.exists())
79  {
80  Log.d(LOGTAG,assetName + " already exists. No extraction needed.\n");
81  }
82  else
83  {
84  Log.d(LOGTAG, assetName + " doesn't exist. Extraction needed. \n");
85  /* [extractAssetBeginning] */
86  /* [tryCatch extractAsset] */
87  try
88  {
89  RandomAccessFile out = new RandomAccessFile(assetDirectory + assetName,"rw");
90  AssetManager am = applicationContext.getResources().getAssets();
91  /* [tryCatch extractAsset] */
92  /* [readWriteFile] */
93  InputStream inputStream = am.open(assetName);
94  byte buffer[] = new byte[1024];
95  int count = inputStream.read(buffer, 0, 1024);
96 
97  while (count > 0)
98  {
99  out.write(buffer, 0, count);
100  count = inputStream.read(buffer, 0, 1024);
101  }
102 
103  out.close();
104  inputStream.close();
105  }
106  catch(Exception e)
107  {
108  Log.e(LOGTAG, "Failure in extractAssets(): " + e.toString() + " " + assetDirectory+assetName);
109  }
110  if(fileTest.exists())
111  {
112  Log.d(LOGTAG,"File extracted successfully");
113  /* [readWriteFile] */
114  }
115  }
116  }
117 }
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
GLenum GLuint buffer
Definition: gl2ext.h:628