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) 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 <stdio.h>
22 #include <stdlib.h>
23 
24 // If the sample does not run appropriately
25 // do run
26 // adb logcat jni/main.cpp:* jni/loader.cpp:* *:S
27 // If something bad happened in main, or if any shaders
28 // or textures failed to load, you will be notified.
29 
30 #include <GLES3/gl3.h>
31 #define GL_GLEXT_PROTOTYPES
32 #include <GLES2/gl2ext.h>
33 #define GL_PATCHES GL_PATCHES_EXT
34 #define GL_PATCH_VERTICES GL_PATCH_VERTICES_EXT
35 #define GL_TESS_CONTROL_SHADER GL_TESS_CONTROL_SHADER_EXT
36 #define GL_TESS_EVALUATION_SHADER GL_TESS_EVALUATION_SHADER_EXT
37 #define glPatchParameteri glPatchParameteriEXT
38 #include "tessellation.cpp"
39 
40 #include <jni.h>
41 #include <android/log.h>
42 #include <sys/time.h>
43 
44 #include "EGLRuntime.h"
45 #include "Platform.h"
46 using namespace MaliSDK;
47 
48 #define BASE_ASSET_PATH "/data/data/com.arm.malideveloper.openglessdk.tessellation/files/"
49 #define HEIGHTMAP_PATH(name) BASE_ASSET_PATH name "_heightmap.png"
50 #define DIFFUSEMAP_PATH(name) BASE_ASSET_PATH name "_diffusemap.png"
51 #define SHADER_PATH(name) BASE_ASSET_PATH name
52 #include "loader.cpp"
53 
54 static timeval start_time;
55 static App app;
56 
57 const char *get_gl_error_msg(GLenum code)
58 {
59  switch (code)
60  {
61  case 0: return "NO_ERROR";
62  case 0x0500: return "INVALID_ENUM";
63  case 0x0501: return "INVALID_VALUE";
64  case 0x0502: return "INVALID_OPERATION";
65  case 0x0503: return "STACK_OVERFLOW";
66  case 0x0504: return "STACK_UNDERFLOW";
67  case 0x0505: return "OUT_OF_MEMORY";
68  case 0x0506: return "INVALID_FRAMEBUFFER_OPERATION";
69  default: return "UNKNOWN";
70  }
71 }
72 
74 {
75  GLenum error = glGetError();
76  if (error != GL_NO_ERROR)
77  {
78  LOGD("An OpenGL error occurred %s", get_gl_error_msg(error));
79  exit(1);
80  }
81 }
82 
83 extern "C"
84 {
86  (JNIEnv *env, jclass jcls)
87  {
88  start_time.tv_sec = 0;
89  start_time.tv_usec = 0;
90  gettimeofday(&start_time, NULL);
91 
92  LOGD("Loading assets");
93  load_assets(&app);
95  LOGD("App successfully initialized");
96  }
97 
99  (JNIEnv *env, jclass jcls, jint width, jint height)
100  {
101  app.window_width = width;
102  app.window_height = height;
103  glViewport(0, 0, width, height);
104  LOGD("Resizing %d %d\n", width, height);
105  }
106 
108  (JNIEnv *env, jclass jcls)
109  {
110  timeval now;
111  gettimeofday(&now, NULL);
112  float seconds = (now.tv_sec - start_time.tv_sec);
113  float milliseconds = (float(now.tv_usec - start_time.tv_usec)) / 1000000.0f;
114  app.elapsed_time = seconds + milliseconds;
115 
116  glClearColor(1.0f, 0.3f, 0.0f, 1.0f);
117  glClear(GL_COLOR_BUFFER_BIT);
119  gl_check_error();
120  }
121 }
void load_assets(App *app)
Definition: loader.cpp:175
void app_update_and_render(App *app)
Definition: geometry.cpp:297
void app_initialize(App *app)
Definition: geometry.cpp:248
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_tessellation_NativeLibrary_init(JNIEnv *env, jclass jcls)
Definition: main.cpp:86
void gl_check_error()
Definition: main.cpp:63
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_tessellation_NativeLibrary_resize(JNIEnv *env, jclass jcls, jint width, jint height)
Definition: main.cpp:99
static timeval start_time
Definition: main.cpp:54
ClipmapApplication * app
Definition: main.cpp:47
GLfloat GLfloat f
Definition: gl2ext.h:2707
const char * get_gl_error_msg(GLenum code)
Definition: main.cpp:34
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_tessellation_NativeLibrary_step(JNIEnv *env, jclass jcls)
Definition: main.cpp:108
Definition: geometry.h:33
precision highp float
Definition: hiz_cull.cs:37
GLint GLsizei width
Definition: gl2ext.h:179
#define LOGD(...)
Definition: main.cpp:29
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)