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
16#include "../../gl_perf/fill_common.cpp"
17
18
19//////////////////////////
20
21// Width and height of the screen
22
23uint32_t w;
24uint32_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
28int stateClock;
29const int doLoopStates = 2;
30const int doSingleTestStates = 2;
31bool done;
32
33// Saves the parameters of the test (so we can print them out when we finish the timing.)
34
35
36int pgm;
37
38void ptSwap() {
39}
40
41void doTest() {
42    uint32_t testNum = stateClock >> 2;
43    int texSize = ((stateClock >> 1) & 0x1) + 1;
44
45    if (testNum >= gFragmentTestCount) {
46       LOGI("done\n");
47       if (fOut) {
48           fclose(fOut);
49           fOut = NULL;
50       }
51       done = true;
52       return;
53    }
54
55    // LOGI("doTest %d %d %d\n", texCount, extraMath, testSubState);
56
57//        for (uint32_t num = 0; num < gFragmentTestCount; num++) {
58    doSingleTest(testNum, texSize);
59}
60
61extern "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
66JNIEXPORT void JNICALL Java_com_android_glperf_GLPerfLib_init(JNIEnv * env, jobject obj,  jint width, jint height)
67{
68    gWidth = width;
69    gHeight = height;
70    if (!done) {
71            stateClock = 0;
72            done = false;
73            setupVA();
74            genTextures();
75            const char* fileName = "/sdcard/glperf.csv";
76            if (fOut != NULL) {
77                 LOGI("Closing partially written output.n");
78                 fclose(fOut);
79                 fOut = NULL;
80            }
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            }
86
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");
89    }
90}
91
92JNIEXPORT void JNICALL Java_com_android_glperf_GLPerfLib_step(JNIEnv * env, jobject obj)
93{
94    if (! done) {
95        if (stateClock > 0 && ((stateClock & 1) == 0)) {
96            //endTimer(100);
97        }
98        doTest();
99        stateClock++;
100    } else {
101            glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
102    }
103}
104