OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
main.cpp
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 #include "app.h"
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 
26 #include <jni.h>
27 #include <android/log.h>
28 #include "common.h"
29 #include "timer.h"
30 
31 double last_tick = 0.0;
32 
33 const char *get_gl_error_msg(GLenum code)
34 {
35  switch (code)
36  {
37  case 0: return "NO_ERROR";
38  case 0x0500: return "INVALID_ENUM";
39  case 0x0501: return "INVALID_VALUE";
40  case 0x0502: return "INVALID_OPERATION";
41  case 0x0503: return "STACK_OVERFLOW";
42  case 0x0504: return "STACK_UNDERFLOW";
43  case 0x0505: return "OUT_OF_MEMORY";
44  case 0x0506: return "INVALID_FRAMEBUFFER_OPERATION";
45  default: return "UNKNOWN";
46  }
47 }
48 
50 {
51  GLenum error = glGetError();
52  if (error != GL_NO_ERROR)
53  {
54  LOGD("An OpenGL error occurred %s", get_gl_error_msg(error));
55  exit(1);
56  }
57 }
58 
59 extern "C"
60 {
62  (JNIEnv *env, jclass jcls, jint width, jint height)
63  {
64  ASSERT(init_app(width, height), "Failed to initialize app");
65  LOGD("OK!");
66  timer_init();
67  last_tick = 0.0;
68  }
69 
71  (JNIEnv *env, jclass jcls)
72  {
73  double now = get_elapsed_time();
74  double dt = now - last_tick;
75  last_tick = now;
76  update_app(dt);
77  render_app(dt);
79  }
80 
82  (JNIEnv *, jclass)
83  {
84  free_app();
85  }
86 
88  (JNIEnv * env, jobject obj, jfloat x, jfloat y)
89  {
90  on_pointer_down(x, y);
91  }
92 
94  (JNIEnv * env, jobject obj, jfloat x, jfloat y)
95  {
96  on_pointer_up(x, y);
97  }
98 }
void on_pointer_down(float x, float y)
Definition: app.cpp:376
float last_tick
Definition: main.cpp:32
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
void gl_check_error()
Definition: main.cpp:63
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_translucency_NativeLibrary_onpointerup(JNIEnv *env, jobject obj, jfloat x, jfloat y)
Definition: main.cpp:94
void on_pointer_up(float x, float y)
Definition: app.cpp:412
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_translucency_NativeLibrary_uninit(JNIEnv *, jclass)
Definition: main.cpp:82
const char * get_gl_error_msg(GLenum code)
Definition: main.cpp:34
void timer_init()
Definition: timer.cpp:26
void init_app(int width, int height)
Definition: app.cpp:176
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_translucency_NativeLibrary_onpointerdown(JNIEnv *env, jobject obj, jfloat x, jfloat y)
Definition: main.cpp:88
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_translucency_NativeLibrary_init(JNIEnv *env, jclass jcls, jint width, jint height)
Definition: main.cpp:62
#define ASSERT(x, s)
Definition: common.h:45
GLint GLsizei width
Definition: gl2ext.h:179
#define LOGD(...)
Definition: main.cpp:29
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
void free_app()
Definition: app.cpp:113
uniform float dt
Definition: update.cs:29
double get_elapsed_time()
Definition: timer.cpp:33
GLint y
Definition: gl2ext.h:179
void render_app(float dt)
Definition: app.cpp:358
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_translucency_NativeLibrary_step(JNIEnv *env, jclass jcls)
Definition: main.cpp:71
void update_app(float dt)
Definition: app.cpp:283