engine/wii/video.c
/**
 * Set the video mode.  This includes the width and height of the game screen,
 * as well as the color mode: 8-bit indexed, 16-bit RGB565, or 32-bit RGB888.
 * @param videomodes the video mode structure (see source/gamelib/types.h)
 * @return 1 on success, 0 on error
 */
Set the video mode.  This includes the width and height of the game screen,
as well as the color mode: 8-bit indexed, 16-bit RGB565, or 32-bit RGB888.
@param videomodes the video mode structure
@return 1 on success, 0 on error
Set the video mode . This includes the width and height of the game screen as well as the color mode : 8 - bit indexed 16 - bit RGB565 or 32 - bit RGB888 . @param videomodes the video mode structure @return 1 on success 0 on error
int video_set_mode(s_videomodes videomodes)
{
	float texscale;
	static const int texture_formats[4] = {GX_TF_CI8, GX_TF_RGB565, GX_TF_RGBA8, GX_TF_RGBA8};
	bytes_per_pixel = videomodes.pixel;
	GX_CopyDisp(xfb[whichbuffer^1], GX_TRUE);
	GX_Flush();
	if(texturemem[0]) { free(texturemem[0]); texturemem[0]=NULL; }
	if(texturemem[1]) { free(texturemem[1]); texturemem[1]=NULL; }
    if(yuvScreen) { freescreen(&yuvScreen); yuvScreen=NULL; }
	textureWidth = videomodes.hRes;
	textureHeight = videomodes.vRes;
	texturemem_size = GX_GetTexBufferSize(textureWidth, textureHeight, texture_formats[bytes_per_pixel-1], 0, 0);
	texturemem[0] = memalign(32, texturemem_size);
	texturemem[1] = memalign(32, texturemem_size);
	texscale = MIN((float)viewportWidth/(float)textureWidth, (float)viewportHeight/(float)textureHeight);
	scaledWidth = (int)(textureWidth * texscale);
	scaledHeight = (int)(textureHeight * texscale);
	xoffset = (viewportWidth - scaledWidth) / 2;
	yoffset = (viewportHeight - scaledHeight) / 2;
	if(bytes_per_pixel == 1)
	{
		GX_InitTexObjCI(&texture[0], texturemem[0], textureWidth, textureHeight, GX_TF_CI8, GX_CLAMP, GX_CLAMP, GX_FALSE, GX_TLUT0);
		GX_InitTexObjCI(&texture[1], texturemem[1], textureWidth, textureHeight, GX_TF_CI8, GX_CLAMP, GX_CLAMP, GX_FALSE, GX_TLUT0);
	}
	else
	{
		GX_InitTexObj(&texture[0], texturemem[0], textureWidth, textureHeight, texture_formats[bytes_per_pixel-1], GX_CLAMP, GX_CLAMP, GX_FALSE);
		GX_InitTexObj(&texture[1], texturemem[1], textureWidth, textureHeight, texture_formats[bytes_per_pixel-1], GX_CLAMP, GX_CLAMP, GX_FALSE);
	}
	return 1;
}
int video_set_mode ( s_videomodes videomodes ) { float texscale ; static const int texture_formats [ 4 ] = { GX_TF_CI8 , GX_TF_RGB565 , GX_TF_RGBA8 , GX_TF_RGBA8 } ; bytes_per_pixel = videomodes . pixel ; GX_CopyDisp ( xfb [ whichbuffer ^ 1 ] , GX_TRUE ) ; GX_Flush ( ) ; if ( texturemem [ 0 ] ) { free ( texturemem [ 0 ] ) ; texturemem [ 0 ] = NULL ; } if ( texturemem [ 1 ] ) { free ( texturemem [ 1 ] ) ; texturemem [ 1 ] = NULL ; } if ( yuvScreen ) { freescreen ( & yuvScreen ) ; yuvScreen = NULL ; } textureWidth = videomodes . hRes ; textureHeight = videomodes . vRes ; texturemem_size = GX_GetTexBufferSize ( textureWidth , textureHeight , texture_formats [ bytes_per_pixel - 1 ] , 0 , 0 ) ; texturemem [ 0 ] = memalign ( 32 , texturemem_size ) ; texturemem [ 1 ] = memalign ( 32 , texturemem_size ) ; texscale = MIN ( ( float ) viewportWidth / ( float ) textureWidth , ( float ) viewportHeight / ( float ) textureHeight ) ; scaledWidth = ( int ) ( textureWidth * texscale ) ; scaledHeight = ( int ) ( textureHeight * texscale ) ; xoffset = ( viewportWidth - scaledWidth ) / 2 ; yoffset = ( viewportHeight - scaledHeight ) / 2 ; if ( bytes_per_pixel == 1 ) { GX_InitTexObjCI ( & texture [ 0 ] , texturemem [ 0 ] , textureWidth , textureHeight , GX_TF_CI8 , GX_CLAMP , GX_CLAMP , GX_FALSE , GX_TLUT0 ) ; GX_InitTexObjCI ( & texture [ 1 ] , texturemem [ 1 ] , textureWidth , textureHeight , GX_TF_CI8 , GX_CLAMP , GX_CLAMP , GX_FALSE , GX_TLUT0 ) ; } else { GX_InitTexObj ( & texture [ 0 ] , texturemem [ 0 ] , textureWidth , textureHeight , texture_formats [ bytes_per_pixel - 1 ] , GX_CLAMP , GX_CLAMP , GX_FALSE ) ; GX_InitTexObj ( & texture [ 1 ] , texturemem [ 1 ] , textureWidth , textureHeight , texture_formats [ bytes_per_pixel - 1 ] , GX_CLAMP , GX_CLAMP , GX_FALSE ) ; } return 1 ; }
Set the video mode.
Set the video mode .
// clear the embedded framebuffer (EFB) by copying its contents to the unused XFB :) // free existing memory // allocate memory for new texture // determine scale factor and on-screen dimensions // determine offsets // initialize the texture object