OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Skybox.h
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 #ifndef SKYBOX_H
22 #define SKYBOX_H
23 
24 #include <android/log.h>
25 #include <GLES3/gl3.h>
26 
27 #define LOG_TAG "libNative"
28 #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
29 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
30 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
31 #define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__)
32 
33 #define MALLOC_CHECK(ptr_type, ptr, size) \
34 { \
35  ptr = (ptr_type) malloc(size); \
36  if (ptr == NULL) \
37  { \
38  LOGF("Memory allocation error FILE: %s LINE: %i\n", __FILE__, __LINE__); \
39  exit(EXIT_FAILURE); \
40  } \
41 }
42 
43 #define REALLOC_CHECK(ptr_type, ptr, size) \
44 { \
45  ptr = (ptr_type) realloc(ptr, size); \
46  if (ptr == NULL) \
47  { \
48  LOGF("Memory allocation error FILE: %s LINE: %i\n", __FILE__, __LINE__); \
49  exit(EXIT_FAILURE); \
50  } \
51 }
52 
53 #define FREE_CHECK(ptr) \
54 { \
55  free((void*) ptr); \
56  ptr = NULL; \
57 }
58 
59 #define GL_CHECK(x) \
60  x; \
61  { \
62  GLenum glError = glGetError(); \
63  if(glError != GL_NO_ERROR) \
64  { \
65  LOGE("glGetError() = %i (%#.8x) at %s:%i\n", glError, glError, __FILE__, __LINE__); \
66  exit(EXIT_FAILURE); \
67  } \
68  }
69 
70 /* Vertex shader source code. */
72 {
73  "#version 300 es\n"
74  "out vec3 texCoord;\n"
75  "uniform mat4 viewMat;\n"
76  "void main(void) {\n"
77  " const vec3 vertices[4] = vec3[4](vec3(-1.0f, -1.0f, 1.0f),\n"
78  " vec3( 1.0f, -1.0f, 1.0f),\n"
79  " vec3(-1.0f, 1.0f, 1.0f),\n"
80  " vec3( 1.0f, 1.0f, 1.0f));\n"
81  " texCoord = mat3(viewMat) * vertices[gl_VertexID];\n"
82  " gl_Position = vec4(vertices[gl_VertexID], 1.0f);\n"
83  "}\n"
84 };
85 
86 /* Fragment shader source code. */
88 {
89  "#version 300 es\n"
90  "precision mediump float;\n"
91  "in vec3 texCoord;\n"
92  "out vec4 color;\n"
93  "uniform samplerCube texCubemap; \n"
94  "void main(void) {\n"
95  " color = texture(texCubemap, texCoord);\n"
96  "}\n"
97 };
98 
106 GLuint load_shader(GLenum shader_type, const char* shader_source);
107 
116 GLuint create_program(const char* vertex_source, const char* fragment_source);
117 
118 #endif /* SKYBOX_H */
const char skybox_vertex_shader_source[]
Definition: Skybox.h:71
const char skybox_fragment_shader_source[]
Definition: Skybox.h:87
GLuint create_program(const char *vertex_source, const char *fragment_source)
Create program object, attach vertex and fragment shader to it. Link program object and check whether...
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
GLuint load_shader(GLenum shader_type, const char *shader_source)
Create shader object and compile its source code.
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count