OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ThreadSync.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2013-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 
31 #include <EGL/egl.h>
32 #include <GLES3/gl3.h>
33 #include <GLES3/gl3ext.h>
34 
35 /* Fencing state. */
36 static bool useFence = true;
37 
38 #include <string>
39 #include <jni.h>
40 #include <android/log.h>
41 
42 #include "ThreadSync.h"
43 #include <pthread.h>
44 #include <unistd.h>
45 #include <stdlib.h>
46 
47 #include "Text.h"
48 #include "Shader.h"
49 #include "Matrix.h"
50 
51 using std::string;
52 using namespace MaliSDK;
53 
54 /* Asset directories and filenames. */
55 string resourceDirectory = "/data/data/com.arm.malideveloper.openglessdk.threadsync/";
56 string vertexShaderFilename = "ThreadSync_cube.vert";
57 string fragmentShaderFilename = "ThreadSync_cube.frag";
58 
59 /* Shader variables. */
63 GLint iLocPosition = -1;
64 GLint iLocTextureMix = -1;
65 GLint iLocTexture = -1;
66 GLint iLocFillColor = -1;
67 GLint iLocTexCoord = -1;
68 GLint iLocProjection = -1;
69 GLint iLocModelview = -1;
70 
71 /* Matrix transformation variables. */
72 static float angleX = 0;
73 static float angleY = 45;
74 static float angleZ = 45;
81 
82 /* Application textures. */
84 
85 int windowWidth = -1;
86 int windowHeight = -1;
87 
88 /* A text object to draw text on the screen. */
90 static string baseString = "Thread Synchronisation Example. ";
91 static string textString = "";
92 
93 /* Context related variables. */
94 EGLContext mainContext = NULL;
95 EGLContext mainDisplay = NULL;
96 EGLSurface pBufferSurface = NULL;
97 EGLContext pBufferContext = NULL;
98 
99 /* Secondary thread related variables. */
100 pthread_t secondThread;
101 bool exitThread = false;
102 
103 /* Sync objects. */
106 GLuint64 timeout = GL_TIMEOUT_IGNORED;
107 
108 /* Texture generation. */
109 unsigned char *textureData = NULL;
110 int swapStripes = -1;
111 int texWidth = 512;
112 int texHeight = 512;
113 
114 unsigned char bakedColours[] =
115 {
116  255, 0, 0, 255,
117  0, 255, 0, 255,
118  255, 255, 0, 255,
119  0, 255, 255, 255,
120 };
121 
122 /* User interaction. */
123 static bool touchStarted = false;
124 
125 void touchStart(int x, int y)
126 {
127  touchStarted = true;
128  /* Empty. */
129 }
130 
131 void touchMove (int x, int y)
132 {
133  /* Empty. */
134 }
135 
136 void touchEnd(int x, int y)
137 {
138  if(touchStarted)
139  {
140  useFence = !useFence;
141  touchStarted = false;
142 
143  text->clear();
144  if(useFence)
145  {
146  textString = baseString + "Fencing enabled.";
147  LOGI("Changed fencing from disabled to enabled.");
148  }
149  else
150  {
151  textString = baseString + "Fencing disabled.";
152  LOGI("Changed fencing from enabled to disabled.")
153  }
154  text->addString(0, 0, textString.c_str(), 255, 255, 0, 255);
155  }
156 }
157 
158 /* Modify the texture. */
160 {
161  static int col = 0;
162  static int col1 = 1;
163  static int col2= 2;
164  static int col3= 3;
165 
166  float r1 = texHeight / 16;
167  float r2 = texHeight / 8;
168  float r3 = texHeight / 4;
169  float r4 = texHeight / 2;
170  float r5 = texHeight / 1;
171 
172  float r12 = r1 * r1;
173  float r22 = r2 * r2;
174  float r32 = r3 * r3;
175  float r42 = r4 * r4;
176  float r52 = r5 * r5;
177 
178  int offset = 0;
179  float d2 = 0.0f;
180 
181  for(int y = 0; y < texHeight; y++)
182  {
183  for(int x = 0; x < texWidth; x++)
184  {
185  /* Squared distance from pixel to centre. */
186  d2 = (y - texHeight / 2) * (y - texHeight / 2) + (x - texWidth / 2) * (x - texWidth / 2);
187 
188  col = col % 4;
189  col1 = col1 % 4;
190  col2 = col2 % 4;
191  col3 = col3 % 4;
192 
193  if(d2 < r12)
194  {
195  textureData[offset] = bakedColours[4 * col+0];
196  textureData[offset + 1] = bakedColours[4 * col+1];
197  textureData[offset + 2] = bakedColours[4 * col+2];
198  textureData[offset + 3] = bakedColours[4 * col + 3];
199  }
200  else if(d2 < r22)
201  {
202 
203  textureData[offset] = bakedColours[4 * (col1) + 0];
204  textureData[offset + 1] = bakedColours[4 * col1 + 1];
205  textureData[offset + 2] = bakedColours[4 * col1 + 2];
206  textureData[offset + 3] = bakedColours[4 * col1 + 3];
207  }
208  else if(d2 < r32)
209  {
210  textureData[offset] = bakedColours[4 * col2 + 0];
211  textureData[offset + 1] = bakedColours[4 * col2 + 1];
212  textureData[offset + 2] = bakedColours[4 * col2 + 2];
213  textureData[offset + 3] = bakedColours[4 * col2 + 3];
214  }
215  else if(d2 < r42)
216  {
217  textureData[offset] = bakedColours[4 * col3 + 0];
218  textureData[offset + 1] = bakedColours[4 * col3 + 1];
219  textureData[offset + 2] = bakedColours[4 * col3 + 2];
220  textureData[offset + 3] = bakedColours[4 * col3 + 3];
221  }
222  else if(d2 < r52)
223  {
224  textureData[offset] = 128;
225  textureData[offset + 1] = 128;
226  textureData[offset + 2] = 128;
227  textureData[offset + 3] = 255;
228  }
229 
230  offset += 4;
231  }
232  }
233 
234  col++;
235  col1++;
236  col2++;
237  col3++;
238 }
239 
240 /* Initialise texture buffer data. */
241 void initTexture(void)
242 {
243  int bytesPerPixel = 4;
244  int numBytes = texWidth * texHeight * bytesPerPixel;
245 
246  /* Allocate data buffer. */
247  textureData = (unsigned char*) malloc(numBytes * sizeof(unsigned char));
248 
249  if(!textureData)
250  {
251  LOGE("Could not allocate memory for texture data.");
252  exit(1);
253  }
254 
255  /* Fill texture buffer with data. Circles with different colours. */
256  animateTexture();
257 
258  /* Initialise texture. */
259  GL_CHECK(glGenTextures(1, &iCubeTex));
260  GL_CHECK(glBindTexture(GL_TEXTURE_2D, iCubeTex));
261 
262  /* Upload texture. */
263  GL_CHECK(glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData));
264 
265  /* Set filtering. */
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));
268 }
269 
270 /* [workingFunction 1] */
271 /* Secondary thread's working function. */
272 static void *workingFunction(void *arg)
273 {
274  /* Secondary thread's surface and rendering context creation. */
275  /* [workingFunction 1] */
276  /* [workingFunction 2] */
277  EGLConfig config = findConfig(mainDisplay, true, true);
278  pBufferSurface = eglCreatePbufferSurface(mainDisplay, config, pBufferAttributes);
279  if(pBufferSurface == EGL_NO_SURFACE)
280  {
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__);
284  exit(1);
285  }
286 
287  LOGI("PBuffer surface created successfully.\n");
288 
289  /* Unconditionally bind to OpenGL ES API. */
290  eglBindAPI(EGL_OPENGL_ES_API);
291 
292  /* [Creating rendering context] */
293  /* Sharing OpenGL ES objects with main thread's rendering context. */
294  pBufferContext = eglCreateContext(mainDisplay, config, mainContext, contextAttributes);
295  /* [Creating rendering context] */
296  if(pBufferContext == EGL_NO_CONTEXT)
297  {
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__);
301  exit(1);
302  }
303 
304  LOGI("PBuffer context created successfully sharing GLES objects with the main context.\n");
306  LOGI("PBuffer context made current successfully.\n");
307  /* [workingFunction 2] */
308  /* [workingFunction 3] */
309  /*
310  * Flags to pass to glFenceSync must be zero as there are no flag defined yet.
311  * The condition must be set to GL_SYNC_GPU_COMMANDS_COMPLETE.
312  */
313  GLbitfield flags = 0;
314  GLenum condition = GL_SYNC_GPU_COMMANDS_COMPLETE;
315 
316  while(!exitThread)
317  {
318  /* Set texture change frequency to 60 frames/s. */
319  usleep(1000000 / 60);
320 
321  /* Change texture. */
322  animateTexture();
323 
324  if(useFence)
325  {
326  if (mainThreadSyncObj != NULL)
327  {
328  GL_CHECK(glWaitSync(mainThreadSyncObj, flags, timeout));
329  }
330  else
331  {
332  continue;
333  }
334 
335  /* Upload texture. */
336  GL_CHECK(glBindTexture(GL_TEXTURE_2D, iCubeTex));
337  GL_CHECK(glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData));
338 
339  /* This fence create a sync object which is signalled when the fence command reaches the end of the graphic pipeline. */
340  secondThreadSyncObj = glFenceSync(condition, flags);
341 
342  EGLint error = eglGetError();
343  if (secondThreadSyncObj == NULL || error == GL_INVALID_ENUM || error == GL_INVALID_VALUE )
344  {
345  LOGE("glFenceSync failed at workingFunction.\n");
346  }
347  }
348  else
349  {
350  /* Upload texture. */
351  GL_CHECK(glBindTexture(GL_TEXTURE_2D, iCubeTex));
352  GL_CHECK(glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData));
353  }
354  }
355 
356  LOGI("Exiting secondary thread.\n");
357 
358  return NULL;
359 }
360 /* [workingFunction 3] */
361 
362 /* Secondary thread's creation. */
364 {
365  int status;
366  pthread_create(&secondThread,NULL, &workingFunction,NULL);
367 }
368 
369 /* Main thread's graphics setup. */
370 bool setupGraphics(int width, int height)
371 {
372  windowWidth = width;
374 
375  /* Full paths to the shader files */
376  string vertexShaderPath = resourceDirectory + vertexShaderFilename;
377  string fragmentShaderPath = resourceDirectory + fragmentShaderFilename;
378 
379  /* Initialise matrices. */
380  projection = Matrix::matrixPerspective(45.0f, windowWidth / (float)windowHeight, 0.01f, 100.0f);
381  /* Move cube 2 further away from camera. */
382  translation = Matrix::createTranslation(0.0f, 0.0f, -2.0f);
383 
384  /* Initialise OpenGL ES. */
385  GL_CHECK(glEnable(GL_CULL_FACE));
386  GL_CHECK(glCullFace(GL_BACK));
387  GL_CHECK(glEnable(GL_DEPTH_TEST));
388  GL_CHECK(glEnable(GL_BLEND));
389  /* Should do src * (src alpha) + dest * (1-src alpha). */
390  GL_CHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
391 
392  /* Initialise the Text object and add some text. */
394 
395  if(useFence)
396  {
397  textString = baseString + "Fencing enabled.";
398  }
399  else
400  {
401  textString = baseString + "Fencing disabled.";
402  }
403  text->addString(0, 0, textString.c_str(), 255, 255, 0, 255);
404 
405  /* Initialisation of some global variables needed in the case the application
406  * is restarted due to orientation change.
407  */
408  mainContext = NULL;
409  mainDisplay = NULL;
410  pBufferSurface = NULL;
411  pBufferContext = NULL;
412  exitThread = false;
413  textureData = NULL;
414 
415  initTexture();
416 
417  /* Process shaders. */
418  Shader::processShader(&vertexShaderID, vertexShaderPath.c_str(), GL_VERTEX_SHADER);
419  Shader::processShader(&fragmentShaderID, fragmentShaderPath.c_str(), GL_FRAGMENT_SHADER);
420 
421  /* Set up shaders. */
422  programID = GL_CHECK(glCreateProgram());
423  GL_CHECK(glAttachShader(programID, vertexShaderID));
424  GL_CHECK(glAttachShader(programID, fragmentShaderID));
425  GL_CHECK(glLinkProgram(programID));
426  GL_CHECK(glUseProgram(programID));
427 
428  /* Vertex positions. */
429  iLocPosition = GL_CHECK(glGetAttribLocation(programID, "a_v4Position"));
430  if(iLocPosition == -1)
431  {
432  LOGE("Attribute not found at %s:%i\n", __FILE__, __LINE__);
433  return false;
434  }
435  GL_CHECK(glEnableVertexAttribArray(iLocPosition));
436 
437  /* Texture mix. */
438  iLocTextureMix = GL_CHECK(glGetUniformLocation(programID, "u_fTex"));
439  if(iLocTextureMix == -1)
440  {
441  LOGD("Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
442  }
443  else
444  {
445  GL_CHECK(glUniform1f(iLocTextureMix, 0.0));
446  }
447 
448  /* Texture. */
449  iLocTexture = GL_CHECK(glGetUniformLocation(programID, "u_s2dTexture"));
450  if(iLocTexture == -1)
451  {
452  LOGD("Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
453  }
454  else
455  {
456  GL_CHECK(glUniform1i(iLocTexture, 0));
457  }
458 
459  /* Vertex colours. */
460  iLocFillColor = GL_CHECK(glGetAttribLocation(programID, "a_v4FillColor"));
461  if(iLocFillColor == -1)
462  {
463  LOGD("Warning: Attribute not found at %s:%i\n", __FILE__, __LINE__);
464  }
465  else
466  {
467  GL_CHECK(glEnableVertexAttribArray(iLocFillColor));
468  }
469 
470  /* Texture coordinates. */
471  iLocTexCoord = GL_CHECK(glGetAttribLocation(programID, "a_v2TexCoord"));
472  if(iLocTexCoord == -1)
473  {
474  LOGD("Warning: Attribute not found at %s:%i\n", __FILE__, __LINE__);
475  }
476  else
477  {
478  GL_CHECK(glEnableVertexAttribArray(iLocTexCoord));
479  }
480 
481  /* Projection matrix. */
482  iLocProjection = GL_CHECK(glGetUniformLocation(programID, "u_m4Projection"));
483  if(iLocProjection == -1)
484  {
485  LOGD("Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
486  }
487  else
488  {
489  GL_CHECK(glUniformMatrix4fv(iLocProjection, 1, GL_FALSE, projection.getAsArray()));
490  }
491 
492  /* Model-view matrix. */
493  iLocModelview = GL_CHECK(glGetUniformLocation(programID, "u_m4Modelview"));
494  if(iLocModelview == -1)
495  {
496  LOGD("Warning: Uniform not found at %s:%i\n", __FILE__, __LINE__);
497  }
498 
499  /* Initialise main display and context variables. */
500  mainDisplay = eglGetCurrentDisplay();
501  mainContext = eglGetCurrentContext();
502 
503  if(useFence)
504  {
505  /* Initialise mainThreadSyncObj to let the render function execute first,
506  * otherwise we get a dead lock between the 2 sync objects.
507  */
508  GLbitfield flags = 0;
509  GLenum condition = GL_SYNC_GPU_COMMANDS_COMPLETE;
510 
511  /* This fence creates a sync object which is signalled when the fence command
512  * reaches the end of the graphic pipeline.
513  */
514  mainThreadSyncObj = glFenceSync(condition, flags);
515  LOGI("Use of GL Fence enabled.")
516  }
517  else
518  {
519  LOGI("Use of GL Fence disabled.")
520  }
521 
522  /* Secondary thread's creation. */
524 
525  return true;
526 }
527 
528 /* [renderFrame 1] */
529 void renderFrame(void)
530 {
531  GLbitfield flags = 0;
532 
533  if(useFence)
534  {
535  if (secondThreadSyncObj != NULL)
536  {
537  GL_CHECK(glWaitSync(secondThreadSyncObj, flags, timeout));
538  }
539  else
540  {
541  return;
542  }
543  }
544 
545  /* Shader program. */
546  GL_CHECK(glUseProgram(programID));
547 
548  /* [renderFrame 1] */
549  /* Vertex data. */
550  GL_CHECK(glEnableVertexAttribArray(iLocPosition));
551  GL_CHECK(glVertexAttribPointer(iLocPosition, 3, GL_FLOAT, GL_FALSE, 0, cubeVertices));
552 
553  /* Colour data. */
554  if(iLocFillColor != -1)
555  {
556  GL_CHECK(glEnableVertexAttribArray(iLocFillColor));
557  GL_CHECK(glVertexAttribPointer(iLocFillColor, 4, GL_FLOAT, GL_FALSE, 0, cubeColors));
558  }
559 
560  /* Texture coordinate data. */
561  if(iLocTexCoord != -1)
562  {
563  GL_CHECK(glEnableVertexAttribArray(iLocTexCoord));
564  GL_CHECK(glVertexAttribPointer(iLocTexCoord, 2, GL_FLOAT, GL_FALSE, 0, cubeTextureCoordinates));
565  }
566 
567  /* [renderFrame 2] */
568  /* Reset viewport to the EGL window surface's dimensions. */
569  GL_CHECK(glViewport(0, 0, windowWidth, windowHeight));
570 
571  /* Clear the screen on the EGL surface. */
572  GL_CHECK(glClearColor(0.0f, 0.0f, 1.0f, 1.0));
573  GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
574  /* [renderFrame 2] */
575  /* Construct different rotation for main cube. */
579 
580  /* Rotate about origin, then translate away from camera. */
584 
585  /* Load EGL window-specific projection and model view matrices. */
586  GL_CHECK(glUniformMatrix4fv(iLocModelview, 1, GL_FALSE, modelView.getAsArray()));
587  GL_CHECK(glUniformMatrix4fv(iLocProjection, 1, GL_FALSE, projection.getAsArray()));
588 
589  /* For the main cube, we use texturing so set the texture mix factor to 1. */
590  if(iLocTextureMix != -1)
591  {
592  GL_CHECK(glUniform1f(iLocTextureMix, 1.0));
593  }
594 
595  /* [renderFrame 3] */
596  /* Ensure the correct texture is bound to texture unit 0. */
597  GL_CHECK(glActiveTexture(GL_TEXTURE0));
598  GL_CHECK(glBindTexture(GL_TEXTURE_2D, iCubeTex));
599 
600  /* Set the sampler to point at the 0th texture unit. */
601  GL_CHECK(glUniform1i(iLocTexture, 0));
602 
603  /* And draw the cube. */
604  GL_CHECK(glDrawElements(GL_TRIANGLE_STRIP, sizeof(cubeIndices) / sizeof(GLubyte), GL_UNSIGNED_BYTE, cubeIndices));
605  /* [renderFrame 3] */
606  /* Draw any text. */
607  text->draw();
608 
609  /* Update cube's rotation angles for animating. */
610  angleX += 0.75;
611  angleY += 0.5;
612  angleZ += 0.25;
613 
614  if(angleX >= 360) angleX -= 360;
615  if(angleY >= 360) angleY -= 360;
616  if(angleZ >= 360) angleZ -= 360;
617  /* [renderFrame 4] */
618  flags = 0;
619  GLenum condition = GL_SYNC_GPU_COMMANDS_COMPLETE;
620  /*
621  * This fence creates a sync object which is signalled when the fence
622  * command reaches the end of the graphic pipeline.
623  */
624  if(useFence)
625  {
626  if(mainThreadSyncObj == NULL)
627  {
628  LOGI("mainThreadSynobj == NULL at the end of renderframe.")
629  }
630 
631  mainThreadSyncObj = glFenceSync(condition, flags);
632  }
633 }
634 /* [renderFrame 4] */
635 
636 extern "C"
637 {
639  (JNIEnv *env, jclass jcls, jint width, jint height)
640  {
641  /* Make sure that all resource files are in place. */
644 
645  setupGraphics(width, height);
646  }
647 
649  (JNIEnv *env, jclass jcls)
650  {
651  renderFrame();
652  }
653 
655  (JNIEnv *, jclass)
656  {
657  /* Finish secondary thread. */
658  exitThread = true;
659  pthread_join(secondThread, NULL);
660 
661  if(textureData != NULL)
662  {
663  free(textureData);
664  }
665 
666  delete text;
667  }
668 
670  (JNIEnv *env, jclass jcls, jint x, jint y)
671  {
672  touchStart(x, y);
673  }
674 
676  (JNIEnv *env, jclass jcls, jint x, jint y)
677  {
678  touchMove(x, y);
679  }
680 
682  (JNIEnv *env, jclass jcls, jint x, jint y)
683  {
684  touchEnd(x, y);
685  }
686 }
static bool touchStarted
Definition: ThreadSync.cpp:123
GLenum condition
Definition: gl2ext.h:2178
GLint iLocTexture
Definition: ThreadSync.cpp:65
void renderFrame(void)
Definition: ThreadSync.cpp:529
static float angleX
Definition: ThreadSync.cpp:72
int windowHeight
Definition: ThreadSync.cpp:86
#define LOGI(...)
Definition: AstcTextures.h:29
int texHeight
Definition: ThreadSync.cpp:112
bool setupGraphics(int width, int height)
Definition: ThreadSync.cpp:370
EGLSurface pBufferSurface
Definition: ThreadSync.cpp:96
GLfloat cubeColors[numberOfValuesInCubeColorsArray]
Definition: Native.cpp:67
Functions for drawing text in OpenGL ES.
Definition: Text.h:44
GLint iLocProjection
Definition: ThreadSync.cpp:68
int texWidth
Definition: ThreadSync.cpp:111
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
void animateTexture()
Definition: ThreadSync.cpp:159
GLuint programID
Definition: ThreadSync.cpp:62
GLenum GLuint GLintptr offset
Definition: gl2ext.h:629
Text * text
Definition: ThreadSync.cpp:89
Matrix rotationX
Definition: ThreadSync.cpp:75
Functions for manipulating matrices.
Definition: Matrix.h:31
pthread_t secondThread
Definition: ThreadSync.cpp:100
Matrix translation
Definition: ThreadSync.cpp:78
GLsync mainThreadSyncObj
Definition: ThreadSync.cpp:105
GLbitfield flags
Definition: gl2ext.h:951
void touchMove(int x, int y)
Definition: ThreadSync.cpp:131
bool exitThread
Definition: ThreadSync.cpp:101
GLuint fragmentShaderID
Definition: ThreadSync.cpp:61
static Matrix createTranslation(float x, float y, float z)
Create and return a translation matrix.
Definition: Matrix.cpp:414
string vertexShaderFilename
Definition: ThreadSync.cpp:56
void clear(void)
Removes the current string from the class.
Definition: Text.cpp:142
#define LOGD(...)
Definition: AstcTextures.h:28
static string baseString
Definition: ThreadSync.cpp:90
int swapStripes
Definition: ThreadSync.cpp:110
static Matrix matrixPerspective(float FOV, float ratio, float zNear, float zFar)
Create and return a perspective projection matrix.
Definition: Matrix.cpp:425
EGLContext mainContext
Definition: ThreadSync.cpp:94
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_step(JNIEnv *env, jclass jcls)
Definition: ThreadSync.cpp:649
EGLContext pBufferContext
Definition: ThreadSync.cpp:97
Matrix rotationY
Definition: ThreadSync.cpp:76
float * getAsArray(void)
Get the matrix elements as a column major order array.
Definition: Matrix.cpp:78
typedef GLuint64(GL_APIENTRYP PFNGLGETTEXTUREHANDLENVPROC)(GLuint texture)
GLint iLocModelview
Definition: ThreadSync.cpp:69
static const float cubeVertices[]
Definition: EGLPreserve.h:42
static const GLubyte cubeIndices[]
Definition: EGLPreserve.h:29
int windowWidth
Definition: ThreadSync.cpp:85
static void * workingFunction(void *arg)
Definition: ThreadSync.cpp:272
void touchEnd(int x, int y)
Definition: ThreadSync.cpp:136
unsigned char bakedColours[]
Definition: ThreadSync.cpp:114
Matrix rotationZ
Definition: ThreadSync.cpp:77
Matrix projection
Definition: ThreadSync.cpp:80
GLfloat GLfloat f
Definition: gl2ext.h:2707
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_uninit(JNIEnv *, jclass)
Definition: ThreadSync.cpp:655
void touchStart(int x, int y)
Definition: ThreadSync.cpp:125
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.
Definition: Text.cpp:157
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_touchMove(JNIEnv *env, jclass jcls, jint x, jint y)
Definition: ThreadSync.cpp:676
#define GL_CHECK(x)
Definition: AstcTextures.h:59
typedef GLsync(GL_APIENTRYP PFNGLFENCESYNCAPPLEPROC)(GLenum condition
static float angleZ
Definition: ThreadSync.cpp:74
static Matrix createRotationY(float angle)
Create and return a rotation matrix around the y-axis matrix.
Definition: Matrix.cpp:511
EGLint contextAttributes[]
Definition: ThreadSync.h:186
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_touchEnd(JNIEnv *env, jclass jcls, jint x, jint y)
Definition: ThreadSync.cpp:682
unsigned char * textureData
Definition: ThreadSync.cpp:109
static Matrix createRotationZ(float angle)
Create and return a rotation matrix around the z-axis matrix.
Definition: Matrix.cpp:523
static float angleY
Definition: ThreadSync.cpp:73
GLuint vertexShaderID
Definition: ThreadSync.cpp:60
GLbitfield GLuint64 timeout
Definition: gl2ext.h:954
static bool getAndroidAsset(JNIEnv *JNIEnvironment, const char destinationDirectory[], const char filename[])
Extract an asset file from the APK.
void createTextureThread(void)
Definition: ThreadSync.cpp:363
EGLContext mainDisplay
Definition: ThreadSync.cpp:95
GLsync secondThreadSyncObj
Definition: ThreadSync.cpp:104
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
string resourceDirectory
Definition: ThreadSync.cpp:55
GLint iLocTextureMix
Definition: ThreadSync.cpp:64
void initTexture(void)
Definition: ThreadSync.cpp:241
GLint iLocTexCoord
Definition: ThreadSync.cpp:67
#define LOGE(...)
Definition: AstcTextures.h:30
EGLConfig findConfig(EGLDisplay display, bool strictMatch, bool offscreen)
Definition: ThreadSync.h:203
GLint GLsizei width
Definition: gl2ext.h:179
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_threadsync_ThreadSync_touchStart(JNIEnv *env, jclass jcls, jint x, jint y)
Definition: ThreadSync.cpp:670
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.
Definition: Shader.cpp:29
string fragmentShaderFilename
Definition: ThreadSync.cpp:57
static const float cubeTextureCoordinates[]
EGLint pBufferAttributes[]
Definition: ThreadSync.h:193
static bool useFence
A sample which illustrates the use of sync objects to synchronise the use of shared objects between m...
Definition: ThreadSync.cpp:36
void draw(void)
Draw the text to the screen.
Definition: Text.cpp:265
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)
Definition: ThreadSync.cpp:639
static Matrix createRotationX(float angle)
Create and return a rotation matrix around the x-axis matrix.
Definition: Matrix.cpp:499
GLint y
Definition: gl2ext.h:179
static string textString
Definition: ThreadSync.cpp:91
GLuint iCubeTex
Definition: ThreadSync.cpp:83
GLint iLocFillColor
Definition: ThreadSync.cpp:66
GLint iLocPosition
Definition: ThreadSync.cpp:63
Matrix modelView
Definition: ThreadSync.cpp:79