OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProjectedLights.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.projectedLights;
22 
23 import java.io.File;
24 import java.io.InputStream;
25 import java.io.RandomAccessFile;
26 import android.os.Bundle;
27 import android.app.Activity;
28 import android.content.res.AssetManager;
29 import android.util.Log;
30 
31 public class ProjectedLights extends Activity
32 {
33  private static android.content.Context applicationContext = null;
34  private static String assetsDirectory = null;
35  private static String LOGTAG = "ProjectedLights";
36  protected TutorialView tutorialView;
37 
38  @Override protected void onCreate(Bundle savedInstanceState)
39  {
40  super.onCreate(savedInstanceState);
41 
42  tutorialView = new TutorialView(getApplication());
43 
44  /* [onCreateNew] */
45  applicationContext = getApplicationContext();
46  assetsDirectory = applicationContext.getFilesDir().getPath() + "/";
47 
48  extractAsset("mali.bmp");
49  extractAsset("render_scene_shader.frag");
50  extractAsset("render_scene_shader.vert");
51 
52  /* [onCreateNew] */
53  setContentView(tutorialView);
54  }
55  @Override protected void onPause()
56  {
57  super.onPause();
58  tutorialView.onPause();
59  }
60  @Override protected void onResume()
61  {
62  super.onResume();
63  tutorialView.onResume();
64  }
65  @Override protected void onDestroy()
66  {
67  super.onDestroy();
68  }
69 
70  private void extractAsset(String assetName)
71  {
72  File file = new File(assetsDirectory + assetName);
73 
74  if(file.exists()) {
75  Log.d(LOGTAG, assetName + " already exists. No extraction needed.\n");
76  } else {
77  Log.d(LOGTAG, assetName + " doesn't exist. Extraction needed. \n");
78 
79  try {
80  RandomAccessFile randomAccessFile = new RandomAccessFile(assetsDirectory + assetName,"rw");
81  AssetManager assetManager = applicationContext.getResources().getAssets();
82  InputStream inputStream = assetManager.open(assetName);
83 
84  byte buffer[] = new byte[1024];
85  int count = inputStream.read(buffer, 0, 1024);
86 
87  while (count > 0) {
88  randomAccessFile.write(buffer, 0, count);
89 
90  count = inputStream.read(buffer, 0, 1024);
91  }
92 
93  randomAccessFile.close();
94  inputStream.close();
95  } catch(Exception e) {
96  Log.e(LOGTAG, "Failure in extractAssets(): " + e.toString() + " " + assetsDirectory + assetName);
97  }
98 
99  if(file.exists()) {
100  Log.d(LOGTAG,"File extracted successfully");
101  }
102  }
103  }
104 }
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
GLenum GLuint buffer
Definition: gl2ext.h:628