[D3D 79] Various refcounting / code factorization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Changelog:
 - fix in the GetHandle method
 - factorize some code between D3D1/2/3 and D3D7
 - fix reference counting for palettes
   
   
-- 
		 Lionel Ulmer - http://www.bbrox.org/
--- /home/ulmer/Wine/wine_base//dlls/ddraw/d3ddevice/mesa.c	2003-01-03 16:02:11.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/d3ddevice/mesa.c	2003-01-03 20:31:04.000000000 +0100
@@ -312,9 +314,11 @@
     
     TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
     if (!--(This->ref)) {
+        int i;
 	/* Release texture associated with the device */ 
-	if (This->current_texture[0] != NULL)
-	    IDirect3DTexture2_Release(ICOM_INTERFACE(This->current_texture[0], IDirect3DTexture2));
+	for (i = 0; i < MAX_TEXTURES; i++) 
+	    if (This->current_texture[i] != NULL)
+	        IDirectDrawSurface7_Release(ICOM_INTERFACE(This->current_texture[i], IDirectDrawSurface7));
 
 	/* And warn the D3D object that this device is no longer active... */
 	This->d3d->removed_device(This->d3d, This);
@@ -1402,12 +1406,13 @@
     TRACE("(%p/%p)->(%08lx,%p)\n", This, iface, dwStage, lpTexture2);
     
     if (This->current_texture[dwStage] != NULL) {
-        /* Seems that this is not right... Need to test in real Windows
-	   IDirect3DTexture2_Release(ICOM_INTERFACE(This->current_texture[dwStage], IDirect3DTexture2)); */
+	IDirectDrawSurface7_Release(ICOM_INTERFACE(This->current_texture[dwStage], IDirectDrawSurface7));
     }
     
     ENTER_GL();
     if (lpTexture2 == NULL) {
+	This->current_texture[dwStage] = NULL;
+
         TRACE(" disabling 2D texturing.\n");
 	glBindTexture(GL_TEXTURE_2D, 0);
         glDisable(GL_TEXTURE_2D);
@@ -2102,9 +2111,6 @@
 	surf->d3ddevice = object;
     }
 
-    /* FIXME: Should handle other versions than just 7 */
-    InitDefaultStateBlock(&object->state_block,7);
-        
     /* FIXME: These 4 statements are kept for compatibility but should be removed as soon
        as they are correctly handled */
     gl_object->render_state.fog_on = FALSE;
@@ -2137,10 +2143,6 @@
     ENTER_GL();
     TRACE(" current context set\n");
 
-    /* Apply default render state values */
-    apply_render_state(gl_object, &object->state_block);
-    /* FIXME: do something similar for ligh_state and texture_stage_state */
-    
     glClearColor(0.0, 0.0, 0.0, 0.0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     glDrawBuffer(buffer);
@@ -2161,6 +2163,12 @@
 
     /* And finally warn D3D that this device is now present */
     object->d3d->added_device(object->d3d, object);
-    
+
+    /* FIXME: Should handle other versions than just 7 */
+    InitDefaultStateBlock(&object->state_block,7);
+    /* Apply default render state values */
+    apply_render_state(gl_object, &object->state_block);
+    /* FIXME: do something similar for ligh_state and texture_stage_state */
+
     return DD_OK;
 }
--- /home/ulmer/Wine/wine_base//dlls/ddraw/d3dtexture.c	2003-01-03 16:02:11.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/d3dtexture.c	2003-01-03 22:23:48.000000000 +0100
@@ -496,8 +496,19 @@
 					 LPD3DTEXTUREHANDLE lpHandle)
 {
     ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
-    FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpDirect3DDevice2, lpHandle);
-    return DD_OK;
+    IDirect3DDeviceImpl *lpDeviceImpl = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice2, lpDirect3DDevice2);
+    
+    TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpDirect3DDevice2, lpHandle);
+
+    /* The handle is simply the pointer to the implementation structure */
+    *lpHandle = (D3DTEXTUREHANDLE) This;
+
+    TRACE(" returning handle %08lx.\n", *lpHandle);
+    
+    /* Now set the device for this texture */
+    This->d3ddevice = lpDeviceImpl;
+
+    return D3D_OK;
 }
 
 HRESULT WINAPI
