OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AstcTextures.h File Reference
#include <android/log.h>
#include <GLES3/gl3.h>

Go to the source code of this file.

Classes

struct  astc_header
 
struct  texture_set
 
struct  texture_set_info
 

Macros

#define LOG_TAG   "libNative"
 
#define LOGD(...)   __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
 
#define LOGI(...)   __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
 
#define LOGE(...)   __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
 
#define LOGF(...)   __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__)
 
#define MALLOC_CHECK(ptr_type, ptr, size)
 
#define REALLOC_CHECK(ptr_type, ptr, size)
 
#define FREE_CHECK(ptr)
 
#define GL_CHECK(x)
 
#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR   (0x93B0)
 
#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR   (0x93B1)
 
#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR   (0x93B2)
 
#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR   (0x93B3)
 
#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR   (0x93B4)
 
#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR   (0x93B5)
 
#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR   (0x93B6)
 
#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR   (0x93B7)
 
#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR   (0x93B8)
 
#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR   (0x93B9)
 
#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR   (0x93BA)
 
#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR   (0x93BB)
 
#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR   (0x93BC)
 
#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR   (0x93BD)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR   (0x93D0)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR   (0x93D1)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR   (0x93D2)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR   (0x93D3)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR   (0x93D4)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR   (0x93D5)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR   (0x93D6)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR   (0x93D7)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR   (0x93D8)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR   (0x93D9)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR   (0x93DA)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR   (0x93DB)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR   (0x93DC)
 
#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR   (0x93DD)
 
#define GL_TEXTURE_ASTC_DECODE_PRECISION_EXT   (0x8F69)
 
#define ASTC_TEXTURE_SWITCH_INTERVAL   (5) /* sec */
 
#define X_ROTATION_SPEED   (5)
 
#define Y_ROTATION_SPEED   (4)
 
#define Z_ROTATION_SPEED   (3)
 

Typedefs

typedef struct texture_set texture_set
 
typedef struct texture_set_info texture_set_info
 

Functions

GLuint load_shader (GLenum shader_type, const char *shader_source)
 Create shader object and compile its source code. More...
 
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 it has succeeded. More...
 
GLint get_and_check_attrib_location (GLuint program, const GLchar *attrib_name)
 Invoke glGetAttribLocation(), if it has returned a positive value. Otherwise, print a message and exit. Function used for clarity reasons. More...
 
GLint get_and_check_uniform_location (GLuint program, const GLchar *uniform_name)
 Invoke glGetUniformLocation, if it has returned a positive value. Otherwise, print a message and exit. Function used for clarity reasons. More...
 

Variables

const char earth_vertex_shader_source []
 
const char earth_fragment_shader_source []
 

Macro Definition Documentation

#define ASTC_TEXTURE_SWITCH_INTERVAL   (5) /* sec */

Definition at line 104 of file AstcTextures.h.

#define FREE_CHECK (   ptr)
Value:
{ \
free((void*) ptr); \
ptr = NULL; \
}

Definition at line 53 of file AstcTextures.h.

#define GL_CHECK (   x)
Value:
x; \
{ \
GLenum glError = glGetError(); \
if(glError != GL_NO_ERROR) \
{ \
LOGE("glGetError() = %i (%#.8x) at %s:%i\n", glError, glError, __FILE__, __LINE__); \
exit(EXIT_FAILURE); \
} \
}
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
#define LOGE(...)
Definition: AstcTextures.h:30

Definition at line 59 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR   (0x93BB)

Definition at line 82 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR   (0x93B8)

Definition at line 79 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR   (0x93B9)

Definition at line 80 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR   (0x93BA)

Definition at line 81 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR   (0x93BC)

Definition at line 83 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR   (0x93BD)

Definition at line 84 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR   (0x93B0)

Definition at line 71 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR   (0x93B1)

Definition at line 72 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR   (0x93B2)

Definition at line 73 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR   (0x93B3)

Definition at line 74 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR   (0x93B4)

Definition at line 75 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR   (0x93B5)

Definition at line 76 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR   (0x93B6)

Definition at line 77 of file AstcTextures.h.

#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR   (0x93B7)

Definition at line 78 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR   (0x93DB)

Definition at line 96 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR   (0x93D8)

Definition at line 93 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR   (0x93D9)

Definition at line 94 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR   (0x93DA)

Definition at line 95 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR   (0x93DC)

Definition at line 97 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR   (0x93DD)

Definition at line 98 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR   (0x93D0)

Definition at line 85 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR   (0x93D1)

Definition at line 86 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR   (0x93D2)

Definition at line 87 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR   (0x93D3)

Definition at line 88 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR   (0x93D4)

Definition at line 89 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR   (0x93D5)

Definition at line 90 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR   (0x93D6)

Definition at line 91 of file AstcTextures.h.

#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR   (0x93D7)

Definition at line 92 of file AstcTextures.h.

#define GL_TEXTURE_ASTC_DECODE_PRECISION_EXT   (0x8F69)

Definition at line 101 of file AstcTextures.h.

#define LOG_TAG   "libNative"

Definition at line 27 of file AstcTextures.h.

#define LOGD (   ...)    __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)

Definition at line 28 of file AstcTextures.h.

#define LOGE (   ...)    __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)

Definition at line 30 of file AstcTextures.h.

#define LOGF (   ...)    __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__)

Definition at line 31 of file AstcTextures.h.

