[qfusion-cvs-commits] SF.net SVN: l33t: [790] trunk/qfusion/source
Brought to you by:
digiman
From: qfusion s. c. <l33...@li...> - 2007-12-05 20:41:34
|
Revision: 790 http://l33t.svn.sourceforge.net/l33t/?rev=790&view=rev Author: digiman Date: 2007-12-05 12:41:22 -0800 (Wed, 05 Dec 2007) Log Message: ----------- Rewrite handling of videomaps, we can now add and remove cinematics on demand and reuse videomap handles for different shaders Modified Paths: -------------- trunk/qfusion/source/client/cin.c trunk/qfusion/source/client/cin.h trunk/qfusion/source/client/cl_cin.c trunk/qfusion/source/ref_gl/r_cin.c trunk/qfusion/source/ref_gl/r_local.h trunk/qfusion/source/ref_gl/r_main.c trunk/qfusion/source/ref_gl/r_register.c trunk/qfusion/source/ref_gl/r_shader.c trunk/qfusion/source/ref_gl/r_shader.h Modified: trunk/qfusion/source/client/cin.c =================================================================== --- trunk/qfusion/source/client/cin.c 2007-12-04 20:33:04 UTC (rev 789) +++ trunk/qfusion/source/client/cin.c 2007-12-05 20:41:22 UTC (rev 790) @@ -89,12 +89,13 @@ cin->height = LittleShort( t[1] ); if( cin->vid_buffer ) - Mem_ZoneFree( cin->vid_buffer ); + Mem_Free( cin->vid_buffer ); - cin->vid_buffer = Mem_ZoneMallocExt( cin->width * cin->height * 4 * 2, 0 ); - // default to 255 for alpha - memset( cin->vid_buffer, 0xFF, cin->width * cin->height * 4 * 2 ); + if( cin->mempool ) + cin->vid_buffer = Mem_AllocExt( cin->mempool, cin->width * cin->height * 4 * 2, 0xFF ); + else + cin->vid_buffer = Mem_ZoneMallocExt( cin->width * cin->height * 4 * 2, 0xFF ); cin->vid_pic[0] = cin->vid_buffer; cin->vid_pic[1] = cin->vid_buffer + cin->width * cin->height * 4; Modified: trunk/qfusion/source/client/cin.h =================================================================== --- trunk/qfusion/source/client/cin.h 2007-12-04 20:33:04 UTC (rev 789) +++ trunk/qfusion/source/client/cin.h 2007-12-05 20:41:22 UTC (rev 790) @@ -76,10 +76,12 @@ int headerlen; int time; // Sys_Milliseconds for first cinematic frame - int frame; + unsigned int frame; qbyte *pic; qbyte *pic_pending; + + mempool_t *mempool; } cinematics_t; void RoQ_Init (void); Modified: trunk/qfusion/source/client/cl_cin.c =================================================================== --- trunk/qfusion/source/client/cl_cin.c 2007-12-04 20:33:04 UTC (rev 789) +++ trunk/qfusion/source/client/cl_cin.c 2007-12-05 20:41:22 UTC (rev 790) @@ -50,7 +50,7 @@ cin->name = NULL; if( cin->vid_buffer ) { - Mem_ZoneFree( cin->vid_buffer ); + Mem_Free( cin->vid_buffer ); cin->vid_buffer = NULL; } } @@ -112,7 +112,7 @@ */ void SCR_RunCinematic( void ) { - int frame; + unsigned int frame; cinematics_t *cin = &cl.cin; if( cin->time <= 0 ) { @@ -127,9 +127,6 @@ return; } - if( cin->frame == -1 ) - return; - frame = (cls.realtime - cin->time) * (float)(RoQ_FRAMERATE) / 1000; if( frame <= cin->frame ) return; Modified: trunk/qfusion/source/ref_gl/r_cin.c =================================================================== --- trunk/qfusion/source/ref_gl/r_cin.c 2007-12-04 20:33:04 UTC (rev 789) +++ trunk/qfusion/source/ref_gl/r_cin.c 2007-12-05 20:41:22 UTC (rev 790) @@ -17,39 +17,36 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +// r_cin.c #include "r_local.h" +#include "../client/cin.h" -//============================================================= +#define MAX_CINEMATICS 256 -/* -================== -R_StopCinematic -================== -*/ -void R_StopCinematic( cinematics_t *cin ) +typedef struct r_cinhandle_s { - cin->time = 0; // done - cin->pic = NULL; - cin->pic_pending = NULL; + unsigned int id; + char *name; + cinematics_t *cin; + image_t *image; + struct r_cinhandle_s *prev, *next; +} r_cinhandle_t; - if( cin->file ) { - FS_FCloseFile( cin->file ); - cin->file = 0; - } - if( cin->vid_buffer ) { - Mem_ZoneFree( cin->vid_buffer ); - cin->vid_buffer = NULL; - } -} +static mempool_t *r_cinMemPool; -//========================================================================== +static r_cinhandle_t *r_cinematics; +static r_cinhandle_t r_cinematics_headnode, *r_free_cinematics; +#define Cin_Malloc(size) _Mem_Alloc(r_cinMemPool,size,0,0,__FILE__,__LINE__) +#define Cin_Free(data) Mem_Free(data) + /* ================== -R_ReadNextCinematicFrame +R_ReadNextRoQFrame ================== */ -static qbyte *R_ReadNextCinematicFrame( cinematics_t *cin ) +static qbyte *R_ReadNextRoQFrame( cinematics_t *cin ) { roq_chunk_t *chunk = &cin->chunk; @@ -76,97 +73,333 @@ /* ================== +R_RunRoQ +================== +*/ +static void R_RunRoQ( cinematics_t *cin ) +{ + unsigned int frame; + + frame = (Sys_Milliseconds () - cin->time) * (float)(RoQ_FRAMERATE) / 1000; + if( frame <= cin->frame ) + return; + if( frame > cin->frame + 1 ) + cin->time = Sys_Milliseconds () - cin->frame * 1000 / RoQ_FRAMERATE; + + cin->pic = cin->pic_pending; + cin->pic_pending = R_ReadNextRoQFrame( cin ); + + if( !cin->pic_pending ) { + FS_Seek( cin->file, cin->headerlen, FS_SEEK_SET ); + cin->frame = 0; + cin->pic_pending = R_ReadNextRoQFrame( cin ); + cin->time = Sys_Milliseconds (); + } + + cin->new_frame = qtrue; +} + +/* +================== +R_StopRoQ +================== +*/ +static void R_StopRoQ( cinematics_t *cin ) +{ + cin->frame = 0; + cin->time = 0; // done + cin->pic = NULL; + cin->pic_pending = NULL; + + if( cin->file ) { + FS_FCloseFile( cin->file ); + cin->file = 0; + } + if( cin->name ) { + Mem_Free( cin->name ); + cin->name = NULL; + } + if( cin->vid_buffer ) { + Mem_Free( cin->vid_buffer ); + cin->vid_buffer = NULL; + } +} + +/* +================== +R_OpenCinematics +================== +*/ +static cinematics_t *R_OpenCinematics( char *filename ) +{ + int file = 0; + cinematics_t *cin = NULL; + roq_chunk_t *chunk = &cin->chunk; + + if( FS_FOpenFile( filename, &file, FS_READ ) == -1 ) + return NULL; + + cin = Cin_Malloc( sizeof( cinematics_t ) ); + memset( cin, 0, sizeof( cinematics_t ) ); + cin->name = filename; + cin->file = file; + cin->mempool = r_cinMemPool; + + // read header + RoQ_ReadChunk( cin ); + + chunk = &cin->chunk; + if( chunk->id != RoQ_HEADER1 || chunk->size != RoQ_HEADER2 || chunk->argument != RoQ_HEADER3 ) { + R_StopRoQ( cin ); + Cin_Free( cin ); + return NULL; + } + + cin->headerlen = FS_Tell( cin->file ); + cin->frame = 0; + cin->pic = cin->pic_pending = R_ReadNextRoQFrame( cin ); + cin->time = Sys_Milliseconds (); + cin->new_frame = qtrue; + + return cin; +} + +/* +================== R_ResampleCinematicFrame ================== */ -image_t *R_ResampleCinematicFrame( shaderpass_t *pass ) +static image_t *R_ResampleCinematicFrame( r_cinhandle_t *handle ) { image_t *image; - cinematics_t *cin = pass->cin; + cinematics_t *cin = handle->cin; if( !cin->pic ) return NULL; - if( pass->anim_frames[0] ) { - image = pass->anim_frames[0]; - } else { - image = R_LoadPic( cin->name, &cin->pic, cin->width, cin->height, IT_CINEMATIC, 3 ); + if( !handle->image ) { + handle->image = R_LoadPic( handle->name, &cin->pic, cin->width, cin->height, IT_CINEMATIC, 3 ); cin->new_frame = qfalse; } if( !cin->new_frame ) - return image; + return handle->image; + cin->new_frame = qfalse; + image = handle->image; GL_Bind( 0, image ); if( image->width != cin->width || image->height != cin->height ) - R_Upload32( &cin->pic, image->width, image->height, IT_CINEMATIC, NULL, NULL, 3, qfalse ); + R_Upload32( &cin->pic, image->width, image->height, IT_CINEMATIC, &(image->upload_width), &(image->upload_height), 3, qfalse ); else - R_Upload32( &cin->pic, image->width, image->height, IT_CINEMATIC, NULL, NULL, 3, qtrue ); + R_Upload32( &cin->pic, image->width, image->height, IT_CINEMATIC, &(image->upload_width), &(image->upload_height), 3, qtrue ); image->width = cin->width; image->height = cin->height; return image; } +//================================================================================== + /* ================== -R_RunCinematic +R_CinList_f ================== */ -void R_RunCinematic( cinematics_t *cin ) +void R_CinList_f( void ) { - int frame; + r_cinhandle_t *handle, *hnode, *next; + cinematics_t *cin; + image_t *image; - frame = (Sys_Milliseconds () - cin->time) * (float)(RoQ_FRAMERATE) / 1000; - if( frame <= cin->frame ) + Com_Printf( "Active cintematics:" ); + hnode = &r_cinematics_headnode; + handle = hnode->prev; + if( handle == hnode ) { + Com_Printf( " none\n" ); return; - if( frame > cin->frame + 1 ) - cin->time = Sys_Milliseconds () - cin->frame * 1000 / RoQ_FRAMERATE; + } - cin->pic = cin->pic_pending; - cin->pic_pending = R_ReadNextCinematicFrame( cin ); + Com_Printf( "\n" ); + for( ; handle != hnode; handle = next ) { + next = handle->prev; - if( !cin->pic_pending ) { - FS_Seek( cin->file, cin->headerlen, FS_SEEK_SET ); - cin->frame = 0; - cin->pic_pending = R_ReadNextCinematicFrame( cin ); - cin->time = Sys_Milliseconds (); + assert( cin ); + cin = handle->cin; + image = handle->image; + + if( image && (cin->width != image->upload_width || cin->height != image->upload_height) ) + Com_Printf( "%s %i(%i)x%i(%i) %i\n", cin->name, cin->width, image->upload_width, cin->height, image->upload_height, cin->frame ); + else + Com_Printf( "%s %ix%i %i\n", cin->name, cin->width, cin->height, cin->frame ); } +} - cin->new_frame = qtrue; +/* +================== +R_InitCinematics +================== +*/ +void R_InitCinematics( void ) +{ + int i; + + r_cinMemPool = Mem_AllocPool( NULL, "Cinematics" ); + + r_cinematics = Cin_Malloc( sizeof( r_cinhandle_t ) * MAX_CINEMATICS ); + memset( r_cinematics, 0, sizeof( r_cinhandle_t ) * MAX_CINEMATICS ); + + // link cinemtics + r_free_cinematics = r_cinematics; + r_cinematics_headnode.id = 0; + r_cinematics_headnode.prev = &r_cinematics_headnode; + r_cinematics_headnode.next = &r_cinematics_headnode; + for( i = 0; i < MAX_CINEMATICS - 1; i++ ) { + if( i < MAX_CINEMATICS - 1 ) + r_cinematics[i].next = &r_cinematics[i+1]; + r_cinematics[i].id = i + 1; + } + + Cmd_AddCommand( "cinlist", R_CinList_f ); } /* ================== -R_PlayCinematic +R_RunAllCinematics ================== */ -void R_PlayCinematic( cinematics_t *cin ) +void R_RunAllCinematics( void ) { - int len; - roq_chunk_t *chunk = &cin->chunk; + r_cinhandle_t *handle, *hnode, *next; - cin->width = cin->height = 0; - len = FS_FOpenFile( cin->name, &cin->file, FS_READ ); - if( !cin->file || len < 1 ) { - cin->time = 0; // done - return; + hnode = &r_cinematics_headnode; + for( handle = hnode->prev; handle != hnode; handle = next ) { + next = handle->prev; + + R_RunRoQ( handle->cin ); } +} - // read header - RoQ_ReadChunk( cin ); +/* +================== +R_UploadCinematics +================== +*/ +image_t *R_UploadCinematics( unsigned int id ) +{ + assert( id > 0 && id <= MAX_CINEMATICS ); + return R_ResampleCinematicFrame( r_cinematics + id - 1 ); +} - if( chunk->id != RoQ_HEADER1 || chunk->size != RoQ_HEADER2 || chunk->argument != RoQ_HEADER3 ) { - R_StopCinematic( cin ); - cin->time = 0; // done +/* +================== +R_StartCinematic +================== +*/ +unsigned int R_StartCinematics( const char *arg ) +{ + char *name = NULL; + size_t name_size; + cinematics_t *cin = NULL; + r_cinhandle_t *handle, *hnode, *next; + + name_size = strlen( "video/" ) + strlen( arg ) + strlen( ".roq" ) + 1; + name = Cin_Malloc( name_size ); + Q_snprintfz( name, name_size, "video/%s", arg ); + COM_DefaultExtension( name, ".roq" ); + + // find cinematics with the same name + hnode = &r_cinematics_headnode; + for( handle = hnode->prev; handle != hnode; handle = next ) { + next = handle->prev; + + assert( handle->cin ); + + // reuse + if( !Q_stricmp( handle->cin->name, name ) ) { + Cin_Free( name ); + return handle->id; + } + } + + // open the file, read header, etc + cin = R_OpenCinematics( name ); + + // take a free cinematic handle if possible + if( !r_free_cinematics || !cin ) { + Cin_Free( name ); + return 0; + } + + handle = r_free_cinematics; + r_free_cinematics = handle->next; + + name = va( "***r_cinematic%i***", handle->id-1 ); + name_size = strlen( name ) + 1; + handle->name = Cin_Malloc( name_size ); + memcpy( handle->name, name, name_size ); + handle->cin = cin; + + // put handle at the start of the list + handle->prev = &r_cinematics_headnode; + handle->next = r_cinematics_headnode.next; + handle->next->prev = handle; + handle->prev->next = handle; + + return handle->id; +} + +/* +================= +R_FreeCinematics +================= +*/ +void R_FreeCinematics( unsigned int id ) +{ + r_cinhandle_t *handle; + + handle = r_cinematics + id - 1; + + if( handle->cin ) { + R_StopRoQ( handle->cin ); + Cin_Free( handle->cin ); + handle->cin = NULL; + } + if( handle->name ) { + Cin_Free( handle->name ); + handle->name = NULL; + } + + // remove from linked active list + handle->prev->next = handle->next; + handle->next->prev = handle->prev; + + // insert into linked free list + handle->next = r_free_cinematics; + r_free_cinematics = handle; +} + + +/* +================== +R_ShutdownCinematics +================== +*/ +void R_ShutdownCinematics( void ) +{ + r_cinhandle_t *handle, *hnode, *next; + + if( !r_cinMemPool ) return; + + hnode = &r_cinematics_headnode; + for( handle = hnode->prev; handle != hnode; handle = next ) { + next = handle->prev; + R_FreeCinematics( handle->id ); } - cin->headerlen = FS_Tell( cin->file ); - cin->frame = 0; - cin->pic = cin->pic_pending = R_ReadNextCinematicFrame( cin ); - cin->time = Sys_Milliseconds (); + Cin_Free( r_cinematics ); + Mem_FreePool( &r_cinMemPool ); - cin->new_frame = qtrue; + Cmd_RemoveCommand( "cinlist" ); } Modified: trunk/qfusion/source/ref_gl/r_local.h =================================================================== --- trunk/qfusion/source/ref_gl/r_local.h 2007-12-04 20:33:04 UTC (rev 789) +++ trunk/qfusion/source/ref_gl/r_local.h 2007-12-05 20:41:22 UTC (rev 790) @@ -20,7 +20,6 @@ */ #include "../qcommon/qcommon.h" -#include "../client/cin.h" #include "r_glimp.h" #include "r_public.h" @@ -374,10 +373,12 @@ // // r_cin.c // -void R_PlayCinematic( cinematics_t *cin ); -void R_RunCinematic( cinematics_t *cin ); -void R_StopCinematic( cinematics_t *cin ); -image_t *R_ResampleCinematicFrame( shaderpass_t *pass ); +void R_InitCinematics( void ); +void R_ShutdownCinematics( void ); +unsigned int R_StartCinematics( const char *arg ); +void R_FreeCinematics( unsigned int id ); +void R_RunAllCinematics( void ); +image_t *R_UploadCinematics( unsigned int id ); // // r_cull.c Modified: trunk/qfusion/source/ref_gl/r_main.c =================================================================== --- trunk/qfusion/source/ref_gl/r_main.c 2007-12-04 20:33:04 UTC (rev 789) +++ trunk/qfusion/source/ref_gl/r_main.c 2007-12-05 20:41:22 UTC (rev 790) @@ -1824,8 +1824,8 @@ R_UpdateHWGamma (); } - // run cinematic passes on shaders - R_RunCinematicShaders (); + // advance cinematics + R_RunAllCinematics (); // go into 2D mode R_Set2DMode( qtrue ); Modified: trunk/qfusion/source/ref_gl/r_register.c =================================================================== --- trunk/qfusion/source/ref_gl/r_register.c 2007-12-04 20:33:04 UTC (rev 789) +++ trunk/qfusion/source/ref_gl/r_register.c 2007-12-05 20:41:22 UTC (rev 790) @@ -989,6 +989,7 @@ R_InitLightStyles (); R_InitGLSLPrograms (); R_InitImages (); + R_InitCinematics (); R_InitShaders( !r_firstTime ); R_InitModels (); R_InitSkinFiles (); @@ -1018,6 +1019,7 @@ R_ShutdownShadows (); R_ShutdownSkinFiles (); R_ShutdownModels (); + R_ShutdownCinematics (); R_ShutdownShaders (); R_ShutdownImages (); R_ShutdownGLSLPrograms (); Modified: trunk/qfusion/source/ref_gl/r_shader.c =================================================================== --- trunk/qfusion/source/ref_gl/r_shader.c 2007-12-04 20:33:04 UTC (rev 789) +++ trunk/qfusion/source/ref_gl/r_shader.c 2007-12-05 20:41:22 UTC (rev 790) @@ -46,9 +46,6 @@ static shader_t *shaders_hash[SHADERS_HASH_SIZE]; static shadercache_t *shadercache_hash[SHADERCACHE_HASH_SIZE]; -static shader_t *r_cinematicShaders[MAX_SHADERS]; -static int r_numCinematicShaders; - static deformv_t r_currentDeforms[MAX_SHADER_DEFORMVS]; static shaderpass_t r_currentPasses[MAX_SHADER_PASSES]; static float r_currentRGBgenArgs[MAX_SHADER_PASSES][3], r_currentAlphagenArgs[MAX_SHADER_PASSES][2]; @@ -67,6 +64,7 @@ static void Shader_ParseFunc( char **args, shaderfunc_t *func ); static void Shader_MakeCache( qboolean silent, const char *name ); static unsigned int Shader_GetCache( char *name, shadercache_t **cache ); +#define Shader_FreePassCinematics(pass) if( (pass)->cin ) { R_FreeCinematics( (pass)->cin ); (pass)->cin = 0; } //=========================================================================== @@ -743,26 +741,23 @@ int flags; char *token; - if( pass->cin ) { - Shader_Free( pass->cin ); - pass->cin = NULL; - } + Shader_FreePassCinematics( pass ); token = Shader_ParseString( ptr ); if( !Q_stricmp( token, "$lightmap" ) ) { pass->tcgen = TC_GEN_LIGHTMAP; - pass->flags = (pass->flags & ~(SHADERPASS_VIDEOMAP|SHADERPASS_PORTALMAP|SHADERPASS_DLIGHT)) | SHADERPASS_LIGHTMAP; + pass->flags = (pass->flags & ~(SHADERPASS_PORTALMAP|SHADERPASS_DLIGHT)) | SHADERPASS_LIGHTMAP; pass->anim_fps = 0; pass->anim_frames[0] = NULL; } else if( !Q_stricmp( token, "$dlight" ) ) { pass->tcgen = TC_GEN_BASE; - pass->flags = (pass->flags & ~(SHADERPASS_LIGHTMAP|SHADERPASS_VIDEOMAP|SHADERPASS_PORTALMAP)) | SHADERPASS_DLIGHT; + pass->flags = (pass->flags & ~(SHADERPASS_LIGHTMAP|SHADERPASS_PORTALMAP)) | SHADERPASS_DLIGHT; pass->anim_fps = 0; pass->anim_frames[0] = NULL; r_shaderHasDlightPass = qtrue; } else if( !Q_stricmp( token, "$portalmap" ) || !Q_stricmp( token, "$mirrormap" ) ) { pass->tcgen = TC_GEN_PROJECTION; - pass->flags = (pass->flags & ~(SHADERPASS_LIGHTMAP|SHADERPASS_VIDEOMAP|SHADERPASS_DLIGHT)) | SHADERPASS_PORTALMAP; + pass->flags = (pass->flags & ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT)) | SHADERPASS_PORTALMAP; pass->anim_fps = 0; pass->anim_frames[0] = NULL; if( (shader->flags & SHADER_PORTAL) && (shader->sort == SHADER_SORT_PORTAL) ) { @@ -780,7 +775,7 @@ flags = Shader_SetImageFlags( shader ) | addFlags; pass->tcgen = TC_GEN_BASE; - pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_VIDEOMAP|SHADERPASS_PORTALMAP); + pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_PORTALMAP); pass->anim_fps = 0; pass->anim_frames[0] = Shader_FindImage( shader, token, flags, 0 ); } @@ -791,15 +786,12 @@ int flags; char *token; - if( pass->cin ) { - Shader_Free( pass->cin ); - pass->cin = NULL; - } + Shader_FreePassCinematics( pass ); flags = Shader_SetImageFlags( shader ) | addFlags; pass->tcgen = TC_GEN_BASE; - pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_VIDEOMAP|SHADERPASS_PORTALMAP); + pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_PORTALMAP); pass->anim_fps = Shader_ParseFloat( ptr ); pass->anim_numframes = 0; @@ -820,15 +812,12 @@ int flags; char *token; - if( pass->cin ) { - Shader_Free( pass->cin ); - pass->cin = NULL; - } + Shader_FreePassCinematics( pass ); token = Shader_ParseString( ptr ); flags = Shader_SetImageFlags( shader ) | addFlags; pass->anim_fps = 0; - pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_VIDEOMAP|SHADERPASS_PORTALMAP); + pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_PORTALMAP); if( !glConfig.ext.texture_cube_map ) { Com_DPrintf( S_COLOR_YELLOW "Shader %s has an unsupported cubemap stage: %s.\n", shader->name ); @@ -874,28 +863,15 @@ static void Shaderpass_VideoMap( shader_t *shader, shaderpass_t *pass, char **ptr ) { char *token; - size_t name_size; - cinematics_t *cin; - if( pass->cin ) { - Shader_Free( pass->cin ); - pass->cin = NULL; - } + Shader_FreePassCinematics( pass ); token = Shader_ParseString( ptr ); - name_size = strlen( "video/" ) + strlen( token ) + strlen( ".roq" ) + 1; - cin = pass->cin = (cinematics_t *)Shader_Malloc( sizeof( cinematics_t ) + name_size ); - cin->frame = -1; - cin->name = ( char * )(( qbyte * )cin + sizeof( cinematics_t ) ); - Q_snprintfz( cin->name, name_size, "video/%s", token ); - COM_DefaultExtension( cin->name, ".roq" ); - + pass->cin = R_StartCinematics( token ); pass->tcgen = TC_GEN_BASE; pass->anim_fps = 0; - pass->flags = (pass->flags & ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_PORTALMAP)) | SHADERPASS_VIDEOMAP; - shader->flags |= SHADER_VIDEOMAP; - r_cinematicShaders[r_numCinematicShaders++] = shader; + pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_PORTALMAP); } static void Shaderpass_NormalMap( shader_t *shader, shaderpass_t *pass, char **ptr ) @@ -910,10 +886,7 @@ return; } - if( pass->cin ) { - Shader_Free( pass->cin ); - pass->cin = NULL; - } + Shader_FreePassCinematics( pass ); flags = Shader_SetImageFlags( shader ); token = Shader_ParseString( ptr ); @@ -925,7 +898,7 @@ } pass->tcgen = TC_GEN_BASE; - pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_VIDEOMAP|SHADERPASS_PORTALMAP); + pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_PORTALMAP); pass->anim_frames[1] = R_FindImage( token, flags, bumpScale ); if( pass->anim_frames[1] ) { pass->program = DEFAULT_GLSL_PROGRAM; @@ -952,10 +925,7 @@ return; } - if( pass->cin ) { - Shader_Free( pass->cin ); - pass->cin = NULL; - } + Shader_FreePassCinematics( pass ); flags = Shader_SetImageFlags( shader ); token = Shader_ParseString( ptr ); @@ -966,7 +936,7 @@ pass->anim_frames[1] = pass->anim_frames[2] = NULL; pass->tcgen = TC_GEN_BASE; - pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_VIDEOMAP|SHADERPASS_PORTALMAP); + pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_PORTALMAP); norm[0] = gloss[0] = '\0'; while( 1 ) { @@ -1022,13 +992,10 @@ return; } - if( pass->cin ) { - Shader_Free( pass->cin ); - pass->cin = NULL; - } + Shader_FreePassCinematics( pass ); flags = Shader_SetImageFlags( shader ); - pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_VIDEOMAP|SHADERPASS_PORTALMAP); + pass->flags &= ~(SHADERPASS_LIGHTMAP|SHADERPASS_DLIGHT|SHADERPASS_PORTALMAP); norm[0] = dudv[0] = '\0'; while( 1 ) { @@ -1481,7 +1448,7 @@ return key; } -void Shader_FreeShader( shader_t *shader ) +static void Shader_FreeShader( shader_t *shader ) { int i; int shaderNum; @@ -1493,12 +1460,9 @@ r_skydomes[shaderNum] = NULL; } - for( i = 0, pass = shader->passes; i < shader->numpasses; i++, pass++ ) { - if( pass->flags & SHADERPASS_VIDEOMAP ) { - R_StopCinematic( pass->cin ); - Shader_Free( pass->cin ); - pass->cin = NULL; - } + if( shader->flags & SHADER_VIDEOMAP ) { + for( i = 0, pass = shader->passes; i < shader->numpasses; i++, pass++ ) + Shader_FreePassCinematics( pass ); } Shader_Free( shader->name ); @@ -1509,17 +1473,18 @@ int i; shader_t *shader; + if( !r_shadersmempool ) + return; + for( i = 0, shader = r_shaders; i < r_numShaders; i++, shader++ ) Shader_FreeShader( shader ); Mem_FreePool( &r_shadersmempool ); r_numShaders = 0; - r_numCinematicShaders = 0; shaderPaths = NULL; memset( r_shaders, 0, sizeof( r_shaders ) ); - memset( r_cinematicShaders, 0, sizeof( r_cinematicShaders ) ); memset( shaders_hash, 0, sizeof( shaders_hash ) ); memset( shadercache_hash, 0, sizeof( shadercache_hash ) ); } @@ -1849,6 +1814,8 @@ s->flags |= SHADER_NO_MODULATIVE_DLIGHTS; for( i = 0, pass = s->passes; i < s->numpasses; i++, pass++ ) { + if( pass->cin ) + s->flags |= SHADER_VIDEOMAP; if( pass->flags & SHADERPASS_LIGHTMAP ) s->flags |= SHADER_LIGHTMAP; if( pass->program ) { @@ -1943,41 +1910,11 @@ // upload cinematics for( j = 0, pass = shader->passes; j < shader->numpasses; j++, pass++ ) { - if( pass->flags & SHADERPASS_VIDEOMAP ) - pass->anim_frames[0] = R_ResampleCinematicFrame( pass ); + if( pass->cin ) + pass->anim_frames[0] = R_UploadCinematics( pass->cin ); } } -void R_RunCinematicShaders( void ) -{ - int i, j; - shader_t *shader; - shaderpass_t *pass; - - for( i = 0; i < r_numCinematicShaders; i++ ) { - shader = r_cinematicShaders[i]; - - for ( j = 0, pass = shader->passes; j < shader->numpasses; j++, pass++ ) { - if( !(pass->flags & SHADERPASS_VIDEOMAP) ) - continue; - - // reinitialize - if( pass->cin->frame == -1 ) { - R_StopCinematic( pass->cin ); - R_PlayCinematic( pass->cin ); - - if( pass->cin->time == 0 ) { // not found - pass->flags &= ~SHADERPASS_VIDEOMAP; - Shader_Free( pass->cin ); - } - continue; - } - - R_RunCinematic( pass->cin ); - } - } -} - void R_DeformvBBoxForShader( shader_t *shader, vec3_t ebbox ) { int dv; Modified: trunk/qfusion/source/ref_gl/r_shader.h =================================================================== --- trunk/qfusion/source/ref_gl/r_shader.h 2007-12-04 20:33:04 UTC (rev 789) +++ trunk/qfusion/source/ref_gl/r_shader.h 2007-12-05 20:41:22 UTC (rev 790) @@ -83,18 +83,17 @@ enum { SHADERPASS_LIGHTMAP = SHADERPASS_MARK_BEGIN, - SHADERPASS_VIDEOMAP = SHADERPASS_MARK_BEGIN << 1, - SHADERPASS_DETAIL = SHADERPASS_MARK_BEGIN << 2, - SHADERPASS_NOCOLORARRAY = SHADERPASS_MARK_BEGIN << 3, - SHADERPASS_DLIGHT = SHADERPASS_MARK_BEGIN << 4, - SHADERPASS_DELUXEMAP = SHADERPASS_MARK_BEGIN << 5, - SHADERPASS_PORTALMAP = SHADERPASS_MARK_BEGIN << 6, - SHADERPASS_STENCILSHADOW = SHADERPASS_MARK_BEGIN << 7, + SHADERPASS_DETAIL = SHADERPASS_MARK_BEGIN << 1, + SHADERPASS_NOCOLORARRAY = SHADERPASS_MARK_BEGIN << 2, + SHADERPASS_DLIGHT = SHADERPASS_MARK_BEGIN << 3, + SHADERPASS_DELUXEMAP = SHADERPASS_MARK_BEGIN << 4, + SHADERPASS_PORTALMAP = SHADERPASS_MARK_BEGIN << 5, + SHADERPASS_STENCILSHADOW = SHADERPASS_MARK_BEGIN << 6, - SHADERPASS_BLEND_REPLACE = SHADERPASS_MARK_BEGIN << 8, - SHADERPASS_BLEND_MODULATE = SHADERPASS_MARK_BEGIN << 9, - SHADERPASS_BLEND_ADD = SHADERPASS_MARK_BEGIN << 10, - SHADERPASS_BLEND_DECAL = SHADERPASS_MARK_BEGIN << 11 + SHADERPASS_BLEND_REPLACE = SHADERPASS_MARK_BEGIN << 7, + SHADERPASS_BLEND_MODULATE = SHADERPASS_MARK_BEGIN << 8, + SHADERPASS_BLEND_ADD = SHADERPASS_MARK_BEGIN << 9, + SHADERPASS_BLEND_DECAL = SHADERPASS_MARK_BEGIN << 10 }; #define SHADERPASS_BLENDMODE (SHADERPASS_BLEND_REPLACE|SHADERPASS_BLEND_MODULATE|SHADERPASS_BLEND_ADD|SHADERPASS_BLEND_DECAL) @@ -229,7 +228,7 @@ unsigned short numtcmods; tcmod_t *tcmods; - cinematics_t *cin; + unsigned int cin; const char *program; unsigned short program_type; @@ -272,14 +271,13 @@ extern int r_numShaders; extern skydome_t *r_skydomes[MAX_SHADERS]; -#define Shader_Malloc(size) Mem_Alloc(r_shadersmempool,size) +#define Shader_Malloc(size) _Mem_Alloc(r_shadersmempool,size,0,0,__FILE__,__LINE__) #define Shader_Free(data) Mem_Free(data) #define Shader_Sortkey(shader,sort) (((sort)<<26)|(shader-r_shaders)) void R_InitShaders( qboolean silent ); void R_ShutdownShaders( void ); -void R_RunCinematicShaders( void ); void R_UploadCinematicShader( shader_t *shader ); void R_DeformvBBoxForShader( shader_t *shader, vec3_t ebbox ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |