blob: f99337152c026810a997b41062843b5f490ef108 [file] [log] [blame]
Jack Palevichc9541152010-07-19 16:27:54 -07001// 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 Sams744f37f2010-07-20 19:37:58 -070016#include "../../gl_perf/fill_common.cpp"
Jack Palevich5a52b1c2010-07-19 17:39:52 -070017
Jack Palevichc9541152010-07-19 16:27:54 -070018
19//////////////////////////
20
Jack Palevich5a52b1c2010-07-19 17:39:52 -070021// Width and height of the screen
Jack Palevichc9541152010-07-19 16:27:54 -070022
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
Jack Palevich5a52b1c2010-07-19 17:39:52 -070033// Saves the parameters of the test (so we can print them out when we finish the timing.)
34
Jason Sams744f37f2010-07-20 19:37:58 -070035
36int pgm;
37
38void ptSwap() {
Jack Palevichc9541152010-07-19 16:27:54 -070039}
40
Jason Samsd997f712010-09-08 15:22:06 -070041void doTest() {
42 uint32_t testNum = stateClock >> 2;
43 int texSize = ((stateClock >> 1) & 0x1) + 1;
Jack Palevichc9541152010-07-19 16:27:54 -070044
Jason Samsd997f712010-09-08 15:22:06 -070045 if (testNum >= gFragmentTestCount) {
Jack Palevich5a52b1c2010-07-19 17:39:52 -070046 LOGI("done\n");
Jason Sams744f37f2010-07-20 19:37:58 -070047 if (fOut) {
48 fclose(fOut);
49 fOut = NULL;
Jack Palevich5a52b1c2010-07-19 17:39:52 -070050 }
Jack Palevichc9541152010-07-19 16:27:54 -070051 done = true;
52 return;
53 }
54
Jack Palevich9778f9f2010-07-19 17:01:25 -070055 // LOGI("doTest %d %d %d\n", texCount, extraMath, testSubState);
56
Jason Samsd997f712010-09-08 15:22:06 -070057// for (uint32_t num = 0; num < gFragmentTestCount; num++) {
58 doSingleTest(testNum, texSize);
Jack Palevichc9541152010-07-19 16:27:54 -070059}
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{
Jason Samsd997f712010-09-08 15:22:06 -070068 gWidth = width;
69 gHeight = height;
Jack Palevich81d7aeb2010-07-19 17:52:12 -070070 if (!done) {
Jason Samsd997f712010-09-08 15:22:06 -070071 stateClock = 0;
72 done = false;
73 setupVA();
74 genTextures();
75 const char* fileName = "/sdcard/glperf.csv";
Jason Sams744f37f2010-07-20 19:37:58 -070076 if (fOut != NULL) {
Jack Palevich81d7aeb2010-07-19 17:52:12 -070077 LOGI("Closing partially written output.n");
Jason Sams744f37f2010-07-20 19:37:58 -070078 fclose(fOut);
79 fOut = NULL;
Jack Palevich81d7aeb2010-07-19 17:52:12 -070080 }
Jason Samsd997f712010-09-08 15:22:06 -070081 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 Palevichc9541152010-07-19 16:27:54 -070086
Jason Samsd997f712010-09-08 15:22:06 -070087 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 Palevich81d7aeb2010-07-19 17:52:12 -070089 }
Jack Palevichc9541152010-07-19 16:27:54 -070090}
91
92JNIEXPORT void JNICALL Java_com_android_glperf_GLPerfLib_step(JNIEnv * env, jobject obj)
93{
94 if (! done) {
Jack Palevich9778f9f2010-07-19 17:01:25 -070095 if (stateClock > 0 && ((stateClock & 1) == 0)) {
Jason Samsd997f712010-09-08 15:22:06 -070096 //endTimer(100);
Jack Palevichc9541152010-07-19 16:27:54 -070097 }
Jason Samsd997f712010-09-08 15:22:06 -070098 doTest();
Jack Palevichc9541152010-07-19 16:27:54 -070099 stateClock++;
Jack Palevich9778f9f2010-07-19 17:01:25 -0700100 } else {
Jason Samsd997f712010-09-08 15:22:06 -0700101 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
Jack Palevichc9541152010-07-19 16:27:54 -0700102 }
103}