OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Native.cpp File Reference
#include <jni.h>
#include <android/log.h>
#include <GLES3/gl3.h>
#include <EGL/egl.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cstring>
#include "Matrix.h"

Go to the source code of this file.

Macros

#define LOG_TAG   "libNative"
 
#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 GL_CHECK(x)
 

Typedefs

typedef void(* PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR )(GLenum, GLenum, GLuint, GLint, GLint, GLsizei)
 

Functions

GLuint loadShader (GLenum shaderType, const char *shaderSource)
 
GLuint createProgram (const char *vertexSource, const char *fragmentSource)
 
bool setupFBO (int width, int height)
 
bool setupGraphics (int width, int height)
 
void renderToFBO (int width, int height)
 
void renderFrame ()
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multiview_NativeLibrary_init (JNIEnv *env, jobject obj, jint width, jint height)
 
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multiview_NativeLibrary_step (JNIEnv *env, jobject obj)
 

Variables

GLuint fboWidth = 1280
 
GLuint fboHeight = 720
 
GLuint screenWidth
 
GLuint screenHeight
 
GLuint frameBufferTextureId
 
GLuint frameBufferDepthTextureId
 
GLuint frameBufferObjectId
 
GLuint multiviewProgram
 
GLuint multiviewVertexLocation
 
GLuint multiviewVertexNormalLocation
 
GLuint multiviewModelViewProjectionLocation
 
GLuint multiviewModelLocation
 
GLuint texturedQuadProgram
 
GLuint texturedQuadVertexLocation
 
GLuint texturedQuadLowResTexCoordLocation
 
GLuint texturedQuadHighResTexCoordLocation
 
GLuint texturedQuadSamplerLocation
 
GLuint texturedQuadLayerIndexLocation
 
Matrix projectionMatrix [4]
 
Matrix viewMatrix [4]
 
Matrix viewProjectionMatrix [4]
 
Matrix modelViewProjectionMatrix [4]
 
Matrix modelMatrix
 
float angle = 0
 
PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR glFramebufferTextureMultiviewOVR
 
static const char multiviewVertexShader []
 
static const char multiviewFragmentShader []
 
static const char texturedQuadVertexShader []
 
static const char texturedQuadFragmentShader []
 
GLfloat multiviewVertices []
 
GLfloat multiviewNormals []
 
GLushort multiviewIndices []
 
float texturedQuadCoordinates []
 
float texturedQuadLowResTexCoordinates []
 
float texturedQuadHighResTexCoordinates []
 

Macro Definition Documentation

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

Definition at line 38 of file Native.cpp.

#define LOG_TAG   "libNative"

Definition at line 34 of file Native.cpp.

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

Definition at line 36 of file Native.cpp.

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

Definition at line 35 of file Native.cpp.

Typedef Documentation

typedef void(* PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR)(GLenum, GLenum, GLuint, GLint, GLint, GLsizei)

Definition at line 78 of file Native.cpp.

Function Documentation

GLuint createProgram ( const char *  vertexSource,
const char *  fragmentSource 
)

Definition at line 342 of file Native.cpp.

JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multiview_NativeLibrary_init ( JNIEnv *  env,
jobject  obj,
jint  width,
jint  height 
)

Definition at line 650 of file Native.cpp.

JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multiview_NativeLibrary_step ( JNIEnv *  env,
jobject  obj 
)

Definition at line 656 of file Native.cpp.

GLuint loadShader ( GLenum  shaderType,
const char *  shaderSource 
)

Definition at line 307 of file Native.cpp.

void renderFrame ( void  )

Definition at line 592 of file Native.cpp.

void renderToFBO ( int  width,
int  height 
)

Definition at line 529 of file Native.cpp.

bool setupFBO ( int  width,
int  height 
)

Definition at line 388 of file Native.cpp.

bool setupGraphics ( int  width,
int  height 
)

Definition at line 428 of file Native.cpp.

Variable Documentation

float angle = 0

Definition at line 76 of file Native.cpp.

GLuint fboHeight = 720

Definition at line 51 of file Native.cpp.

GLuint fboWidth = 1280

Definition at line 50 of file Native.cpp.

GLuint frameBufferDepthTextureId

Definition at line 55 of file Native.cpp.

GLuint frameBufferObjectId

Definition at line 56 of file Native.cpp.

GLuint frameBufferTextureId

Definition at line 54 of file Native.cpp.

PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR glFramebufferTextureMultiviewOVR

Definition at line 79 of file Native.cpp.

Matrix modelMatrix

Definition at line 75 of file Native.cpp.

Matrix modelViewProjectionMatrix[4]

Definition at line 74 of file Native.cpp.

const char multiviewFragmentShader[]
static
Initial value:
=
"#version 300 es\n"
"precision highp float;\n"
"in vec3 v_normal;\n"
"out vec4 f_color;\n"
"vec3 light(vec3 n, vec3 l, vec3 c)\n"
"{\n"
" float ndotl = max(dot(n, l), 0.0);\n"
" return ndotl * c;\n"
"}\n"
"void main()\n"
"{\n"
" vec3 albedo = vec3(0.95, 0.84, 0.62);\n"
" vec3 n = normalize(v_normal);\n"
" f_color.rgb = vec3(0.0);\n"
" f_color.rgb += light(n, normalize(vec3(1.0)), vec3(1.0));\n"
" f_color.rgb += light(n, normalize(vec3(-1.0, -1.0, 0.0)), vec3(0.2, 0.23, 0.35));\n"
" f_color.a = 1.0;\n"
"}\n"

