Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 1 | // OpenGL ES 2.0 code |
| 2 | |
| 3 | #include <nativehelper/jni.h> |
| 4 | #define LOG_TAG "GLPerf gl_code.cpp" |
| 5 | #include <utils/Log.h> |
| 6 | |
| 7 | #include <EGL/egl.h> |
| 8 | #include <GLES2/gl2.h> |
| 9 | #include <GLES2/gl2ext.h> |
| 10 | #include <utils/Timers.h> |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <math.h> |
| 15 | |
Jason Sams | 744f37f | 2010-07-20 19:37:58 -0700 | [diff] [blame] | 16 | #include "../../gl_perf/fill_common.cpp" |
Jack Palevich | 5a52b1c | 2010-07-19 17:39:52 -0700 | [diff] [blame] | 17 | |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 18 | |
| 19 | ////////////////////////// |
| 20 | |
Jack Palevich | 5a52b1c | 2010-07-19 17:39:52 -0700 | [diff] [blame] | 21 | // Width and height of the screen |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 22 | |
| 23 | uint32_t w; |
| 24 | uint32_t h; |
| 25 | |
| 26 | // The stateClock starts at zero and increments by 1 every time we draw a frame. It is used to control which phase of the test we are in. |
| 27 | |
| 28 | int stateClock; |
| 29 | const int doLoopStates = 2; |
| 30 | const int doSingleTestStates = 2; |
| 31 | bool done; |
| 32 | |
Jack Palevich | 5a52b1c | 2010-07-19 17:39:52 -0700 | [diff] [blame] | 33 | // Saves the parameters of the test (so we can print them out when we finish the timing.) |
| 34 | |
Jason Sams | 744f37f | 2010-07-20 19:37:58 -0700 | [diff] [blame] | 35 | |
| 36 | int pgm; |
| 37 | |
| 38 | void ptSwap() { |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Jason Sams | d997f71 | 2010-09-08 15:22:06 -0700 | [diff] [blame] | 41 | void doTest() { |
| 42 | uint32_t testNum = stateClock >> 2; |
| 43 | int texSize = ((stateClock >> 1) & 0x1) + 1; |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 44 | |
Jason Sams | d997f71 | 2010-09-08 15:22:06 -0700 | [diff] [blame] | 45 | if (testNum >= gFragmentTestCount) { |
Jack Palevich | 5a52b1c | 2010-07-19 17:39:52 -0700 | [diff] [blame] | 46 | LOGI("done\n"); |
Jason Sams | 744f37f | 2010-07-20 19:37:58 -0700 | [diff] [blame] | 47 | if (fOut) { |
| 48 | fclose(fOut); |
| 49 | fOut = NULL; |
Jack Palevich | 5a52b1c | 2010-07-19 17:39:52 -0700 | [diff] [blame] | 50 | } |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 51 | done = true; |
| 52 | return; |
| 53 | } |
| 54 | |
Jack Palevich | 9778f9f | 2010-07-19 17:01:25 -0700 | [diff] [blame] | 55 | // LOGI("doTest %d %d %d\n", texCount, extraMath, testSubState); |
| 56 | |
Jason Sams | d997f71 | 2010-09-08 15:22:06 -0700 | [diff] [blame] | 57 | // for (uint32_t num = 0; num < gFragmentTestCount; num++) { |
| 58 | doSingleTest(testNum, texSize); |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | extern "C" { |
| 62 | JNIEXPORT void JNICALL Java_com_android_glperf_GLPerfLib_init(JNIEnv * env, jobject obj, jint width, jint height); |
| 63 | JNIEXPORT void JNICALL Java_com_android_glperf_GLPerfLib_step(JNIEnv * env, jobject obj); |
| 64 | }; |
| 65 | |
| 66 | JNIEXPORT void JNICALL Java_com_android_glperf_GLPerfLib_init(JNIEnv * env, jobject obj, jint width, jint height) |
| 67 | { |
Jason Sams | d997f71 | 2010-09-08 15:22:06 -0700 | [diff] [blame] | 68 | gWidth = width; |
| 69 | gHeight = height; |
Jack Palevich | 81d7aeb | 2010-07-19 17:52:12 -0700 | [diff] [blame] | 70 | if (!done) { |
Jason Sams | d997f71 | 2010-09-08 15:22:06 -0700 | [diff] [blame] | 71 | stateClock = 0; |
| 72 | done = false; |
| 73 | setupVA(); |
| 74 | genTextures(); |
| 75 | const char* fileName = "/sdcard/glperf.csv"; |
Jason Sams | 744f37f | 2010-07-20 19:37:58 -0700 | [diff] [blame] | 76 | if (fOut != NULL) { |
Jack Palevich | 81d7aeb | 2010-07-19 17:52:12 -0700 | [diff] [blame] | 77 | LOGI("Closing partially written output.n"); |
Jason Sams | 744f37f | 2010-07-20 19:37:58 -0700 | [diff] [blame] | 78 | fclose(fOut); |
| 79 | fOut = NULL; |
Jack Palevich | 81d7aeb | 2010-07-19 17:52:12 -0700 | [diff] [blame] | 80 | } |
Jason Sams | d997f71 | 2010-09-08 15:22:06 -0700 | [diff] [blame] | 81 | LOGI("Writing to: %s\n",fileName); |
| 82 | fOut = fopen(fileName, "w"); |
| 83 | if (fOut == NULL) { |
| 84 | LOGE("Could not open: %s\n", fileName); |
| 85 | } |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 86 | |
Jason Sams | d997f71 | 2010-09-08 15:22:06 -0700 | [diff] [blame] | 87 | LOGI("\nvarColor, texCount, modulate, extraMath, texSize, blend, Mpps, DC60\n"); |
| 88 | if (fOut) fprintf(fOut,"varColor, texCount, modulate, extraMath, texSize, blend, Mpps, DC60\r\n"); |
Jack Palevich | 81d7aeb | 2010-07-19 17:52:12 -0700 | [diff] [blame] | 89 | } |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | JNIEXPORT void JNICALL Java_com_android_glperf_GLPerfLib_step(JNIEnv * env, jobject obj) |
| 93 | { |
| 94 | if (! done) { |
Jack Palevich | 9778f9f | 2010-07-19 17:01:25 -0700 | [diff] [blame] | 95 | if (stateClock > 0 && ((stateClock & 1) == 0)) { |
Jason Sams | d997f71 | 2010-09-08 15:22:06 -0700 | [diff] [blame] | 96 | //endTimer(100); |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 97 | } |
Jason Sams | d997f71 | 2010-09-08 15:22:06 -0700 | [diff] [blame] | 98 | doTest(); |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 99 | stateClock++; |
Jack Palevich | 9778f9f | 2010-07-19 17:01:25 -0700 | [diff] [blame] | 100 | } else { |
Jason Sams | d997f71 | 2010-09-08 15:22:06 -0700 | [diff] [blame] | 101 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
Jack Palevich | c954115 | 2010-07-19 16:27:54 -0700 | [diff] [blame] | 102 | } |
| 103 | } |