X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=cl_video.c;h=fcfd0d0a96b452ec84cace550305635de677753c;hb=26c627af105b03b2e1f5d74279163712ea546749;hp=42c0496d679026ff9e5229329b32cd27bd6321cc;hpb=9f904fa9411f2b09cd33a5ee11639ae46b17c0e1;p=xonotic%2Fdarkplaces.git diff --git a/cl_video.c b/cl_video.c index 42c0496d..fcfd0d0a 100644 --- a/cl_video.c +++ b/cl_video.c @@ -1,5 +1,6 @@ #include "quakedef.h" +#include "cl_dyntexture.h" #include "cl_video.h" #include "dpvsimpledecode.h" @@ -34,15 +35,32 @@ static qboolean OpenStream( clvideo_t * video ) return true; } +static void VideoUpdateCallback(rtexture_t *rt, void *data) { + clvideo_t *video = (clvideo_t *) data; + R_UpdateTexture( video->cpif.tex, (unsigned char *)video->imagedata, 0, 0, video->cpif.width, video->cpif.height ); +} + +static void LinkVideoTexture( clvideo_t *video ) { + video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name, + video->cpif.width, video->cpif.height, NULL, TEXTYPE_BGRA, TEXF_PERSISTENT | TEXF_ALLOWUPDATES, NULL ); + R_MakeTextureDynamic( video->cpif.tex, VideoUpdateCallback, video ); + CL_LinkDynTexture( video->cpif.name, video->cpif.tex ); +} + +static void UnlinkVideoTexture( clvideo_t *video ) { + CL_UnlinkDynTexture( video->cpif.name ); + // free the texture + R_FreeTexture( video->cpif.tex ); + // free the image data + Mem_Free( video->imagedata ); +} + static void SuspendVideo( clvideo_t * video ) { if( video->suspended ) return; video->suspended = true; - // free the texture - R_FreeTexture( video->cpif.tex ); - // free the image data - Mem_Free( video->imagedata ); + UnlinkVideoTexture( video ); // if we are in firstframe mode, also close the stream if( video->state == CLVIDEO_FIRSTFRAME ) dpvsimpledecode_close( video->stream ); @@ -61,8 +79,7 @@ static qboolean WakeVideo( clvideo_t * video ) } video->imagedata = Mem_Alloc( cls.permanentmempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel ); - video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name, - video->cpif.width, video->cpif.height, NULL, TEXTYPE_RGBA, TEXF_ALWAYSPRECACHE, NULL ); + LinkVideoTexture( video ); // update starttime video->starttime += realtime - video->lasttime; @@ -88,10 +105,8 @@ static clvideo_t* OpenVideo( clvideo_t *video, const char *filename, const char video->cpif.width = dpvsimpledecode_getwidth( video->stream ); video->cpif.height = dpvsimpledecode_getheight( video->stream ); - video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name, - video->cpif.width, video->cpif.height, NULL, TEXTYPE_RGBA, TEXF_ALWAYSPRECACHE, NULL ); - - video->imagedata = Mem_Alloc( cls.permanentmempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel ); + video->imagedata = Mem_Alloc( cls.permanentmempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel ); + LinkVideoTexture( video ); return video; } @@ -99,16 +114,22 @@ static clvideo_t* OpenVideo( clvideo_t *video, const char *filename, const char clvideo_t* CL_OpenVideo( const char *filename, const char *name, int owner ) { clvideo_t *video; + // sanity check + if( !name || !*name || strncmp( name, CLVIDEOPREFIX, sizeof( CLVIDEOPREFIX ) - 1 ) != 0 ) { + Con_DPrintf( "CL_OpenVideo: Bad video texture name '%s'!\n", name ); + return NULL; + } video = FindUnusedVid(); if( !video ) { - Con_Printf( "unable to open video \"%s\" - video limit reached\n", filename ); + Con_Printf( "CL_OpenVideo: unable to open video \"%s\" - video limit reached\n", filename ); return NULL; } video = OpenVideo( video, filename, name, owner ); // expand the active range to include the new entry - if (video) + if (video) { cl_num_videos = max(cl_num_videos, (int)(video - cl_videos) + 1); + } return video; } @@ -175,8 +196,7 @@ void CL_CloseVideo( clvideo_t * video ) if( !video->suspended || video->state != CLVIDEO_FIRSTFRAME ) dpvsimpledecode_close( video->stream ); if( !video->suspended ) { - Mem_Free( video->imagedata ); - R_FreeTexture( video->cpif.tex ); + UnlinkVideoTexture( video ); } video->state = CLVIDEO_UNUSED; @@ -205,11 +225,11 @@ static void VideoFrame( clvideo_t *video ) return; } } while( video->framenum < destframe ); - R_UpdateTexture( video->cpif.tex, (unsigned char *)video->imagedata, 0, 0, video->cpif.width, video->cpif.height ); + R_MarkDirtyTexture( video->cpif.tex ); } } -void CL_VideoFrame( void ) // update all videos +void CL_Video_Frame( void ) // update all videos { int i; clvideo_t *video; @@ -265,7 +285,8 @@ void CL_VideoStart(char *filename) if( cl_videos->state != CLVIDEO_UNUSED ) CL_CloseVideo( cl_videos ); - if( !OpenVideo( cl_videos, filename, va( CLVIDEOPREFIX "%s", filename ), 0 ) ) + // already contains video/ + if( !OpenVideo( cl_videos, filename, va( CLDYNTEXTUREPREFIX "%s", filename ), 0 ) ) return; // expand the active range to include the new entry cl_num_videos = max(cl_num_videos, 1); @@ -305,7 +326,7 @@ static void CL_PlayVideo_f(void) return; } - sprintf(name, "video/%s.dpv", Cmd_Argv(1)); + dpsnprintf(name, sizeof(name), "video/%s.dpv", Cmd_Argv(1)); CL_VideoStart(name); } @@ -323,12 +344,12 @@ static void cl_video_start( void ) for( video = cl_videos, i = 0 ; i < cl_num_videos ; i++, video++ ) if( video->state != CLVIDEO_UNUSED && !video->suspended ) - video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name, - video->cpif.width, video->cpif.height, NULL, TEXTYPE_RGBA, TEXF_ALWAYSPRECACHE, NULL ); + LinkVideoTexture( video ); } static void cl_video_shutdown( void ) { + // TODO: unlink video textures? R_FreeTexturePool( &cl_videotexturepool ); } @@ -338,11 +359,20 @@ static void cl_video_newmap( void ) void CL_Video_Init( void ) { + union + { + unsigned char b[4]; + unsigned int i; + } + bgra; + cl_num_videos = 0; cl_videobytesperpixel = 4; - cl_videormask = BigLong(0xFF000000); - cl_videogmask = BigLong(0x00FF0000); - cl_videobmask = BigLong(0x0000FF00); + + // set masks in an endian-independent way (as they really represent bytes) + bgra.i = 0;bgra.b[0] = 0xFF;cl_videobmask = bgra.i; + bgra.i = 0;bgra.b[1] = 0xFF;cl_videogmask = bgra.i; + bgra.i = 0;bgra.b[2] = 0xFF;cl_videormask = bgra.i; Cmd_AddCommand( "playvideo", CL_PlayVideo_f, "play a .dpv video file" ); Cmd_AddCommand( "stopvideo", CL_StopVideo_f, "stop playing a .dpv video file" );