22 #include <android/log.h>
24 #include <GLES2/gl2.h>
25 #include <GLES2/gl2ext.h>
34 #define LOG_TAG "libNative"
35 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
36 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
39 "attribute vec4 vertexPosition;\n"
40 "attribute vec2 vertexTextureCord;\n"
41 "varying vec2 textureCord;\n"
42 "uniform mat4 projection;\n"
43 "uniform mat4 modelView;\n"
46 " gl_Position = projection * modelView * vertexPosition;\n"
47 " textureCord = vertexTextureCord;\n"
51 "precision mediump float;\n"
52 "uniform sampler2D texture;\n"
53 "varying vec2 textureCord;\n"
56 " gl_FragColor = texture2D(texture, textureCord);\n"
61 GLuint shader = glCreateShader(shaderType);
64 glShaderSource(shader, 1, &shaderSource, NULL);
65 glCompileShader(shader);
68 glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
70 if (compiled != GL_TRUE)
73 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
77 char * logBuffer = (
char*) malloc(infoLen);
79 if (logBuffer != NULL)
81 glGetShaderInfoLog(shader, infoLen, NULL, logBuffer);
82 LOGE(
"Could not Compile Shader %d:\n%s\n", shaderType, logBuffer);
87 glDeleteShader(shader);
99 if (vertexShader == 0)
105 if (fragmentShader == 0)
114 glAttachShader(program , vertexShader);
115 glAttachShader(program, fragmentShader);
116 glLinkProgram(program);
117 GLint linkStatus = GL_FALSE;
118 glGetProgramiv(program , GL_LINK_STATUS, &linkStatus);
120 if(linkStatus != GL_TRUE)
124 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
128 char* logBuffer = (
char*) malloc(bufLength);
130 if (logBuffer != NULL)
132 glGetProgramInfoLog(program, bufLength, NULL, logBuffer);
133 LOGE(
"Could not link program:\n%s\n", logBuffer);
138 glDeleteProgram(program);
167 LOGE (
"Could not create program");
181 glEnable(GL_DEPTH_TEST);
183 glViewport(0, 0, width, height);
189 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
193 glActiveTexture(GL_TEXTURE0);
199 loadTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level0.raw", 0, 512, 512);
200 loadTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level1.raw", 1, 256, 256);
201 loadTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level2.raw", 2, 128, 128);
202 loadTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level3.raw", 3, 64, 64);
203 loadTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level4.raw", 4, 32, 32);
204 loadTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level5.raw", 5, 16, 16);
205 loadTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level6.raw", 6, 8, 8);
206 loadTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level7.raw", 7, 4, 4);
207 loadTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level8.raw", 8, 2, 2);
208 loadTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level9.raw", 9, 1, 1);
213 glActiveTexture(GL_TEXTURE1);
218 loadCompressedTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level0.pkm", 0);
219 loadCompressedTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level1.pkm", 1);
220 loadCompressedTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level2.pkm", 2);
221 loadCompressedTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level3.pkm", 3);
222 loadCompressedTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level4.pkm", 4);
223 loadCompressedTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level5.pkm", 5);
224 loadCompressedTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level6.pkm", 6);
225 loadCompressedTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level7.pkm", 7);
226 loadCompressedTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level8.pkm", 8);
227 loadCompressedTexture(
"/data/data/com.arm.malideveloper.openglessdk.mipmapping/files/level9.pkm", 9);
251 glClearColor(0.0
f, 0.0
f, 0.0
f, 1.0
f);
252 glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
271 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
indicies);
286 JNIEnv * env, jobject obj);
290 JNIEnv * env, jobject obj, jint
width, jint
height)
296 JNIEnv * env, jobject obj)
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_mipmapping_NativeLibrary_step(JNIEnv *env, jobject obj)
float projectionMatrix[16]
float modelViewMatrix[16]
GLint GLsizei GLsizei height
void matrixIdentityFunction(float *matrix)
Takes a 4 * 4 and sets the elements to the Identity function.
static const char glFragmentShader[]
void loadTexture(const char *texture, unsigned int level, unsigned int width, unsigned int height)
Loads a desired texture into memory at an appropriate mipmap level.
void loadCompressedTexture(const char *texture, unsigned int level)
Loads a compressed texture into memory at an appropriate mipmap level.
const float squareVertices[]
void matrixPerspective(float *matrix, float fieldOfView, float aspectRatio, float zNear, float zFar)
Create a perspective projection matrix and store the results in the first parameter.
static const char glVertexShader[]
GLuint textureCordLocation
GLuint createProgram(const char *vertexSource, const char *fragmentSource)
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_mipmapping_NativeLibrary_init(JNIEnv *env, jobject obj, jint width, jint height)
GLuint loadShader(GLenum shaderType, const char *shaderSource)
void matrixTranslate(float *matrix, float x, float y, float z)
Takes in a 4 * 4 matrix and translates it by the vector defined by x y and z.
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
GLsizei GLsizei GLfloat distance
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
GLuint projectionLocation