[D3D 52] Implement GetTransform

Lionel Ulmer lionel.ulmer at free.fr
Thu Dec 26 06:18:17 CST 2002


Changelog
 Implement GetTransform and rework a bit the matrices storage

-- 
		 Lionel Ulmer - http://www.bbrox.org/
-------------- next part --------------
--- /home/ulmer/Wine/wine_base//dlls/ddraw/d3ddevice/main.c	2002-12-25 22:12:33.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/d3ddevice/main.c	2002-12-26 12:35:42.000000000 +0100
@@ -211,7 +211,32 @@
                                               LPD3DMATRIX lpD3DMatrix)
 {
     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
-    FIXME("(%p/%p)->(%08x,%p): stub!\n", This, iface, dtstTransformStateType, lpD3DMatrix);
+    TRACE("(%p/%p)->(%08x,%p)\n", This, iface, dtstTransformStateType, lpD3DMatrix);
+
+    switch (dtstTransformStateType) {
+        case D3DTRANSFORMSTATE_WORLD: {
+	    TRACE(" returning D3DTRANSFORMSTATE_WORLD :\n");
+	    memcpy(lpD3DMatrix, This->world_mat, 16 * sizeof(D3DVALUE));
+	    dump_mat(lpD3DMatrix);
+	} break;
+
+	case D3DTRANSFORMSTATE_VIEW: {
+	    TRACE(" returning D3DTRANSFORMSTATE_VIEW :\n");
+	    memcpy(lpD3DMatrix, This->world_mat, 16 * sizeof(D3DVALUE));
+	    dump_mat(lpD3DMatrix);
+	} break;
+
+	case D3DTRANSFORMSTATE_PROJECTION: {
+	    TRACE(" returning D3DTRANSFORMSTATE_PROJECTION :\n");
+	    memcpy(lpD3DMatrix, This->world_mat, 16 * sizeof(D3DVALUE));
+	    dump_mat(lpD3DMatrix);
+	} break;
+
+	default:
+	    ERR("Unknown transform type %08x !!!\n", dtstTransformStateType);
+	    return DDERR_INVALIDPARAMS;
+    }
+
     return DD_OK;
 }
 
--- /home/ulmer/Wine/wine_base//dlls/ddraw/d3ddevice/mesa.c	2002-12-25 22:12:33.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/d3ddevice/mesa.c	2002-12-26 12:38:00.000000000 +0100
@@ -306,6 +306,10 @@
 	/* And warn the D3D object that this device is no longer active... */
 	This->d3d->removed_device(This->d3d, This);
 
+	HeapFree(GetProcessHeap(), 0, This->world_mat);
+	HeapFree(GetProcessHeap(), 0, This->view_mat);
+	HeapFree(GetProcessHeap(), 0, This->proj_mat);
+
 	ENTER_GL();
 	glXDestroyContext(glThis->display, glThis->gl_context);
 	LEAVE_GL();
@@ -359,8 +363,8 @@
     TRACE("Enumerating GL_RGBA unpacked (32)\n");
     pformat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
     pformat->u1.dwRGBBitCount = 32;
-    pformat->u2.dwRBitMask =         0xFF000000;
-    pformat->u3.dwGBitMask =         0x00FF0000;
+    pformat->u2.dwRBitMask =        0xFF000000;
+    pformat->u3.dwGBitMask =        0x00FF0000;
     pformat->u4.dwBBitMask =        0x0000FF00;
     pformat->u5.dwRGBAlphaBitMask = 0x000000FF;
     if (cb_1) if (cb_1(&sdesc , context) == 0) return DD_OK;
@@ -369,8 +373,8 @@
     TRACE("Enumerating GL_RGB unpacked (24)\n");
     pformat->dwFlags = DDPF_RGB;
     pformat->u1.dwRGBBitCount = 24;
-    pformat->u2.dwRBitMask =  0x00FF0000;
-    pformat->u3.dwGBitMask =  0x0000FF00;
+    pformat->u2.dwRBitMask = 0x00FF0000;
+    pformat->u3.dwGBitMask = 0x0000FF00;
     pformat->u4.dwBBitMask = 0x000000FF;
     pformat->u5.dwRGBAlphaBitMask = 0x00000000;
     if (cb_1) if (cb_1(&sdesc , context) == 0) return DD_OK;
@@ -379,8 +383,8 @@
     TRACE("Enumerating GL_RGB packed GL_UNSIGNED_SHORT_5_6_5 (16)\n");
     pformat->dwFlags = DDPF_RGB;
     pformat->u1.dwRGBBitCount = 16;
