OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tessellation.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.tessellation;
22 
23 import java.io.File;
24 import java.io.InputStream;
25 import java.io.RandomAccessFile;
26 import android.os.Bundle;
27 import android.os.Build;
28 import android.app.Activity;
29 import android.app.ActivityManager;
30 import android.content.res.AssetManager;
31 import android.util.Log;
32 import android.view.MotionEvent;
33 import android.content.Context;
34 import android.content.pm.ConfigurationInfo;
35 import android.opengl.GLSurfaceView;
36 import android.widget.Toast;
37 import android.content.res.AssetManager;
38 import android.content.pm.PackageManager;
39 import android.view.Window;
40 import android.view.WindowManager;
41 import android.opengl.GLSurfaceView.EGLContextFactory;
42 import android.opengl.GLES31;
43 import javax.microedition.khronos.egl.EGLContext;
44 import javax.microedition.khronos.egl.EGLDisplay;
45 import javax.microedition.khronos.egl.EGL10;
46 
47 import javax.microedition.khronos.egl.EGLConfig;
48 import javax.microedition.khronos.opengles.GL10;
49 
50 public class Tessellation extends Activity
51 {
52  private static android.content.Context applicationContext = null;
53  private static String assetsDirectory = null;
54  private static String LOGTAG = "libNative";
55  private GLSurfaceView view;
56 
57  @Override protected void onCreate(Bundle savedInstanceState)
58  {
59  super.onCreate(savedInstanceState);
60 
61  this.requestWindowFeature(Window.FEATURE_NO_TITLE);
62  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
63  WindowManager.LayoutParams.FLAG_FULLSCREEN);
64 
65  view = new GLSurfaceView(this);
66  view.setEGLContextClientVersion(2);
67  view.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
68  view.setRenderer(new Renderer());
69  setContentView(view);
70 
71  applicationContext = getApplicationContext();
72  assetsDirectory = applicationContext.getFilesDir().getPath() + "/";
73 
74  extractAsset("backdrop.vs");
75  extractAsset("backdrop.fs");
76 
77  extractAsset("shader.vs");
78  extractAsset("shader.tcs");
79  extractAsset("shader.tes");
80  extractAsset("shader.fs");
81 
82  extractAsset("magicmoon_heightmap.png");
83  extractAsset("magicmoon_diffusemap.png");
84 
85  extractAsset("swirly_heightmap.png");
86  extractAsset("swirly_diffusemap.png");
87 
88  extractAsset("voronoi_env_heightmap.png");
89  extractAsset("voronoi_env_diffusemap.png");
90 
91  extractAsset("voronoi_sharp_heightmap.png");
92  extractAsset("voronoi_sharp_diffusemap.png");
93 
94  extractAsset("wavey_heightmap.png");
95  extractAsset("wavey_diffusemap.png");
96  }
97 
98  @Override protected void onPause()
99  {
100  super.onPause();
101  view.onPause();
102  }
103 
104  @Override protected void onResume()
105  {
106  super.onResume();
107  view.onResume();
108  }
109 
110  private void extractAsset(String assetName)
111  {
112  File file = new File(assetsDirectory + assetName);
113 
114  if(file.exists()) {
115  Log.d(LOGTAG, assetName + " already exists. No extraction needed.\n");
116  } else {
117  Log.d(LOGTAG, assetName + " doesn't exist. Extraction needed. \n");
118 
119  try {
120  RandomAccessFile randomAccessFile = new RandomAccessFile(assetsDirectory + assetName,"rw");
121  AssetManager assetManager = applicationContext.getResources().getAssets();
122  InputStream inputStream = assetManager.open(assetName);
123 
124  byte buffer[] = new byte[1024];
125  int count = inputStream.read(buffer, 0, 1024);
126 
127  while (count > 0) {
128  randomAccessFile.write(buffer, 0, count);
129 
130  count = inputStream.read(buffer, 0, 1024);
131  }
132 
133  randomAccessFile.close();
134  inputStream.close();
135  } catch(Exception e) {
136  Log.e(LOGTAG, "Failure in extractAssets(): " + e.toString() + " " + assetsDirectory + assetName);
137  }
138 
139  if(file.exists()) {
140  Log.d(LOGTAG,"File extracted successfully");
141  }
142  }
143  }
144 
145  private static class Renderer implements GLSurfaceView.Renderer
146  {
147  public void onDrawFrame(GL10 gl)
148  {
149  NativeLibrary.step();
150  }
151 
152  public void onSurfaceChanged(GL10 gl, int width, int height)
153  {
154  NativeLibrary.resize(width, height);
155  }
156 
157  public void onSurfaceCreated(GL10 gl, EGLConfig config)
158  {
159  NativeLibrary.init();
160  }
161  }
162 }
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
GLenum GLuint buffer
Definition: gl2ext.h:628
GLint GLsizei width
Definition: gl2ext.h:179