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 <jni.h>
22 #include <android/log.h>
23 #include <stdlib.h>
24 #include <GLES3/gl3.h>
25 #include <EGL/egl.h>
26 #include <EGL/eglext.h>
27 
28 #include "app.h"
29 #include "timer.h"
30 #include "common.h"
31 
32 float last_tick;
33 
34 const char *get_gl_error_msg(GLenum code)
35 {
36  switch (code)
37  {
38  case 0: return "NO_ERROR";
39  case 0x0500: return "INVALID_ENUM";
40  case 0x0501: return "INVALID_VALUE";
41  case 0x0502: return "INVALID_OPERATION";
42  case 0x0503: return "STACK_OVERFLOW";
43  case 0x0504: return "STACK_UNDERFLOW";
44  case 0x0505: return "OUT_OF_MEMORY";
45  case 0x0506: return "INVALID_FRAMEBUFFER_OPERATION";
46  default: return "UNKNOWN";
47  }
48 }
49 
50 extern "C"
51 {
53  (JNIEnv *env, jclass jcls, jint width, jint height)
54  {
55  ASSERT(load_app(), "Failed to load content");
56  init_app(width, height);
57 
58  last_tick = 0.0f;
59  timer_init();
60  }
61 
63  (JNIEnv *env, jclass jcls)
64  {
65  double curr_tick = get_elapsed_time();
66  double dt = curr_tick - last_tick;
67  last_tick = curr_tick;
68 
69  update_app(dt);
70  render_app(dt);
71 
72  GLenum error = glGetError();
73  bool were_errors = false;
74  while (error != GL_NO_ERROR)
75  {
76  LOGD("An OPENGL error occured %s", get_gl_error_msg(error));
77  were_errors = true;
78  error = glGetError();
79  }
80  if (were_errors) exit(1);
81  }
82 
84  (JNIEnv *, jclass)
85  {
86  free_app();
87  }
88 
90  (JNIEnv * env, jobject obj, jfloat x, jfloat y)
91  {
92  on_pointer_up(x, y);
93  }
94 
96  (JNIEnv * env, jobject obj, jfloat x, jfloat y)
97  {
98  on_pointer_down(x, y);
99  }
100 }
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
bool load_app()
Definition: app.cpp:88
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_computeparticles_ComputeParticles_onpointerdown(JNIEnv *env, jobject obj, jfloat x, jfloat y)
Definition: main.cpp:96
void on_pointer_up(float x, float y)
Definition: app.cpp:412
const char * get_gl_error_msg(GLenum code)
Definition: main.cpp:34
void timer_init()
Definition: timer.cpp:26
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_computeparticles_ComputeParticles_onpointerup(JNIEnv *env, jobject obj, jfloat x, jfloat y)
Definition: main.cpp:90
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_computeparticles_ComputeParticles_init(JNIEnv *env, jclass jcls, jint width, jint height)
Definition: main.cpp:53
void init_app(int width, int height)
Definition: app.cpp:176
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_computeparticles_ComputeParticles_step(JNIEnv *env, jclass jcls)
Definition: main.cpp:63
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
#define ASSERT(x, s)
Definition: common.h:45
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_computeparticles_ComputeParticles_uninit(JNIEnv *, jclass)
Definition: main.cpp:84
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
void update_app(float dt)
Definition: app.cpp:283