int main(int argc, char* argv[]) { unsigned int i,j; pspDebugScreenInit(); SetupCallbacks(); #ifdef ENABLE_PROFILER // Enable profiling pspDebugProfilerClear(); pspDebugProfilerEnable(); #endif // initialize global context g_context.iterationCount = NUM_VERTEX_BUFFERS * NUM_ITERATIONS; g_context.t = 0; g_context.sint = 0; // initialize torus for (i = 0; i < NUM_SLICES; ++i) { for (j = 0; j < NUM_ROWS; ++j) { float s = i + 0.5f, t = j; float x,y,z; x = (RING_SIZE + RING_RADIUS * cosf(s * ((GU_PI*2)/NUM_SLICES))) * cosf(t * ((GU_PI*2)/NUM_ROWS)); y = (RING_SIZE + RING_RADIUS * cosf(s * ((GU_PI*2)/NUM_SLICES))) * sinf(t * ((GU_PI*2)/NUM_ROWS)); z = RING_RADIUS * sinf(s * ((GU_PI*2)/NUM_SLICES)); torus_vertices[j + i * NUM_ROWS].x = x; torus_vertices[j + i * NUM_ROWS].y = y; torus_vertices[j + i * NUM_ROWS].z = z; } } // initialize torus modifiers for (j = 0; j < NUM_ROWS; ++j) { float t = j; torus_modifiers[j].x = 0; torus_modifiers[j].y = 0; torus_modifiers[j].z = 0.3*cosf( t * 8.0f *((GU_PI*2)/NUM_ROWS) ); } // init GU and set callbacks sceGuInit(); // 0x01 - user callback // 0x04 - 'rendering finished' callback sceGuSetCallback(1, &mySignalHandler); sceGuSetCallback(4, &myFinishHandler); // setup GU sceGuStart(GU_DIRECT,list); sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUF_WIDTH); sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x88000,BUF_WIDTH); sceGuDepthBuffer((void*)0x110000,BUF_WIDTH); sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2)); sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT); sceGuDepthRange(0xc350,0x2710); sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuAlphaFunc(GU_GREATER,0,0xff); sceGuEnable(GU_ALPHA_TEST); sceGuDepthFunc(GU_GEQUAL); sceGuEnable(GU_DEPTH_TEST); sceGuFrontFace(GU_CW); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_CULL_FACE); sceGuEnable(GU_TEXTURE_2D); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); // run sample #ifdef USING_SIGNALS sceGuCallMode(1); #endif // generate callable command-list with texture setup { sceGuStart(GU_CALL, smallList1); // setup texture sceGuTexMode(GU_PSM_5551,0,0,0); sceGuTexImage(0,32,32,32,ball_start); // width, height, buffer width, tbp sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGBA); // NOTE: this enables reads of the alpha-component from the texture, otherwise blend/test won't work sceGuTexFilter(GU_NEAREST,GU_NEAREST); sceGuTexWrap(GU_CLAMP,GU_CLAMP); sceGuTexScale(1,1); sceGuTexOffset(0,0); sceGuAmbientColor(0xffffffff); sceGuFinish(); sceGuSync(0,0); } // generate callable command-list for cube rendering { sceGuStart(GU_CALL, smallList2); // draw cube sceGuDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,cubeVertices); sceGuFinish(); sceGuSync(0,0); } for(;;) { sceGuStart(GU_DIRECT,list); unsigned int i = 0; for( ; i < NUM_VERTEX_BUFFERS; i++ ) g_context.vbuffer[i] = sceGuGetMemory((NUM_SLICES/g_context.iterationCount) * 2 * NUM_ROWS * sizeof(Vertex)); g_context.vertsRendered = 0; // clear screen sceGuClearColor(0x00334455); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); // setup matrices sceGumMatrixMode(GU_PROJECTION); sceGumLoadIdentity(); sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f); sceGumMatrixMode(GU_VIEW); sceGumLoadIdentity(); sceGumMatrixMode(GU_MODEL); { ScePspFVector3 pos = {0.0f,0.0f,-3.5f}; ScePspFVector3 rot = {g_context.t * 0.3f * (GU_PI/180.0f), g_context.t * 0.7f * (GU_PI/180.0f), g_context.t * 1.3f * (GU_PI/180.0f)}; sceGumLoadIdentity(); sceGumTranslate(&pos); sceGumRotateXYZ(&rot); } sceGumStoreMatrix(&g_context.world); // call pregenerated command-list to setup texture sceGuCallList(smallList1); // start billboard rendering render_billboards(0); // call pregenerated command-list to render cube { ScePspFVector3 scale = {0.3f, 0.3f, 0.3f}; sceGumScale(&scale); } sceGumUpdateMatrix(); sceGuCallList(smallList2); #ifndef USING_SIGNALS // HACK: sceGuFinish() is called inside the signal interupt handler when all rendering job is done // this is done in order to stall GPU if it is ahead of CPU sceGuFinish(); #endif sceGuSync(0,0); #ifndef ENABLE_FRAMERATE // wait for next frame sceDisplayWaitVblankStart(); #endif sceGuSwapBuffers(); pspDebugScreenSetXY(0,0); #ifdef ENABLE_PROFILER // Print profile information to the screen pspDebugProfilerPrint(); #endif #ifdef ENABLE_FRAMERATE // simple frame rate counter static float curr_ms = 1.0f; static struct timeval time_slices[16]; static int t = 0; float curr_fps = 1.0f / curr_ms; t++; float vertsPerSec = g_context.vertsRendered*curr_fps; float kbPerSec = vertsPerSec * sizeof(Vertex) / 1024.0f; gettimeofday(&time_slices[t & 15],0); pspDebugScreenPrintf("fps: %d.%03d ms: %d vert/s: %dK MB/s: %d.%03d",(int)curr_fps, ((int)(curr_fps*1000.0f)%1000), (int)(curr_ms*1000.0f), (int)(vertsPerSec/1000.0f), (int)(kbPerSec/1024.0f), (int)((1000.0f/1024.0f)*((int)kbPerSec%1024)) ); if (!(t & 15)) { struct timeval last_time = time_slices[0]; unsigned int i; curr_ms = 0; for (i = 1; i < 16; ++i) { struct timeval curr_time = time_slices[i]; int curr_time_usec = curr_time.tv_usec + curr_time.tv_sec * 1000000; int last_time_usec = last_time.tv_usec + last_time.tv_sec * 1000000; if( last_time_usec < curr_time_usec ) curr_ms += (( curr_time_usec - last_time_usec ) * (1.0f/1000000.0f)); last_time = time_slices[i]; } curr_ms /= 15.0f; } #endif } sceGuTerm(); sceKernelExitGame(); return 0; }
void update_frame_ge(void) { check_gba_video_status(); // return; // printf("video mode: %u\n", gba_video_registers->lcd_control.bg_mode); int i; palette_ram_8bit[0]=palette_ram[0]&0x7FFF; for (i=1; i<256;i++) palette_ram_8bit[i]=palette_ram[i]|0x8000; palette_ram_8bit[256]=palette_ram[256]&0x7FFF; for (i=257; i<512;i++) palette_ram_8bit[i]=palette_ram[i]|0x8000; for (i=0; i<512;i++) { if (i&0xF) palette_ram_4bit[i]=palette_ram_8bit[i]|0x8000; else palette_ram_4bit[i]=palette_ram_8bit[i]&0x7FFF; } // sceKernelDcacheWritebackAll(); // sceKernelDcacheWritebackInvalidateAll(); RETRO_PERFORMANCE_INIT(gu_sync_time); RETRO_PERFORMANCE_START(gu_sync_time); sceGuSync(0,0); RETRO_PERFORMANCE_STOP(gu_sync_time); main_context_status= sceGuGetAllStatus(); sceGeSaveContext(&main_context_buffer); sceGuSetCallback(GU_CALLBACK_FINISH, list_finish_callback); sceGuStart(GU_DIRECT, d_list); init_3Dprojection(); setup_3Dprojection_16bit(); sceGuDisable(GU_DEPTH_TEST); // sceGuDepthBuffer((void*)VRAM_DEPTH,512); sceGuDepthMask(GU_TRUE); sceGuDepthRange(0,65535); sceGuDisable(GU_CULL_FACE); sceGuDisable(GU_CLIP_PLANES); // sceGuTexFilter(GU_NEAREST,GU_NEAREST); RETRO_PERFORMANCE_INIT(gba_upload_vram_proc); RETRO_PERFORMANCE_START(gba_upload_vram_proc); gba_upload_vram(); RETRO_PERFORMANCE_STOP(gba_upload_vram_proc); // sceGuDrawBufferList(GU_PSM_5551, GBA_FRAME_TEXTURE_GU, GBA_LINE_SIZE); sceGuDrawBufferList(GU_PSM_8888, GBA_FRAME_TEXTURE_GU, GBA_LINE_SIZE); sceGuDepthBuffer(GBA_DEPTH_BUFFER, GBA_LINE_SIZE); sceGuScissor(0,0,GBA_SCREEN_WIDTH,GBA_SCREEN_HEIGHT); sceGuScissor(0,0,240,160); sceGuEnable(GU_SCISSOR_TEST); // sceGuClearColor(0x000000FF); // sceGuClearColor((palette_ram[0]&0x1F<<3)|(palette_ram[0]&0x3E0<<6)|(palette_ram[0]&0x7C00<<9)|0xFF000000); sceGuClearColor(GU_COLOR(((palette_ram[0]>> 0) & 31) / 31.0f, ((palette_ram[0]>> 5) & 31) / 31.0f, ((palette_ram[0]>>10) & 31) / 31.0f, 1.0)); sceGuClear(GU_COLOR_BUFFER_BIT); // if (gba_draw_bg[gba_video_registers->lcd_control.bg_mode]) // gba_draw_bg[gba_video_registers->lcd_control.bg_mode](); RETRO_PERFORMANCE_INIT(gba_draw_bg_mode0_proc); RETRO_PERFORMANCE_START(gba_draw_bg_mode0_proc); gba_draw_bg_mode0(); RETRO_PERFORMANCE_STOP(gba_draw_bg_mode0_proc); // sceGuFinish(); sceGuFinishId(GBA_DISPLAY_LIST_ID); // RETRO_PERFORMANCE_INIT(gu_sync_time); // RETRO_PERFORMANCE_START(gu_sync_time); // sceGuSync(0,0); // RETRO_PERFORMANCE_STOP(gu_sync_time); }