[D3D 48] Miscellaneous fixes

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

 



Changelog:
 - do not use the alpha coordinates when ALPHABLEND is disabled
 - disable fogging in the XYZRHW case
 - various other small fixes

-- 
		 Lionel Ulmer - http://www.bbrox.org/
--- /home/ulmer/Wine/wine_base//dlls/ddraw/d3ddevice/mesa.c	2002-12-24 18:12:53.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/d3ddevice/mesa.c	2002-12-25 17:19:08.000000000 +0100
@@ -710,6 +710,8 @@
 	glMultMatrixf((float *) glThis->world_mat);
 	glMatrixMode(GL_PROJECTION);
 	glLoadMatrixf((float *) glThis->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))) {
@@ -732,6 +734,9 @@
 	glLoadIdentity();
 	glMatrixMode(GL_PROJECTION);
 	glLoadMatrixf(trans_mat);
+
+	/* Remove also fogging... */
+	glDisable(GL_FOG);
     }
     glThis->matrices_changed = FALSE;
     
@@ -936,10 +941,15 @@
 	       (*color >> 24) & 0xFF);
 }
 inline static void handle_diffuse_and_specular(DWORD *color_d, DWORD *color_s) {
-    glColor4ub((*color_d >> 16) & 0xFF,
-	       (*color_d >>  8) & 0xFF,
-	       (*color_d >>  0) & 0xFF,
-	       (*color_d >> 24) & 0xFF);
+    handle_diffuse(color_d);
+}
+inline static void handle_diffuse_no_alpha(DWORD *color) {
+    glColor3ub((*color >> 16) & 0xFF,
+	       (*color >>  8) & 0xFF,
+	       (*color >>  0) & 0xFF);
+}
+inline static void handle_diffuse_and_specular_no_alpha(DWORD *color_d, DWORD *color_s) {
+    handle_diffuse_no_alpha(color_d);
 }
 inline static void handle_texture(D3DVALUE *coords) {
     glTexCoord2fv(coords);
@@ -1005,7 +1015,10 @@
 	    D3DVALUE *position =
 	      (D3DVALUE *) (((char *) lpD3DDrawPrimStrideData->position.lpvData) + i * lpD3DDrawPrimStrideData->position.dwStride);
 
-	    handle_diffuse_and_specular(color_d, color_s);
+	    if (glThis->render_state.alpha_blend_enable == TRUE)
+	        handle_diffuse_and_specular(color_d, color_s);
+	    else
+	        handle_diffuse_and_specular_no_alpha(color_d, color_s);
 	    handle_texture(tex_coord);
 	    handle_xyzrhw(position);
 
@@ -1040,7 +1053,10 @@
 		  (DWORD *) (((char *) lpD3DDrawPrimStrideData->diffuse.lpvData) + i * lpD3DDrawPrimStrideData->diffuse.dwStride);
 		DWORD *color_s = 
 		  (DWORD *) (((char *) lpD3DDrawPrimStrideData->specular.lpvData) + i * lpD3DDrawPrimStrideData->specular.dwStride);
-		handle_diffuse_and_specular(color_d, color_s);
+		if (glThis->render_state.alpha_blend_enable == TRUE)
+		    handle_diffuse_and_specular(color_d, color_s);
+		else
+		    handle_diffuse_and_specular_no_alpha(color_d, color_s);
 	    } else {
 	        if (d3dvtVertexType & D3DFVF_SPECULAR) { 
 		    DWORD *color_s = 
@@ -1049,7 +1065,10 @@
 		} else if (d3dvtVertexType & D3DFVF_DIFFUSE) {
 		    DWORD *color_d = 
 		      (DWORD *) (((char *) lpD3DDrawPrimStrideData->diffuse.lpvData) + i * lpD3DDrawPrimStrideData->diffuse.dwStride);
-		    handle_diffuse(color_d);
+		    if (glThis->render_state.alpha_blend_enable == TRUE)
+		        handle_diffuse(color_d);
+		    else
+		        handle_diffuse_no_alpha(color_d);
 		}
 	    }
 		