-    pformat->u2.dwRBitMask =  0x0000F800;
-    pformat->u3.dwGBitMask =  0x000007E0;
+    pformat->u2.dwRBitMask = 0x0000F800;
+    pformat->u3.dwGBitMask = 0x000007E0;
     pformat->u4.dwBBitMask = 0x0000001F;
     pformat->u5.dwRGBAlphaBitMask = 0x00000000;
     if (cb_1) if (cb_1(&sdesc , context) == 0) return DD_OK;
@@ -449,9 +453,9 @@
     TRACE("Enumerating Paletted (8)\n");
     pformat->dwFlags = DDPF_PALETTEINDEXED8;
     pformat->u1.dwRGBBitCount = 8;
-    pformat->u2.dwRBitMask =  0x00000000;
-    pformat->u3.dwGBitMask =  0x00000000;
-    pformat->u4.dwBBitMask = 0x00000000;
+    pformat->u2.dwRBitMask =        0x00000000;
+    pformat->u3.dwGBitMask =        0x00000000;
+    pformat->u4.dwBBitMask =        0x00000000;
     pformat->u5.dwRGBAlphaBitMask = 0x00000000;
     if (cb_1) if (cb_1(&sdesc , context) == 0) return DD_OK;
     if (cb_2) if (cb_2(pformat, context) == 0) return DD_OK;
@@ -624,25 +628,31 @@
     switch (dtstTransformStateType) {
         case D3DTRANSFORMSTATE_WORLD: {
 	    TRACE(" D3DTRANSFORMSTATE_WORLD :\n");
-	    conv_mat(lpD3DMatrix, glThis->world_mat);
-	    glMatrixMode(GL_MODELVIEW);
-	    glLoadMatrixf((float *) glThis->view_mat);
-	    glMultMatrixf((float *) glThis->world_mat);
+	    conv_mat(lpD3DMatrix, This->world_mat);
+	    if (glThis->last_vertices_transformed == FALSE) {
+	        glMatrixMode(GL_MODELVIEW);
+		glLoadMatrixf((float *) This->view_mat);
+		glMultMatrixf((float *) This->world_mat);
+	    }
 	} break;
 
 	case D3DTRANSFORMSTATE_VIEW: {
 	    TRACE(" D3DTRANSFORMSTATE_VIEW :\n");
-	    conv_mat(lpD3DMatrix, glThis->view_mat);
-	    glMatrixMode(GL_MODELVIEW);
-	    glLoadMatrixf((float *) glThis->view_mat);
-	    glMultMatrixf((float *) glThis->world_mat);
+	    conv_mat(lpD3DMatrix, This->view_mat);
+	    if (glThis->last_vertices_transformed == FALSE) {
+	        glMatrixMode(GL_MODELVIEW);
+		glLoadMatrixf((float *) This->view_mat);
+		glMultMatrixf((float *) This->world_mat);
+	    }
 	} break;
 
 	case D3DTRANSFORMSTATE_PROJECTION: {
 	    TRACE(" D3DTRANSFORMSTATE_PROJECTION :\n");
-	    conv_mat(lpD3DMatrix, glThis->proj_mat);
-	    glMatrixMode(GL_PROJECTION);
-	    glLoadMatrixf((float *) glThis->proj_mat);
+	    conv_mat(lpD3DMatrix, This->proj_mat);
+	    if (glThis->last_vertices_transformed == FALSE) {
+	        glMatrixMode(GL_PROJECTION);
+		glLoadMatrixf((float *) This->proj_mat);
+	    }
 	} break;
 
 	default:
@@ -651,9 +661,6 @@
     }
     LEAVE_GL();
 
-    /* And set the 'matrix changed' flag */
-    glThis->matrices_changed = TRUE;
-
     return DD_OK;
 }
 
@@ -696,26 +703,26 @@
     }
 }
 
