/* * z64 * * This program is free software; you can redistribute it and/ * or modify it under the terms of the GNU General Public Li- * cence as published by the Free Software Foundation; either * version 2 of the Licence, or any later version. * * This program is distributed in the hope that it will be use- * ful, but WITHOUT ANY WARRANTY; without even the implied war- * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public Licence for more details. * * You should have received a copy of the GNU General Public * Licence along with this program; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, * USA. * **/ #include "Gfx #1.3.h" #include "rdp.h" #include "rgl.h" #include #include #include int screen_width = 1024, screen_height = 768; SDL_Surface *sdl_Screen; static __inline__ unsigned long long RDTSC(void) { unsigned long long int x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } void renderquad(int nbtex) { glBegin(GL_TRIANGLE_STRIP); if (nbtex == 2) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.5, 0); if (nbtex == 3) glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.5, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0); glVertex3f(1, 0, 0); if (nbtex == 2) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0); if (nbtex == 3) glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0); glVertex3f(0, 0, 1); if (nbtex == 2) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.5, 0.5); if (nbtex == 3) glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.5, 0.5); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1); glVertex3f(1, 1, 1); if (nbtex == 2) glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0.5); if (nbtex == 3) glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0, 0.5); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1); glVertex3f(0, 1, 0); glEnd(); } void test(int num, const char * vsrc, const char * fsrc, int nbtex) { int i; rglShader_t * shader; static char src[10000]; char * p = src; if (nbtex == 2) p += sprintf(p, "uniform sampler2D texture1; \n" ); if (nbtex == 3) p += sprintf(p, "uniform sampler2D texture2; \n" ); p += sprintf(p, "uniform sampler2D texture0; \n" " \n" "void main() \n" "{ \n" ); p += sprintf(p, fsrc ); p += sprintf(p, "} \n" ); shader = rglCreateShader(vsrc, src); rglUseShader(shader); int location; location = glGetUniformLocationARB(shader->prog, "texture0"); glUniform1iARB(location, 0); if (nbtex == 2) { location = glGetUniformLocationARB(shader->prog, "texture1"); glUniform1iARB(location, 1); } if (nbtex == 3) { location = glGetUniformLocationARB(shader->prog, "texture2"); glUniform1iARB(location, 2); } glDisable(GL_DEPTH_TEST); glViewport(0, 0, screen_width, screen_height); glColor4ub(255,255,255,255); renderquad(nbtex); glFinish(); uint64_t t = RDTSC(); for (i=0; i<10; i++) { renderquad(nbtex); } glFinish(); t = RDTSC() - t; printf("test #%02d %g\n", num, double(t) / 1000000); fflush(stdout); } void dobenchmark() { static char tex[256*256*4]; int i; float env[4]; glewInit(); glViewport(0, 0, screen_width, screen_height); glLoadIdentity(); glScalef(2, 2, 1); glTranslatef(-0.5, -0.5, 0); for (i=0; ihw_available) videoFlags |= SDL_HWSURFACE; else videoFlags |= SDL_SWSURFACE; if(videoInfo->blit_hw) videoFlags |= SDL_HWACCEL; // if (rglStatus == RGL_STATUS_FULLSCREEN) // videoFlags |= SDL_FULLSCREEN; SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); //printf("(II) Setting video mode %dx%d...\n", screen_width, screen_height); if(!(sdl_Screen = SDL_SetVideoMode(screen_width, screen_height, 0, videoFlags))) { printf("(EE) Error setting videomode %dx%d: %s\n", screen_width, screen_height, SDL_GetError()); SDL_QuitSubSystem(SDL_INIT_VIDEO); return -1; } char caption[500]; sprintf(caption, "z64 benchmarker"); SDL_WM_SetCaption(caption, caption); dobenchmark(); rglUseShader(0); SDL_GL_SwapBuffers(); //getchar(); return 0; }