#define LOGI (   ...)    __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)

Definition at line 29 of file AstcTextures.h.

#define MALLOC_CHECK (   ptr_type,
  ptr,
  size 
)
Value:
{ \
ptr = (ptr_type) malloc(size); \
if (ptr == NULL) \
{ \
LOGF("Memory allocation error FILE: %s LINE: %i\n", __FILE__, __LINE__); \
exit(EXIT_FAILURE); \
} \
}
#define LOGF(...)
Definition: AstcTextures.h:31
GLenum GLuint GLintptr GLsizeiptr size
Definition: gl2ext.h:629

Definition at line 33 of file AstcTextures.h.

#define REALLOC_CHECK (   ptr_type,
  ptr,
  size 
)
Value:
{ \
ptr = (ptr_type) realloc(ptr, size); \
if (ptr == NULL) \
{ \
LOGF("Memory allocation error FILE: %s LINE: %i\n", __FILE__, __LINE__); \
exit(EXIT_FAILURE); \
} \
}
#define LOGF(...)
Definition: AstcTextures.h:31
GLenum GLuint GLintptr GLsizeiptr size
Definition: gl2ext.h:629

Definition at line 43 of file AstcTextures.h.

#define X_ROTATION_SPEED   (5)

Definition at line 107 of file AstcTextures.h.

#define Y_ROTATION_SPEED   (4)

Definition at line 108 of file AstcTextures.h.

#define Z_ROTATION_SPEED   (3)

Definition at line 109 of file AstcTextures.h.

Typedef Documentation

typedef struct texture_set texture_set

Function Documentation

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 it has succeeded.

Parameters
[in]vertex_sourceVertex or fragment shader.
[in]fragment_sourceShader source code.
Returns
Program object ID.

Definition at line 229 of file AstcTextures.cpp.

GLint get_and_check_attrib_location ( GLuint  program,
const GLchar *  attrib_name 
)

Invoke glGetAttribLocation(), if it has returned a positive value. Otherwise, print a message and exit. Function used for clarity reasons.

Parameters
[in]programOpenGL ES specific.
[in]attrib_nameOpenGL ES specific.

Definition at line 160 of file AstcTextures.cpp.

GLint get_and_check_uniform_location ( GLuint  program,
const GLchar *  uniform_name 
)

Invoke glGetUniformLocation, if it has returned a positive value. Otherwise, print a message and exit. Function used for clarity reasons.

Parameters
[in]programOpenGL ES specific.
[in]uniform_nameOpenGL ES specific.

Definition at line 174 of file AstcTextures.cpp.

GLuint load_shader ( GLenum  shader_type,
const char *  shader_source 
)

Create shader object and compile its source code.

Parameters
[in]shader_typeVertex or fragment shader.
[in]shader_sourceShader source code.
Returns
Shader object ID.

Definition at line 188 of file AstcTextures.cpp.

Variable Documentation

const char earth_fragment_shader_source[]
Initial value:
=
{
"#version 300 es\n"
"precision mediump float;\n"
"uniform sampler2D cloud_texture;\n"
"uniform sampler2D daytime_texture;\n"
"uniform sampler2D nighttime_texture;\n"
"in vec2 tex2dcoord;\n"
"in vec3 normal;\n"
"in vec3 light;\n"
"in vec3 view;\n"
"out vec4 color;\n"
"void main() {\n"
" vec3 diffuse_albedo = vec3(2.0, 2.0, 3.0);\n"
" vec3 specular_albedo = vec3(0.1);\n"
" float specular_power = 16.0;\n"
" vec3 Normal = normalize(normal);\n"
" vec3 Light = normalize(light);\n"
" vec3 View = normalize(view);\n"
" vec3 reflected_light = reflect(-Light, Normal);\n"
" vec3 diffuse = max(dot(Normal, Light), 0.0) * diffuse_albedo;\n"
" vec3 specular = pow(max(dot(reflected_light, View), 0.0), specular_power) * specular_albedo;\n"
" vec2 clouds = texture(cloud_texture, tex2dcoord).rg;\n"
" vec3 daytime = (texture(daytime_texture, tex2dcoord).rgb * diffuse + specular * clouds.g) * (1.0 - clouds.r) + clouds.r * diffuse;\n"
" vec3 nighttime = texture(nighttime_texture, tex2dcoord).rgb * (1.0 - clouds.r) * 2.0;\n"
" color = vec4(mix(nighttime, daytime, 0.5), 1.0);\n"
"}\n"
}

Definition at line 136 of file AstcTextures.h.

const char earth_vertex_shader_source[]
Initial value:
=
{
"#version 300 es\n"
"in vec4 av4position;\n"
"in vec3 vv3normal;\n"
"in vec2 vv3tex2dcoord;\n"
"uniform mat4 mv;\n"
"uniform mat4 mvp;\n"
"out vec2 tex2dcoord;\n"
"out vec3 normal;\n"
"out vec3 light;\n"
"out vec3 view;\n"
"void main() {\n"
" vec3 light_position = vec3(15.0, 0.0, 0.0);\n"
" vec4 P = mv * av4position;\n"
" normal = mat3(mv) * vv3normal;\n"
" light = light_position - P.xyz;\n"
" view = -P.xyz;\n"
" tex2dcoord = vv3tex2dcoord;\n"
" gl_Position = mvp * av4position;\n"
"}\n"
}

Definition at line 112 of file AstcTextures.h.