OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OcclusionCulling.java
Go to the documentation of this file.
1 /* Copyright (c) 2011-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.occlusionculling;
22 
23 import java.io.File;
24 import java.io.InputStream;
25 import java.io.RandomAccessFile;
26 import android.content.res.AssetManager;
27 import android.util.Log;
28 
29 import javax.microedition.khronos.egl.EGLConfig;
30 import javax.microedition.khronos.opengles.GL10;
31 import android.content.Context;
32 import android.opengl.GLSurfaceView;
33 import android.os.Bundle;
34 import android.view.Window;
35 import android.view.WindowManager;
36 import com.arm.malideveloper.openglessdk.*;
37 
38 class OcclusionCullingView extends MaliSamplesView
39 {
40  public OcclusionCullingView(Context context)
41  {
42  super(context, GlesVersion.GLES3);
43  }
44 
45  @Override protected void setRendererCallback()
46  {
47  setRenderer(new Renderer());
48  }
49 
50  @Override protected void destroyContextCallback()
51  {
52  OcclusionCulling.uninit();
53  }
54 
55  protected class Renderer implements GLSurfaceView.Renderer
56  {
57  public void onDrawFrame(GL10 gl)
58  {
59  OcclusionCulling.step();
60  }
61 
62  public void onSurfaceChanged(GL10 gl, int width, int height)
63  {
64  OcclusionCulling.init(width, height);
65  }
66 
67  public void onSurfaceCreated(GL10 gl, EGLConfig config)
68  {
69  }
70  }
71 };
72 
74 {
75  OcclusionCullingView mView;
76  private static android.content.Context applicationContext = null;
77  private static String assetsDirectory = null;
78  private static String LOGTAG = "libNative";
79 
80  public static native void init(int width, int height);
81  public static native void step();
82  public static native void uninit();
83 
84  @Override protected void onCreate(Bundle savedInstanceState)
85  {
86  super.onCreate(savedInstanceState);
87 
88  this.requestWindowFeature(Window.FEATURE_NO_TITLE);
89  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
90  WindowManager.LayoutParams.FLAG_FULLSCREEN);
91 
92  applicationContext = getApplicationContext();
93  assetsDirectory = applicationContext.getFilesDir().getPath() + "/";
94 
95  extractAsset("font.frag");
96  extractAsset("font.vert");
97  extractAsset("font.raw");
98 
99  extractAsset("depth.fs");
100  extractAsset("depth.vs");
101  extractAsset("depth_mip.fs");
102 
103  extractAsset("hiz_cull.cs");
104  extractAsset("hiz_cull_no_lod.cs");
105  extractAsset("physics.cs");
106 
107  extractAsset("quad.vs");
108  extractAsset("quad.fs");
109  extractAsset("scene.vs");
110  extractAsset("scene.fs");
111  extractAsset("scene_sphere.vs");
112  extractAsset("scene_sphere.fs");
113 
114  mView = new OcclusionCullingView(getApplication());
115  mView.getHolder().setFixedSize(1280, 720);
116  setContentView(mView);
117  }
118 
119  @Override protected void onPause()
120  {
121  super.onPause();
122  mView.onPause();
123  }
124 
125  @Override protected void onResume()
126  {
127  super.onResume();
128  mView.onResume();
129  }
130 
131  @Override protected void onDestroy()
132  {
133  super.onDestroy();
134  }
135 
136  private void extractAsset(String assetName)
137  {
138  File file = new File(assetsDirectory + assetName);
139 
140  if(file.exists()) {
141  Log.d(LOGTAG, assetName + " already exists. No extraction needed.\n");
142  } else {
143  Log.d(LOGTAG, assetName + " doesn't exist. Extraction needed. \n");
144 
145  try {
146  RandomAccessFile randomAccessFile = new RandomAccessFile(assetsDirectory + assetName,"rw");
147  AssetManager assetManager = applicationContext.getResources().getAssets();
148  InputStream inputStream = assetManager.open(assetName);
149 
150  byte buffer[] = new byte[1024];
151  int count = inputStream.read(buffer, 0, 1024);
152 
153  while (count > 0) {
154  randomAccessFile.write(buffer, 0, count);
155 
156  count = inputStream.read(buffer, 0, 1024);
157  }
158 
159  randomAccessFile.close();
160  inputStream.close();
161  } catch(Exception e) {
162  Log.e(LOGTAG, "Failure in extractAssets(): " + e.toString() + " " + assetsDirectory + assetName);
163  }
164 
165  if(file.exists()) {
166  Log.d(LOGTAG,"File extracted successfully");
167  }
168  }
169  }
170 
171 
172  static
173  {
174  // Load the NDK library for this example, built with ndk-build
175  System.loadLibrary("Native");
176  }
177 }
178 
179 
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