From a6cd51357b59bc588e47d3827953340c4de33d12 Mon Sep 17 00:00:00 2001 From: res Date: Wed, 12 Dec 2007 00:08:17 +0000 Subject: [PATCH] Gecko resizing support git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7786 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_gecko.c | 61 +++++++++++++++++++++++++++++++++++++++++++++------ cl_gecko.h | 5 ++--- gl_textures.c | 6 +++++ mvm_cmds.c | 4 +++- prvm_cmds.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++ prvm_cmds.h | 2 ++ r_textures.h | 3 +++ 7 files changed, 127 insertions(+), 11 deletions(-) diff --git a/cl_gecko.c b/cl_gecko.c index 22890211..d9950a14 100644 --- a/cl_gecko.c +++ b/cl_gecko.c @@ -12,6 +12,8 @@ #include "cl_gecko.h" #include "timing.h" +#define DEFAULT_SIZE 512 + static rtexturepool_t *cl_geckotexturepool; static OSGK_Embedding *cl_geckoembedding; @@ -20,6 +22,8 @@ struct clgecko_s { char name[ MAX_QPATH + 32 ]; OSGK_Browser *browser; + int w, h; + int texW, texH; rtexture_t *texture; }; @@ -59,17 +63,18 @@ clgecko_t * CL_Gecko_FindBrowser( const char *name ) { static void cl_gecko_updatecallback( rtexture_t *texture, clgecko_t *instance ) { const unsigned char *data; - if( instance->browser && osgk_browser_query_dirty (instance->browser) ) { + if( instance->browser ) { // TODO: OSGK only supports BGRA right now TIMING_TIMESTATEMENT(data = osgk_browser_lock_data( instance->browser, NULL )); - R_UpdateTexture( texture, data, 0, 0, DEFAULT_GECKO_WIDTH, DEFAULT_GECKO_HEIGHT ); + R_UpdateTexture( texture, data, 0, 0, instance->w, instance->h); osgk_browser_unlock_data( instance->browser, data ); } } static void cl_gecko_linktexture( clgecko_t *instance ) { // TODO: assert that instance->texture == NULL - instance->texture = R_LoadTexture2D( cl_geckotexturepool, instance->name, DEFAULT_GECKO_WIDTH, DEFAULT_GECKO_HEIGHT, NULL, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PERSISTENT, NULL ); + instance->texture = R_LoadTexture2D( cl_geckotexturepool, instance->name, + instance->texW, instance->texH, NULL, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PERSISTENT, NULL ); R_MakeTextureDynamic( instance->texture, cl_gecko_updatecallback, instance ); CL_LinkDynTexture( instance->name, instance->texture ); } @@ -101,9 +106,13 @@ clgecko_t * CL_Gecko_CreateBrowser( const char *name ) { instance->active = true; strlcpy( instance->name, name, sizeof( instance->name ) ); - instance->browser = osgk_browser_create( cl_geckoembedding, DEFAULT_GECKO_WIDTH, DEFAULT_GECKO_HEIGHT ); + instance->browser = osgk_browser_create( cl_geckoembedding, DEFAULT_SIZE, DEFAULT_SIZE ); // TODO: assert != NULL + instance->texW = DEFAULT_SIZE; + instance->texH = DEFAULT_SIZE; + instance->w = DEFAULT_SIZE; + instance->h = DEFAULT_SIZE; cl_gecko_linktexture( instance ); return instance; @@ -294,8 +303,8 @@ void CL_Gecko_Event_CursorMove( clgecko_t *instance, float x, float y ) { return; } - mappedx = x * DEFAULT_GECKO_WIDTH; - mappedy = y * DEFAULT_GECKO_HEIGHT; + mappedx = x * instance->w; + mappedy = y * instance->h; osgk_browser_event_mouse_move( instance->browser, mappedx, mappedy ); } @@ -408,4 +417,42 @@ qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventty return false; } -#endif \ No newline at end of file +void CL_Gecko_Resize( clgecko_t *instance, int w, int h ) { + int newW, newH; + + if( !instance || !instance->browser ) { + return; + } + + newW = 1; while( newW < w ) newW *= 2; + newH = 1; while( newH < h ) newH *= 2; + if ((newW != instance->texW) || (newH != instance->texH)) + { + cl_gecko_unlinktexture( instance ); + instance->texW = newW; + instance->texH = newH; + cl_gecko_linktexture( instance ); + } + else + { + /* The gecko area will only cover a part of the texture; to avoid + 'old' pixels bleeding in at the border clear the texture. */ + R_ClearTexture( instance->texture ); + } + + osgk_browser_resize( instance->browser, w, h); + instance->w = w; + instance->h = h; +} + +void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* u, float* v ) +{ + if( !instance || !instance->browser ) { + return; + } + + *u = (float)instance->w / instance->texW; + *v = (float)instance->h / instance->texH; +} + +#endif diff --git a/cl_gecko.h b/cl_gecko.h index c5bb63d2..b4efeffa 100644 --- a/cl_gecko.h +++ b/cl_gecko.h @@ -7,9 +7,6 @@ #include "cl_dyntexture.h" -#define DEFAULT_GECKO_WIDTH 512 -#define DEFAULT_GECKO_HEIGHT DEFAULT_GECKO_WIDTH - #define CLGECKOPREFIX CLDYNTEXTUREPREFIX "gecko/" #define MAX_GECKO_INSTANCES 16 @@ -38,6 +35,8 @@ void CL_Gecko_Event_CursorMove( clgecko_t *instance, float x, float y ); // returns whether the key/button event was handled or not qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventtype_t eventtype ); +void CL_Gecko_Resize( clgecko_t *instance, int w, int h ); +void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* u, float* v ); #endif #endif diff --git a/gl_textures.c b/gl_textures.c index ab18e722..f2fac414 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -1131,3 +1131,9 @@ void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, in R_Upload(glt, data, x, y, 0, width, height, 1); } +void R_ClearTexture (rtexture_t *rt) +{ + gltexture_t *glt = (gltexture_t *)rt; + + R_Upload( glt, NULL, 0, 0, 0, glt->tilewidth, glt->tileheight, glt->tiledepth ); +} diff --git a/mvm_cmds.c b/mvm_cmds.c index c4b194a9..2947ebfa 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -1268,15 +1268,17 @@ VM_gecko_destroy, // #488 VM_gecko_navigate, // #489 VM_gecko_keyevent, // #490 VM_gecko_movemouse, // #491 +VM_gecko_resize, // #492 +VM_gecko_get_texture_extent, // #493 #else NULL, // #487 NULL, // #488 NULL, // #489 NULL, // #490 NULL, // #491 -#endif NULL, // #492 NULL, // #493 +#endif NULL, // #494 NULL, // #495 NULL, // #496 diff --git a/prvm_cmds.c b/prvm_cmds.c index 3a8b38a3..cc01c830 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -3248,6 +3248,63 @@ void VM_gecko_movemouse( void ) { } CL_Gecko_Event_CursorMove( instance, x, y ); } + + +/* +======================== +VM_gecko_resize + +void gecko_resize( string name, float w, float h ) +======================== +*/ +void VM_gecko_resize( void ) { + const char *name; + float w, h; + clgecko_t *instance; + + VM_SAFEPARMCOUNT( 3, VM_gecko_movemouse ); + + name = PRVM_G_STRING( OFS_PARM0 ); + VM_CheckEmptyString( name ); + w = PRVM_G_FLOAT( OFS_PARM1 ); + h = PRVM_G_FLOAT( OFS_PARM2 ); + + instance = CL_Gecko_FindBrowser( name ); + if( !instance ) { + return; + } + CL_Gecko_Resize( instance, w, h ); +} + + +/* +======================== +VM_gecko_get_texture_extent + +vector gecko_get_texture_extent( string name ) +======================== +*/ +void VM_gecko_get_texture_extent( void ) { + const char *name; + clgecko_t *instance; + + VM_SAFEPARMCOUNT( 1, VM_gecko_movemouse ); + + name = PRVM_G_STRING( OFS_PARM0 ); + VM_CheckEmptyString( name ); + + PRVM_G_VECTOR(OFS_RETURN)[2] = 0; + instance = CL_Gecko_FindBrowser( name ); + if( !instance ) { + PRVM_G_VECTOR(OFS_RETURN)[0] = 0; + PRVM_G_VECTOR(OFS_RETURN)[1] = 0; + return; + } + CL_Gecko_GetTextureExtent( instance, + PRVM_G_VECTOR(OFS_RETURN), PRVM_G_VECTOR(OFS_RETURN)+1 ); +} + + #endif /* diff --git a/prvm_cmds.h b/prvm_cmds.h index b9d16bdb..73c8c191 100644 --- a/prvm_cmds.h +++ b/prvm_cmds.h @@ -364,6 +364,8 @@ void VM_gecko_destroy( void ); void VM_gecko_navigate( void ); void VM_gecko_keyevent( void ); void VM_gecko_movemouse( void ); +void VM_gecko_resize( void ); +void VM_gecko_get_texture_extent( void ); #endif void VM_drawline (void); diff --git a/r_textures.h b/r_textures.h index aac4bdec..f31460ac 100644 --- a/r_textures.h +++ b/r_textures.h @@ -110,5 +110,8 @@ void R_Textures_Frame(void); void R_MarkDirtyTexture(rtexture_t *rt); void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data); +// Clear the texture's contents +void R_ClearTexture (rtexture_t *rt); + #endif -- 2.39.2