extern "C" int main(int argc, char *argv[]) { init(); checkpointNext("Nearest, clamp:"); sceGuStart(GU_DIRECT, list); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuTexWrap(GU_CLAMP, GU_CLAMP); sceGuFinish(); sceGuSync(0, 0); drawInterTransfer(); checkpointNext("Linear, clamp:"); sceGuStart(GU_DIRECT, list); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuTexWrap(GU_CLAMP, GU_CLAMP); sceGuFinish(); sceGuSync(0, 0); drawInterTransfer(); checkpointNext("Nearest, wrap:"); sceGuStart(GU_DIRECT, list); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuTexWrap(GU_REPEAT, GU_REPEAT); sceGuFinish(); sceGuSync(0, 0); drawInterTransfer(); checkpointNext("Linear, wrap:"); sceGuStart(GU_DIRECT, list); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuTexWrap(GU_REPEAT, GU_REPEAT); sceGuFinish(); sceGuSync(0, 0); drawInterTransfer(); drawIntraTransfer(); drawUploadTransfer(); sceGuTerm(); return 0; }
void _gInit() { // Init & setup GU sceGuInit(); sceGuStart(GU_DIRECT,list); sceGuDrawBuffer(GU_PSM_8888,(void*)FRAMEBUFFER_SIZE,PSP_LINE_SIZE); sceGuDispBuffer(G_SCR_W,G_SCR_H,(void*)0,PSP_LINE_SIZE); sceGuDepthBuffer((void*)(FRAMEBUFFER_SIZE*2),PSP_LINE_SIZE); sceGuOffset(2048-(G_SCR_W/2),2048-(G_SCR_H/2)); sceGuViewport(2048,2048,G_SCR_W,G_SCR_H); gResetScissor(); sceGuDepthRange(65535,0); sceGuClearDepth(65535); sceGuAlphaFunc(GU_GREATER,0,0xff); sceGuDepthFunc(GU_LEQUAL); sceGuBlendFunc(GU_ADD,GU_SRC_ALPHA,GU_ONE_MINUS_SRC_ALPHA,0,0); sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGBA); sceGuTexFilter(GU_LINEAR,GU_LINEAR); sceGuShadeModel(GU_FLAT); sceGuDisable(GU_CULL_FACE); sceGuDisable(GU_CLIP_PLANES); sceGuDisable(GU_DITHER); sceGuEnable(GU_ALPHA_TEST); sceGuEnable(GU_SCISSOR_TEST); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); init = G_TRUE; }
void drawUploadTransfer() { sceDisplaySetMode(0, SCR_WIDTH, SCR_HEIGHT); sceGuStart(GU_DIRECT, list); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuFinish(); sceGuSync(0, 0); // This time, we only need one buffer. switchBuf(0, GU_PSM_8888); drawTexFlush(2, 2, 16, GU_PSM_T8, imageData, clutAddOne, vertices1); sceDisplayWaitVblank(); // Okay, let's draw a totally different pattern in memory. for (int y = 0; y < 272; ++y) { for (int x = 0; x < 512; ++x) { copybuf[y * 512 + x] = (x & 1) + (y & 1); } } sceKernelDcacheWritebackInvalidateAll(); sceDmacMemcpy(getBufAddr(0), copybuf, sizeof(copybuf)); sceKernelDcacheWritebackInvalidateAll(); // Now download should display out pattern. displayBuffer("Pattern"); }
void vidgu_render_nostretch(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) { int start, end; sceGuStart(GU_DIRECT,list); sceGuTexMode(GU_PSM_5650,0,0,0); // 16-bit RGBA sceGuTexImage(0,512,512,512,g_pBlitBuff); // setup texture as a 256x256 texture //sceKernelDcacheWritebackAll(); sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGBA); // don't get influenced by any vertex colors sceGuTexFilter(GU_NEAREST,GU_NEAREST); // point-filtered sampling for (start = sx, end = sx+sw; start < end; start += SLICE_SIZE, dx += SLICE_SIZE) { struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex)); int width = (start + SLICE_SIZE) < end ? SLICE_SIZE : end-start; vertices[0].u = start; vertices[0].v = sy; vertices[0].color = 0; vertices[0].x = dx; vertices[0].y = dy; vertices[0].z = 0; vertices[1].u = start + width; vertices[1].v = sy + sh; vertices[1].color = 0; vertices[1].x = dx + width; vertices[1].y = dy + sh; vertices[1].z = 0; sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_5650|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices); } sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuSwapBuffers(); //sceGuSwapBuffers(); }
// These are GU commands that should always stay the same inline void MasterGuRenderer::guPreRender() { DEBUG_ENTER_FUNC(); #ifdef USE_DISPLAY_CALLBACK _renderSema.take(); // Take the semaphore to prevent writes // to the palette/screen before we're done _renderFinished = false; // set to synchronize with callback thread #endif #ifdef ENABLE_RENDER_MEASURE _lastRenderTime = g_system->getMillis(); #endif /* ENABLE_RENDER_MEASURE */ sceGuStart(0, _displayList); sceGuClearColor(0xFF000000); sceGuClear(GU_COLOR_BUFFER_BIT); sceGuAmbientColor(0xFFFFFFFF); sceGuColor(0xFFFFFFFF); sceGuTexOffset(0, 0); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); // Also good enough for all purposes sceGuAlphaFunc(GU_GREATER, 0, 0xFF); // Also good enough for all purposes }
void pgeTextureActivate(pgeTexture *texture) { if(texture->format == PGE_PIXEL_FORMAT_T4) { sceGuClutMode(texture->palFormat, 0, 0xff, 0); sceGuClutLoad(2, texture->palette); } else if(texture->format == PGE_PIXEL_FORMAT_T8) { sceGuClutMode(texture->palFormat, 0, 0xff, 0); sceGuClutLoad(32, texture->palette); } sceGuEnable(GU_TEXTURE_2D); sceGuTexWrap(GU_REPEAT, GU_REPEAT); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuTexFunc(pgeTextureMode, GU_TCC_RGBA); sceGuTexEnvColor(0xFFFFFFFF); sceGuColor(0xFFFFFFFF); sceGuAmbientColor(0xFFFFFFFF); sceGuTexOffset(0.0f, 0.0f); sceGuTexScale(1.0f/(float)texture->textureWidth, 1.0f/(float)texture->textureHeight); sceGuTexMode(texture->format, 0, 0, texture->swizzled); sceGuTexImage(0, texture->textureWidth, texture->textureHeight, texture->textureWidth, texture->data); }
int SetDrawMode(int Mode) { GUINITCHECK; GUSTART; switch(Mode) { case DX_DRAWMODE_NEAREST: sceGuTexFilter(GU_NEAREST,GU_NEAREST); dxpGraphicsData.bilinear_enable = 0; return 0; case DX_DRAWMODE_BILINEAR: sceGuTexFilter(GU_LINEAR,GU_LINEAR); dxpGraphicsData.bilinear_enable = 1; return 0; default: return -1; } }
void gEnd() { if (!obj_begin || obj_list_size <= 0) { obj_begin = G_FALSE; return; } // Manage pspgu extensions if (obj_use_z) sceGuEnable(GU_DEPTH_TEST); else sceGuDisable(GU_DEPTH_TEST); if (obj_use_blend) sceGuEnable(GU_BLEND); else sceGuDisable(GU_BLEND); if (obj_use_vert_color) sceGuColor(WHITE); else sceGuColor(obj_list[0].color); if (!obj_use_tex) sceGuDisable(GU_TEXTURE_2D); else { sceGuEnable(GU_TEXTURE_2D); if (obj_use_tex_linear) sceGuTexFilter(GU_LINEAR,GU_LINEAR); else sceGuTexFilter(GU_NEAREST,GU_NEAREST); if (obj_use_tex_repeat) sceGuTexWrap(GU_REPEAT,GU_REPEAT); else sceGuTexWrap(GU_CLAMP,GU_CLAMP); // Load texture sceGuTexMode(GU_PSM_8888,0,0,obj_tex->swizzled); sceGuTexImage(0,obj_tex->tw,obj_tex->th,obj_tex->tw,obj_tex->data); } switch (obj_type) { case RECTS: _gEndRects(); break; case LINES: _gEndLines(); break; case QUADS: _gEndQuads(); break; } sceGuColor(WHITE); sceGuEnable(GU_BLEND); obj_begin = G_FALSE; if (obj_use_z) zclear = G_TRUE; }
void vidgu_render(int sx, int sy, int sw,int sh,int dx, int dy, int dw,int dh) { unsigned int j,cx,cy; struct Vertex* vertices; cx=(480-dw)/2; cy=(272-dh)/2; sceGuStart(GU_DIRECT,list); sceGuTexMode(GU_PSM_5650,0,0,0); // 16-bit RGBA sceGuTexImage(0,512,512,512,g_pBlitBuff); // setup texture as a 256x256 texture //sceKernelDcacheWritebackAll(); sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGBA); // don't get influenced by any vertex colors sceGuTexFilter(GU_LINEAR,GU_LINEAR); // point-filtered sampling int start, end; float ustart = (float)sx; float ustep = (float)sw / (float)(dw / SLICE_SIZE); // blit maximizing the use of the texture-cache for (start = sx, end = sx+dw; start < end; start += SLICE_SIZE, dx += SLICE_SIZE) { struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex)); int width = (start + SLICE_SIZE) < end ? SLICE_SIZE : end-start; vertices[0].u = ustart; vertices[0].v = (float)sy; vertices[0].color = 0; vertices[0].x = dx; vertices[0].y = dy; vertices[0].z = 0; vertices[1].u = ustart + ustep; vertices[1].v = (float)(sy + sh); vertices[1].color = 0; vertices[1].x = dx + width; vertices[1].y = dy + dh; vertices[1].z = 0; sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_5650|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices); ustart += ustep; } sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuSwapBuffers(); }
void drawWithIndexOffsets() { sceDisplaySetMode(0, SCR_WIDTH, SCR_HEIGHT); sceGuStart(GU_DIRECT, list); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuFinish(); sceGuSync(0, 0); checkpointNext("Index shifts 8888:"); drawWithIndexOffsetsFmt(GU_PSM_8888); schedf("\n"); checkpointNext("Index shifts 4444:"); drawWithIndexOffsetsFmt(GU_PSM_4444); }
void Texture::use() { #ifdef ARCH_PSP sceGuEnable( GU_TEXTURE_2D ); sceGuTexFilter( GU_LINEAR, GU_LINEAR ); sceGuTexMode( GU_PSM_8888, 0, 0, psp_texture.Swizzled() ); sceGuTexImage( 0, psp_texture.Width(), psp_texture.Height(), psp_texture.Width(), psp_texture.Image() ); sceGuTexFunc( GU_TFX_MODULATE, GU_TCC_RGB ); sceGuTexScale( 1.0f, 1.0f ); // No scaling sceGuTexOffset( 0.0f, 0.0f ); #else glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,glTexId); #endif };
void psp_sdl_gu_init(void) { sceGuStart(GU_DIRECT,list); sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(GU_PSM_5650, 0, 0, GU_FALSE); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuDisable(GU_BLEND); sceGuDisable(GU_DEPTH_TEST); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); }
void Red3dInitScreen() { intraFontInit(); ltn = intraFontLoad("flash0:/font/ltn8.pgf", 0); if(!ltn) sceKernelExitGame(); intraFontSetStyle(ltn, 1.0f, 0xFFFFFFFF, 0xBFBFBFBF, 0); void *fbp0 = vrelptr(valloc((FRAMEBUFFER_WIDTH * sizeof(unsigned int)) * SCREEN_HEIGHT)); void *fbp1 = vrelptr(valloc((FRAMEBUFFER_WIDTH * sizeof(unsigned int)) * SCREEN_HEIGHT)); void *zbp = vrelptr(valloc((FRAMEBUFFER_WIDTH * sizeof(unsigned short)) * SCREEN_HEIGHT)); pspDebugScreenInit(); sceGuInit(); sceGuStart(GU_DIRECT,list); sceGuDrawBuffer(GU_PSM_8888, fbp0, FRAMEBUFFER_WIDTH); sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, fbp1, FRAMEBUFFER_WIDTH); sceGuDepthBuffer(zbp, FRAMEBUFFER_WIDTH); sceGuOffset(2048 - (SCREEN_WIDTH/2),2048 - (SCREEN_HEIGHT/2)); sceGuViewport(2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT); sceGuDepthRange(65535, 0); sceGuScissor(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); sceGuDepthFunc(GU_GEQUAL); sceGuEnable(GU_DEPTH_TEST); sceGuEnable(GU_SCISSOR_TEST); sceGuFrontFace(GU_CCW); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_CULL_FACE); sceGuEnable(GU_CLIP_PLANES); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuEnable(GU_TEXTURE_2D); sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGBA); sceGuTexFilter(GU_LINEAR,GU_LINEAR); sceGuFinish(); sceGuSync(0,0); Red3dSetupScreen(); }
static void psp_set_texture_frame(void *data, const void *frame, bool rgb32, unsigned width, unsigned height, float alpha) { psp1_video_t *psp = (psp1_video_t*)data; (void) rgb32; (void) alpha; #ifdef DEBUG /* psp->menu.frame buffer size is (480 * 272)*2 Bytes */ rarch_assert((width*height) < (480 * 272)); #endif psp_set_screen_coords(psp->menu.frame_coords, 0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, 0); psp_set_tex_coords(psp->menu.frame_coords, width, height); sceKernelDcacheWritebackRange(frame, width * height * 2); sceGuStart(GU_DIRECT, psp->main_dList); sceGuCopyImage(GU_PSM_4444, 0, 0, width, height, width, (void*)frame, 0, 0, width, psp->menu.frame); sceGuFinish(); sceGuStart(GU_SEND, psp->menu.dList); sceGuTexMode(GU_PSM_4444, 0, 0, GU_FALSE); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuTexImage(0, next_pow2(width), next_pow2(height), width, psp->menu.frame); sceGuEnable(GU_BLEND); #if 0 /* default blending */ sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); #endif sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xF0F0F0F0, 0x0F0F0F0F); ; sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, psp->menu.frame_coords); sceGuFinish(); }
void drawCube( Texture* texture, int val ) { // setup matrices for cube sceGumMatrixMode(GU_PROJECTION); sceGumLoadIdentity(); sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f); sceGumMatrixMode(GU_VIEW); { ScePspFVector3 pos = {0.0f,0.0f,-2.5f}; sceGumLoadIdentity(); sceGumTranslate(&pos); } sceGumMatrixMode(GU_MODEL); { ScePspFVector3 rot = {val * 0.263f * (GU_PI/180.0f), val * 0.32f * (GU_PI/180.0f), val * 0.44f * (GU_PI/180.0f)}; sceGumLoadIdentity(); sceGumRotateXYZ(&rot); } // setup texture sceGuTexMode(texture->format,0,0,0); sceGuTexImage(texture->mipmap,texture->width,texture->height,texture->stride,texture->data); sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB); sceGuTexFilter(GU_LINEAR,GU_LINEAR); sceGuTexScale(1.0f,1.0f); sceGuTexOffset(0.0f,0.0f); sceGuAmbientColor(0xffffffff); sceGuEnable(GU_TEXTURE_2D); // draw cube sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,cube_vertices); sceGuDisable(GU_TEXTURE_2D); }
void FZTexture::bindForDisplay() { // support only for main ram textures - very slow // TODO: investigate vram textures: when and how to // transfer? if (texImage->getCLUT() != NULL) { int n = texImage->getCLUTSize(); sceGuClutMode(GU_PSM_8888, 0, n - 1, 0); // 32-bit palette sceGuClutLoad((n/8), texImage->getCLUT()); // upload entries (8 colors base unit) } sceGuTexFunc(texenv, pixelComponent); //sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuTexMode(pixelFormat, 0, 0, GU_TRUE); //sceGuTexMode(pixelFormat, 0, 0, GU_FALSE); sceGuTexImage(0, width, height, width, texImage->getData()); sceGuTexScale(1.0f, 1.0f); sceGuTexOffset(0.0f, 0.0f); sceGuTexFilter(texMin, texMag); FZScreen::setBoundTexture((FZTexture*)this); }
void drawIntraTransfer() { sceDisplaySetMode(0, SCR_WIDTH, SCR_HEIGHT); sceGuStart(GU_DIRECT, list); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuFinish(); sceGuSync(0, 0); // This time, we only need one buffer. switchBuf(0, GU_PSM_8888); drawTexFlush(2, 2, 16, GU_PSM_T8, imageData, clutAddOne, vertices1); sceDisplayWaitVblank(); // Next, let's copy from this buffer to itself. sceKernelDcacheWritebackInvalidateAll(); sceDmacMemcpy(getBufAddr(0), (u8 *)getBufAddr(0) + sizeof(copybuf) / 2, sizeof(copybuf) / 2); sceKernelDcacheWritebackInvalidateAll(); // Now download should display a different buffer. displayBuffer("Spliced buffer"); }
void blit_start(int start, int end) { clip_min_y = start; clip_max_y = end + 1; spr_num = 0; spr_index = 0; if (start == FIRST_VISIBLE_LINE) { clut = (UINT16 *)PSP_UNCACHE_PTR(&video_palettebank[palette_bank]); fix_num = 0; spr_disable = 0; if (clear_spr_texture) blit_clear_spr_sprite(); if (clear_fix_texture) blit_clear_fix_sprite(); sceGuStart(GU_DIRECT, gulist); sceGuDrawBufferList(GU_PSM_5551, draw_frame, BUF_WIDTH); sceGuScissor(0, 0, BUF_WIDTH, SCR_WIDTH); sceGuClear(GU_COLOR_BUFFER_BIT | GU_FAST_CLEAR_BIT); sceGuDrawBufferList(GU_PSM_5551, work_frame, BUF_WIDTH); sceGuClear(GU_COLOR_BUFFER_BIT | GU_FAST_CLEAR_BIT); sceGuScissor(24, 16, 336, 240); sceGuClearColor(CNVCOL15TO32(video_palette[4095])); sceGuClear(GU_COLOR_BUFFER_BIT | GU_FAST_CLEAR_BIT); sceGuClearColor(0); sceGuEnable(GU_ALPHA_TEST); sceGuTexMode(GU_PSM_T8, 0, 0, GU_TRUE); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuFinish(); sceGuSync(0, GU_SYNC_FINISH); } }
void initGraphics() { dispBufferNumber = 0; sceGuInit(); guStart(); sceGuDrawBuffer(GU_PSM_8888, (void*)FRAMEBUFFER_SIZE, PSP_LINE_SIZE); sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, (void*)0, PSP_LINE_SIZE); sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); sceGuDepthBuffer((void*) (FRAMEBUFFER_SIZE*2), PSP_LINE_SIZE); sceGuOffset(2048 - (SCREEN_WIDTH / 2), 2048 - (SCREEN_HEIGHT / 2)); sceGuViewport(2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT); sceGuDepthRange(0xc350, 0x2710); sceGuScissor(0, 0, SCREEN_WIDTH, SCREEN_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); sceGuEnable(GU_CLIP_PLANES); sceGuTexMode(GU_PSM_8888, 0, 0, 0); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuAmbient(0xffffffff); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); initialized = 1; }
virtual void draw() { sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(GU_PSM_8888, 0, 0, GU_FALSE); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuTexImage(0, 256, 256, 256, data_.get().data()); sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuTexFilter(GU_LINEAR, GU_LINEAR); bright_texture_vertex * const vertex = static_cast<bright_texture_vertex *>(sceGuGetMemory(2 * sizeof(*vertex))); vertex[0].u = u_; vertex[0].v = v_; vertex[0].color = color_ | static_cast<boost::uint32_t>(alpha_) << 24; vertex[0].x = x_; vertex[0].y = y_; vertex[0].z = 0.f; vertex[1].u = u_ + u_size_; vertex[1].v = v_ + v_size_; vertex[1].color = color_ | static_cast<boost::uint32_t>(alpha_) << 24; vertex[1].x = x_ + width_; vertex[1].y = y_ + height_; vertex[1].z = 0.f; sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, vertex); }
static bool psp_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { static char fps_txt[128], fps_text_buf[128]; psp1_video_t *psp = (psp1_video_t*)data; #ifdef DISPLAY_FPS static uint64_t currentTick,lastTick; static float fps=0.0; static int frames; #endif if (!width || !height) return false; if (((uint32_t)frame&0x04000000) || (frame == RETRO_HW_FRAME_BUFFER_VALID)) psp->hw_render = true; else if (frame) psp->hw_render = false; if (!psp->hw_render) sceGuSync(0, 0); /* let the core decide when to sync when HW_RENDER */ pspDebugScreenSetBase(psp->draw_buffer); pspDebugScreenSetXY(0,0); video_monitor_get_fps(fps_txt, sizeof(fps_txt), g_settings.fps_show ? fps_text_buf : NULL, g_settings.fps_show ? sizeof(fps_text_buf) : 0); if(g_settings.fps_show) { pspDebugScreenSetXY(68 - strlen(fps_text_buf) - 1,0); pspDebugScreenPuts(fps_text_buf); pspDebugScreenSetXY(0,1); } if (msg) pspDebugScreenPuts(msg); if ((psp->vsync)&&(psp->vblank_not_reached)) sceDisplayWaitVblankStart(); psp->vblank_not_reached = true; #ifdef DISPLAY_FPS frames++; sceRtcGetCurrentTick(¤tTick); uint32_t diff = currentTick - lastTick; if(diff > 1000000) { fps = (float)frames * 1000000.0 / diff; lastTick = currentTick; frames = 0; } pspDebugScreenSetXY(0,0); pspDebugScreenPrintf("%f", fps); #endif psp->draw_buffer = FROM_GU_POINTER(sceGuSwapBuffers()); g_extern.frame_count++; RARCH_PERFORMANCE_INIT(psp_frame_run); RARCH_PERFORMANCE_START(psp_frame_run); if (psp->should_resize) psp_update_viewport(psp); psp_set_tex_coords(psp->frame_coords, width, height); sceGuStart(GU_DIRECT, psp->main_dList); sceGuTexFilter(psp->tex_filter, psp->tex_filter); sceGuClear(GU_COLOR_BUFFER_BIT); /* frame in VRAM ? texture/palette was * set in core so draw directly */ if (psp->hw_render) sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, (void*)(psp->frame_coords)); else { if (frame) { sceKernelDcacheWritebackRange(frame,pitch * height); sceGuCopyImage(GU_PSM_5650, ((u32)frame & 0xF) >> psp->bpp_log2, 0, width, height, pitch >> psp->bpp_log2, (void*)((u32)frame & ~0xF), 0, 0, width, psp->texture); } sceGuTexImage(0, next_pow2(width), next_pow2(height), width, psp->texture); sceGuCallList(psp->frame_dList); } sceGuFinish(); RARCH_PERFORMANCE_STOP(psp_frame_run); if(psp->menu.active) { sceGuSendList(GU_TAIL, psp->menu.dList, &(psp->menu.context_storage)); sceGuSync(0, 0); } return true; }
static void *psp_init(const video_info_t *video, const input_driver_t **input, void **input_data) { /* to-do : add ASSERT() checks or use main RAM if * VRAM is too low for desired video->input_scale. */ void *pspinput; int pixel_format, lut_pixel_format, lut_block_count; unsigned int red_shift, color_mask; void *displayBuffer, *LUT_r, *LUT_b; psp1_video_t *psp = (psp1_video_t*)calloc(1, sizeof(psp1_video_t)); if (!psp) return NULL; sceGuInit(); psp->vp.x = 0; psp->vp.y = 0; psp->vp.width = SCEGU_SCR_WIDTH; psp->vp.height = SCEGU_SCR_HEIGHT; psp->vp.full_width = SCEGU_SCR_WIDTH; psp->vp.full_height = SCEGU_SCR_HEIGHT; /* Make sure anything using uncached pointers reserves * whole cachelines (memory address and size need to be a multiple of 64) * so it isn't overwritten by an unlucky cache writeback. * * This includes display lists since the Gu library uses * uncached pointers to write to them. */ /* Allocate more space if bigger display lists are needed. */ psp->main_dList = memalign(64, 256); psp->frame_dList = memalign(64, 256); psp->menu.dList = memalign(64, 256); psp->menu.frame = memalign(16, 2 * 480 * 272); psp->frame_coords = memalign(64, (((PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)) + 63) & ~63)); psp->menu.frame_coords = memalign(64, (((PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)) + 63) & ~63)); memset(psp->frame_coords, 0, PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)); memset(psp->menu.frame_coords, 0, PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)); sceKernelDcacheWritebackInvalidateAll(); psp->frame_coords = TO_UNCACHED_PTR(psp->frame_coords); psp->menu.frame_coords = TO_UNCACHED_PTR(psp->menu.frame_coords); psp->frame_coords->v0.x = 60; psp->frame_coords->v0.y = 0; psp->frame_coords->v0.u = 0; psp->frame_coords->v0.v = 0; psp->frame_coords->v1.x = 420; psp->frame_coords->v1.y = SCEGU_SCR_HEIGHT; psp->frame_coords->v1.u = 256; psp->frame_coords->v1.v = 240; psp->vsync = video->vsync; psp->rgb32 = video->rgb32; if(psp->rgb32) { uint32_t* LUT_r_local = (uint32_t*)(SCEGU_VRAM_BP32_2); uint32_t* LUT_b_local = (uint32_t*)(SCEGU_VRAM_BP32_2) + (1 << 8); red_shift = 8 + 8; color_mask = 0xFF; lut_block_count = (1 << 8) / 8; psp->texture = (void*)(LUT_b_local + (1 << 8)); psp->draw_buffer = SCEGU_VRAM_BP32_0; psp->bpp_log2 = 2; pixel_format = GU_PSM_8888; lut_pixel_format = GU_PSM_T32; displayBuffer = SCEGU_VRAM_BP32_1; for (u32 i=0; i < (1 << 8); i++){ LUT_r_local[i]= i; LUT_b_local[i]= i << (8 + 8); } LUT_r = (void*)LUT_r_local; LUT_b = (void*)LUT_b_local; } else { uint16_t* LUT_r_local = (uint16_t*)(SCEGU_VRAM_BP_2); uint16_t* LUT_b_local = (uint16_t*)(SCEGU_VRAM_BP_2) + (1 << 5); red_shift = 6 + 5; color_mask = 0x1F; lut_block_count = (1 << 5) / 8; psp->texture = (void*)(LUT_b_local + (1 << 5)); psp->draw_buffer = SCEGU_VRAM_BP_0; psp->bpp_log2 = 1; pixel_format = (g_extern.system.pix_fmt == RETRO_PIXEL_FORMAT_0RGB1555) ? GU_PSM_5551 : GU_PSM_5650 ; lut_pixel_format = GU_PSM_T16; displayBuffer = SCEGU_VRAM_BP_1; for (u16 i = 0; i < (1 << 5); i++) { LUT_r_local[i]= i; LUT_b_local[i]= i << (5 + 6); } LUT_r = (void*)LUT_r_local; LUT_b = (void*)LUT_b_local; } psp->tex_filter = video->smooth? GU_LINEAR : GU_NEAREST; /* TODO: check if necessary. */ sceDisplayWaitVblankStart(); sceGuDisplay(GU_FALSE); sceGuStart(GU_DIRECT, psp->main_dList); sceGuDrawBuffer(pixel_format, TO_GU_POINTER(psp->draw_buffer), SCEGU_VRAM_WIDTH); sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, TO_GU_POINTER(displayBuffer), SCEGU_VRAM_WIDTH); sceGuClearColor(0); sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuTexFilter(psp->tex_filter, psp->tex_filter); sceGuTexWrap (GU_CLAMP, GU_CLAMP); sceGuEnable(GU_TEXTURE_2D); sceGuDisable(GU_DEPTH_TEST); sceGuCallMode(GU_FALSE); sceGuFinish(); sceGuSync(0, 0); /* TODO : check if necessary */ sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); pspDebugScreenSetColorMode(pixel_format); pspDebugScreenSetBase(psp->draw_buffer); /* fill frame_dList : */ sceGuStart(GU_CALL, psp->frame_dList); sceGuTexMode(pixel_format, 0, 0, GU_FALSE); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuEnable(GU_BLEND); /* green only */ sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0x0000FF00, 0xFFFFFFFF); sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, (void*)(psp->frame_coords)); /* restore */ sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xFFFFFFFF, 0xFFFFFFFF); sceGuTexMode(lut_pixel_format, 0, 0, GU_FALSE); sceGuClutMode(pixel_format, red_shift, color_mask, 0); sceGuClutLoad(lut_block_count, LUT_r); sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, (void*)(psp->frame_coords)); sceGuClutMode(pixel_format, 0, color_mask, 0); sceGuClutLoad(lut_block_count, LUT_b); sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, (void*)(psp->frame_coords)); sceGuFinish(); if (input && input_data) { pspinput = input_psp.init(); *input = pspinput ? &input_psp : NULL; *input_data = pspinput; } psp->vblank_not_reached = true; sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0, psp_on_vblank, psp); sceKernelEnableSubIntr(PSP_VBLANK_INT, 0); psp->keep_aspect = true; psp->should_resize = true; psp->hw_render = false; return psp; error: RARCH_ERR("PSP1 video could not be initialized.\n"); return (void*)-1; }
int dxpGraphicsInit() { u32 i; //構造体初期化 if(dxpGraphicsData.init)return 0; {//深度バッファの初期化 dxpGraphicsData.depthbuffer.psm = GU_PSM_4444; dxpGraphicsData.depthbuffer.ppalette = NULL; dxpGraphicsData.depthbuffer.texdata = NULL; dxpGraphicsData.depthbuffer.width = 480; dxpGraphicsData.depthbuffer.height = 272; dxpGraphicsData.depthbuffer.pitch = 512; dxpGraphicsData.depthbuffer.umax = 480; dxpGraphicsData.depthbuffer.vmax = 272; dxpGraphicsData.depthbuffer.colorkey = 0; dxpGraphicsData.depthbuffer.size2_nflag = 0; dxpGraphicsData.depthbuffer.swizzledflag = 1; dxpGraphicsData.depthbuffer.reloadflag = 1; dxpGraphicsData.depthbuffer.alphabit = 0; dxpGraphicsData.depthbuffer.refcount = 0; dxpGraphicsData.depthbuffer.thisptrptr = NULL; if(dxpGraphicsData.usedepth || dxpGraphicsData.usedepth3d) { dxpGraphicsData.depthbuffer.texvram = valloc(vgetMemorySize(512,272,GU_PSM_4444)); if(!dxpGraphicsData.depthbuffer.texvram)return -1; }else dxpGraphicsData.depthbuffer.texvram = NULL; } for(i = 0;i < 2;++i) {//フレームバッファの初期化 dxpGraphicsData.displaybuffer[i].psm = dxpGraphicsData.display_psm; dxpGraphicsData.displaybuffer[i].ppalette = NULL; dxpGraphicsData.displaybuffer[i].texdata = NULL; dxpGraphicsData.displaybuffer[i].texvram = valloc(vgetMemorySize(512,272,dxpGraphicsData.display_psm)); dxpGraphicsData.displaybuffer[i].width = 480; dxpGraphicsData.displaybuffer[i].height = 272; dxpGraphicsData.displaybuffer[i].pitch = 512; // dxpGraphicsData.displaybuffer[i].pitch = 480;//試したら見事に駄目だったw dxpGraphicsData.displaybuffer[i].umax = 480; dxpGraphicsData.displaybuffer[i].vmax = 272; dxpGraphicsData.displaybuffer[i].colorkey = 0; dxpGraphicsData.displaybuffer[i].size2_nflag = 0; dxpGraphicsData.displaybuffer[i].swizzledflag = 0; dxpGraphicsData.displaybuffer[i].reloadflag = 1; dxpGraphicsData.displaybuffer[i].alphabit = 0; dxpGraphicsData.displaybuffer[i].refcount = 0; } if(!dxpGraphicsData.displaybuffer[0].texvram || !dxpGraphicsData.displaybuffer[1].texvram) { vfree(dxpGraphicsData.displaybuffer[0].texvram); vfree(dxpGraphicsData.displaybuffer[1].texvram); vfree(dxpGraphicsData.depthbuffer.texvram); return -1; } dxpGraphicsData.displaybuffer_back = &dxpGraphicsData.displaybuffer[0]; dxpGraphicsData.rendertarget = dxpGraphicsData.displaybuffer_back; dxpGraphicsData.texture = NULL; dxpGraphicsData.clear_color_value = 0; dxpGraphicsData.clear_depth_value = 0; dxpGraphicsData.clear_stencil_value = 0; dxpGraphicsData.gustarted = 0; dxpGraphicsData.clear_depth = 0; dxpGraphicsData.clear_stencil = 0; dxpGraphicsData.bilinear_enable = 0; dxpGraphicsData.create_vram_graph = 1; dxpGraphicsData.create_swizzled_graph = 1; dxpGraphicsData.colorkey = 0; dxpGraphicsData.blendmode = DX_BLENDMODE_NOBLEND; dxpGraphicsData.drawstate = DXP_DRAWSTATE_EITHER; dxpGraphicsData.flag = 0xffffffff; dxpGraphicsData.forceupdate = 1; dxpGraphicsData.z_2d = 0; dxpGraphicsData.color = 0xffffffff; //dxpGraphicsData.usedepth = 0; //dxpGraphicsData.usedepth3d = 0; dxpGraphicsData.writedepth = 0; dxpGraphicsData.writedepth3d = 0; dxpGraphicsData.fog_color = 0xffffffff; dxpGraphicsData.fog_near = 10.0f; dxpGraphicsData.fog_far = 100.0f; dxpGraphicsData.intrafont_scissor[0] = 0; dxpGraphicsData.intrafont_scissor[1] = 0; dxpGraphicsData.intrafont_scissor[2] = 480; dxpGraphicsData.intrafont_scissor[3] = 272; dxpGraphicsData.depthfunc = GU_GEQUAL; for(i = 0;i < DXP_BUILDOPTION_TEXTURE_MAXNUM;++i)dxpGraphicsData.texarray[i] = NULL; for(i = 0;i < DXP_BUILDOPTION_GHANDLE_MAXNUM;++i)dxpGraphicsData.grapharray[i] = NULL; //GEのセットアップ sceGuInit(); GUSTART sceGuDrawBuffer(dxpGraphicsData.display_psm,vGuPointer(dxpGraphicsData.displaybuffer[0].texvram),dxpGraphicsData.displaybuffer[0].pitch); sceGuDispBuffer(480,272,vGuPointer(dxpGraphicsData.displaybuffer[1].texvram),dxpGraphicsData.displaybuffer[1].pitch); sceGuOffset(2048 - (480/2),2048 - (272/2)); sceGuViewport(2048,2048,480,272); sceGuScissor( dxpGraphicsData.intrafont_scissor[0], dxpGraphicsData.intrafont_scissor[1], dxpGraphicsData.intrafont_scissor[2], dxpGraphicsData.intrafont_scissor[3] ); sceGuClearDepth(0); sceGuDepthRange(65535,0); sceGuEnable(GU_SCISSOR_TEST); sceGuFrontFace(GU_CW); sceGuShadeModel(GU_FLAT); sceGuTexScale(1.0f,1.0f); sceGuTexOffset(0.0f,0.0f); sceGuTexFilter(GU_NEAREST,GU_NEAREST); sceGuTexWrap(GU_CLAMP,GU_CLAMP); /* memo カメラ位置(画面横幅/2,画面縦幅/2,画面縦幅/(2 * tan(fovy))) 注視点位置(画面横幅/2,画面縦幅/2,1) 上 (0,1,0) */ #ifndef DXP_BUILDOPTION_NO3D VECTOR v[3] = {{240,136,-235.5589f},{240,136,0},{0,1,0}}; SetCameraPositionAndTargetAndUpVec(v[0],v[1],v[2]); sceGumMatrixMode(GU_MODEL); sceGumLoadIdentity(); dxpGraphicsData.camera.aspect = 480.0f / 272.0f; dxpGraphicsData.camera.near = 0.5f; dxpGraphicsData.camera.far = 1000.0f; dxpGraphicsData.camera.fov = 60; dxpGraphics3dUpdateProjectionMatrix(); #endif GUFINISH; sceDisplayWaitVblankStart(); GUSTART; sceGuDisplay(GU_TRUE); dxpGraphicsData.init = 1; return 0; }
int dxpGraphicsSetup2DTex(DXPTEXTURE3 *texptr,int flag) { if(!texptr)return -1; //設定が同じなら変更処理をしない if(dxpGraphicsData.drawstate == DXP_DRAWSTATE_TEX2D && flag == dxpGraphicsData.flag && texptr == dxpGraphicsData.texture && !texptr->reloadflag && !dxpGraphicsData.forceupdate )return 0; GUSTART; if(dxpGraphicsData.drawstate != DXP_DRAWSTATE_TEX2D) {//2Dテクスチャ用の描画設定を行う。 dxpGraphicsData.drawstate = DXP_DRAWSTATE_TEX2D; dxpGraphicsData.forceupdate = 1; GUENABLE(GU_TEXTURE_2D); if(dxpGraphicsData.bilinear_enable) sceGuTexFilter(GU_LINEAR,GU_LINEAR); else sceGuTexFilter(GU_NEAREST,GU_NEAREST); if(dxpGraphicsData.usedepth) { GUENABLE(GU_DEPTH_TEST); sceGuDepthFunc(dxpGraphicsData.depthfunc); sceGuDepthBuffer(dxpGraphicsData.depthbuffer.texvram,512); //深度バッファを有効にするときでいい if(dxpGraphicsData.writedepth)sceGuDepthMask(0); else sceGuDepthMask(1); } else GUDISABLE(GU_DEPTH_TEST); } //テクスチャの設定開始 if(texptr != dxpGraphicsData.texture || texptr->reloadflag) {//GUにテクスチャの指定をする if(texptr->ppalette && (texptr->psm == GU_PSM_T8 || texptr->psm == GU_PSM_T4)) {//パレットの設定 sceGuClutMode(GU_PSM_8888,0,0xff,0); sceGuClutLoad(texptr->psm == GU_PSM_T4 ? 2 : 32,texptr->ppalette); } sceGuTexMode(texptr->psm,0,0,texptr->swizzledflag); sceGuTexImage(0,texptr->width,texptr->height,texptr->pitch,texptr->texvram ? texptr->texvram : texptr->texdata); dxpGraphicsData.texture = texptr; if(texptr != &dxpGraphicsData.displaybuffer[0] && texptr != &dxpGraphicsData.displaybuffer[1])texptr->reloadflag = 0; } u8 colorKey = 0,alphaEnable = 0; if(flag) { if(texptr->alphabit) alphaEnable = 1; else colorKey = 1; } if(colorKey) { GUENABLE(GU_COLOR_TEST); sceGuColorFunc(GU_NOTEQUAL,texptr->colorkey,0x00fefefe); } else { GUDISABLE(GU_COLOR_TEST); } int op; int src,dest; unsigned int srcfix; unsigned int destfix; switch(dxpGraphicsData.blendmode) { case DX_BLENDMODE_NOBLEND: op = GU_ADD; src = GU_FIX; dest = GU_FIX; srcfix = 0xffffffff; destfix = 0; if(!alphaEnable)break; case DX_BLENDMODE_ALPHA: op = GU_ADD; src = GU_SRC_ALPHA; dest = GU_ONE_MINUS_SRC_ALPHA; srcfix = 0; destfix = 0; break; case DX_BLENDMODE_ADD: op = GU_ADD; src = GU_SRC_ALPHA; dest = GU_FIX; srcfix = 0xffffffff; destfix = 0xffffffff; break; case DX_BLENDMODE_SUB: op = GU_REVERSE_SUBTRACT; src = GU_SRC_ALPHA; dest = GU_FIX; srcfix = 0xffffffff; destfix = 0xffffffff; break; case DX_BLENDMODE_MUL: op = GU_ADD; src = GU_DST_COLOR; dest = GU_FIX; srcfix = 0xffffffff; destfix = 0; break; case DX_BLENDMODE_DESTCOLOR: op = GU_ADD; src = GU_FIX; dest = GU_FIX; srcfix = 0; destfix = 0xffffffff; break; case DX_BLENDMODE_INVDESTCOLOR: op = GU_ADD; src = GU_ONE_MINUS_DST_COLOR; dest = GU_FIX; srcfix = 0; destfix = 0; break; case DX_BLENDMODE_INVSRC: op = GU_ADD; src = GU_SRC_ALPHA; dest = GU_ONE_MINUS_SRC_ALPHA; srcfix = 0; destfix = 0; break; default: return -1; } if(dxpGraphicsData.blendmode == DX_BLENDMODE_NOBLEND && !alphaEnable) { GUDISABLE(GU_BLEND); } else { GUENABLE(GU_BLEND); if(dxpGraphicsData.forceupdate || dxpGraphicsData.op != op || dxpGraphicsData.src != src || dxpGraphicsData.dest != dest || dxpGraphicsData.srcfix != srcfix || dxpGraphicsData.destfix != destfix ){ sceGuBlendFunc(op,src,dest,srcfix,destfix); dxpGraphicsData.op = op; dxpGraphicsData.src = src; dxpGraphicsData.dest = dest; dxpGraphicsData.srcfix = srcfix; dxpGraphicsData.destfix = destfix; } } if(dxpGraphicsData.forceupdate || dxpGraphicsData.color != dxpGraphicsData.gucolor) {//色を設定 sceGuColor(dxpGraphicsData.color); dxpGraphicsData.gucolor = dxpGraphicsData.color; } int tfx,tcc; switch(dxpGraphicsData.blendmode) { case DX_BLENDMODE_NOBLEND: case DX_BLENDMODE_MUL: case DX_BLENDMODE_DESTCOLOR: tcc = GU_TCC_RGB; tfx = GU_TFX_MODULATE; if(!alphaEnable) { GUDISABLE(GU_ALPHA_TEST); break; } case DX_BLENDMODE_ALPHA: case DX_BLENDMODE_ADD: case DX_BLENDMODE_SUB: case DX_BLENDMODE_INVDESTCOLOR: tcc = GU_TCC_RGBA; tfx = GU_TFX_MODULATE; GUENABLE(GU_ALPHA_TEST); sceGuAlphaFunc(GU_NOTEQUAL,0x00,0xff); break; case DX_BLENDMODE_INVSRC: sceGuTexEnvColor(0x00000000); tcc = GU_TCC_RGBA; tfx = GU_TFX_BLEND; GUDISABLE(GU_ALPHA_TEST); break; default: return -1; } if(dxpGraphicsData.forceupdate || dxpGraphicsData.tfx != tfx || dxpGraphicsData.tcc != tcc) { sceGuTexFunc(tfx,tcc); dxpGraphicsData.tfx = tfx; dxpGraphicsData.tcc = tcc; } dxpGraphicsData.forceupdate = 0; dxpGraphicsData.flag = flag; return 0; }
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 app() { setupCallbacks(); #ifdef DEBUG pspDebugScreenInit(); #endif sceGuInit(); 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); 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); sceGuClearDepth(65535); sceGuDepthFunc(GU_LEQUAL); sceGuAlphaFunc(GU_GREATER, 0, 255); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_DEPTH_TEST); sceGuEnable(GU_ALPHA_TEST); sceGuEnable(GU_SCISSOR_TEST); sceGuEnable(GU_BLEND); sceGuDisable(GU_CULL_FACE); sceGuDisable(GU_CLIP_PLANES); sceGuDisable(GU_DITHER); sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); //g2dInit(); /*tileset_tex = g2dTexLoad((char *) "resources/tilemap.png", G2D_SWIZZLE); outline_tex = g2dTexLoad((char *) "resources/tilemap2.png", G2D_SWIZZLE); text_tex = g2dTexLoad((char *) "resources/ui-font.png", G2D_SWIZZLE); frame_tex = g2dTexLoad((char *) "resources/frame.png", G2D_SWIZZLE);*/ while (running()) { sceGuStart(GU_DIRECT,list); // Clear screen sceGuClearColor(0xff554433); // TODO change to black when everything works sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT); // Process and draw a frame //menu.update(); //background.draw(); //menu.draw(); sceGuFinish(); sceGuSync(0,0); // Swap buffers and wait for VSYNC sceDisplayWaitVblankStart(); sceGuSwapBuffers(); } sceGuDisplay(GU_FALSE); sceGuTerm(); sceKernelExitGame(); }
int main() { SceCtrlData pad; int cancel = 0, uninstall = 0, reinstall = 0, lftv = 0, ok = 0, installed = 0, uninstalled = 0, autoExit = 0; SetupCallbacks(); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_LTRIGGER) { quickinstall = 1; lftv = 1; } else if (pad.Buttons & PSP_CTRL_RTRIGGER) { quickinstall = 1; } if (fileExist(PRX_LFTVBACKUP) | fileExist(PRX_RPLYBACKUP)) uninstall = 1; sceGuInit(); sceGuStart(GU_DIRECT, list); sceGuClearColor(0xFFFFFFFF); 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); sceGuDisable(GU_DEPTH_TEST); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(GU_PSM_8888, 0, 0, 0); sceGuTexImage(0, 256, 128, 256, font); sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuTexEnvColor(0x0); sceGuTexOffset(0.0f, 0.0f); sceGuTexScale(1.0f / 256.0f, 1.0f / 128.0f); sceGuTexWrap(GU_REPEAT, GU_REPEAT); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuFinish(); sceGuSync(0,0); sceGuDisplay(GU_TRUE); // Check for low battery. if ((scePowerGetBatteryLifePercent() < 25) & !scePowerIsPowerOnline()) { sceGuStart(GU_DIRECT, list); sceGuClear(GU_COLOR_BUFFER_BIT); drawStringCenter("Battery charge should be at least 25% when modifying flash!", 40 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("Connect the AC adapter to ignore this warning and continue!", 40 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter(uninstall ? "Press any button to cancel uninstallation of warPSP." : "Press any button to cancel installation of warPSP.", 50 + (10 * i), 0xFF0000FF, 8); i += 2; drawObjects(); while (!scePowerIsPowerOnline()) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons) { cancel = 1; break; } } } if (!cancel) { float c = 0.0; for (c = 10.0; c <= 100.0; c++) { unsigned int col = 0xFF000000 | (unsigned int)((c / 100.0) * 255.0f) << 16 | (unsigned int)((c / 100.0) * 255.0f) << 8 | (unsigned int)((c / 100.0) * 255.0f) << 0; sceGuClearColor(col); clearScreenPrintHeader(90); if (quickinstall & (c > 50)) drawStringCenter("Quick Install Activated!", 250, 0xFF006600, 8); drawObjects(); } sceKernelDelayThread(3000000); for (c = 100.0; c >= 10.0; c--) { unsigned int col = 0xFF000000 | (unsigned int)((c / 100.0) * 255.0f) << 16 | (unsigned int)((c / 100.0) * 255.0f) << 8 | (unsigned int)((c / 100.0) * 255.0f) << 0; sceGuClearColor(col); clearScreenPrintHeader(90); drawObjects(); } } sceGuClearColor(0xFFFFFFFF); // Show disclaimer and options. if (!cancel & !quickinstall) { sceGuStart(GU_DIRECT, list); sceGuClear(GU_COLOR_BUFFER_BIT); drawStringCenter("!!! DISCLAIMER !!!", 40 + (10 * i), 0xFF0000FF, 10); i += 2; drawStringCenter("This program modifies the flash drive of your Sony PSP.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("You accept the risk when running this installation app.", 60 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("DO NOT REMOVE THE MEMORY STICK WHEN ORANGE LED FLASHES.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("DO NOT TURN OFF THE PSP SYSTEM WHEN ORANGE LED FLASHES.", 60 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("Press START to acknowledge and to continue to briefing.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("Press SELECT to decline and to abort installing warPSP.", 60 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("THE AUTHOR DOES NOT HOLD RESPONSIBILITY FOR ANY DAMAGE.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("THIS SOFTWARE IS PRESENTED WITHOUT WARRANTY/GUARANTEES.", 60 + (10 * i), 0xFF0000FF, 8); i += 4; drawObjects(); while (1) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_START) { break; } if (pad.Buttons & PSP_CTRL_SELECT) { cancel = 1; break; } } } // Check if backup file exists. if (!cancel & !quickinstall) { swapBuffers(); clearScreenPrintHeader(0); drawObjects(); clearScreenPrintHeader(0); drawStringCenter("Briefing", 50 + (10 * i), 0xFF000000, 0); i+= 2; drawStringCenter("Thanks for your interest in the warPSP Software Suite!", 50 + (10 * i), 0xFF006600, 0); i += 2; drawStringCenter("warPSP is an advanced warXing utility for the Sony PSP.", 50 + (10 * i), 0xFF000000, 8); i += 2; drawStringCenter("Please see the README.TXT file for more information.", 50 + (10 * i), 0xFF660000, 8); i += 3; drawStringCenter("Options", 50 + (10 * i), 0xFF000000, 0); i += 2; if (uninstall) { drawStringCenter("Press SQUARE to uninstall warPSP and restore backup files.", 50 + (10 * i), 0xFF000000, 8); i++; drawStringCenter("Press CIRCLE to reinstall warPSP to the last slot selected.", 50 + (10 * i), 0xFF000000, 8); i++; } else { drawStringCenter("Press SQUARE to install warPSP to the LFTV Player slot.", 50 + (10 * i), 0xFF000000, 8); i++; drawStringCenter("Press CIRCLE to install warPSP to the Remote Play slot.", 50 + (10 * i), 0xFF000000, 8); i++; } drawStringCenter(uninstall ? "Press SELECT to cancel uninstallation of warPSP and exit." : "Press SELECT to cancel installation of warPSP and exit.", 50 + (10 * i), 0xFF000099, 8); i += 2; drawObjects(); while (1) { sceCtrlReadBufferPositive(&pad, 1); if (uninstall) { if (pad.Buttons & PSP_CTRL_SQUARE) { break; } if (pad.Buttons & PSP_CTRL_CIRCLE) { uninstall = 0; reinstall = 1; if (fileExist(PRX_LFTVBACKUP)) lftv = 1; else lftv = 0; break; } } else { if (pad.Buttons & PSP_CTRL_SQUARE) { lftv = 1; break; } if (pad.Buttons & PSP_CTRL_CIRCLE) { lftv = 0; break; } } if (pad.Buttons & PSP_CTRL_SELECT) { cancel = 1; break; } } } if (!cancel) { if ((scePowerGetBatteryLifePercent() < 25) & !scePowerIsPowerOnline()) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter(" Battery is below 25%% and AC adapter is not connected!", 50 + (10 * i), 0xFF000099, 0); i += 2; cancel = 1; drawObjects(); } } if (cancel) { swapBuffers(); sceGuStart(GU_DIRECT, list); sprintf(buffer, "%sstallation cancelled!", uninstall ? "Unin" : "In"); drawStringCenter(buffer, 50 + (10 * i), 0xFF0000FF, 0); i += 2; drawObjects(); sceKernelDelayThread(1000000); } // Perform installation, uninstallation or reinstallation. if (!cancel) { scePowerLock(0); swapBuffers(); clearScreenPrintHeader(0); drawObjects(); clearScreenPrintHeader(0); drawObjects(); swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter(uninstall ? "Uninstallation" : "Installation", 50 + (10 * i), 0xFF990000, 0); i += 2; if (quickinstall) { drawStringCenter("Quick installing warPSP to the location free player slot.", 50 + (10 * i), 0xFF990000, 0); i += 2; } drawObjects(); swapBuffers(); sceGuStart(GU_DIRECT, list); if (uninstall) { if (fileExist(PRX_LFTVBACKUP)) { lftv = 1; ok = 1; } else if (fileExist(PRX_RPLYBACKUP)) { lftv = 0; ok = 1; } if (ok) { drawStringCenter("Backup prx found. Ok to uninstall!", 50 + (10 * i), 0xFF990000, 8); i++; drawStringCenter("The backup prx will be copied to the flash drive of your PSP!", 50 + (10 * i), 0xFF000000, 8); i += 2; drawObjects(); if (fileCopy(lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP, lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Backup file reinstalled successfully!", 50 + (10 * i), 0xFF006600, 8); sceIoRemove(lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP); uninstalled = 1; } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Backup file reinstallation failed!", 50 + (10 * i), 0xFF000099, 8); } i += 2; drawObjects(); if (uninstalled) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("To reinstall warPSP, rerun the Easy Installation Program.", 50 + (10 * i), 0xFF990000, 8); i += 2; drawObjects(); } } } else { if (fileExist(PRX_WARPSP_XMB)) { sceIoRemove(PRX_WARPSP_XMB); sceKernelDelayThread(1000000); } drawStringCenter("Extracting warPSP.prx to the root of the memory stick.", 50 + (10 * i), 0xFF000000, 8); i += 2; drawObjects(); sceKernelDelayThread(2000000); // Open PBP file and read contents into the buffer. int pbpFile, prxFile, pkgSize = 0, prxSize = 0; char buf[1024*1024]; pbpFile = sceIoOpen(PBP_WARPSP_EIP, PSP_O_RDONLY, 0); sceKernelDelayThread(1000000); if (pbpFile) { // Get size of entire package. pkgSize = sceIoRead(pbpFile, buf, sizeof(buf)); sceKernelDelayThread(1000000); if (pkgSize > 0) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("EBOOT.PBP loaded into memory successfully!", 50 + (10 * i), 0xFF006600, 8); i += 2; drawObjects(); // Calculate size of prx to extract (size of entire package - size of eboot.pbp). prxSize = pkgSize - pbpSize; // Open PRX file and write buffer into the contents. prxFile = sceIoOpen(PRX_WARPSP_XMB, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); sceKernelDelayThread(100000); if (prxFile) { // Write prx file from end of eboot.pbp. sceIoWrite(prxFile, buf + pbpSize, prxSize); sceKernelDelayThread(1000000); sceIoClose(prxFile); sceKernelDelayThread(1000000); swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP.prx extracted from memory successfully!", 50 + (10 * i), 0xFF006600, 8); drawObjects(); } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP.prx extraction from memory failed!", 50 + (10 * i), 0xFF000099, 8); drawObjects(); } i += 2; } sceIoClose(pbpFile); sceKernelDelayThread(1000000); } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("EBOOT.PBP load into memory failed!", 50 + (10 * i), 0xFF000099, 8); i += 2; drawObjects(); } buf[0] = (char)"\0"; swapBuffers(); sceGuStart(GU_DIRECT, list); if (!fileExist(PRX_WARPSP_XMB)) { drawStringCenter("warPSP.prx not found! Install cancelled!", 50 + (10 * i), 0xFF000099, 8); } else { drawStringCenter("warPSP.prx found. Ok to install!", 50 + (10 * i), 0xFF006600, 8); ok = 1; } i += 2; drawObjects(); // Create backup of original file and install warPSP. if (ok) { if (!reinstall) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("The backup file will be copied to the memory stick!", 50 + (10 * i), 0xFF990000, 8); i++; drawObjects(); if (fileCopy(lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY, lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Original prx file backed up successfully!", 50 + (10 * i), 0xFF006600, 8); } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Original prx file back up failed!", 50 + (10 * i), 0xFF000099, 8); } i += 2; drawObjects(); } if (fileCopy(PRX_WARPSP_XMB, lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP^xmb installed successfully!", 50 + (10 * i), 0xFF006600, 8); sceIoRemove(PRX_WARPSP_XMB); installed = 1; } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP^xmb installation failed!", 50 + (10 * i), 0xFF000099, 8); installed = 0; } i += 2; drawObjects(); } } scePowerUnlock(0); } if (installed | uninstalled) { sceKernelDelayThread(1000000); } if (!quickinstall) { swapBuffers(); sceGuStart(GU_DIRECT, list); sprintf(buffer, "Press any button to %s! (Auto-Exit in 10s).", (installed | uninstalled) ? "restart the PSP" : "return to the xmb"); drawStringCenter(buffer, 50 + (10 * i), 0xFF000000, 8); i++; if (installed) { drawStringCenter("Happy warXing!", 50 + (10 * i), 0xFF006600, 8); i++; } else if (uninstalled) { drawStringCenter("Thank you for using warPSP", 50 + (10 * i), 0xFF990000, 8); i++; } drawObjects(); // Wait for exit. while (1) { if (autoExit >= 1000) break; sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons) break; sceKernelDelayThread(10000); autoExit++; } } if (quickinstall) { sceKernelDelayThread(1000000); } swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Exiting!", 50 + (10 * i), (installed | uninstalled) ? 0xFF990000 : 0xFF0000FF, 8); drawObjects(); if (installed | uninstalled) { sceKernelExitGame(); scePower_0442D852(50000); } else { sceKernelExitGame(); } return 0; }
static void dod_init_gu() { void* pDrawBuffer = dod_get_static_vram_buffer(DOD_BUFFER_WIDTH, DOD_SCREEN_HEIGHT, GU_PSM_8888); void* pDispBuffer = dod_get_static_vram_buffer(DOD_BUFFER_WIDTH, DOD_SCREEN_HEIGHT, GU_PSM_8888); void* pZBuffer = dod_get_static_vram_buffer(DOD_BUFFER_WIDTH, DOD_SCREEN_HEIGHT, GU_PSM_4444); sceGuInit(); sceGuStart(GU_DIRECT, s_list); sceGuDrawBuffer(GU_PSM_8888, pDrawBuffer, DOD_BUFFER_WIDTH); sceGuDispBuffer(DOD_SCREEN_WIDTH, DOD_SCREEN_HEIGHT, pDispBuffer, DOD_BUFFER_WIDTH); sceGuDepthBuffer(pZBuffer, DOD_BUFFER_WIDTH); sceGuOffset(2048 - (DOD_SCREEN_WIDTH / 2), 2048 - (DOD_SCREEN_HEIGHT / 2)); sceGuViewport(2048, 2048, DOD_SCREEN_WIDTH, DOD_SCREEN_HEIGHT); sceGuDepthRange(65535, 0); sceGuScissor(0, 0, DOD_SCREEN_WIDTH, DOD_SCREEN_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuEnable(GU_CULL_FACE); sceGuFrontFace(GU_CCW); sceGuShadeModel(GU_SMOOTH); //sceGuDepthFunc(GU_GEQUAL); //sceGuDepthMask(GU_TRUE); // disable z-writes //sceGuEnable(GU_DEPTH_TEST); sceGuEnable(GU_TEXTURE_2D); //sceGuEnable(GU_CLIP_PLANES); sceGuDisable(GU_COLOR_TEST); sceGuDisable(GU_ALPHA_TEST); sceGuDisable(GU_CLIP_PLANES); // Lighting sceGuDisable(GU_LIGHTING); sceGuDisable(GU_LIGHT0); sceGuDisable(GU_LIGHT1); sceGuDisable(GU_LIGHT2); sceGuDisable(GU_LIGHT3); // Texturing sceGuTexWrap(GU_CLAMP, GU_CLAMP); sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuTexOffset(0.f, 0.f); sceGuTexScale(1.f, 1.f); //sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); //sceGuTexEnvColor(0xffffffff); //sceGuColor(0xffffffff); //sceGuAmbientColor(0xffffffff); // Blending //sceGuEnable(GU_BLEND); //sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); //sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); //sceGuTexFilter(GU_LINEAR, GU_LINEAR); sceGuDisable(GU_DITHER); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); }
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); }
static void *psp_init(const video_info_t *video, const input_driver_t **input, void **input_data) { // to-do : add ASSERT() checks or use main RAM if VRAM is too low for desired video->input_scale void *pspinput; int pixel_format, lut_pixel_format, lut_block_count; unsigned int red_shift, color_mask; void *displayBuffer, *LUT_r, *LUT_b; psp1_video_t *psp = (psp1_video_t*)calloc(1, sizeof(psp1_video_t)); if (!psp) return NULL; sceGuInit(); psp->main_dList = memalign(16, 256); // make sure to allocate more space if bigger display lists are needed. psp->frame_dList = memalign(16, 256); psp->rgui.dList = memalign(16, 256); psp->rgui.frame = memalign(16, 2 * 480 * 272); psp->frame_coords = memalign(64, 1 * sizeof(psp1_sprite_t)); psp->rgui.frame_coords = memalign(64, 16 * sizeof(psp1_sprite_t)); memset(psp->frame_coords , 0, 1 * sizeof(psp1_sprite_t)); memset(psp->rgui.frame_coords , 0, 16 * sizeof(psp1_sprite_t)); sceKernelDcacheWritebackInvalidateAll(); psp->frame_coords = TO_UNCACHED_PTR(psp->frame_coords); psp->rgui.frame_coords = TO_UNCACHED_PTR(psp->rgui.frame_coords);; psp->frame_coords->v0.x = 60; psp->frame_coords->v0.y = 0; psp->frame_coords->v0.u = 0; psp->frame_coords->v0.v = 0; psp->frame_coords->v1.x = 420; psp->frame_coords->v1.y = SCEGU_SCR_HEIGHT; psp->frame_coords->v1.u = 256; psp->frame_coords->v1.v = 240; psp->vsync = video->vsync; psp->rgb32 = video->rgb32; if(psp->rgb32) { uint32_t* LUT_r_local = (uint32_t*)(SCEGU_VRAM_BP32_2); uint32_t* LUT_b_local = (uint32_t*)(SCEGU_VRAM_BP32_2) + (1 << 8); red_shift = 8 + 8; color_mask = 0xFF; lut_block_count = (1 << 8) / 8; psp->texture = (void*)(LUT_b_local + (1 << 8)); psp->draw_buffer = SCEGU_VRAM_BP32_0; psp->bpp_log2 = 2; pixel_format = GU_PSM_8888; lut_pixel_format = GU_PSM_T32; displayBuffer = SCEGU_VRAM_BP32_1; for (u32 i=0; i < (1 << 8); i++) { LUT_r_local[i]= i; LUT_b_local[i]= i << (8 + 8); } LUT_r = (void*)LUT_r_local; LUT_b = (void*)LUT_b_local; } else { uint16_t* LUT_r_local = (uint16_t*)(SCEGU_VRAM_BP_2); uint16_t* LUT_b_local = (uint16_t*)(SCEGU_VRAM_BP_2) + (1 << 5); red_shift = 6 + 5; color_mask = 0x1F; lut_block_count = (1 << 5) / 8; psp->texture = (void*)(LUT_b_local + (1 << 5)); psp->draw_buffer = SCEGU_VRAM_BP_0; psp->bpp_log2 = 1; pixel_format = GU_PSM_5650; lut_pixel_format = GU_PSM_T16; displayBuffer = SCEGU_VRAM_BP_1; for (u16 i = 0; i < (1 << 5); i++) { LUT_r_local[i]= i; LUT_b_local[i]= i << (5 + 6); } LUT_r = (void*)LUT_r_local; LUT_b = (void*)LUT_b_local; } sceDisplayWaitVblankStart(); // TODO : check if necessary sceGuDisplay(GU_FALSE); sceGuStart(GU_DIRECT, psp->main_dList); sceGuDrawBuffer(pixel_format, TO_GU_POINTER(psp->draw_buffer), SCEGU_VRAM_WIDTH); sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, TO_GU_POINTER(displayBuffer), SCEGU_VRAM_WIDTH); sceGuClearColor(0); sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuTexFilter(GU_LINEAR, GU_LINEAR); // TODO , move this to display list sceGuTexWrap (GU_CLAMP, GU_CLAMP); sceGuEnable(GU_TEXTURE_2D); sceGuDisable(GU_DEPTH_TEST); sceGuCallMode(GU_FALSE); sceGuFinish(); sceGuSync(0, 0); sceDisplayWaitVblankStart(); // TODO : check if necessary sceGuDisplay(GU_TRUE); pspDebugScreenSetColorMode(pixel_format); pspDebugScreenSetBase(psp->draw_buffer); // fill frame_dList : sceGuStart(GU_CALL, psp->frame_dList); sceGuTexMode(pixel_format, 0, 0, GU_FALSE); sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0x0000FF00, 0xFFFFFFFF); // green only sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_COLOR_4444 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL, (void*)(psp->frame_coords)); sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xFFFFFFFF, 0xFFFFFFFF); // restore sceGuTexMode(lut_pixel_format, 0, 0, GU_FALSE); sceGuClutMode(pixel_format, red_shift, color_mask, 0); sceGuClutLoad(lut_block_count, LUT_r); sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_COLOR_4444 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL, (void*)(psp->frame_coords)); sceGuClutMode(pixel_format, 0, color_mask, 0); sceGuClutLoad(lut_block_count, LUT_b); sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_COLOR_4444 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL, (void*)(psp->frame_coords)); sceGuFinish(); if (input && input_data) { pspinput = input_psp.init(); *input = pspinput ? &input_psp : NULL; *input_data = pspinput; } return psp; error: RARCH_ERR("PSP1 video could not be initialized.\n"); return (void*)-1; }