@@ -525,9 +536,10 @@
 {
     IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
     DWORD mem_used;
+    int i;
 
     TRACE(" deleting texture with GL id %d.\n", glThis->tex_name);
-      
+
     /* And delete texture handle */
     ENTER_GL();
     if (glThis->tex_name != 0)
@@ -536,8 +548,9 @@
 
     /* And if this texture was the current one, remove it at the device level */
     if (This->d3ddevice != NULL)
-        if (This->d3ddevice->current_texture[0] == This)
-	    This->d3ddevice->current_texture[0] = NULL;
+        for (i = 0; i < MAX_TEXTURES; i++)
+	    if (This->d3ddevice->current_texture[i] == This)
+	        This->d3ddevice->current_texture[i] = NULL;
 
     /* All this should be part of main surface management not just a hack for texture.. */
     if (glThis->loaded) {
@@ -570,37 +583,6 @@
 }
 
 HRESULT WINAPI
-GL_IDirect3DTextureImpl_2_1T_GetHandle(LPDIRECT3DTEXTURE2 iface,
-				       LPDIRECT3DDEVICE2 lpDirect3DDevice2,
-				       LPD3DTEXTUREHANDLE lpHandle)
-{
-    ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
-    IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
-    IDirect3DDeviceImpl *lpDeviceImpl = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice2, lpDirect3DDevice2);
-    
-    TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpDirect3DDevice2, lpHandle);
-
-    /* The handle is simply the pointer to the implementation structure */
-    *lpHandle = (D3DTEXTUREHANDLE) This;
-
-    TRACE(" returning handle %08lx.\n", *lpHandle);
-    
-    /* Now, bind a new texture */
-    This->d3ddevice = lpDeviceImpl;
-
-    /* Associate the texture with the device and perform the appropriate AddRef/Release */
-    /* FIXME: Is there only one or several textures associated with the device ? */
-    if (lpDeviceImpl->current_texture[0] != NULL)
-        IDirectDrawSurface7_Release(ICOM_INTERFACE(lpDeviceImpl->current_texture[0], IDirectDrawSurface7));
-    IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This, IDirectDrawSurface7));
-    lpDeviceImpl->current_texture[0] = This;
-
-    TRACE("OpenGL texture handle is : %d\n", glThis->tex_name);
-
-    return D3D_OK;
-}
-
-HRESULT WINAPI
 GL_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface,
 				  LPDIRECT3DTEXTURE2 lpD3DTexture2)
 {
@@ -641,12 +623,11 @@
     if (This->palette == NULL) {
         This->palette = lpD3DTextureImpl->palette;
 	if (lpD3DTextureImpl->palette != NULL) IDirectDrawPalette_AddRef(ICOM_INTERFACE(lpD3DTextureImpl->palette,
-										IDirectDrawPalette));
+											IDirectDrawPalette));
     } else {
         if (lpD3DTextureImpl->palette != NULL) {
 	    PALETTEENTRY palent[256];
 	    IDirectDrawPalette *pal_int = ICOM_INTERFACE(lpD3DTextureImpl->palette, IDirectDrawPalette);
-	    IDirectDrawPalette_AddRef(pal_int);
 	    IDirectDrawPalette_GetEntries(pal_int, 0, 0, 256, palent);
 	    IDirectDrawPalette_SetEntries(ICOM_INTERFACE(This->palette, IDirectDrawPalette),
 					  0, 0, 256, palent);
@@ -667,6 +648,7 @@
 
         /* Copy also the ColorKeying stuff */
         if (src_d->dwFlags & DDSD_CKSRCBLT) {
+	    dst_d->dwFlags |= DDSD_CKSRCBLT;
 	    dst_d->ddckCKSrcBlt.dwColorSpaceLowValue = src_d->ddckCKSrcBlt.dwColorSpaceLowValue;
 	    dst_d->ddckCKSrcBlt.dwColorSpaceHighValue = src_d->ddckCKSrcBlt.dwColorSpaceHighValue;
 	}
@@ -780,7 +762,7 @@
     XCAST(QueryInterface) Thunk_IDirect3DTextureImpl_2_QueryInterface,
     XCAST(AddRef) Thunk_IDirect3DTextureImpl_2_AddRef,
     XCAST(Release) Thunk_IDirect3DTextureImpl_2_Release,
-    XCAST(GetHandle) GL_IDirect3DTextureImpl_2_1T_GetHandle,
+    XCAST(GetHandle) Main_IDirect3DTextureImpl_2_1T_GetHandle,
     XCAST(PaletteChanged) Main_IDirect3DTextureImpl_2_1T_PaletteChanged,
     XCAST(Load) GL_IDirect3DTextureImpl_2_1T_Load,
 };
--- /home/ulmer/Wine/wine_base//dlls/ddraw/mesa.c	2003-01-03 16:02:11.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/mesa.c	2003-01-03 20:32:26.000000000 +0100
@@ -81,23 +81,12 @@
 	    case D3DRENDERSTATE_TEXTUREHANDLE: {    /*  1 */
 	        IDirectDrawSurfaceImpl *tex = (IDirectDrawSurfaceImpl*) dwRenderState;
 		
-		if (tex == NULL) {
-		    glBindTexture(GL_TEXTURE_2D, 0);
-		    glDisable(GL_TEXTURE_2D);
-		    TRACE("disabling texturing\n");
-		} else {
-		    glEnable(GL_TEXTURE_2D);
-		    
-		    /* Default parameters */
-		    gltex_upload_texture(tex);
-		    
-		    /* To prevent state change, we could test here what are the parameters
-		       stored in the texture */
-		    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, rs->mag);
-		    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, rs->min);
-		}
+		LEAVE_GL();
+		IDirect3DDevice7_SetTexture(ICOM_INTERFACE(&(This->parent), IDirect3DDevice7),
+					    0, 
+					    ICOM_INTERFACE(tex, IDirectDrawSurface7));
+		ENTER_GL();
 	    } break;
-
 	      
 	    case D3DRENDERSTATE_TEXTUREADDRESSU:  /* 44 */
 	    case D3DRENDERSTATE_TEXTUREADDRESSV:  /* 45 */

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux