Gecko resizing support
authorres <res@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 12 Dec 2007 00:08:17 +0000 (00:08 +0000)
committerres <res@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 12 Dec 2007 00:08:17 +0000 (00:08 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7786 d7cf8633-e32d-0410-b094-e92efae38249

cl_gecko.c
cl_gecko.h
gl_textures.c
mvm_cmds.c
prvm_cmds.c
prvm_cmds.h
r_textures.h

index 2289021..d9950a1 100644 (file)
@@ -12,6 +12,8 @@
 #include "cl_gecko.h"\r
 #include "timing.h"\r
 \r
+#define DEFAULT_SIZE     512\r
+\r
 static rtexturepool_t *cl_geckotexturepool;\r
 static OSGK_Embedding *cl_geckoembedding;\r
 \r
@@ -20,6 +22,8 @@ struct clgecko_s {
        char name[ MAX_QPATH + 32 ];\r
 \r
        OSGK_Browser *browser;\r
+       int w, h;\r
+       int texW, texH;\r
        \r
        rtexture_t *texture;\r
 };\r
@@ -59,17 +63,18 @@ clgecko_t * CL_Gecko_FindBrowser( const char *name ) {
 \r
 static void cl_gecko_updatecallback( rtexture_t *texture, clgecko_t *instance ) {\r
        const unsigned char *data;\r
-       if( instance->browser && osgk_browser_query_dirty (instance->browser) ) {\r
+       if( instance->browser ) {\r
                // TODO: OSGK only supports BGRA right now\r
                TIMING_TIMESTATEMENT(data = osgk_browser_lock_data( instance->browser, NULL ));\r
-               R_UpdateTexture( texture, data, 0, 0, DEFAULT_GECKO_WIDTH, DEFAULT_GECKO_HEIGHT );\r
+               R_UpdateTexture( texture, data, 0, 0, instance->w, instance->h);\r
                osgk_browser_unlock_data( instance->browser, data );\r
        }\r
 }\r
 \r
 static void cl_gecko_linktexture( clgecko_t *instance ) {\r
        // TODO: assert that instance->texture == NULL\r
-       instance->texture = R_LoadTexture2D( cl_geckotexturepool, instance->name, DEFAULT_GECKO_WIDTH, DEFAULT_GECKO_HEIGHT, NULL, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PERSISTENT, NULL );\r
+       instance->texture = R_LoadTexture2D( cl_geckotexturepool, instance->name, \r
+               instance->texW, instance->texH, NULL, TEXTYPE_BGRA, TEXF_ALPHA | TEXF_PERSISTENT, NULL );\r
        R_MakeTextureDynamic( instance->texture, cl_gecko_updatecallback, instance );\r
        CL_LinkDynTexture( instance->name, instance->texture );\r
 }\r
@@ -101,9 +106,13 @@ clgecko_t * CL_Gecko_CreateBrowser( const char *name ) {
 \r
        instance->active = true;\r
        strlcpy( instance->name, name, sizeof( instance->name ) );\r
-       instance->browser = osgk_browser_create( cl_geckoembedding, DEFAULT_GECKO_WIDTH, DEFAULT_GECKO_HEIGHT );\r
+       instance->browser = osgk_browser_create( cl_geckoembedding, DEFAULT_SIZE, DEFAULT_SIZE );\r
        // TODO: assert != NULL\r
 \r
+       instance->texW = DEFAULT_SIZE;\r
+       instance->texH = DEFAULT_SIZE;\r
+       instance->w = DEFAULT_SIZE;\r
+       instance->h = DEFAULT_SIZE;\r
        cl_gecko_linktexture( instance );\r
 \r
        return instance;\r
@@ -294,8 +303,8 @@ void CL_Gecko_Event_CursorMove( clgecko_t *instance, float x, float y ) {
                return;\r
        }\r
 \r
-       mappedx = x * DEFAULT_GECKO_WIDTH;\r
-       mappedy = y * DEFAULT_GECKO_HEIGHT;\r
+       mappedx = x * instance->w;\r
+       mappedy = y * instance->h;\r
        osgk_browser_event_mouse_move( instance->browser, mappedx, mappedy );\r
 }\r
 \r
@@ -408,4 +417,42 @@ qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventty
        return false;\r
 }\r
 \r
-#endif
\ No newline at end of file
+void CL_Gecko_Resize( clgecko_t *instance, int w, int h ) {\r
+       int newW, newH;\r
+\r
+       if( !instance || !instance->browser ) {\r
+               return;\r
+       }\r
+\r
+       newW = 1; while( newW < w ) newW *= 2;\r
+       newH = 1; while( newH < h ) newH *= 2;\r
+       if ((newW != instance->texW) || (newH != instance->texH))\r
+       {\r
+         cl_gecko_unlinktexture( instance );\r
+         instance->texW = newW;\r
+         instance->texH = newH;\r
+         cl_gecko_linktexture( instance );\r
+       }\r
+       else\r
+       {\r
+         /* The gecko area will only cover a part of the texture; to avoid\r
+            'old' pixels bleeding in at the border clear the texture. */\r
+         R_ClearTexture( instance->texture );\r
+       }\r
+\r
+       osgk_browser_resize( instance->browser, w, h);\r
+       instance->w = w;\r
+       instance->h = h;\r
+}\r
+\r
+void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* u, float* v )\r
+{\r
+       if( !instance || !instance->browser ) {\r
+               return;\r
+       }\r
+\r
+       *u = (float)instance->w / instance->texW;\r
+       *v = (float)instance->h / instance->texH;\r
+}\r
+\r
+#endif\r
index c5bb63d..b4efeff 100644 (file)
@@ -7,9 +7,6 @@
 \r
 #include "cl_dyntexture.h"\r
 \r
-#define DEFAULT_GECKO_WIDTH    512\r
-#define DEFAULT_GECKO_HEIGHT   DEFAULT_GECKO_WIDTH\r
-\r
 #define CLGECKOPREFIX                  CLDYNTEXTUREPREFIX "gecko/"\r
 #define MAX_GECKO_INSTANCES    16\r
 \r
@@ -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\r
 qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventtype_t eventtype );\r
 \r
+void CL_Gecko_Resize( clgecko_t *instance, int w, int h );\r
+void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* u, float* v );\r
 #endif\r
 \r
 #endif\r
index ab18e72..f2fac41 100644 (file)
@@ -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 );
+}
index c4b194a..2947ebf 100644 (file)
@@ -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
index 3a8b38a..cc01c83 100644 (file)
@@ -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
 
 /*
index b9d16bd..73c8c19 100644 (file)
@@ -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);
index aac4bde..f31460a 100644 (file)
@@ -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