@@ -1866,6 +1889,8 @@
     gl_object->render_state.min = GL_NEAREST;
     gl_object->render_state.alpha_ref = 0.0; /* No actual idea about the real default value... */
     gl_object->render_state.alpha_func = GL_ALWAYS; /* Here either but it seems logical */
+    gl_object->render_state.alpha_blend_enable = FALSE;
+    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));
@@ -1884,7 +1909,6 @@
     ENTER_GL();
     TRACE(" current context set\n");
     glClearColor(0.0, 0.0, 0.0, 0.0);
-    glColor3f(1.0, 1.0, 1.0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     glDrawBuffer(buffer);
     glReadBuffer(buffer);
--- /home/ulmer/Wine/wine_base//dlls/ddraw/d3dtexture.c	2002-12-24 18:31:09.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/d3dtexture.c	2002-12-25 17:03:17.000000000 +0100
@@ -137,7 +137,7 @@
     return DD_OK;
 }
 
-static void
+static HRESULT
 gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
     IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
     GLuint current_texture;
@@ -148,7 +148,7 @@
 			       GLsizei width, GLenum format, GLenum type, const GLvoid *table) = NULL;
     BOOL upload_done = FALSE;
     BOOL error = FALSE;
-    GLenum format, pixel_format;
+    GLenum format = GL_RGBA, pixel_format = GL_UNSIGNED_BYTE; /* This is only to prevent warnings.. */
     VOID *surface = NULL;
 
     DDSURFACEDESC *src_d = (DDSURFACEDESC *)&(This->surface_desc);
@@ -179,7 +179,7 @@
 	if (pal == NULL) {
 	    ERR("Palettized texture Loading with a NULL palette !\n");
 	    glBindTexture(GL_TEXTURE_2D, current_texture);
-	    return;
+	    return D3DERR_INVALIDPALETTE;
 	}
 	/* Get the surface's palette */
 	for (i = 0; i < 256; i++) {
@@ -323,6 +323,7 @@
     }
 
     glBindTexture(GL_TEXTURE_2D, current_texture);
+    return DD_OK;
 }
 
 HRESULT WINAPI
@@ -462,6 +463,7 @@
     IDirectDrawSurfaceImpl *lpD3DTextureImpl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, lpD3DTexture2);
     DWORD mem_used;
     DDSURFACEDESC *src_d, *dst_d;
+    HRESULT ret_value = D3D_OK;
     
     TRACE("(%p/%p)->(%p)\n", This, iface, lpD3DTexture2);
 
@@ -521,14 +523,14 @@
 	    /* Now, load the texture */
 	    /* d3dd->set_context(d3dd); We need to set the context somehow.... */
 	    
-	    gltex_upload_texture(This, glThis->first_unlock);
+	    ret_value = gltex_upload_texture(This, glThis->first_unlock);
 	    glThis->first_unlock = FALSE;
 	    
 	    LEAVE_GL();
 	}
     }
 
-    return D3D_OK;
+    return ret_value;
 }
 
 HRESULT WINAPI
@@ -553,7 +555,7 @@
 Thunk_IDirect3DTextureImpl_2_Release(LPDIRECT3DTEXTURE2 iface)
 {
     TRACE("(%p)->() thunking to IDirectDrawSurface7 interface.\n", iface);
-    return IDirectDrawSurface7_AddRef(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture2, IDirectDrawSurface7, iface));
+    return IDirectDrawSurface7_Release(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture2, IDirectDrawSurface7, iface));
 }
 
 HRESULT WINAPI
