00001
00018 #include "test_fill.h"
00019 #include "test_frag.h"
00020 #include "test_geom.h"
00021 #include "test_vert.h"
00022 #include "test_complex.h"
00023 #include "test_compute.h"
00024
00025 using namespace std;
00026
00028 int curr_test;
00030 int final_test;
00032 Test *test;
00034 float total_score = 0.0;
00035
00037 unsigned cycle = 0;
00039 unsigned fps;
00040
00042 TScene *s;
00044 string msg;
00046 bool wire = false;
00047
00049 stringstream results;
00050
00052 bool info = false;
00054 int meminfo[4];
00056 int resx;
00058 int resy;
00060 int fsaa = 1;
00061
00063 bool devmode = false;
00064
00071 int CalcHash(string str)
00072 {
00073 int ret = 0;
00074 for(unsigned i=0; i<str.length(); i++)
00075 ret += str[i]*17 + str[i]*57 + str[i]*93;
00076
00077 return ret;
00078 }
00079
00084 void WriteResults()
00085 {
00086
00087 if(devmode)
00088 total_score = 0;
00089 cout<<"TOTAL SCORE: "<<total_score<<endl;
00090
00091 results<<"<total_score>\n"<<total_score<<"</total_score>\n<check>"<<CalcHash(num2str(total_score))<<"</check>\n</root>\n";
00092 ofstream fout("results.xml");
00093 if(!fout)
00094 {
00095 ShowMessage("Cannot write results to file! (read-only filesystem?)",false);
00096 #ifdef _WIN_
00098 SDL_Quit();
00099 #endif
00100 exit(1);
00101 }
00102 fout<<results.str();
00103 fout.close();
00104 }
00105
00111 bool NextTest()
00112 {
00113 delete test;
00114 test = NULL;
00115 delete s;
00116
00117
00118 int msaa;
00119 if(curr_test == COMPLEX_SSAMPLING)
00120 msaa = 1;
00121 else
00122 msaa = fsaa;
00123
00124
00125 s = new TScene();
00126 if(!s->PreInit(resx, resy, 0.1f, 1000.0f, 45.0f,msaa))
00127 return false;
00128
00129 try
00130 {
00131
00132 if(curr_test <= TEXEL_FILLRATE_FLOAT32)
00133 test = new TestFill(10000,curr_test,s);
00134 else if(curr_test == FRAG_LIGHTS)
00135 test = new TestFrag(30000,curr_test,s);
00136 else if(curr_test == FRAG_NOISE || curr_test == FRAG_REFRACT)
00137 test = new TestFrag(20000,curr_test,s);
00138 else if(curr_test == FRAG_PROCEDURAL || curr_test == FRAG_PARALLAX)
00139 test = new TestFrag(15000,curr_test,s);
00140 else if(curr_test == GEOM_TESSELATE)
00141 test = new TestGeom(20000,curr_test,s);
00142 else if(curr_test == GEOM_CUBEMAP)
00143 test = new TestGeom(20000,curr_test,s);
00144 else if(curr_test == GEOM_PARTICLES || curr_test == GEOM_INSTANCING)
00145 test = new TestGeom(20000,curr_test,s);
00146 else if(curr_test == VERT_LIGHTS)
00147 test = new TestVert(30000,curr_test,s);
00148 else if(curr_test == VERT_WAVES)
00149 test = new TestVert(15000,curr_test,s);
00150 else if(curr_test == VERT_DISPLACE)
00151 test = new TestVert(20000,curr_test,s);
00152 else if(curr_test >= COMPLEX_HDR && curr_test <= COMPLEX_SSAMPLING)
00153 test = new TestComplex(30000,curr_test,s);
00154 #ifdef USE_CL
00155 else if(curr_test >= COMPUTE_NBODY)
00156 test = new TestCompute(15000,curr_test,s);
00157 #endif
00158 }
00159 catch(int err)
00160 {
00161 delete test;
00162 test = NULL;
00163 curr_test++;
00164 return false;
00165 }
00166 curr_test++;
00167 return true;
00168 }
00169
00170
00176 bool InitScene()
00177 {
00178
00179 #ifdef _WIN_
00180
00181 typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)( int );
00182 PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0;
00183 const char *extensions = (const char*)glGetString( GL_EXTENSIONS );
00184
00185 if( strstr( extensions, "WGL_EXT_swap_control" ) == 0 )
00186 cout<<"Warning, vsync may be enabled."<<endl;
00187 else
00188 {
00189 wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress( "wglSwapIntervalEXT" );
00190
00191 if( wglSwapIntervalEXT )
00192 wglSwapIntervalEXT(0);
00193 }
00194 #endif
00195
00196
00197 results<<"<?xml version=\"1.0\"?>\n<root>\n";
00198
00199
00200 SystemInfo();
00201
00202
00203 NextTest();
00204 return true;
00205 }
00206
00207
00212 void SysInfo()
00213 {
00214
00215 s = new TScene();
00216 s->PreInit(resx, resy, 0.1f, 1000.0f, 45.0f,false,false);
00217
00218
00219 results<<"<?xml version=\"1.0\"?>\n<root>\n";
00220
00221 SystemInfo();
00222
00223 results<<"</root>\n";
00224
00225 ofstream fout;
00226 fout.open("sysinfo.xml");
00227 fout<<results.str();
00228 fout.close();
00229 }
00230
00231
00236 void Redraw()
00237 {
00238 test->Run();
00239 cycle++;
00240
00241
00242 msg = num2str(fps) + " FPS";
00243 s->DrawScreenText(msg.c_str(),50.0,1.0,1.0);
00244
00245 if(devmode)
00246 {
00247
00248 glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI,meminfo);
00249 msg = "VRAM used: " + num2str(1024 - meminfo[0]/1024) + " MB";
00250 s->DrawScreenText(msg.c_str(),8.0,1.0,1.0);
00251 }
00252 }
00253
00254
00260 void KeyInput(SDL_Event event)
00261 {
00262 switch(event.key.keysym.sym)
00263 {
00264 case SDLK_SPACE:
00265 if(devmode)
00266 {
00267
00268 if(curr_test - 1 == final_test)
00269 {
00270 delete test;
00271 delete s;
00272
00273 WriteResults();
00274 #ifdef _WIN_
00276 SDL_Quit();
00277 #endif
00278 exit(0);
00279 }
00280 NextTest();
00281 }
00282 break;
00283
00284 case SDLK_w:
00285 if(devmode)
00286 {
00287 wire = !wire;
00288 if(wire)
00289 glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
00290 else
00291 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
00292 }
00293 break;
00294
00295
00296 case SDLK_ESCAPE:
00297 delete test;
00298 test = NULL;
00299 delete s;
00300
00301 WriteResults();
00302
00303 #ifdef _WIN_
00305 SDL_Quit();
00306 #endif
00307 exit(0);
00308 break;
00309 default:
00310 break;
00311 }
00312 }
00313
00314
00316 int status;
00322 void MouseClick(SDL_Event event)
00323 {
00324 if(event.button.state = SDL_RELEASED)
00325 status = 0;
00326 else
00327 status = event.button.button;
00328 }
00329
00335 void MouseMotion(SDL_Event event)
00336 {
00337 if(devmode)
00338 {
00339 int x = event.motion.xrel;
00340 int y = event.motion.yrel;
00341
00342 if(status == SDL_BUTTON_LEFT)
00343 {
00344 s->RotateCamera((float)y, A_X);
00345 s->RotateCamera((float)x, A_Y);
00346 }
00347 else if(status == 4)
00348 s->MoveCamera(0.0f,0.0f, x/10.0f );
00349 else if(status == SDL_BUTTON_MIDDLE)
00350 s->MoveCamera( x/10.0f , -y/10.0f, 0.0f);
00351
00352
00353
00354 }
00355 }
00356
00361 void WrongParams()
00362 {
00363 cout<<"Wrong parameters.\n"
00364 "Usage: bin/bench.exe [-w|-f resX resY][-aa value]\n"
00365 "Parameters:\n"
00366 "-w,-f: windowed/fullscreen mode\n"
00367 "resX, resY: screen resolution in pixels\n"
00368 "-aa: antialiasing strength (0,1 = off)\n"
00369 "-t: test suite (can be \"all\", \"fillrate\", \"fragment\", \"geometry\", \"vertex\", \"complex\", \"compute\", \"info\")\n";
00370 #ifdef _WIN_
00372 SDL_Quit();
00373 #endif
00374 exit(1);
00375 }
00376
00377
00383 int Timer(void *unused)
00384 {
00385 int msec = 0;
00386
00387 while(true)
00388 {
00389
00390 if(test != NULL)
00391 test->Animate();
00392 msec++;
00393
00394
00395 if(msec == 100)
00396 {
00397
00398 fps = cycle;
00399 if(test != NULL)
00400 test->UpdateFPS(fps);
00401 cycle = 0;
00402 msec = 0;
00403 }
00404 SDL_Delay(10);
00405 }
00406 return 0;
00407 }
00408
00409
00410
00414
00419
00420 int main(int argc, char **argv)
00421 {
00422
00423 string param, test_suite = "all";
00424 bool fullscreen = false;
00425 resx = 1024;
00426 resy = 768;
00427
00428
00429 for(int i=1; i<argc; i++)
00430 {
00431 param = argv[i];
00432
00434
00435 if(param == "-w" || param == "-f")
00436 {
00437 if(param == "-w")
00438 fullscreen = false;
00439 else if(param == "-f")
00440 fullscreen = true;
00441
00442 if(i+2 < argc)
00443 {
00444 resx = atoi(argv[i+1]);
00445 resy = atoi(argv[i+2]);
00446 i += 2;
00447 }
00448 else
00449 WrongParams();
00450 }
00452
00453 else if(param == "-aa")
00454 {
00455 if(i+1 < argc)
00456 {
00457 fsaa = atoi(argv[i+1]);
00458 i++;
00459 }
00460 else
00461 WrongParams();
00462 }
00464
00465 else if(param == "-t")
00466 {
00467 if(i+1 < argc)
00468 {
00469 test_suite = argv[i+1];
00470 i++;
00471 }
00472 else
00473 WrongParams();
00474 }
00476
00477 else if(param == "-dev")
00478 devmode = true;
00480
00481 else
00482 WrongParams();
00483 }
00484
00486
00487
00488 int test_num = atoi(test_suite.c_str());
00489
00490 if(test_suite == "all")
00491 {
00492 curr_test = TEXEL_FILLRATE_SINGLE;
00493 #ifdef USE_CL
00494 final_test = COMPUTE_NBODY;
00495 #else
00496 final_test = COMPLEX_SSAMPLING;
00497 #endif
00498 }
00499
00500 else if(test_suite == "fillrate")
00501 {
00502 curr_test = TEXEL_FILLRATE_SINGLE;
00503 final_test = TEXEL_FILLRATE_FLOAT32;
00504 }
00505
00506 else if(test_suite == "fragment")
00507 {
00508 curr_test = FRAG_LIGHTS;
00509 final_test = FRAG_REFRACT;
00510 }
00511
00512 else if(test_suite == "geometry")
00513 {
00514 curr_test = GEOM_TESSELATE;
00515 final_test = GEOM_INSTANCING;
00516 }
00517
00518 else if(test_suite == "vertex")
00519 {
00520 curr_test = VERT_LIGHTS;
00521 final_test = VERT_DISPLACE;
00522 }
00523
00524 else if(test_suite == "complex")
00525 {
00526 curr_test = COMPLEX_HDR;
00527 final_test = COMPLEX_SSAMPLING;
00528 }
00529 #ifdef USE_CL
00530
00531 else if(test_suite == "compute")
00532 {
00533 curr_test = COMPUTE_NBODY;
00534 final_test = COMPUTE_NBODY;
00535 }
00536 #endif
00537 else if(test_suite == "info")
00538 info = true;
00539
00540 else if(test_num >= 0 && test_num < 21)
00541 {
00542 curr_test = test_num;
00543 final_test = test_num;
00544 }
00545 else
00546 WrongParams();
00547
00548
00549 if(SDL_Init(SDL_INIT_VIDEO) < 0)
00550 return 1;
00551
00552 #ifdef GL3
00553
00554 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
00555 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
00556 #endif
00557
00558
00559 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
00560 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
00561
00562
00563 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
00564 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
00565
00566 SDL_WM_SetCaption("gluxMark 2.0", 0);
00567
00568
00569 if(info)
00570 {
00571 cout<<"Gathering system info...\n";
00572 fullscreen = false;
00573 resx = resy = 1;
00574 }
00575
00576
00577 int mode = SDL_OPENGL;
00578 if(fullscreen)
00579 mode |= SDL_FULLSCREEN;
00580 if(SDL_SetVideoMode(resx, resy, 32, mode) == NULL)
00581 {
00582 ShowMessage("Display mode not supported\n");
00583 #ifdef _WIN_
00585 SDL_Quit();
00586 #endif
00587 return 1;
00588 }
00589
00590 SDL_ShowCursor(SDL_DISABLE);
00591
00592
00593 if(glewInit() != GLEW_OK)
00594 {
00595 ShowMessage("GLEW initialization failed!\n");
00596 #ifdef _WIN_
00598 SDL_Quit();
00599 #endif
00600 return 1;
00601 }
00602
00603
00604 if(!GLEW_ARB_multitexture || !GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader || !GLEW_ARB_multisample || !GLEW_EXT_framebuffer_object )
00605 {
00606 cout<<"Your video card doesn't meet minimum requirements. You won't be able to run any of the test\n";
00607 return -1;
00608 }
00609
00610
00611 if(info)
00612 {
00613 SysInfo();
00614 #ifdef _WIN_
00616 SDL_Quit();
00617 #endif
00618 return 0;
00619 }
00620
00621
00622 if(!InitScene())
00623 {
00624 #ifdef _WIN_
00626 SDL_Quit();
00627 #endif
00628 exit(1);
00629 }
00630
00631
00632 results<<"<settings>\n"
00633 "<resolution>"<<resx<<"x"<<resy<<"</resolution>\n"
00634 "<antialias>"<<fsaa<<"</antialias>\n"
00635 "<series>"<<test_suite<<"</series>\n"
00636 "</settings>\n";
00637
00638
00639 SDL_Thread *time_thread;
00640 time_thread = SDL_CreateThread(Timer, NULL);
00641
00642 if(time_thread == NULL )
00643 {
00644 ShowMessage("Cannot create timer thread!\n");
00645 #ifdef _WIN_
00647 SDL_Quit();
00648 #endif
00649 return 1;
00650 }
00651
00652
00653 SDL_Event event;
00654 while(true)
00655 {
00656
00657 if(SDL_PollEvent(&event))
00658 {
00659 if(event.type == SDL_QUIT)
00660 break;
00661
00662 else if(event.type == SDL_KEYDOWN)
00663 KeyInput(event);
00664
00665 else if(event.type == SDL_MOUSEMOTION)
00666 {
00667 MouseMotion(event);
00668 MouseClick(event);
00669 }
00670 }
00671
00672
00673 if(test == NULL || test->HasEnded())
00674 {
00675
00676 if(curr_test - 1 == final_test)
00677 {
00678
00679 if(test != NULL)
00680 total_score += test->GetScore();
00681 delete test;
00682 test = NULL;
00683 WriteResults();
00684
00685 #ifdef _WIN_
00687 SDL_Quit();
00688 #endif
00689 exit(0);
00690 }
00691
00692 if(test != NULL)
00693 total_score += test->GetScore();
00694
00695 if(!NextTest())
00696 continue;
00697 }
00698
00699 Redraw();
00700 SDL_GL_SwapBuffers();
00701 }
00702
00703
00704 #ifdef _WIN_
00706 SDL_Quit();
00707 #endif
00708 return 0;
00709 }