void gsKit_clear(GSGLOBAL *gsGlobal, u64 color) { u8 PrevZState = gsGlobal->Test->ZTST; gsKit_set_test(gsGlobal, GS_ZTEST_OFF); u8 strips = gsGlobal->Width / 64; u8 remain = gsGlobal->Width % 64; u32 pos = 0; strips++; while(strips-- > 0) { gsKit_prim_sprite(gsGlobal, pos, 0, pos + 64, gsGlobal->Height, 0, color); pos += 64; } if(remain > 0) { gsKit_prim_sprite(gsGlobal, pos, 0, remain + pos, gsGlobal->Height, 0, color); } gsGlobal->Test->ZTST = PrevZState; gsKit_set_test(gsGlobal, 0); }
int rmSetMode(int force) { if (gVMode < RM_VMODE_AUTO || gVMode >= NUM_RM_VMODES) gVMode = RM_VMODE_AUTO; // we don't want to set the vmode without a reason... int changed = (vmode != gVMode || force); if (changed) { vmode = gVMode; gsGlobal->Mode = rm_mode_table[vmode].mode; gsGlobal->Height = rm_mode_table[vmode].height; if (vmode == RM_VMODE_DTV480P || vmode == RM_VMODE_DTV576P || vmode == RM_VMODE_VGA_640_60) { gsGlobal->Interlace = GS_NONINTERLACED; gsGlobal->Field = GS_FRAME; } else { gsGlobal->Interlace = GS_INTERLACED; gsGlobal->Field = GS_FIELD; } gsGlobal->Width = 640; gsGlobal->PSM = GS_PSM_CT24; gsGlobal->PSMZ = GS_PSMZ_16S; gsGlobal->ZBuffering = GS_SETTING_OFF; gsGlobal->PrimAlphaEnable = GS_SETTING_ON; gsGlobal->DoubleBuffering = GS_SETTING_ON; if ((gsGlobal->Mode) == GS_MODE_DTV_576P) { // Write X, Y, DW and DH positions for DTV576P (not covered by GSKit lib) gsGlobal->StartX = 324; gsGlobal->StartY = 72; gsGlobal->DW = 1280; gsGlobal->DH = 512; } gsKit_init_screen(gsGlobal); if (vmode == RM_VMODE_DTV480P) { // Overwrite X, Y and DW GSKit params for DTV480P gsGlobal->StartX = 312; gsGlobal->StartY = 37 + (480-448)/2; gsGlobal->DW = 1280; gsGlobal->DH = 448; } else if (vmode == RM_VMODE_VGA_640_60) { // Overwrite X, Y GSKit params for VGA_640_60 gsGlobal->StartX = 276; gsGlobal->StartY = 42; } if ((vmode == RM_VMODE_DTV480P) || (vmode == RM_VMODE_VGA_640_60)) { // Commit settings for DTV480P and VGA_650_60 DIntr(); // disable interrupts GS_SET_DISPLAY1(gsGlobal->StartX, // X position in the display area (in VCK unit gsGlobal->StartY, // Y position in the display area (in Raster u gsGlobal->MagH, // Horizontal Magnification gsGlobal->MagV, // Vertical Magnification gsGlobal->DW - 1, // Display area width gsGlobal->DH - 1); // Display area height GS_SET_DISPLAY2(gsGlobal->StartX, // X position in the display area (in VCK units) gsGlobal->StartY, // Y position in the display area (in Raster units) gsGlobal->MagH, // Horizontal Magnification gsGlobal->MagV, // Vertical Magnification gsGlobal->DW - 1, // Display area width gsGlobal->DH - 1); // Display area height __asm__("sync.l; sync.p;"); EIntr(); // enable interrupts } gsKit_mode_switch(gsGlobal, GS_ONESHOT); gsKit_set_test(gsGlobal, GS_ZTEST_OFF); // reset the contents of the screen to avoid garbage being displayed gsKit_clear(gsGlobal, gColBlack); gsKit_sync_flip(gsGlobal); LOG("RENDERMAN New vmode: %d, %d x %d\n", vmode, gsGlobal->Width, gsGlobal->Height); } return changed; }
int main(void) { GSGLOBAL *gsGlobal = gsKit_init_global(); //GS_MODE_VGA_640_60 #ifdef HAVE_LIBTIFF GSTEXTURE Sprite; u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00); #endif u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00); u64 Red = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x00,0x00); u64 Green = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x00,0x00); u64 Blue = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x00,0x00); u64 BlueTrans = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x40,0x00); float x = 10; float y = 10; float width = 150; float height = 150; float VHeight = gsGlobal->Height; gsGlobal->PSM = GS_PSM_CT24; gsGlobal->PSMZ = GS_PSMZ_16S; // gsGlobal->DoubleBuffering = GS_SETTING_OFF; // gsGlobal->ZBuffering = GS_SETTING_OFF; dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF); // Initialize the DMAC dmaKit_chan_init(DMA_CHANNEL_GIF); dmaKit_chan_init(DMA_CHANNEL_FROMSPR); dmaKit_chan_init(DMA_CHANNEL_TOSPR); gsGlobal->PrimAlphaEnable = GS_SETTING_ON; gsKit_init_screen(gsGlobal); #ifdef HAVE_LIBTIFF if(gsKit_texture_tiff(gsGlobal, &Sprite, "host:alpha.tiff") < 0) { printf("Loading Failed!\n"); } #endif gsKit_mode_switch(gsGlobal, GS_PERSISTENT); while(1) { if( y <= 10 && (x + width) < (gsGlobal->Width - 10)) x+=10; else if( (y + height) < (VHeight - 10) && (x + width) >= (gsGlobal->Width - 10) ) y+=10; else if( (y + height) >= (VHeight - 10) && x > 10 ) x-=10; else if( y > 10 && x <= 10 ) y-=10; gsKit_clear(gsGlobal, White); gsKit_prim_quad_gouraud(gsGlobal, 250.0f, 50.0f, 250.0f, 400.0f, 400.0f, 50.0f, 400.0f, 400.0f, 1, Red, Green, Blue, White); gsKit_prim_sprite(gsGlobal, x, y, x + width, y + height, 2, BlueTrans); gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0); gsKit_set_test(gsGlobal, GS_ATEST_OFF); #ifdef HAVE_LIBTIFF gsKit_prim_sprite_texture(gsGlobal, &Sprite, 310.0f, // X1 50.0f, // Y2 0.0f, // U1 0.0f, // V1 Sprite.Width + 310.0f, // X2 Sprite.Height + 50.0f, // Y2 Sprite.Width, // U2 Sprite.Height, // V2 3, TexCol); #endif gsKit_set_test(gsGlobal, GS_ATEST_ON); gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0); gsKit_sync_flip(gsGlobal); gsKit_queue_exec(gsGlobal); gsKit_queue_reset(gsGlobal->Per_Queue); } return 0; }
int main(void) { GSGLOBAL *gsGlobal = gsKit_init_global(); //GS_MODE_VGA_640_60 GSTEXTURE Sprite; u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00); #ifdef HAVE_LIBPNG u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00); #endif gsGlobal->PSM = GS_PSM_CT24; gsGlobal->PSMZ = GS_PSMZ_16S; // gsGlobal->DoubleBuffering = GS_SETTING_OFF; // gsGlobal->ZBuffering = GS_SETTING_OFF; dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF); // Initialize the DMAC dmaKit_chan_init(DMA_CHANNEL_GIF); gsGlobal->PrimAlphaEnable = GS_SETTING_ON; gsKit_init_screen(gsGlobal); Sprite.Delayed = GS_SETTING_ON; #ifdef HAVE_LIBPNG if(gsKit_texture_png(gsGlobal, &Sprite, "host:texstream.png") < 0) { printf("Loading Failed!\n"); } #endif Sprite.Vram = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(Sprite.Width, Sprite.Height, Sprite.PSM), GSKIT_ALLOC_USERBUFFER); gsKit_mode_switch(gsGlobal, GS_ONESHOT); while(1) { gsKit_clear(gsGlobal, White); gsKit_texture_send_inline(gsGlobal, Sprite.Mem, Sprite.Width, Sprite.Height, Sprite.Vram, Sprite.PSM, Sprite.TBW, GS_CLUT_NONE); gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0); gsKit_set_test(gsGlobal, GS_ATEST_OFF); #ifdef HAVE_LIBPNG gsKit_prim_sprite_texture(gsGlobal, &Sprite, 310.0f, // X1 50.0f, // Y2 0.0f, // U1 0.0f, // V1 Sprite.Width + 310.0f, // X2 Sprite.Height + 50.0f, // Y2 Sprite.Width, // U2 Sprite.Height, // V2 3, TexCol); #endif gsKit_set_test(gsGlobal, GS_ATEST_ON); gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0); gsKit_sync_flip(gsGlobal); gsKit_queue_exec(gsGlobal); } return 0; }
int render(GSGLOBAL *gsGlobal) { #ifdef TEX_BG u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00); GSTEXTURE bigtex; #endif #ifdef FHD_BG GSTEXTURE fhdbg; #endif int i; // Matrices to setup the 3D environment and camera MATRIX local_world; MATRIX local_light; MATRIX world_view; MATRIX view_screen; MATRIX local_screen; VECTOR *temp_normals; VECTOR *temp_lights; color_f_t *temp_colours; vertex_f_t *temp_vertices; xyz_t *verts; color_t *colors; // Allocate calculation space. temp_normals = (VECTOR *)memalign(128, sizeof(VECTOR) * vertex_count); temp_lights = (VECTOR *)memalign(128, sizeof(VECTOR) * vertex_count); temp_colours = (color_f_t *)memalign(128, sizeof(color_f_t) * vertex_count); temp_vertices = (vertex_f_t *)memalign(128, sizeof(vertex_f_t) * vertex_count); // Allocate register space. verts = (xyz_t *)memalign(128, sizeof(xyz_t) * vertex_count); colors = (color_t *)memalign(128, sizeof(color_t) * vertex_count); #ifdef TEX_BG bigtex.Filter = GS_FILTER_LINEAR; bigtex.Delayed = 0; gsKit_texture_jpeg(gsGlobal, &bigtex, "host:bigtex.jpg"); #endif #ifdef FHD_BG fhdbg.Filter = GS_FILTER_LINEAR; fhdbg.Delayed = 1; fhdbg.Vram = GSKIT_ALLOC_ERROR; gsKit_texture_jpeg(gsGlobal, &fhdbg, "host:fhdbg.jpg"); gsKit_hires_prepare_bg(gsGlobal, &fhdbg); gsKit_hires_set_bg(gsGlobal, &fhdbg); #endif printf("VRAM used: %dKiB\n", gsGlobal->CurrentPointer / 1024); printf("VRAM free: %dKiB\n", 4096 - (gsGlobal->CurrentPointer / 1024)); // Create the view_screen matrix. create_view_screen(view_screen, 16.0f/9.0f, -0.20f, 0.20f, -0.20f, 0.20f, 1.00f, 2000.00f); if (gsGlobal->ZBuffering == GS_SETTING_ON) gsKit_set_test(gsGlobal, GS_ZTEST_ON); // A,B,C,D,FIX = 0,1,0,1,0: // A = 0 = Cs (Color Source) // B = 1 = Cd (Color Destination) // C = 0 = As (Alpha Source) // D = 1 = Cd (Color Destination) // FIX = not used // // Resulting color = (A-B)*C+D = (Cs-Cd)*As+Cd // This will blend the source over the destination // Note: // - Alpha 0x00 = fully transparent // - Alpha 0x80 = fully visible gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 128), 0); gsGlobal->PrimAlphaEnable = GS_SETTING_OFF; gsGlobal->PrimAAEnable = GS_SETTING_ON; // The main loop... for (;;) { // Spin the teapot a bit. object_rotation[1] += 0.005f; while (object_rotation[1] > 3.14f) { object_rotation[1] -= 6.28f; } // Create the local_world matrix. create_local_world(local_world, object_position, object_rotation); // Create the local_light matrix. create_local_light(local_light, object_rotation); // Create the world_view matrix. create_world_view(world_view, camera_position, camera_rotation); // Create the local_screen matrix. create_local_screen(local_screen, local_world, world_view, view_screen); // Calculate the normal values. calculate_normals(temp_normals, vertex_count, normals, local_light); // Calculate the lighting values. calculate_lights(temp_lights, vertex_count, temp_normals, light_direction, light_colour, light_type, light_count); // Calculate the colour values after lighting. calculate_colours((VECTOR *)temp_colours, vertex_count, colours, temp_lights); // Calculate the vertex values. calculate_vertices((VECTOR *)temp_vertices, vertex_count, vertices, local_screen); // Convert floating point vertices to fixed point and translate to center of screen. draw_convert_xyz(verts, 2048, 2048, 16, vertex_count, temp_vertices); // Convert floating point colours to fixed point. draw_convert_rgbq(colors, vertex_count, temp_vertices, temp_colours, 0x80); #ifdef DYNAMIC_DITHERING // Dithering: // The standard 4x4 dithering matrix creates static noise to eliminate banding. // This static noise is a little visible, and can be improved by changing the matrix every frame // Keep adding 5 to get the most noisy pattern possible: // 0, 5, 2, 7, 4, 1, 6, 3 for(i = 0; i < 15; i++) gsGlobal->DitherMatrix[i] = (gsGlobal->DitherMatrix[i] + 5) & 7; gsKit_set_dither_matrix(gsGlobal); #endif #ifdef TEX_BG if(bigtex.Vram != GSKIT_ALLOC_ERROR) { gsKit_prim_sprite_texture(gsGlobal, &bigtex, 0.0f, // X1 0.0f, // Y1 0.0f, // U1 0.0f, // V1 gsGlobal->Width, // X2 gsGlobal->Height, // Y2 bigtex.Width, // U2 bigtex.Height, // V2 2, TexCol); } #endif for (i = 0; i < points_count; i+=3) { float fX=gsGlobal->Width/2; float fY=gsGlobal->Height/2; gsKit_prim_triangle_gouraud_3d(gsGlobal , (temp_vertices[points[i+0]].x + 1.0f) * fX, (temp_vertices[points[i+0]].y + 1.0f) * fY, verts[points[i+0]].z , (temp_vertices[points[i+1]].x + 1.0f) * fX, (temp_vertices[points[i+1]].y + 1.0f) * fY, verts[points[i+1]].z , (temp_vertices[points[i+2]].x + 1.0f) * fX, (temp_vertices[points[i+2]].y + 1.0f) * fY, verts[points[i+2]].z , colors[points[i+0]].rgbaq, colors[points[i+1]].rgbaq, colors[points[i+2]].rgbaq); } #ifdef HIRES_MODE gsKit_hires_sync(gsGlobal); gsKit_hires_flip(gsGlobal); #else gsKit_queue_exec(gsGlobal); gsKit_sync_flip(gsGlobal); #endif } free(temp_normals); free(temp_lights); free(temp_colours); free(temp_vertices); free(verts); free(colors); return 0; }
int main(void) { GSGLOBAL *gsGlobal = gsKit_init_global(); GSTEXTURE Tex1; int x = 0, y = 0; #ifdef HAVE_LIBPNG u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00); #endif u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00); u64 BlueTrans = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x40,0x00); u64 Green = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x00,0x00); gsGlobal->PSM = GS_PSM_CT32; gsGlobal->PSMZ = GS_PSMZ_16S; gsGlobal->ZBuffering = GS_SETTING_ON; dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF); // Initialize the DMAC dmaKit_chan_init(DMA_CHANNEL_GIF); dmaKit_chan_init(DMA_CHANNEL_FROMSPR); dmaKit_chan_init(DMA_CHANNEL_TOSPR); #ifdef HAVE_LIBPNG printf("alpha\n"); gsGlobal->PrimAlphaEnable = GS_SETTING_ON; #endif gsKit_init_screen(gsGlobal); float VHeight = gsGlobal->Height; gsKit_clear(gsGlobal, White); #ifdef HAVE_LIBPNG gsKit_texture_png(gsGlobal, &Tex1, "host:test.png"); printf("Texture 1 Height: %i\n",Tex1.Height); printf("Texture 1 Width: %i\n",Tex1.Width); printf("Texure 1 VRAM Range = 0x%X - 0x%X\n",Tex1.Vram, Tex1.Vram +gsKit_texture_size(Tex1.Width, Tex1.Height, Tex1.PSM) - 1); #endif gsKit_mode_switch(gsGlobal, GS_PERSISTENT); while(1) { if( y <= 10 && (x + Tex1.Width) < (gsGlobal->Width - 10)) x+=10; else if( (y + Tex1.Height) < (VHeight - 10) && (x + Tex1.Width) >= (gsGlobal->Width - 10) ) y+=10; else if( (y + Tex1.Height) >= (VHeight - 10) && x > 10 ) x-=10; else if( y > 10 && x <= 10 ) y-=10; gsKit_clear(gsGlobal, Green); gsKit_prim_sprite(gsGlobal, x, y, x + Tex1.Width, y + Tex1.Height, 1, BlueTrans); #ifdef HAVE_LIBPNG gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0); gsKit_set_test(gsGlobal, GS_ATEST_OFF); gsKit_prim_sprite_texture(gsGlobal, &Tex1, 0.0f, // X1 0.0f, // Y2 0.0f, // U1 0.0f, // V1 Tex1.Width, // X2 Tex1.Height, // Y2 Tex1.Width, // U2 Tex1.Height, // V2 2, TexCol); gsKit_set_test(gsGlobal, GS_ATEST_ON); gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0); #endif gsKit_sync_flip(gsGlobal); gsKit_queue_exec(gsGlobal); #ifdef HAVE_LIBPNG gsKit_queue_reset(gsGlobal->Per_Queue); #endif } return 0; }