Definition at line 101 of file Native.cpp.

GLushort multiviewIndices[]
Initial value:
=
{
0, 1, 2,
0, 2, 3,
4, 5, 6,
4, 6, 7,
8, 9, 10,
8, 10, 11,
12, 13, 14,
12, 14, 15,
16, 17, 18,
16, 18, 19,
20, 21, 22,
20, 22, 23
}

Definition at line 244 of file Native.cpp.

GLuint multiviewModelLocation

Definition at line 62 of file Native.cpp.

GLuint multiviewModelViewProjectionLocation

Definition at line 61 of file Native.cpp.

GLfloat multiviewNormals[]

Definition at line 204 of file Native.cpp.

GLuint multiviewProgram

Definition at line 58 of file Native.cpp.

GLuint multiviewVertexLocation

Definition at line 59 of file Native.cpp.

GLuint multiviewVertexNormalLocation

Definition at line 60 of file Native.cpp.

const char multiviewVertexShader[]
static
Initial value:
=
"#version 300 es\n"
"#extension GL_OVR_multiview : enable\n"
"layout(num_views = 4) in;\n"
"in vec3 vertexPosition;\n"
"in vec3 vertexNormal;\n"
"uniform mat4 modelViewProjection[4];\n"
"uniform mat4 model;\n"
"out vec3 v_normal;\n"
"void main()\n"
"{\n"
" gl_Position = modelViewProjection[gl_ViewID_OVR] * vec4(vertexPosition, 1.0);\n"
" v_normal = (model * vec4(vertexNormal, 0.0f)).xyz;\n"
"}\n"

Definition at line 82 of file Native.cpp.

GLfloat multiviewVertices[]

Definition at line 165 of file Native.cpp.

Matrix projectionMatrix[4]

Definition at line 71 of file Native.cpp.

GLuint screenHeight

Definition at line 53 of file Native.cpp.

GLuint screenWidth

Definition at line 52 of file Native.cpp.

float texturedQuadCoordinates[]
Initial value:
=
{
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f
}

Definition at line 272 of file Native.cpp.

const char texturedQuadFragmentShader[]
static
Initial value:
=
"#version 300 es\n"
"precision mediump float;\n"
"precision mediump int;\n"
"precision mediump sampler2DArray;\n"
"in vec2 vLowResTexCoord;\n"
"in vec2 vHighResTexCoord;\n"
"out vec4 fragColor;\n"
"uniform sampler2DArray tex;\n"
"uniform int layerIndex;\n"
"void main()\n"
"{\n"
" vec4 lowResSample = texture(tex, vec3(vLowResTexCoord, layerIndex));\n"
" vec4 highResSample = texture(tex, vec3(vHighResTexCoord, layerIndex + 2));\n"
" // Using squared distance to middle of screen for interpolating.\n"
" vec2 distVec = vec2(0.5) - vHighResTexCoord;\n"
" float squaredDist = dot(distVec, distVec);\n"
" // Using the high res texture when distance from center is less than 0.5 in texture coordinates (0.25 is 0.5 squared).\n"
" // When the distance is less than 0.2 (0.04 is 0.2 squared), only the high res texture will be used.\n"
" float lerpVal = smoothstep(-0.25, -0.04, -squaredDist);\n"
" fragColor = mix(lowResSample, highResSample, lerpVal);\n"
"}\n"

Definition at line 141 of file Native.cpp.

float texturedQuadHighResTexCoordinates[]
Initial value:
=
{
-0.5, -0.5,
1.5, -0.5,
1.5, 1.5,
-0.5, -0.5,
1.5, 1.5,
-0.5, 1.5
}

Definition at line 296 of file Native.cpp.

GLuint texturedQuadHighResTexCoordLocation

Definition at line 67 of file Native.cpp.

GLuint texturedQuadLayerIndexLocation

Definition at line 69 of file Native.cpp.

float texturedQuadLowResTexCoordinates[]
Initial value:
=
{
0, 0,
1, 0,
1, 1,
0, 0,
1, 1,
0, 1
}

Definition at line 284 of file Native.cpp.

GLuint texturedQuadLowResTexCoordLocation

Definition at line 66 of file Native.cpp.

GLuint texturedQuadProgram

Definition at line 64 of file Native.cpp.

GLuint texturedQuadSamplerLocation

Definition at line 68 of file Native.cpp.

GLuint texturedQuadVertexLocation

Definition at line 65 of file Native.cpp.

const char texturedQuadVertexShader[]
static
Initial value:
=
"#version 300 es\n"
"in vec3 attributePosition;\n"
"in vec2 attributeLowResTexCoord;\n"
"in vec2 attributeHighResTexCoord;\n"
"out vec2 vLowResTexCoord;\n"
"out vec2 vHighResTexCoord;\n"
"void main()\n"
"{\n"
" vLowResTexCoord = attributeLowResTexCoord;\n"
" vHighResTexCoord = attributeHighResTexCoord;\n"
" gl_Position = vec4(attributePosition, 1.0);\n"
"}\n"

Definition at line 126 of file Native.cpp.

Matrix viewMatrix[4]

Definition at line 72 of file Native.cpp.

Matrix viewProjectionMatrix[4]

Definition at line 73 of file Native.cpp.