OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShadowMapping.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.shadowMapping;
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 ShadowMapping extends Activity
32 {
33  private static android.content.Context applicationContext = null;
34  private static String assetsDirectory = null;
35  private static String LOGTAG = "ShadowMapping";
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("cube_light_fragment_shader_source.frag");
49  extractAsset("cube_light_vertex_shader_source.vert");
50  extractAsset("lighting_fragment_shader_source.frag");
51  extractAsset("model_vertex.vert");
52 
53  /* [onCreateNew] */
54  setContentView(tutorialView);
55  }
56  @Override protected void onPause()
57  {
58  super.onPause();
59  tutorialView.onPause();
60  }
61  @Override protected void onResume()
62  {
63  super.onResume();
64  tutorialView.onResume();
65  }
66  @Override protected void onDestroy()
67  {
68  super.onDestroy();
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 }
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
GLenum GLuint buffer
Definition: gl2ext.h:628