VR SDK for Android 0.1.1 ARM Developer Center
main.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2015-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 #include <jni.h>
22 #include <stdlib.h>
23 #include <time.h>
24 #include <loader.h>
25 
26 #define BASE_ASSET_PATH "/data/data/com.arm.developer.vrsdk.simplevr/files/"
27 #define SHADER_PATH(name) BASE_ASSET_PATH name
28 
29 static timeval start_time;
30 static App app;
31 
32 const char *get_gl_error_msg(GLenum code)
33 {
34  switch (code)
35  {
36  case 0: return "NO_ERROR";
37  case 0x0500: return "INVALID_ENUM";
38  case 0x0501: return "INVALID_VALUE";
39  case 0x0502: return "INVALID_OPERATION";
40  case 0x0503: return "STACK_OVERFLOW";
41  case 0x0504: return "STACK_UNDERFLOW";
42  case 0x0505: return "OUT_OF_MEMORY";
43  case 0x0506: return "INVALID_FRAMEBUFFER_OPERATION";
44  default: return "UNKNOWN";
45  }
46 }
47 
48 void gl_check()
49 {
50  GLenum error = glGetError();
51  if (error != GL_NO_ERROR)
52  {
53  LOGD("An OpenGL error occurred %s", get_gl_error_msg(error));
54  exit(1);
55  }
56 }
57 
58 extern "C"
59 {
60  JNIEXPORT void JNICALL Java_com_arm_malideveloper_vrsdk_armvr_ARMVR_init(JNIEnv* env, jobject obj)
61  {
62  LOGD("Init\n");
63  start_time.tv_sec = 0;
64  start_time.tv_usec = 0;
65  gettimeofday(&start_time, NULL);
66 
67  LOGD("Load assets\n");
68  load_assets(&app);
69  app_initialize(&app);
70  }
71 
72  JNIEXPORT void JNICALL Java_com_arm_malideveloper_vrsdk_armvr_ARMVR_resize(JNIEnv* env, jobject obj, jint width, jint height)
73  {
74  app.window_width = width;
75  app.window_height = height;
76  app.elapsed_time = 0.0f;
77  glViewport(0, 0, width, height);
78  LOGD("Resizing %d %d\n", width, height);
79  }
80 
81  JNIEXPORT void JNICALL Java_com_arm_malideveloper_vrsdk_armvr_ARMVR_step(JNIEnv* env, jobject obj)
82  {
83  timeval now;
84  gettimeofday(&now, NULL);
85  float seconds = (now.tv_sec - start_time.tv_sec);
86  float milliseconds = (float(now.tv_usec - start_time.tv_usec)) / 1000000.0f;
87  float elapsed_time = seconds + milliseconds;
88  app.frame_time = elapsed_time - app.elapsed_time;
89  app.elapsed_time = elapsed_time;
90 
92  gl_check();
93  }
94 };
#define LOGD(...)
Definition: armvr.h:89
float frame_time
Definition: armvr.h:152
int window_width
Definition: armvr.h:150
static App app
Definition: main.cpp:30
void gl_check()
Definition: main.cpp:48
float elapsed_time
Definition: armvr.h:153
int window_height
Definition: armvr.h:151
static timeval start_time
Definition: main.cpp:29
void load_assets(App *app)
Definition: loader.cpp:117
JNIEXPORT void JNICALL Java_com_arm_malideveloper_vrsdk_armvr_ARMVR_init(JNIEnv *env, jobject obj)
Definition: main.cpp:60
typedef GLenum
Definition: armvr.cpp:53
void app_initialize(App *app)
Definition: armvr.cpp:294
const char * get_gl_error_msg(GLenum code)
Definition: main.cpp:32
void app_update_and_render(App *app)
Definition: armvr.cpp:424
JNIEXPORT void JNICALL Java_com_arm_malideveloper_vrsdk_armvr_ARMVR_resize(JNIEnv *env, jobject obj, jint width, jint height)
Definition: main.cpp:72
Definition: armvr.h:148
JNIEXPORT void JNICALL Java_com_arm_malideveloper_vrsdk_armvr_ARMVR_step(JNIEnv *env, jobject obj)
Definition: main.cpp:81