-static void draw_primitive_handle_GL_state(IDirect3DDeviceGLImpl *glThis,
+static void draw_primitive_handle_GL_state(IDirect3DDeviceImpl *This,
 					   BOOLEAN vertex_transformed,
 					   BOOLEAN vertex_lit) {
+    IDirect3DDeviceGLImpl* glThis = (IDirect3DDeviceGLImpl*) This;
+  
     /* Puts GL in the correct lighting / transformation mode */
     if ((vertex_transformed == FALSE) && 
-	((glThis->last_vertices_transformed == TRUE) ||
-	 (glThis->matrices_changed == TRUE))) {
+	(glThis->last_vertices_transformed == TRUE)) {
         /* Need to put the correct transformation again if we go from Transformed
 	   vertices to non-transformed ones.
 	*/
         glMatrixMode(GL_MODELVIEW);
-	glLoadMatrixf((float *) glThis->view_mat);
-	glMultMatrixf((float *) glThis->world_mat);
+	glLoadMatrixf((float *) This->view_mat);
+	glMultMatrixf((float *) This->world_mat);
 	glMatrixMode(GL_PROJECTION);
-	glLoadMatrixf((float *) glThis->proj_mat);
+	glLoadMatrixf((float *) This->proj_mat);
 
 	if (glThis->render_state.fog_on == TRUE) glEnable(GL_FOG);
     } else if ((vertex_transformed == TRUE) &&
-	       ((glThis->last_vertices_transformed == FALSE) ||
-		(glThis->matrices_changed == TRUE))) {
+	       (glThis->last_vertices_transformed == FALSE)) {
         GLfloat height, width;
 	GLfloat trans_mat[16];
 	
@@ -739,7 +746,6 @@
 	/* Remove also fogging... */
 	glDisable(GL_FOG);
     }
-    glThis->matrices_changed = FALSE;
     
     if ((glThis->last_vertices_lit == TRUE) && (vertex_lit == FALSE)) {
         glEnable(GL_LIGHTING);
@@ -976,7 +982,7 @@
     }
 
     ENTER_GL();
-    draw_primitive_handle_GL_state(glThis,
+    draw_primitive_handle_GL_state(This,
 				   (d3dvtVertexType & D3DFVF_POSITION_MASK) != D3DFVF_XYZ,
 				   (d3dvtVertexType & D3DFVF_NORMAL) == 0);
     draw_primitive_start_GL(d3dptPrimitiveType);
@@ -1958,14 +1968,12 @@
     gl_object->render_state.fog_on = FALSE;
     
     /* Allocate memory for the matrices */
-    gl_object->world_mat = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
-    gl_object->view_mat  = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
-    gl_object->proj_mat  = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
-    gl_object->matrices_changed = TRUE;
-    
-    memcpy(gl_object->world_mat, id_mat, 16 * sizeof(float));
-    memcpy(gl_object->view_mat , id_mat, 16 * sizeof(float));
-    memcpy(gl_object->proj_mat , id_mat, 16 * sizeof(float));
+    object->world_mat = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
+    object->view_mat  = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
+    object->proj_mat  = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
+    memcpy(object->world_mat, id_mat, 16 * sizeof(float));
+    memcpy(object->view_mat , id_mat, 16 * sizeof(float));
+    memcpy(object->proj_mat , id_mat, 16 * sizeof(float));
 
     /* Initialisation */
     TRACE(" setting current context\n");
--- /home/ulmer/Wine/wine_base//dlls/ddraw/d3d_private.h	2002-12-24 15:48:07.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/d3d_private.h	2002-12-26 12:30:09.000000000 +0100
@@ -181,6 +181,11 @@
 
     IDirectDrawSurfaceImpl *current_texture[MAX_TEXTURES];
 
+    /* Current transformation matrices */
+    D3DMATRIX *world_mat;
+    D3DMATRIX *view_mat;
+    D3DMATRIX *proj_mat;
+
     void (*set_context)(IDirect3DDeviceImpl*);
     HRESULT (*clear)(IDirect3DDeviceImpl *This,
 		     DWORD dwCount,
--- /home/ulmer/Wine/wine_base//dlls/ddraw/d3dexecutebuffer.c	2002-12-22 12:06:18.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/d3dexecutebuffer.c	2002-12-26 12:39:33.000000000 +0100
@@ -243,16 +243,16 @@
 			glLoadIdentity(); /* The model transformation was done during the
 					     transformation phase */
 			glMatrixMode(GL_PROJECTION);
-			TRACE("  Projection Matrix : (%p)\n", lpDeviceGL->proj_mat);
-			dump_mat(lpDeviceGL->proj_mat);
-			TRACE("  View       Matrix : (%p)\n", lpDeviceGL->view_mat);
-			dump_mat(lpDeviceGL->view_mat);
+			TRACE("  Projection Matrix : (%p)\n", lpDevice->proj_mat);
+			dump_mat(lpDevice->proj_mat);
+			TRACE("  View       Matrix : (%p)\n", lpDevice->view_mat);
+			dump_mat(lpDevice->view_mat);
 
 			/* Although z axis is inverted between OpenGL and Direct3D, the z projected coordinates
 			   are always 0.0 at the front viewing volume and 1.0 at the back with Direct 3D and with
 			   the default behaviour of OpenGL. So, no additional transformation is required. */
-			glLoadMatrixf((float *) lpDeviceGL->proj_mat);
-			glMultMatrixf((float *) lpDeviceGL->view_mat);
+			glLoadMatrixf((float *) lpDevice->proj_mat);
+			glMultMatrixf((float *) lpDevice->view_mat);
 			break;
 
 		    case D3DVT_LVERTEX:
@@ -265,16 +265,16 @@
 					     transformation phase */
 			glMatrixMode(GL_PROJECTION);
 			
-			TRACE("  Projection Matrix : (%p)\n", lpDeviceGL->proj_mat);
-			dump_mat(lpDeviceGL->proj_mat);
-			TRACE("  View       Matrix : (%p)\n", lpDeviceGL->view_mat);
-			dump_mat(lpDeviceGL->view_mat);
+			TRACE("  Projection Matrix : (%p)\n", lpDevice->proj_mat);
+			dump_mat(lpDevice->proj_mat);
+			TRACE("  View       Matrix : (%p)\n", lpDevice->view_mat);
+			dump_mat(lpDevice->view_mat);
 			
 			/* Although z axis is inverted between OpenGL and Direct3D, the z projected coordinates
 			   are always 0 at the front viewing volume and 1 at the back with Direct 3D and with
 			   the default behaviour of OpenGL. So, no additional transformation is required. */
-			glLoadMatrixf((float *) lpDeviceGL->proj_mat);
-			glMultMatrixf((float *) lpDeviceGL->view_mat);
+			glLoadMatrixf((float *) lpDevice->proj_mat);
+			glMultMatrixf((float *) lpDevice->view_mat);
 			break;
 
 		    case D3DVT_TLVERTEX: {
@@ -379,17 +379,17 @@
 		    switch (ci->u1.dtstTransformStateType) {
 		        case D3DTRANSFORMSTATE_WORLD: {
 			    TRACE("  WORLD (%p)\n", (D3DMATRIX*) ci->u2.dwArg[0]);
-			    lpDeviceGL->world_mat = (D3DMATRIX*) ci->u2.dwArg[0];
+			    lpDevice->world_mat = (D3DMATRIX*) ci->u2.dwArg[0];
 			} break;
 
 			case D3DTRANSFORMSTATE_VIEW: {
 			    TRACE("  VIEW (%p)\n", (D3DMATRIX*) ci->u2.dwArg[0]);
-			    lpDeviceGL->view_mat = (D3DMATRIX*) ci->u2.dwArg[0];
+			    lpDevice->view_mat = (D3DMATRIX*) ci->u2.dwArg[0];
 			} break;
 
 			case D3DTRANSFORMSTATE_PROJECTION: {
 			    TRACE("  PROJECTION (%p)\n", (D3DMATRIX*) ci->u2.dwArg[0]);
-			    lpDeviceGL->proj_mat = (D3DMATRIX*) ci->u2.dwArg[0];
+			    lpDevice->proj_mat = (D3DMATRIX*) ci->u2.dwArg[0];
 			} break;
 			  
 			default:
@@ -538,7 +538,7 @@
 		        int nb;
 			D3DVERTEX  *src = ((LPD3DVERTEX)  (This->desc.lpData + vs)) + ci->wStart;
 			OGL_Vertex *dst = ((OGL_Vertex *) (This->vertex_data)) + ci->wDest;
-			D3DMATRIX *mat = lpDeviceGL->world_mat;
+			D3DMATRIX *mat = lpDevice->world_mat;
 			
 			TRACE("  World Matrix : (%p)\n", mat);
 			dump_mat(mat);
@@ -567,7 +567,7 @@
 		        int nb;
 			D3DLVERTEX *src  = ((LPD3DLVERTEX) (This->desc.lpData + vs)) + ci->wStart;
 			OGL_LVertex *dst = ((OGL_LVertex *) (This->vertex_data)) + ci->wDest;
-			D3DMATRIX *mat = lpDeviceGL->world_mat;
+			D3DMATRIX *mat = lpDevice->world_mat;
 			
 			TRACE("  World Matrix : (%p)\n", mat);
 			dump_mat(mat);
--- /home/ulmer/Wine/wine_base//dlls/ddraw/mesa_private.h	2002-12-25 17:25:28.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/mesa_private.h	2002-12-26 12:29:47.000000000 +0100
@@ -118,11 +118,6 @@
     BOOLEAN last_vertices_transformed;
     BOOLEAN last_vertices_lit;
 
-    D3DMATRIX *world_mat;
-    D3DMATRIX *view_mat;
-    D3DMATRIX *proj_mat;
-    BOOLEAN matrices_changed;
-
     Display  *display;
     Drawable drawable;
 } IDirect3DDeviceGLImpl;


More information about the wine-patches mailing list