pgeTexture* pgeTextureLoadMemory(unsigned char *buffer, int size, enum pgeMemoryLocation location, unsigned char swizzle) { pgeTexture *texture = (pgeTexture*) pgeMalloc(sizeof(pgeTexture)); if(!texture) return NULL; texture->location = location; if(!pgeTextureLoadPngMemoryInternal(buffer, size, texture)) { pgeFree(texture); return NULL; } sceKernelDcacheWritebackAll(); if(swizzle) { #ifdef __PSP__ if(!pgeTextureSwizzle(texture)) { pgeFree(texture); return NULL; } #endif } sceKernelDcacheWritebackAll(); return texture; }
int LoadGraph(const char *FileName) { GUINITCHECK; DXPGRAPHICSHANDLE *gptr = NULL; DXPTEXTURE3 *texptr = NULL; gptr = dxpGraphicsCreateGraphicHandle(); if(!gptr)return -1; texptr = LoadPngImage(FileName); if(!texptr) { dxpGraphicsReleseGraphicHandle(gptr); return -1; } gptr->tex = texptr; ++texptr->refcount; gptr->u0 = gptr->v0 = 0; gptr->u1 = texptr->umax; gptr->v1 = texptr->vmax; if(dxpGraphicsData.create_vram_graph)MoveGraphToVRAM(gptr->handle); if(dxpGraphicsData.create_swizzled_graph)SwizzleGraph(gptr->handle); // AppLogAdd("fh=%d;uv::%d,%d,%d,%d",gptr->handle,gptr->u0,gptr->u1,gptr->v0,gptr->v1); sceKernelDcacheWritebackAll(); return gptr->handle; }
void _gStart() { if (!init) _gInit(); sceKernelDcacheWritebackAll(); sceGuStart(GU_DIRECT,list); start = G_TRUE; }
int InitME(volatile struct me_struct *mei, int devkitVersion) { unsigned int k1; k1 = pspSdkSetK1(0); if (mei == 0) { pspSdkSetK1(k1); return -1; } // initialize the MediaEngine Instance mei->start = 0; mei->done = 1; mei->func = 0; mei->param = 0; mei->result = 0; mei->precache_len = 0; mei->precache_addr = 0; mei->postcache_len = 0; mei->postcache_addr = 0; mei->signals = 0; mei->init = 1; // start the MediaEngine memcpy((void *)0xbfc00040, me_stub, (int)(me_stub_end - me_stub)); _sw((unsigned int)me_loop, 0xbfc00600); // k0 _sw((unsigned int)mei, 0xbfc00604); // a0 sceKernelDcacheWritebackAll(); if (devkitVersion < 0x03070110) { sceSysregMeResetEnable(); sceSysregMeBusClockEnable(); sceSysregMeResetDisable(); } else { sceSysregMeResetEnable371(); sceSysregMeBusClockEnable371(); sceSysregMeResetDisable371(); } //Find SceMeRpc and disable it(causes indefinate wait when handling events, like suspend) PspSysEventHandler *handlers = sceKernelReferSysEventHandler(); while (handlers != NULL){ if (strcmp(handlers->name, "SceMeRpc") == 0){ handler = handlers; sceKernelUnregisterSysEventHandler(handler); break; } handlers = handlers->next; } pspSdkSetK1(k1); return 0; }
/* Must be called from KERNEL thread */ int pspAdhocLoadDrivers() { _net_adhoc_matching_start = 0; _net_adhoc_matching_create = 0; _net_adhoc_matching_init = 0; _net_adhoc_pdp_create = 0; _net_adhoc_ctl_connect = 0; _net_adhoc_ctl_init = 0; _net_adhoc_init = 0; _net_init = 0; #if (_PSP_FW_VERSION < 200) int modID; modID = pspSdkLoadStartModule("flash0:/kd/ifhandle.prx", PSP_MEMORY_PARTITION_KERNEL); if (modID < 0) return modID; modID = pspSdkLoadStartModule("flash0:/kd/memab.prx", PSP_MEMORY_PARTITION_KERNEL); if (modID < 0) return modID; modID = pspSdkLoadStartModule("flash0:/kd/pspnet_adhoc_auth.prx", PSP_MEMORY_PARTITION_KERNEL); if (modID < 0) return modID; modID = pspSdkLoadStartModule("flash0:/kd/pspnet.prx", PSP_MEMORY_PARTITION_USER); if (modID < 0) return modID; else pspSdkFixupImports(modID); modID = pspSdkLoadStartModule("flash0:/kd/pspnet_adhoc.prx", PSP_MEMORY_PARTITION_USER); if (modID < 0) return modID; else pspSdkFixupImports(modID); modID = pspSdkLoadStartModule("flash0:/kd/pspnet_adhocctl.prx", PSP_MEMORY_PARTITION_USER); if (modID < 0) return modID; else pspSdkFixupImports(modID); modID = pspSdkLoadStartModule("flash0:/kd/pspnet_adhoc_matching.prx", PSP_MEMORY_PARTITION_USER); if (modID < 0) return modID; else pspSdkFixupImports(modID); sceKernelDcacheWritebackAll(); sceKernelIcacheInvalidateAll(); #else sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON); sceUtilityLoadNetModule(PSP_NET_MODULE_ADHOC); #endif return 1; }
void renderSH(const int* m) { struct Vertex* vtx = vertices; struct Vertex* currvtx = vtx; float du = (GU_PI*2) / (GRID_WIDTH-1); float dv = GU_PI / (GRID_HEIGHT-1); unsigned int i,j; // position for (i = 0; i < GRID_WIDTH; ++i) { float u = fmod(i * du,GU_PI*2); for (j = 0; j < GRID_HEIGHT; ++j) { float v = (j * dv); evalSH(u,v,m,&(currvtx->position)); currvtx++; } } // normal for (i = 0; i < GRID_WIDTH; ++i) { for (j = 0; j < GRID_HEIGHT; ++j) { ScePspFVector3 l1,l2; unsigned short* curr = &indices[(j + (i * (GRID_HEIGHT))) * 6]; ScePspFVector3* normal = &vtx[curr[0]].normal; l1.x = vtx[curr[1]].position.x - vtx[curr[0]].position.x; l1.y = vtx[curr[1]].position.y - vtx[curr[0]].position.y; l1.z = vtx[curr[1]].position.z - vtx[curr[0]].position.z; l2.x = vtx[curr[2]].position.x - vtx[curr[0]].position.x; l2.y = vtx[curr[2]].position.y - vtx[curr[0]].position.y; l2.z = vtx[curr[2]].position.z - vtx[curr[0]].position.z; gumCrossProduct(normal,&l1,&l2); gumNormalize(normal); } } sceKernelDcacheWritebackAll(); sceGumDrawSpline(GU_NORMAL_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF, GRID_HEIGHT,GRID_WIDTH,3,3,indices,vertices); }
void *psp_showPage(image *framebuffer, int tyres) { //perhaps: //sync at the top, instead of the bottom, //so that the framerendering can go on while the engine //proceeds instead of having to wait in showpage //sceGuSync(0,0); //swap the R and B bitfields, goddammit /*int w = framebuffer->width; int p = framebuffer->pitch; int h = framebuffer->height; unsigned short *buf = (unsigned short *)framebuffer->data; for(int y=0;y<h;y++) { for(int x=0;x<w;x++) buf[x] = (buf[x]<<11)|(buf[x]>>11)|(buf[x]&0x07E0); buf += p; }*/ //make sure the software buffer is flushed sceKernelDcacheWritebackAll(); //sceGuStart(GU_DIRECT,list); //// clear screen ////sceGuClearColor(0xff000000); ////sceGuClear(GU_COLOR_BUFFER_BIT); //sceGuTexMode(GU_PSM_5650,0,0,0); //sceGuTexImage(0,framebuffer->pitch,tyres,framebuffer->pitch,framebuffer->data); //sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB); //sceGuTexFilter(GU_NEAREST,GU_NEAREST); //sceGuTexScale(1.0f/(float)framebuffer->pitch,1.0f/(float)tyres); //sceGuTexOffset(0.0f,0.0f); //psp_renderSprite(0, // (480-framebuffer->width)/2, // (272-framebuffer->height)/2, // framebuffer->width,framebuffer->height); //sceGuFinish(); //sceGuSync(0,0); sceDisplayWaitVblankStart(); void *backBuffer = sceGuSwapBuffers(); //sceGuSync(0,0); return backBuffer; //sceDisplayWaitVblankStart(); }
int hook_global_module_jal(SceModule2 * mod, uint32_t oldcall, uint32_t newcall) { // Invalid Arguments if(mod == NULL) return -1; // Hook Counter int counter = 0; // Machine Code of Module uint32_t * asmtext = (uint32_t *)mod->text_addr; // Machine Code Segment Size uint32_t asmsize = mod->text_size; // ASM Iterator uint32_t i = 0; // Iterate Machine Code for(; i < asmsize / 4; i ++) { // Get Instruction uint32_t inst = asmtext[i]; // JAL Instruction if((inst & 0xFC000000) == 0x0C000000) { // Matching JAL found if(GET_CALL_ADDR(inst) == oldcall) { // Overwrite JAL asmtext[i] = MAKE_CALL(newcall); // Log Overwrite counter++; } } } // Hooked Calls if(counter > 0) { // Synchronize Cache sceKernelDcacheWritebackAll(); sceKernelIcacheInvalidateAll(); } // Return Hook Counter return counter; }
/** * start_channel: Allocate a new channel and starts playback. * * [Parameters] * buffer_desc: Playback buffer descriptor * [Return value] * Nonzero on success, zero on error */ static int start_channel(PSPSoundBufferDesc *buffer_desc) { if (!buffer_desc) { DMSG("buffer_desc == NULL"); return 0; } if (buffer_desc->started) { DMSG("Buffer is already started!"); return 0; } /* Allocate a hardware channel */ buffer_desc->channel = sceAudioChReserve( PSP_AUDIO_NEXT_CHANNEL, BUFFER_SIZE, PSP_AUDIO_FORMAT_STEREO ); if (buffer_desc->channel < 0) { DMSG("Failed to allocate channel: %s", psp_strerror(buffer_desc->channel)); return 0; } /* Initialize the ring buffer */ buffer_desc->cur_play = NUM_BUFFERS - 1; buffer_desc->next_play = 0; buffer_desc->next_write = 0; int i; for (i = 0; i < NUM_BUFFERS; i++) { buffer_desc->write_ready[i] = 1; } buffer_desc->stop = 0; /* Also write everything out of the cache so it's ready for the ME */ sceKernelDcacheWritebackAll(); /* Start the playback thread */ char thname[100]; snprintf(thname, sizeof(thname), "YabauseSoundCh%d", buffer_desc->channel); SceUID handle = sys_start_thread(thname, playback_thread, THREADPRI_SOUND, 0x1000, sizeof(buffer_desc), &buffer_desc); if (handle < 0) { DMSG("Failed to create thread: %s", psp_strerror(handle)); sceAudioChRelease(buffer_desc->channel); return 0; } buffer_desc->thread = handle; /* Success */ buffer_desc->started = 1; return 1; }
pgeTexture* pgeTextureLoad(const char *filename, enum pgeMemoryLocation location, unsigned char swizzle) { pgeTexture *texture = (pgeTexture*) pgeMalloc(sizeof(pgeTexture)); if(!texture) { debugOut("12\n"); return NULL; } texture->location = location; if(!pgeTextureLoadPngFile(filename, texture)) { debugOut("13\n"); pgeFree(texture); return NULL; } sceKernelDcacheWritebackAll(); if(swizzle) { #ifdef __PSP__ if(!pgeTextureSwizzle(texture)) { debugOut("14\n"); pgeFree(texture); return NULL; } #endif } sceKernelDcacheWritebackAll(); return texture; }
static void addmedialistpath(char *path) { int dirid; int retval; int x; int found; SceIoDirent *direntt; if ((dirid = sceIoDopen(path)) > 0) { // Opened ok retval = 1; //direntt = (SceIoDirent *)malloc(sizeof(SceIoDirent)); direntt = (SceIoDirent *) & direnta; while ((retval > 0) && (files_infonum < MAX_FILE_NUM)) { retval = sceIoDread(dirid, direntt); if (retval > 0) { sceKernelDcacheWritebackAll(); if ((direntt->d_stat.st_attr & 0x10) == 0x10) { // directory if (direntt->d_name[0] != '.') { char *pathname = (char *) malloc(200); sprintf(pathname, "%s%s/", path, direntt->d_name); addmedialistpath(pathname); //free(pathname); // dont free, as used in files } } // else if (((direntt->d_stat.st_attr & 0x20) == 0x20) && (direntt->d_name[0] != 0)) { // File else if (direntt->d_name[0] != 0) { // File // Only add files of types known to codecs loaded // Now check against the codecs known to us found = 0; for (x = 0; x < codecnum; x++) { char *ptr = stubs[x].extension; while (*ptr != 0) { if (strncasecmp(&direntt->d_name[strlen(direntt->d_name) - 3], ptr, 3) == 0) found = 1; ptr += 4; } } if (found == 1) { files_info[files_infonum].filename = (char *) malloc(200); memcpy(files_info[files_infonum].filename, direntt->d_name, 200); files_info[files_infonum].pathname = path; files_infonum++; } // if found } // if d_name } // if retval //free(direntt); } // while sceIoDclose(dirid); } // if }
int InitME(volatile struct me_struct *mei, int devkitVersion) { unsigned int k1; k1 = pspSdkSetK1(0); if (mei == 0) { pspSdkSetK1(k1); return -1; } // initialize the MediaEngine Instance mei->start = 0; mei->done = 1; mei->func = 0; mei->param = 0; mei->result = 0; mei->precache_len = 0; mei->precache_addr = 0; mei->postcache_len = 0; mei->postcache_addr = 0; mei->signals = 0; mei->init = 1; // start the MediaEngine memcpy((void *)0xbfc00040, me_stub, (int)(me_stub_end - me_stub)); _sw((unsigned int)me_loop, 0xbfc00600); // k0 _sw((unsigned int)mei, 0xbfc00604); // a0 sceKernelDcacheWritebackAll(); if (devkitVersion < 0x03070110) { sceSysregMeResetEnable(); sceSysregMeBusClockEnable(); sceSysregMeResetDisable(); } else { sceSysregMeResetEnable371(); sceSysregMeBusClockEnable371(); sceSysregMeResetDisable371(); } pspSdkSetK1(k1); return 0; }
gImage* gTexLoad(char path[], bool use_swizzle) { if (path == NULL) return NULL; gImage* tex = malloc(sizeof(gImage)); if (tex == NULL) return NULL; FILE* fp = fopen(path,"rb"); if (fp == NULL) return NULL; #ifdef USE_PNG if (strstr(path,".png") != NULL) { _gTexLoadPNG(fp,tex); tex->can_blend = G_TRUE; } #endif #ifdef USE_JPEG if (strstr(path,".jpg") != NULL || strstr(path,".jpeg") != NULL ) { _gTexLoadJPEG(fp,tex); tex->can_blend = G_FALSE; } #endif fclose(fp); sceKernelDcacheWritebackAll(); // The PSP can't draw 512*512+ textures. if (tex->w > 512 || tex->h > 512) { gTexFree(&tex); return NULL; } // Swizzling is useless with small textures. if (use_swizzle && (tex->w >= 16 || tex->h >= 16)) { u8* tmp = malloc(tex->tw*tex->th*PIXEL_SIZE); _swizzle(tmp,(u8*)tex->data,tex->tw*PIXEL_SIZE,tex->th); free(tex->data); tex->data = (gColor*)tmp; tex->swizzled = G_TRUE; } return tex; }
void App_Initialize( void ) { Gamepad gamepad; dList = malloc( 262144 ); sceneList = malloc( 262144 ); fbp0 = 0; sceKernelDcacheWritebackAll(); pspDebugScreenInit(); myScene = new Scene(SCR_WIDTH, SCR_HEIGHT); /////////////////////////////////////////////////// // Load Resources /////////////////////////////////////////////////// char *sceneName = "courtyard.lws"; printf("Loading Lightwave Scene: %s\n", sceneName); loadLWS(*myScene, sceneName); // printf("Caching CVR scene: %s\n", sceneName); // myScene->cache(true); printf("Retrieving scene motion controller: %s\n", sceneName); mySceneMotion = &myScene->motion(sceneName); /////////////////////////////////////////////////// // END Load Resources /////////////////////////////////////////////////// printf("\n\n--------------------------\n"); printf(" Press X to start...\n"); printf("--------------------------\n\n\n"); while(!gamepad.ButtonDown(PSP_CTRL_CROSS)) { gamepad.Poll(); } InitGU(); SetupProjection(); SetupCallbacks(); }
int MakeGraphFromScreen(void) { GUINITCHECK; DXPGRAPHICSHANDLE *gptr = dxpGraphicsCreateGraphicHandle(); if ( !gptr ) return -1; DXPTEXTURE3 *texptr = LoadScreen(); if ( !texptr ) { dxpGraphicsReleseGraphicHandle(gptr); return -1; } gptr->tex = texptr; ++texptr->refcount; gptr->u0 = gptr->v0 = 0; gptr->u1 = texptr->umax; gptr->v1 = texptr->vmax; if ( dxpGraphicsData.create_vram_graph ) MoveGraphToVRAM( gptr->handle ); if ( dxpGraphicsData.create_swizzled_graph ) SwizzleGraph( gptr->handle ); sceKernelDcacheWritebackAll(); return gptr->handle; }
int pgeTextureToVram(pgeTexture *texture) { if(texture->location == PGE_VRAM) return 0; unsigned int *destination = (unsigned int *)pgeVramAlloc(texture->size); if(destination == NULL) return 0; memcpy(destination, texture->data, texture->size); pgeFree(texture->data); texture->data = destination; texture->location = PGE_VRAM; sceKernelDcacheWritebackAll(); return 1; }
void indicesSH() { unsigned short i,j; for (i = 0; i < GRID_WIDTH; ++i) { for (j = 0; j < GRID_HEIGHT; ++j) { unsigned short* curr = &indices[(j + (i * (GRID_HEIGHT))) * 6]; unsigned short i1 = (i+1) % GRID_WIDTH; unsigned short j1 = (j+1) % GRID_HEIGHT; *curr++ = j + i * GRID_HEIGHT; *curr++ = j1 + i * GRID_HEIGHT; *curr++ = j + i1 * GRID_HEIGHT; *curr++ = j1 + i * GRID_HEIGHT; *curr++ = j1 + i1 * GRID_HEIGHT; *curr++ = j + i1 * GRID_HEIGHT; } } sceKernelDcacheWritebackAll(); }
int module_start( SceSize args, void *argp ) { SceUID file = sceIoOpen("ms0:/seplugins/language.bin", PSP_O_RDONLY, 0777); if (!file) { return 0; } sceIoRead(file, &languagePatch, 1); sceIoClose(file); if ((languagePatch < 0) || (languagePatch > 11)) { return 0; } u32 functionAddress = sctrlHENFindFunction("sceUtility_Driver", "sceUtility", 0xA5DA2406); sceUtilityGetSystemParamInt = (void *)functionAddress; sctrlHENPatchSyscall(functionAddress, sceUtilityGetSystemParamInt_patched); sceKernelDcacheWritebackAll(); sceKernelIcacheClearAll(); return 0; }
// ZIPで圧縮されたRONのロード // 返り値:-2=一時ファイルを作成/-1=エラー/その他=ROMのサイズ // もし、ROMのサイズ>ROMバッファのサイズ の場合は一時ファイルを作成 s32 load_file_zip(char *filename) { struct SZIPFileHeader data; char tmp[MAX_PATH]; s32 retval = -1; u8 *buffer = NULL; u8 *cbuffer; char *ext; FILE_ID fd; FILE_ID tmp_fd; u32 zip_buffer_size; u32 write_tmp_flag = NO; u32 use_vram; use_vram = NO; zip_buffer_size = 16 * 1024 * 1024; cbuffer = malloc(zip_buffer_size); while(cbuffer == NULL) { zip_buffer_size -= (256 * 1024); if(zip_buffer_size == 0) break; cbuffer = malloc(zip_buffer_size); } if(zip_buffer_size == 0) { use_vram = YES; zip_buffer_size = ZIP_BUFFER_SIZE; cbuffer = (u8 *)UNIVERSAL_VRAM_ADDR; // 汎用フレームバッファを使用 } chdir(rom_path); FILE_OPEN(fd, filename, READ); if(!FILE_CHECK_VALID(fd)) return -1; { FILE_READ(fd, &data, sizeof(struct SZIPFileHeader)); // EDIT: Check if this is a zip file without worrying about endian // It checks for the following: 0x50 0x4B 0x03 0x04 (PK..) // Used to be: if(data.Sig != 0x04034b50) break; if( data.Sig[0] != 0x50 || data.Sig[1] != 0x4B || data.Sig[2] != 0x03 || data.Sig[3] != 0x04 ) { goto outcode; } FILE_READ(fd, tmp, data.FilenameLength); tmp[data.FilenameLength] = 0; // end string if(data.ExtraFieldLength) FILE_SEEK(fd, data.ExtraFieldLength, SEEK_CUR); if(data.GeneralBitFlag & 0x0008) { FILE_READ(fd, &data.DataDescriptor, sizeof(struct SZIPFileDataDescriptor)); } ext = strrchr(tmp, '.') + 1; // file is too big if(data.DataDescriptor.UncompressedSize > gamepak_ram_buffer_size) { write_tmp_flag = YES; // テンポラリを使用するフラグをONに FILE_OPEN(tmp_fd, ZIP_TMP, WRITE); } else write_tmp_flag = NO; if(!strncasecmp(ext, "bin", 3) || !strncasecmp(ext, "gba", 3)) { buffer = gamepak_rom; // ok, found switch(data.CompressionMethod) { case 0: //無圧縮 retval = data.DataDescriptor.UncompressedSize; FILE_READ(fd, buffer, retval); goto outcode; case 8: //圧縮 { z_stream stream = {0}; s32 err; /* * z.next_in = 入力ポインタ; * z.avail_in = 入力データの残量; * z.next_out = 出力ポインタ; * z.avail_out = 出力バッファの残量; */ stream.next_in = (Bytef*)cbuffer; stream.avail_in = (u32)zip_buffer_size; stream.next_out = (Bytef*)buffer; if(write_tmp_flag == NO) { stream.avail_out = data.DataDescriptor.UncompressedSize; retval = (u32)data.DataDescriptor.UncompressedSize; } else { stream.avail_out = gamepak_ram_buffer_size; retval = -2; } stream.zalloc = (alloc_func)0; stream.zfree = (free_func)0; stream.opaque = (voidpf)0; err = inflateInit2(&stream, -MAX_WBITS); FILE_READ(fd, cbuffer, zip_buffer_size); sceKernelDcacheWritebackAll(); if(err == Z_OK) { while(err != Z_STREAM_END) { err = inflate(&stream, Z_SYNC_FLUSH); if(err == Z_BUF_ERROR) { stream.avail_in = (u32)zip_buffer_size; stream.next_in = (Bytef*)cbuffer; FILE_READ(fd, cbuffer, zip_buffer_size); sceKernelDcacheWritebackAll(); } if((write_tmp_flag == YES) && (stream.avail_out == 0)) /* 出力バッファが尽きれば */ { FILE_WRITE(tmp_fd, buffer, gamepak_ram_buffer_size); stream.next_out = buffer; /* 出力ポインタを元に戻す */ stream.avail_out = gamepak_ram_buffer_size; /* 出力バッファ残量を元に戻す */ } } if((write_tmp_flag == YES) && ((gamepak_ram_buffer_size - stream.avail_out) != 0)) FILE_WRITE(tmp_fd, buffer, gamepak_ram_buffer_size - stream.avail_out); err = Z_OK; inflateEnd(&stream); } goto outcode; } } } } outcode: FILE_CLOSE(fd); if(write_tmp_flag == YES) FILE_CLOSE(tmp_fd); if(use_vram == NO) free(cbuffer); chdir(main_path); return retval; }
void S9xSceGURenderTex (char *tex, int width, int height, int x, int y, int xscale, int yscale, int xres, int yres) { // If you don't call this, Gu will run into cache problems with // reading pixel data... sceKernelDcacheWritebackAll (); unsigned int j; const int slice_scale = ((float)xscale / (float)width) * (float)SLICE_SIZE; const int tex_filter = (PSP_Settings.bBilinearFilter ? GU_LINEAR : GU_NEAREST); struct Vertex* vertices; struct Vertex* vtx_iter; // If the x/y scale matches the width/height, we can take a shortcut and // merely copy tex into the VRAM at the given (x,y) coordinate. // // NOTE: This disables bilinear filtering, but that's not saying a whole // lot, since the image will not require a min / mag filter. if ((xscale == width) && (yscale == height)) { sceGuStart (0, SceGU.list); sceGuCopyImage (SceGU.pixel_format, 0, 0, xres, yres, width, tex, x, y, SceGU.line_size, (void *)(0x04000000 + (uint32)SceGU.vram_offset)); sceGuFinish (); } // If the scale doesn't match the width/height, we have to perform a // special blit to stretch the image. else { #ifdef SCEGU_DIRECT_COPY sceGuStart (0, SceGU.list); sceGuCopyImage (SceGU.pixel_format, 0, 0, width, height, width, tex, 0, 0, SceGU.line_size, (void *)(0x04000000 + (uint32)SceGU.vram_offset)); #endif sceGuStart (0, SceGU.list); sceGuTexMode (SceGU.texture_format, 0, 0, 0); #ifndef SCEGU_DIRECT_COPY sceGuTexImage (0, width, height, width, tex); #else sceGuTexImage (0, width, height, SceGU.line_size, (void *)(0x04000000 + (uint32)SceGU.vram_offset)); #endif sceGuTexFunc (GU_TFX_REPLACE, 0); sceGuTexFilter (tex_filter, tex_filter); sceGuTexScale (1, 1); sceGuTexOffset (0, 0); sceGuAmbientColor (0xffffffff); sceGuScissor (x, y, xres, yres); #ifdef DRAW_SINGLE_BATCH // Allocate (memory map) the "vertex array" beforehand const int num_verts = (width / SLICE_SIZE) * 2; const int vtx_alloc = num_verts * sizeof (struct Vertex); vertices = (struct Vertex *)sceGuGetMemory (vtx_alloc); vtx_iter = vertices; #endif // Do a striped blit (takes the page-cache into account) for (j = 0; j < width; j += SLICE_SIZE, x += slice_scale) { #ifndef DRAW_SINGLE_BATCH vtx_iter = (struct Vertex *)sceGuGetMemory (sizeof (struct Vertex) * 2); #endif vtx_iter [0].u = j; vtx_iter [0].v = 0; vtx_iter [0].x = x; vtx_iter [0].y = y; vtx_iter [0].z = 0; vtx_iter [1].u = (j + SLICE_SIZE); vtx_iter [1].v = height; vtx_iter [1].x = (x + slice_scale); vtx_iter [1].y = (y + yscale); vtx_iter [1].z = 0; vtx_iter [0].color = vtx_iter [1].color = 0; #ifndef DRAW_SINGLE_BATCH sceGuDrawArray (GU_SPRITES, SceGU.tt | SceGU.ct | SceGU.mt | SceGU.dm, 2, 0, vtx_iter); vtx_iter += 2; #endif } #ifdef DRAW_SINGLE_BATCH sceGuDrawArray (GU_SPRITES, GE_SETREG_VTYPE (SceGU.tt, SceGU.ct, 0, SceGU.mt, 0, 0, 0, 0, SceGU.dm), num_verts, 0, vertices); #endif sceGuFinish (); } #ifdef SCEGU_DOUBLE_BUFFERED sceGuSync (0, 0); if (PSP_Settings.bVSync) sceDisplayWaitVblankStart (); #endif #ifdef SCEGU_DOUBLE_BUFFERED S9xSceGUSwapBuffers (); #endif }
void CPlanarShadow::render() { video::IVideoDriver* driver = SceneManager->getVideoDriver(); int i; core::vector3df lpos; s32 lights = SceneManager->getVideoDriver()->getDynamicLightCount(); for (i=0; i<lights; ++i) { const video::SLight& dl = SceneManager->getVideoDriver()->getDynamicLight(i); lpos = dl.Position; if (dl.CastShadows && fabs((lpos - Transform.getTranslation()).getLengthSQ()) <= (dl.Radius*dl.Radius*4.0f)) { core::matrix4 mat; mat.buildShadowMatrix(dl.Position, Plane, 0.f ); mat *= Transform; core::matrix4 backup_view = driver->getTransform(video::ETS_VIEW); mat = View*mat; for (int x = 0; x<16; x++) mat.M[x]/=Divisor; driver->setTransform(video::ETS_VIEW, core::matrix4()); driver->setTransform(video::ETS_WORLD, mat); glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT ); glEnable(GL_STENCIL_TEST); glDisable(GL_ALPHA_TEST); glDisable(GL_TEXTURE_2D); if (enableDepth == false) glDisable (GL_DEPTH_TEST ); else { glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); } glStencilOp(GL_INCR, GL_INCR, GL_INCR); glStencilFunc(GL_EQUAL, 128, 0xFF); video::SColor pow = SceneManager->getShadowColor(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_LIGHTING); glColor4f(pow.getRed()/255.f, pow.getGreen()/255.f, pow.getBlue()/255.f, pow.getAlpha()/255.f); sceKernelDcacheWritebackAll(); __pspgl_context_render_prim(pspgl_curctx, GE_TRIANGLES, IndexCount, GE_VERTEX_32BITF|GE_VINDEX_16BIT|GE_TRANSFORM_3D, Vertices, Indices); glFlush(); if (enableDepth == false) glEnable (GL_DEPTH_TEST ); else { glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); } glDisable(GL_STENCIL_TEST); glPopAttrib(); driver->setTransform(video::ETS_VIEW, backup_view); } } }
void _flush_cache() { sceKernelDcacheWritebackAll(); }
int main(int argc, char* argv[]) { setupCallbacks(); int i, j; // Load emd mesh from file EMD_MESH* mesh = EMD_LoadMeshFromFile("scene.emd"); int vert_count = EMD_GetVertexCount(mesh); int idx_count = 0; int elem_count = EMD_GetElementCount(mesh); for (i=0; i<elem_count; i++) { idx_count += EMD_GetIndexCount(mesh, i); } VERTEX* vert_buf = (VERTEX*)memalign(16, sizeof(VERTEX) * vert_count); GW_UINT16* idx_buf = (GW_UINT16*)memalign(16, sizeof(GW_UINT16) * idx_count); for (i=0; i<vert_count; i++) { EMD_GetVertexByIndex(mesh, i, &vert_buf[i].x, &vert_buf[i].y, &vert_buf[i].z); EMD_GetTexcoordByIndex(mesh, i, &vert_buf[i].u, &vert_buf[i].v); EMD_GetNormalByIndex(mesh, i, &vert_buf[i].nx, &vert_buf[i].ny, &vert_buf[i].nz); //vert_buf[i].color = 0xffffffff; } GW_UINT32 idx_head = 0; GW_UINT32* data; GW_UINT32 count; // Pack 32-bit index into 16-bit buffer for (i=0; i<elem_count; i++) { count = EMD_GetIndexCount(mesh, i); data = EMD_GetIndexArray(mesh, i); for (j=0; j<count; j++) { idx_buf[j + idx_head] = (GW_UINT16)data[j]; } idx_head += count; } EMD_FreeMesh(mesh); // flush cache so that no stray data remains sceKernelDcacheWritebackAll(); // setup GU void* fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888); void* fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888); void* zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444); pspDebugScreenInit(); sceGuInit(); sceGuStart(GU_DIRECT,list); sceGuDrawBuffer(GU_PSM_8888,fbp0,BUF_WIDTH); sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH); sceGuDepthBuffer(zbp,BUF_WIDTH); sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2)); sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT); sceGuDepthRange(65535,0); sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuDepthFunc(GU_GEQUAL); sceGuEnable(GU_DEPTH_TEST); sceGuFrontFace(GU_CCW); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_CULL_FACE); //sceGuDisable(GU_TEXTURE_2D); sceGuEnable(GU_CLIP_PLANES); sceGuEnable(GU_LIGHTING); sceGuEnable(GU_LIGHT0); sceGuEnable(GU_LIGHT1); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); // run sample int val = 0; while(running()) { sceGuStart(GU_DIRECT,list); // clear screen sceGuClearColor(0xff554433); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); // setup lights ScePspFVector3 light_dir = { 1.0f, 1.0f, 1.0f }; // GU_DIRECTIONAL // GU_POINTLIGHT sceGuLight(0, GU_POINTLIGHT, GU_DIFFUSE, &light_dir); sceGuLightColor(0, GU_DIFFUSE, 0xffffffff); sceGuAmbient(0x00202020); light_dir.x = -light_dir.x; light_dir.y = -light_dir.y; light_dir.z = -light_dir.z; sceGuLight(1, GU_DIRECTIONAL, GU_DIFFUSE_AND_SPECULAR, &light_dir); sceGuLightColor(1, GU_DIFFUSE, 0xff7f7f7f); // setup matrices for cube sceGumMatrixMode(GU_PROJECTION); sceGumLoadIdentity(); sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f); sceGumMatrixMode(GU_VIEW); sceGumLoadIdentity(); sceGumMatrixMode(GU_MODEL); sceGumLoadIdentity(); { ScePspFVector3 pos = { 0, 0, -5.0f }; ScePspFVector3 rot = { val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f) }; sceGumTranslate(&pos); sceGumRotateXYZ(&rot); } // setup texture //sceGuTexMode(GU_PSM_4444,0,0,0); // sceGuTexImage(0,64,64,64,logo_start); //sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB); //sceGuTexEnvColor(0xffff00); //sceGuTexFilter(GU_LINEAR,GU_LINEAR); //sceGuTexScale(1.0f,1.0f); //sceGuTexOffset(0.0f,0.0f); //sceGuAmbientColor(0xff7f7f7f); // draw cube sceGuColor(0xffffff); sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_INDEX_16BIT|GU_TRANSFORM_3D, idx_count, idx_buf, vert_buf); pspDebugScreenSetXY(0, 0); pspDebugScreenPrintf("v: %d", vert_count); pspDebugScreenSetXY(0, 1); pspDebugScreenPrintf("i: %d", idx_count); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuSwapBuffers(); val++; } sceGuTerm(); // Release buffers free(vert_buf); free(idx_buf); sceKernelExitGame(); return 0; }
int main(int argc, char* argv[]) { /* Setup Homebutton Callbacks */ setupCallbacks(); sceKernelDcacheWritebackAll(); // setup GU SceCtrlData pad; sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL); sceGuInit(); 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); sceGuDepthFunc(GU_GEQUAL); sceGuEnable(GU_DEPTH_TEST); sceGuFrontFace(GU_CCW); sceGuColor(0xffffffff); sceGuShadeModel(GU_SMOOTH); // sceGuEnable(GU_CULL_FACE); sceGuEnable(GU_CLIP_PLANES); sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(GU_PSM_8888, 0, 0, 0); sceGuTexImage(0, 16, 16, 16, texture); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuTexEnvColor(0xffffff); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuTexWrap(GU_REPEAT, GU_REPEAT); sceGuTexScale(1.0f, 1.0f); sceGuTexOffset(0.0f, 0.0f); sceGuAmbientColor(0xffffffff); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); void* buffer = 0; pspDebugScreenInit(); unsigned int old = 0; unsigned int flags = PSP_CTRL_CIRCLE | PSP_CTRL_CROSS; int tex = 1; while(running()) { sceGuStart(GU_DIRECT,list); sceGuClearColor(0); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); sceGumMatrixMode(GU_PROJECTION); sceGumLoadIdentity(); sceGumPerspective(90.0f, 480.0/272.0f, 0.1f, 10.0f); sceGumMatrixMode(GU_VIEW); sceGumLoadIdentity(); ScePspFVector3 trans = { 0.0f, 0.0f, -1.8f }; sceGumTranslate(&trans); sceGumMatrixMode(GU_MODEL); sceGumLoadIdentity(); sceGumDrawArray(objects[o].prim, objects[o].flags, objects[o].count, 0, objects[o].data); sceCtrlReadBufferPositive(&pad, 1); if(old != pad.Buttons) { if(pad.Buttons & PSP_CTRL_CROSS) { o++; if(o >= sizeof(objects) / sizeof(Object)) { o = 0; } } if(pad.Buttons & PSP_CTRL_CIRCLE) { tex = !tex; if(tex) { sceGuEnable(GU_TEXTURE_2D); } else { sceGuDisable(GU_TEXTURE_2D); } } } old = pad.Buttons; sceGuFinish(); sceGuSync(0,0); pspDebugScreenSetOffset((int)buffer); pspDebugScreenSetXY(0, 0); pspDebugScreenPrintf("Mode: %s (X to change) Texture: %s (O to change)", objects[o].text, tex ? "on " : "off"); sceDisplayWaitVblankStart(); buffer = sceGuSwapBuffers(); } sceGuTerm(); sceKernelExitGame(); return 0; }
void psp_sdl_gu_stretch(SDL_Rect* srcrect, SDL_Rect* dstrect) { SDL_Surface* src = blit_surface; unsigned short old_slice = 0; /* set when we load 2nd tex */ unsigned int slice, num_slices, width, height, tbw, off_x, off_bytes; struct texVertex *vertices; char *pixels; sceKernelDcacheWritebackAll(); off_bytes = (long)(((char*)src->pixels) + srcrect->x * src->format->BytesPerPixel) & 0xf; off_x = off_bytes / src->format->BytesPerPixel; width = roundUpToPowerOfTwo(srcrect->w + off_bytes); height = roundUpToPowerOfTwo(srcrect->h); tbw = src->pitch / src->format->BytesPerPixel; /* Align the texture prior to srcrect->x */ pixels = ((char*)src->pixels) + (srcrect->x - off_x) * src->format->BytesPerPixel + src->pitch * srcrect->y; num_slices = (srcrect->w + (PSP_SLICE_SIZE - 1)) / PSP_SLICE_SIZE; /* GE doesn't appreciate textures wider than 512 */ if (width > 512) width = 512; sceGuStart(GU_DIRECT,list); sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(GU_PSM_5650, 0, 0, GU_FALSE); sceGuTexImage(0, width, height, tbw, pixels); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuTexFilter(GU_LINEAR, GU_LINEAR); for (slice = 0; slice < num_slices; slice++) { vertices = (struct texVertex*)sceGuGetMemory(2 * sizeof(struct texVertex)); if ((slice * PSP_SLICE_SIZE) < width) { vertices[0].u = slice * PSP_SLICE_SIZE + off_x; } else { if (!old_slice) { /* load another texture (src width > 512) */ pixels += width * src->format->BytesPerPixel; sceGuTexImage(0, roundUpToPowerOfTwo(srcrect->w - width), height, tbw, pixels); sceGuTexSync(); old_slice = slice; } vertices[0].u = (slice - old_slice) * PSP_SLICE_SIZE + off_x; } vertices[1].u = vertices[0].u + PSP_SLICE_SIZE; if (vertices[1].u > (off_x + srcrect->w)) vertices[1].u = off_x + srcrect->w; vertices[0].v = 0; vertices[1].v = vertices[0].v + srcrect->h; vertices[0].x = dstrect->x + (slice * PSP_SLICE_SIZE * dstrect->w + (srcrect->w - 1)) / srcrect->w; vertices[1].x = vertices[0].x + (PSP_SLICE_SIZE * dstrect->w + (srcrect->w - 1)) / srcrect->w; if (vertices[1].x > (dstrect->x + dstrect->w)) vertices[1].x = dstrect->x + dstrect->w; vertices[0].y = dstrect->y; vertices[1].y = vertices[0].y + dstrect->h; vertices[0].z = 0; vertices[1].z = 0; sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D, 2,0,vertices); } sceGuFinish(); sceGuSync(0, 0); }
int main(int argc, char* argv[]) { SetupCallbacks(); // generate geometry genGrid( GRID_ROWS, GRID_COLUMNS, GRID_SIZE, grid_vertices, grid_indices ); genTorus( TORUS_ROWS, TORUS_SLICES, TORUS_RADIUS, TORUS_THICKNESS, torus_vertices, torus_indices ); // flush cache so that no stray data remains sceKernelDcacheWritebackAll(); // setup VRAM buffers void* frameBuffer = (void*)0; const void* doubleBuffer = (void*)0x44000; const void* renderTarget = (void*)0x88000; const void* depthBuffer = (void*)0x110000; // setup GU sceGuInit(); sceGuStart(GU_DIRECT,list); sceGuDrawBuffer(GU_PSM_4444,frameBuffer,BUF_WIDTH); sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)doubleBuffer,BUF_WIDTH); sceGuDepthBuffer((void*)depthBuffer,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); sceGuDepthFunc(GU_GEQUAL); sceGuEnable(GU_DEPTH_TEST); sceGuFrontFace(GU_CW); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_CULL_FACE); sceGuEnable(GU_TEXTURE_2D); sceGuEnable(GU_DITHER); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); // setup matrices ScePspFMatrix4 identity; ScePspFMatrix4 projection; ScePspFMatrix4 view; gumLoadIdentity(&identity); gumLoadIdentity(&projection); gumPerspective(&projection,75.0f,16.0f/9.0f,0.5f,1000.0f); { ScePspFVector3 pos = {0,0,-5.0f}; gumLoadIdentity(&view); gumTranslate(&view,&pos); } ScePspFMatrix4 textureProjScaleTrans; gumLoadIdentity(&textureProjScaleTrans); textureProjScaleTrans.x.x = 0.5; textureProjScaleTrans.y.y = -0.5; textureProjScaleTrans.w.x = 0.5; textureProjScaleTrans.w.y = 0.5; ScePspFMatrix4 lightProjection; ScePspFMatrix4 lightProjectionInf; ScePspFMatrix4 lightView; ScePspFMatrix4 lightMatrix; gumLoadIdentity(&lightProjection); gumPerspective(&lightProjection,75.0f,1.0f,0.1f,1000.0f); gumLoadIdentity(&lightProjectionInf); gumPerspective(&lightProjectionInf,75.0f,1.0f,0.0f,1000.0f); gumLoadIdentity(&lightView); gumLoadIdentity(&lightMatrix); // define shadowmap Texture shadowmap = { GU_PSM_4444, 0, 128, 128, 128, sceGeEdramGetAddr() + (int)renderTarget }; // define geometry Geometry torus = { identity, sizeof(torus_indices)/sizeof(unsigned short), torus_indices, torus_vertices, 0xffffff }; Geometry grid = { identity, sizeof(grid_indices)/sizeof(unsigned short), grid_indices, grid_vertices, 0xff7777 }; // run sample int val = 0; for(;;) { // update matrices // grid { ScePspFVector3 pos = {0,-1.5f,0}; gumLoadIdentity(&grid.world); gumTranslate(&grid.world,&pos); } // torus { ScePspFVector3 pos = {0,0.5f,0.0f}; ScePspFVector3 rot = {val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f)}; gumLoadIdentity(&torus.world); gumTranslate(&torus.world,&pos); gumRotateXYZ(&torus.world,&rot); } // orbiting light { ScePspFVector3 lightLookAt = { torus.world.w.x, torus.world.w.y, torus.world.w.z }; ScePspFVector3 rot1 = {0,val * 0.79f * (GU_PI/180.0f),0}; ScePspFVector3 rot2 = {-(GU_PI/180.0f)*60.0f,0,0}; ScePspFVector3 pos = {0,0,LIGHT_DISTANCE}; gumLoadIdentity(&lightMatrix); gumTranslate(&lightMatrix,&lightLookAt); gumRotateXYZ(&lightMatrix,&rot1); gumRotateXYZ(&lightMatrix,&rot2); gumTranslate(&lightMatrix,&pos); } gumFastInverse(&lightView,&lightMatrix); // render to shadow map { sceGuStart(GU_DIRECT,list); // set offscreen texture as a render target sceGuDrawBufferList(GU_PSM_4444,(void*)renderTarget,shadowmap.stride); // setup viewport sceGuOffset(2048 - (shadowmap.width/2),2048 - (shadowmap.height/2)); sceGuViewport(2048,2048,shadowmap.width,shadowmap.height); // clear screen sceGuClearColor(0xffffffff); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); // setup view/projection from light sceGuSetMatrix(GU_PROJECTION,&lightProjection); sceGuSetMatrix(GU_VIEW,&lightView); // shadow casters are drawn in black // disable lighting and texturing sceGuDisable(GU_LIGHTING); sceGuDisable(GU_TEXTURE_2D); // draw torus to shadow map drawShadowCaster( &torus ); sceGuFinish(); sceGuSync(0,0); } // render to frame buffer { sceGuStart(GU_DIRECT,list); // set frame buffer sceGuDrawBufferList(GU_PSM_4444,(void*)frameBuffer,BUF_WIDTH); // setup viewport sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2)); sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT); // clear screen sceGuClearColor(0xff554433); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); // setup view/projection from camera sceGuSetMatrix(GU_PROJECTION,&projection); sceGuSetMatrix(GU_VIEW,&view); sceGuSetMatrix(GU_MODEL,&identity); // setup a light ScePspFVector3 lightPos = { lightMatrix.w.x, lightMatrix.w.y, lightMatrix.w.z }; ScePspFVector3 lightDir = { lightMatrix.z.x, lightMatrix.z.y, lightMatrix.z.z }; sceGuLight(0,GU_SPOTLIGHT,GU_DIFFUSE,&lightPos); sceGuLightSpot(0,&lightDir, 5.0, 0.6); sceGuLightColor(0,GU_DIFFUSE,0x00ff4040); sceGuLightAtt(0,1.0f,0.0f,0.0f); sceGuAmbient(0x00202020); sceGuEnable(GU_LIGHTING); sceGuEnable(GU_LIGHT0); // draw torus drawGeometry( &torus ); // setup texture projection sceGuTexMapMode( GU_TEXTURE_MATRIX, 0, 0 ); sceGuTexProjMapMode( GU_POSITION ); // set shadowmap as a texture sceGuTexMode(shadowmap.format,0,0,0); sceGuTexImage(shadowmap.mipmap,shadowmap.width,shadowmap.height,shadowmap.stride,shadowmap.data); sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGB); sceGuTexFilter(GU_LINEAR,GU_LINEAR); sceGuTexWrap(GU_CLAMP,GU_CLAMP); sceGuEnable(GU_TEXTURE_2D); // calculate texture projection matrix for shadowmap ScePspFMatrix4 shadowProj; gumMultMatrix(&shadowProj, &lightProjectionInf, &lightView); gumMultMatrix(&shadowProj, &textureProjScaleTrans, &shadowProj); // draw grid receiving shadow drawShadowReceiver( &grid, shadowProj ); sceGuFinish(); sceGuSync(0,0); } sceDisplayWaitVblankStart(); frameBuffer = sceGuSwapBuffers(); val++; } sceGuTerm(); sceKernelExitGame(); return 0; }
int pgeTextureUnswizzle(pgeTexture *texture) { if(!texture->swizzled) return 1; int blockx, blocky; int bytewidth = texture->textureWidth*(texture->bits>>3); int height = texture->size / bytewidth; int widthblocks = bytewidth/16; int heightblocks = height/8; int dstpitch = (bytewidth - 16)/4; int dstrow = bytewidth * 8; unsigned int *src = (unsigned int*) texture->data; unsigned char *data = NULL; if(texture->location == PGE_VRAM) data = (void*) pgeVramAlloc(texture->size); else data = pgeMalloc(texture->size); if(!data) return 0; sceKernelDcacheWritebackAll(); int j; unsigned char *ydst = (unsigned char *)data; for(blocky = 0; blocky < heightblocks; ++blocky) { unsigned char *xdst = ydst; for(blockx = 0; blockx < widthblocks; ++blockx) { unsigned int *block; if(texture->location == PGE_VRAM) block = (unsigned int*)((unsigned int)xdst|0x40000000); else block = (unsigned int*)xdst; for(j = 0; j < 8; ++j) { *(block++) = *(src++); *(block++) = *(src++); *(block++) = *(src++); *(block++) = *(src++); block += dstpitch; } xdst += 16; } ydst += dstrow; } if(texture->location == PGE_VRAM) pgeVramFree(texture->data); else pgeFree(texture->data); texture->data = data; texture->swizzled = 0; return 1; }
int main(int argc, char* argv[]) { SetupCallbacks(); // generate geometry genTorus( TORUS_ROWS, TORUS_SLICES, TORUS_RADIUS, TORUS_THICKNESS, torus_vertices, torus_indices ); // flush cache so that no stray data remains sceKernelDcacheWritebackAll(); // setup Edram buffers void* frameBuffer = (void*)0; const void* doubleBuffer = (void*)0x44000; const void* renderTarget = (void*)0x88000; const void* depthBuffer = (void*)0x110000; // setup GU sceGuInit(); sceGuStart(GU_DIRECT,list); sceGuDrawBuffer(GU_PSM_4444,frameBuffer,BUF_WIDTH); sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)doubleBuffer,BUF_WIDTH); sceGuDepthBuffer((void*)depthBuffer,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); 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 int val = 0; Texture offscreenTexture = { GU_PSM_4444, 0, 128, 128, 128, sceGeEdramGetAddr() + (int)renderTarget }; for(;;) { sceGuStart(GU_DIRECT,list); { sceGuDrawBufferList(GU_PSM_4444,(void*)renderTarget,offscreenTexture.stride); // setup viewport sceGuOffset(2048 - (offscreenTexture.width/2),2048 - (offscreenTexture.height/2)); sceGuViewport(2048,2048,offscreenTexture.width,offscreenTexture.height); // clear screen sceGuClearColor(0xffffffff); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); // draw torus to offscreen texture drawTorus( val ); } { // set frame buffer sceGuDrawBufferList(GU_PSM_4444,(void*)frameBuffer,BUF_WIDTH); // setup viewport sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2)); sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT); // clear screen sceGuClearColor(0xff554433); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); // draw cube using offscreen texture drawCube( &offscreenTexture, val ); } sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); frameBuffer = sceGuSwapBuffers(); val++; } sceGuTerm(); sceKernelExitGame(); return 0; }