@@ -578,7 +580,7 @@
 Thunk_IDirect3DTextureImpl_1_Release(LPDIRECT3DTEXTURE iface)
 {
     TRACE("(%p)->() thunking to IDirectDrawSurface7 interface.\n", iface);
-    return IDirectDrawSurface7_AddRef(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirectDrawSurface7, iface));
+    return IDirectDrawSurface7_Release(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirectDrawSurface7, iface));
 }
 
 HRESULT WINAPI
--- /home/ulmer/Wine/wine_base//dlls/ddraw/helper.c	2002-12-22 12:06:18.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/helper.c	2002-12-25 13:57:17.000000000 +0100
@@ -577,7 +577,10 @@
 {
     int i;
 
-    DDRAW_dump_surface_desc(&(surface->surface_desc));
+    if (TRACE_ON(ddraw)) {
+        DPRINTF("Dumping surface : \n");
+        DDRAW_dump_surface_desc(&(surface->surface_desc));
+    }
     
     fprintf(f, "P6\n%ld %ld\n255\n", surface->surface_desc.dwWidth, surface->surface_desc.dwHeight);
 
--- /home/ulmer/Wine/wine_base//dlls/ddraw/mesa.c	2002-12-23 18:34:52.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/mesa.c	2002-12-25 17:17:56.000000000 +0100
@@ -227,8 +227,8 @@
 	        switch ((D3DTEXTUREBLEND) dwRenderState) {
 		    case D3DTBLEND_MODULATE:
 		    case D3DTBLEND_MODULATEALPHA:
-		          glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-			  break;
+		        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+			break;
 		    default:
 			  ERR("Unhandled texture environment %ld !\n",dwRenderState);
 		}
@@ -239,13 +239,16 @@
 		    case D3DCULL_NONE:
 		         glDisable(GL_CULL_FACE);
 			 break;
+			 /* Not sure about these... The DirectX doc is, well, pretty unclear :-) */
 		    case D3DCULL_CW:
 			 glEnable(GL_CULL_FACE);
 			 glFrontFace(GL_CW);
+			 glCullFace(GL_BACK);
 			 break;
 		    case D3DCULL_CCW:
 			 glEnable(GL_CULL_FACE);
 			 glFrontFace(GL_CCW);
+			 glCullFace(GL_BACK);
 			 break;
 		    default:
 			 ERR("Unhandled cull mode %ld !\n",dwRenderState);
@@ -274,17 +277,23 @@
 	        break;
 
 	    case D3DRENDERSTATE_ALPHABLENDENABLE:   /* 27 */
-	        if (dwRenderState)
+	        if (dwRenderState) {
 		    glEnable(GL_BLEND);
-		else
+		    rs->alpha_blend_enable = TRUE;
+		} else {
 		    glDisable(GL_BLEND);
+		    rs->alpha_blend_enable = FALSE;
+		}
 	        break;
 	      
 	    case D3DRENDERSTATE_FOGENABLE: /* 28 */
-	        if (dwRenderState)
+	        if (dwRenderState) {
 		    glEnable(GL_FOG);
-		else
+		    rs->fog_on = TRUE;
+		} else {
 		    glDisable(GL_FOG);
+		    rs->fog_on = FALSE;
+		}
 	        break;
 
 	    case D3DRENDERSTATE_SPECULARENABLE: /* 29 */
--- /home/ulmer/Wine/wine_base//dlls/ddraw/mesa_private.h	2002-12-24 15:48:08.000000000 +0100
+++ /home/ulmer/Wine/wine_work//dlls/ddraw/mesa_private.h	2002-12-25 17:17:15.000000000 +0100
@@ -67,6 +67,10 @@
     /* This is needed for the Alpha stuff */
     GLenum alpha_func;
     GLclampf alpha_ref;
+    BOOLEAN alpha_blend_enable;
+
+    /* This is needed to re-enable fogging when XYZRHW and XYZ primitives are mixed */
+    BOOLEAN fog_on;
 } RenderState;
 
 /* Common functions defined in d3dcommon.c */

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

  Powered by Linux