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