2018-08-02 19:13:45 +00:00
|
|
|
/*
|
|
|
|
KallistiGL 2.0.0
|
|
|
|
|
|
|
|
quadmark.c
|
|
|
|
(c)2018 Luke Benstead
|
|
|
|
(c)2014 Josh Pearson
|
|
|
|
(c)2002 Dan Potter, Paul Boese
|
|
|
|
*/
|
|
|
|
|
2021-04-19 19:43:56 +00:00
|
|
|
#ifdef __DREAMCAST__
|
2018-08-02 19:13:45 +00:00
|
|
|
#include <kos.h>
|
2021-04-20 15:08:58 +00:00
|
|
|
#include "../profiler.h"
|
2021-04-19 19:43:56 +00:00
|
|
|
#endif
|
2018-08-02 19:13:45 +00:00
|
|
|
|
|
|
|
#include <GL/gl.h>
|
2021-04-09 15:24:47 +00:00
|
|
|
#include <GL/glkos.h>
|
2018-08-02 19:13:45 +00:00
|
|
|
|
2021-04-20 15:08:58 +00:00
|
|
|
#include <stdint.h>
|
2018-08-02 19:13:45 +00:00
|
|
|
#include <stdlib.h>
|
2021-04-19 19:43:56 +00:00
|
|
|
#include <stdio.h>
|
2018-08-02 19:13:45 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
enum { PHASE_HALVE, PHASE_INCR, PHASE_DECR, PHASE_FINAL };
|
|
|
|
|
|
|
|
int polycnt;
|
|
|
|
int phase = PHASE_HALVE;
|
|
|
|
float avgfps = -1;
|
|
|
|
|
|
|
|
void running_stats() {
|
2021-04-19 19:43:56 +00:00
|
|
|
#ifdef __DREAMCAST__
|
2018-08-02 19:13:45 +00:00
|
|
|
pvr_stats_t stats;
|
|
|
|
pvr_get_stats(&stats);
|
|
|
|
|
|
|
|
if(avgfps == -1)
|
|
|
|
avgfps = stats.frame_rate;
|
|
|
|
else
|
|
|
|
avgfps = (avgfps + stats.frame_rate) / 2.0f;
|
2021-04-19 19:43:56 +00:00
|
|
|
#endif
|
2018-08-02 19:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void stats() {
|
2021-04-19 19:43:56 +00:00
|
|
|
#ifdef __DREAMCAST__
|
2018-08-02 19:13:45 +00:00
|
|
|
pvr_stats_t stats;
|
|
|
|
|
|
|
|
pvr_get_stats(&stats);
|
|
|
|
dbglog(DBG_DEBUG, "3D Stats: %d VBLs, frame rate ~%f fps\n",
|
|
|
|
stats.vbl_count, stats.frame_rate);
|
2021-04-19 19:43:56 +00:00
|
|
|
#endif
|
2018-08-02 19:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int check_start() {
|
2021-04-19 19:43:56 +00:00
|
|
|
#ifdef __DREAMCAST__
|
2018-08-02 19:13:45 +00:00
|
|
|
maple_device_t *cont;
|
|
|
|
cont_state_t *state;
|
|
|
|
|
|
|
|
cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
|
|
|
|
|
|
|
|
if(cont) {
|
|
|
|
state = (cont_state_t *)maple_dev_status(cont);
|
|
|
|
|
|
|
|
if(state)
|
|
|
|
return state->buttons & CONT_START;
|
|
|
|
}
|
2021-04-19 19:43:56 +00:00
|
|
|
#endif
|
2018-08-02 19:13:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup() {
|
2022-09-14 18:20:24 +00:00
|
|
|
//PVR needs to warm up for a frame, or results will be low
|
2018-08-02 19:13:45 +00:00
|
|
|
glKosInit();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
glOrtho(0, 640, 0, 480, -100, 100);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
2021-04-26 15:14:33 +00:00
|
|
|
|
|
|
|
glDisable(GL_NEARZ_CLIPPING_KOS);
|
2022-09-14 18:20:24 +00:00
|
|
|
|
|
|
|
pvr_wait_ready();
|
|
|
|
pvr_scene_begin();
|
|
|
|
pvr_scene_finish();
|
2018-08-02 19:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void do_frame() {
|
|
|
|
int x, y, z;
|
|
|
|
int size;
|
|
|
|
int i;
|
|
|
|
float col;
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
|
|
|
for(i = 0; i < polycnt; i++) {
|
|
|
|
x = rand() % 640;
|
|
|
|
y = rand() % 480;
|
|
|
|
z = rand() % 100 + 1;
|
|
|
|
size = rand() % 50 + 1;
|
|
|
|
col = (rand() % 255) * 0.00391f;
|
|
|
|
|
|
|
|
glColor3f(col, col, col);
|
|
|
|
glVertex3f(x - size, y - size, z);
|
|
|
|
glVertex3f(x + size, y - size, z);
|
|
|
|
glVertex3f(x + size, y + size, z);
|
|
|
|
glVertex3f(x - size, y + size, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glKosSwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t start;
|
|
|
|
void switch_tests(int ppf) {
|
|
|
|
printf("Beginning new test: %d polys per frame (%d per second at 60fps)\n",
|
|
|
|
ppf * 2, ppf * 2 * 60);
|
|
|
|
avgfps = -1;
|
|
|
|
polycnt = ppf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_switch() {
|
|
|
|
time_t now;
|
|
|
|
|
|
|
|
now = time(NULL);
|
|
|
|
|
|
|
|
if(now >= (start + 5)) {
|
|
|
|
start = time(NULL);
|
|
|
|
printf(" Average Frame Rate: ~%f fps (%d pps)\n", avgfps, (int)(polycnt * avgfps * 2));
|
|
|
|
|
|
|
|
switch(phase) {
|
|
|
|
case PHASE_HALVE:
|
|
|
|
|
|
|
|
if(avgfps < 55) {
|
|
|
|
switch_tests(polycnt / 1.2f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf(" Entering PHASE_INCR\n");
|
|
|
|
phase = PHASE_INCR;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHASE_INCR:
|
|
|
|
|
|
|
|
if(avgfps >= 55) {
|
|
|
|
switch_tests(polycnt + 15);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf(" Entering PHASE_DECR\n");
|
|
|
|
phase = PHASE_DECR;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHASE_DECR:
|
|
|
|
|
|
|
|
if(avgfps < 55) {
|
|
|
|
switch_tests(polycnt - 30);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf(" Entering PHASE_FINAL\n");
|
|
|
|
phase = PHASE_FINAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHASE_FINAL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2021-04-20 15:08:58 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
#ifdef __DREAMCAST__
|
|
|
|
profiler_init("/pc/gmon.out");
|
|
|
|
profiler_start();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-08-02 19:13:45 +00:00
|
|
|
setup();
|
|
|
|
|
|
|
|
/* Start off with something obscene */
|
|
|
|
switch_tests(200000 / 60);
|
|
|
|
start = time(NULL);
|
|
|
|
|
2021-04-20 15:08:58 +00:00
|
|
|
uint32_t iterations = 2000;
|
|
|
|
|
2018-08-02 19:13:45 +00:00
|
|
|
for(;;) {
|
2021-04-20 15:08:58 +00:00
|
|
|
if(check_start() || iterations-- == 0)
|
2018-08-02 19:13:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
printf(" \r");
|
|
|
|
do_frame();
|
|
|
|
running_stats();
|
|
|
|
check_switch();
|
|
|
|
}
|
|
|
|
|
|
|
|
stats();
|
|
|
|
|
2021-04-20 15:08:58 +00:00
|
|
|
#ifdef __DREAMCAST__
|
|
|
|
#ifndef NDEBUG
|
|
|
|
profiler_stop();
|
|
|
|
profiler_clean_up();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-08-02 19:13:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|