32 #include <GLES3/gl3.h>
33 #include <GLES3/gl3ext.h>
40 #include <android/log.h>
52 using namespace MaliSDK;
90 static string baseString =
"Thread Synchronisation Example. ";
147 LOGI(
"Changed fencing from disabled to enabled.");
152 LOGI(
"Changed fencing from enabled to disabled.")
186 d2 = (
y - texHeight / 2) * (
y - texHeight / 2) + (
x - texWidth / 2) * (
x - texWidth / 2);
243 int bytesPerPixel = 4;
247 textureData = (
unsigned char*) malloc(numBytes *
sizeof(
unsigned char));
251 LOGE(
"Could not allocate memory for texture data.");
266 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
267 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
281 EGLint error = eglGetError();
282 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
283 LOGE(
"Failed to create EGL pixel buffer surface at %s:%i\n", __FILE__, __LINE__);
287 LOGI(
"PBuffer surface created successfully.\n");
290 eglBindAPI(EGL_OPENGL_ES_API);
298 EGLint error = eglGetError();
299 LOGE(
"eglGetError(): %i (0x%.4x)\n", (
int)error, (
int)error);
300 LOGE(
"Failed to create EGL pBufferContext at %s:%i\n", __FILE__, __LINE__);
304 LOGI(
"PBuffer context created successfully sharing GLES objects with the main context.\n");
306 LOGI(
"PBuffer context made current successfully.\n");
313 GLbitfield
flags = 0;
319 usleep(1000000 / 60);
342 EGLint error = eglGetError();
345 LOGE(
"glFenceSync failed at workingFunction.\n");
356 LOGI(
"Exiting secondary thread.\n");
390 GL_CHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
432 LOGE(
"Attribute not found at %s:%i\n", __FILE__, __LINE__);
441 LOGD(
"Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
452 LOGD(
"Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
463 LOGD(
"Warning: Attribute not found at %s:%i\n", __FILE__, __LINE__);
474 LOGD(
"Warning: Attribute not found at %s:%i\n", __FILE__, __LINE__);
485 LOGD(
"Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
496 LOGD(
"Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
508 GLbitfield
flags = 0;
515 LOGI(
"Use of GL Fence enabled.")
519 LOGI(
"Use of GL Fence disabled.")
531 GLbitfield
flags = 0;
573 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
597 GL_CHECK(glActiveTexture(GL_TEXTURE0));
628 LOGI(
"mainThreadSynobj == NULL at the end of renderframe.")
649 (JNIEnv *env, jclass jcls)
670 (JNIEnv *env, jclass jcls, jint
x, jint
y)
676 (JNIEnv *env, jclass jcls, jint x, jint y)
682 (JNIEnv *env, jclass jcls, jint x, jint y)
bool setupGraphics(int width, int height)
EGLSurface pBufferSurface
GLfloat cubeColors[numberOfValuesInCubeColorsArray]
Functions for drawing text in OpenGL ES.
GLint GLsizei GLsizei height
GLenum GLuint GLintptr offset
Functions for manipulating matrices.
void touchMove(int x, int y)
static Matrix createTranslation(float x, float y, float z)
Create and return a translation matrix.
string vertexShaderFilename
void clear(void)
Removes the current string from the class.
static Matrix matrixPerspective(float FOV, float ratio, float zNear, float zFar)
Create and return a perspective projection matrix.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_step(JNIEnv *env, jclass jcls)
EGLContext pBufferContext
float * getAsArray(void)
Get the matrix elements as a column major order array.
typedef GLuint64(GL_APIENTRYP PFNGLGETTEXTUREHANDLENVPROC)(GLuint texture)
static const float cubeVertices[]
static const GLubyte cubeIndices[]
static void * workingFunction(void *arg)
void touchEnd(int x, int y)
unsigned char bakedColours[]
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_uninit(JNIEnv *, jclass)
void touchStart(int x, int y)
void addString(int xPosition, int yPosition, const char *string, int red, int green, int blue, int alpha)
Add a std::string to be drawn to the screen.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_touchMove(JNIEnv *env, jclass jcls, jint x, jint y)
typedef GLsync(GL_APIENTRYP PFNGLFENCESYNCAPPLEPROC)(GLenum condition
static Matrix createRotationY(float angle)
Create and return a rotation matrix around the y-axis matrix.
EGLint contextAttributes[]
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_touchEnd(JNIEnv *env, jclass jcls, jint x, jint y)
unsigned char * textureData
static Matrix createRotationZ(float angle)
Create and return a rotation matrix around the z-axis matrix.
GLbitfield GLuint64 timeout
void createTextureThread(void)
GLsync secondThreadSyncObj
GLint GLint GLint GLint GLint x
EGLConfig findConfig(EGLDisplay display, bool strictMatch, bool offscreen)
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_touchStart(JNIEnv *env, jclass jcls, jint x, jint y)
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
static void processShader(GLuint *shader, const char *filename, GLint shaderType)
Create shader, load in source, compile, and dump debug as necessary.
string fragmentShaderFilename
static const float cubeTextureCoordinates[]
EGLint pBufferAttributes[]
static bool useFence
A sample which illustrates the use of sync objects to synchronise the use of shared objects between m...
void draw(void)
Draw the text to the screen.
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_init(JNIEnv *env, jclass jcls, jint width, jint height)
static Matrix createRotationX(float angle)
Create and return a rotation matrix around the x-axis matrix.