OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProceduralGeometry.java
Go to the documentation of this file.
1 /* Copyright (c) 2015-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.proceduralgeometry;
22 
23 import android.content.res.AssetManager;
24 import android.app.Activity;
25 import android.os.Bundle;
26 import android.util.Log;
27 import android.view.WindowManager;
28 
29 import java.io.File;
30 import java.io.InputStream;
31 import java.io.RandomAccessFile;
32 
33 public class ProceduralGeometry extends Activity {
34 
35  ProceduralGeometryView mView;
36  private static android.content.Context applicationContext = null;
37  private static String assetsDirectory = null;
38  private static String LOGTAG = "ProceduralGeometry";
39 
40  @Override protected void onCreate(Bundle savedInstanceState) {
41  super.onCreate(savedInstanceState);
42  mView = new ProceduralGeometryView(getApplication());
43  setContentView(mView);
44 
45  applicationContext = getApplicationContext();
46  assetsDirectory = applicationContext.getFilesDir().getPath() + "/";
47 
48  extractAsset("backdrop.vs");
49  extractAsset("backdrop.fs");
50 
51  extractAsset("generate.cs");
52  extractAsset("centroid.cs");
53 
54  extractAsset("geometry.vs");
55  extractAsset("geometry.gs");
56  extractAsset("geometry.fs");
57 
58  extractAsset("texture11.jpg");
59  }
60 
61  @Override protected void onPause() {
62  super.onPause();
63  mView.onPause();
64  }
65 
66  @Override protected void onResume() {
67  super.onResume();
68  mView.onResume();
69  }
70 
71  private void extractAsset(String assetName)
72  {
73  File file = new File(assetsDirectory + assetName);
74 
75  if(file.exists()) {
76  Log.d(LOGTAG, assetName + " already exists. No extraction needed.\n");
77  } else {
78  Log.d(LOGTAG, assetName + " doesn't exist. Extraction needed. \n");
79 
80  try {
81  RandomAccessFile randomAccessFile = new RandomAccessFile(assetsDirectory + assetName,"rw");
82  AssetManager assetManager = applicationContext.getResources().getAssets();
83  InputStream inputStream = assetManager.open(assetName);
84 
85  byte buffer[] = new byte[1024];
86  int count = inputStream.read(buffer, 0, 1024);
87 
88  while (count > 0) {
89  randomAccessFile.write(buffer, 0, count);
90 
91  count = inputStream.read(buffer, 0, 1024);
92  }
93 
94  randomAccessFile.close();
95  inputStream.close();
96  } catch(Exception e) {
97  Log.e(LOGTAG, "Failure in extractAssets(): " + e.toString() + " " + assetsDirectory + assetName);
98  }
99 
100  if(file.exists()) {
101  Log.d(LOGTAG,"File extracted successfully");
102  }
103  }
104  }
105 
106  public static native void init();
107  public static native void resize(int width, int height);
108  public static native void step();
109  public static native void onpointerdown(float x, float y);
110  public static native void onpointerup(float x, float y);
111 
112  static {
113  System.loadLibrary("Native");
114  }
115 }
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
GLenum GLuint buffer
Definition: gl2ext.h:628
GLint GLsizei width
Definition: gl2ext.h:179
GLint y
Definition: gl2ext.h:179