Commit c3d89f55 authored by Lionel Ulmer's avatar Lionel Ulmer Committed by Alexandre Julliard

- do not use the alpha coordinates when ALPHABLEND is disabled

- disable fogging in the XYZRHW case - various other small fixes
parent 62d4f41e
...@@ -710,6 +710,8 @@ static void draw_primitive_handle_GL_state(IDirect3DDeviceGLImpl *glThis, ...@@ -710,6 +710,8 @@ static void draw_primitive_handle_GL_state(IDirect3DDeviceGLImpl *glThis,
glMultMatrixf((float *) glThis->world_mat); glMultMatrixf((float *) glThis->world_mat);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadMatrixf((float *) glThis->proj_mat); glLoadMatrixf((float *) glThis->proj_mat);
if (glThis->render_state.fog_on == TRUE) glEnable(GL_FOG);
} else if ((vertex_transformed == TRUE) && } else if ((vertex_transformed == TRUE) &&
((glThis->last_vertices_transformed == FALSE) || ((glThis->last_vertices_transformed == FALSE) ||
(glThis->matrices_changed == TRUE))) { (glThis->matrices_changed == TRUE))) {
...@@ -732,6 +734,9 @@ static void draw_primitive_handle_GL_state(IDirect3DDeviceGLImpl *glThis, ...@@ -732,6 +734,9 @@ static void draw_primitive_handle_GL_state(IDirect3DDeviceGLImpl *glThis,
glLoadIdentity(); glLoadIdentity();
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadMatrixf(trans_mat); glLoadMatrixf(trans_mat);
/* Remove also fogging... */
glDisable(GL_FOG);
} }
glThis->matrices_changed = FALSE; glThis->matrices_changed = FALSE;
...@@ -936,10 +941,15 @@ inline static void handle_diffuse(DWORD *color) { ...@@ -936,10 +941,15 @@ inline static void handle_diffuse(DWORD *color) {
(*color >> 24) & 0xFF); (*color >> 24) & 0xFF);
} }
inline static void handle_diffuse_and_specular(DWORD *color_d, DWORD *color_s) { inline static void handle_diffuse_and_specular(DWORD *color_d, DWORD *color_s) {
glColor4ub((*color_d >> 16) & 0xFF, handle_diffuse(color_d);
(*color_d >> 8) & 0xFF, }
(*color_d >> 0) & 0xFF, inline static void handle_diffuse_no_alpha(DWORD *color) {
(*color_d >> 24) & 0xFF); 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) { inline static void handle_texture(D3DVALUE *coords) {
glTexCoord2fv(coords); glTexCoord2fv(coords);
...@@ -1005,7 +1015,10 @@ static void draw_primitive_strided_7(IDirect3DDeviceImpl *This, ...@@ -1005,7 +1015,10 @@ static void draw_primitive_strided_7(IDirect3DDeviceImpl *This,
D3DVALUE *position = D3DVALUE *position =
(D3DVALUE *) (((char *) lpD3DDrawPrimStrideData->position.lpvData) + i * lpD3DDrawPrimStrideData->position.dwStride); (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_texture(tex_coord);
handle_xyzrhw(position); handle_xyzrhw(position);
...@@ -1040,7 +1053,10 @@ static void draw_primitive_strided_7(IDirect3DDeviceImpl *This, ...@@ -1040,7 +1053,10 @@ static void draw_primitive_strided_7(IDirect3DDeviceImpl *This,
(DWORD *) (((char *) lpD3DDrawPrimStrideData->diffuse.lpvData) + i * lpD3DDrawPrimStrideData->diffuse.dwStride); (DWORD *) (((char *) lpD3DDrawPrimStrideData->diffuse.lpvData) + i * lpD3DDrawPrimStrideData->diffuse.dwStride);
DWORD *color_s = DWORD *color_s =
(DWORD *) (((char *) lpD3DDrawPrimStrideData->specular.lpvData) + i * lpD3DDrawPrimStrideData->specular.dwStride); (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 { } else {
if (d3dvtVertexType & D3DFVF_SPECULAR) { if (d3dvtVertexType & D3DFVF_SPECULAR) {
DWORD *color_s = DWORD *color_s =
...@@ -1049,7 +1065,10 @@ static void draw_primitive_strided_7(IDirect3DDeviceImpl *This, ...@@ -1049,7 +1065,10 @@ static void draw_primitive_strided_7(IDirect3DDeviceImpl *This,
} else if (d3dvtVertexType & D3DFVF_DIFFUSE) { } else if (d3dvtVertexType & D3DFVF_DIFFUSE) {
DWORD *color_d = DWORD *color_d =
(DWORD *) (((char *) lpD3DDrawPrimStrideData->diffuse.lpvData) + i * lpD3DDrawPrimStrideData->diffuse.dwStride); (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 +1885,8 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfa ...@@ -1866,6 +1885,8 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfa
gl_object->render_state.min = GL_NEAREST; 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_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_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 */ /* Allocate memory for the matrices */
gl_object->world_mat = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float)); gl_object->world_mat = (D3DMATRIX *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 16 * sizeof(float));
...@@ -1884,7 +1905,6 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfa ...@@ -1884,7 +1905,6 @@ d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfa
ENTER_GL(); ENTER_GL();
TRACE(" current context set\n"); TRACE(" current context set\n");
glClearColor(0.0, 0.0, 0.0, 0.0); 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); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glDrawBuffer(buffer); glDrawBuffer(buffer);
glReadBuffer(buffer); glReadBuffer(buffer);
......
...@@ -137,7 +137,7 @@ HRESULT WINAPI gltex_setcolorkey_cb(IDirectDrawSurfaceImpl *texture, DWORD dwFla ...@@ -137,7 +137,7 @@ HRESULT WINAPI gltex_setcolorkey_cb(IDirectDrawSurfaceImpl *texture, DWORD dwFla
return DD_OK; return DD_OK;
} }
static void static HRESULT
gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private; IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
GLuint current_texture; GLuint current_texture;
...@@ -148,7 +148,7 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { ...@@ -148,7 +148,7 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
GLsizei width, GLenum format, GLenum type, const GLvoid *table) = NULL; GLsizei width, GLenum format, GLenum type, const GLvoid *table) = NULL;
BOOL upload_done = FALSE; BOOL upload_done = FALSE;
BOOL error = 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; VOID *surface = NULL;
DDSURFACEDESC *src_d = (DDSURFACEDESC *)&(This->surface_desc); DDSURFACEDESC *src_d = (DDSURFACEDESC *)&(This->surface_desc);
...@@ -179,7 +179,7 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { ...@@ -179,7 +179,7 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
if (pal == NULL) { if (pal == NULL) {
ERR("Palettized texture Loading with a NULL palette !\n"); ERR("Palettized texture Loading with a NULL palette !\n");
glBindTexture(GL_TEXTURE_2D, current_texture); glBindTexture(GL_TEXTURE_2D, current_texture);
return; return D3DERR_INVALIDPALETTE;
} }
/* Get the surface's palette */ /* Get the surface's palette */
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
...@@ -323,6 +323,7 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { ...@@ -323,6 +323,7 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
} }
glBindTexture(GL_TEXTURE_2D, current_texture); glBindTexture(GL_TEXTURE_2D, current_texture);
return DD_OK;
} }
HRESULT WINAPI HRESULT WINAPI
...@@ -462,6 +463,7 @@ GL_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface, ...@@ -462,6 +463,7 @@ GL_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface,
IDirectDrawSurfaceImpl *lpD3DTextureImpl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, lpD3DTexture2); IDirectDrawSurfaceImpl *lpD3DTextureImpl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, lpD3DTexture2);
DWORD mem_used; DWORD mem_used;
DDSURFACEDESC *src_d, *dst_d; DDSURFACEDESC *src_d, *dst_d;
HRESULT ret_value = D3D_OK;
TRACE("(%p/%p)->(%p)\n", This, iface, lpD3DTexture2); TRACE("(%p/%p)->(%p)\n", This, iface, lpD3DTexture2);
...@@ -521,14 +523,14 @@ GL_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface, ...@@ -521,14 +523,14 @@ GL_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface,
/* Now, load the texture */ /* Now, load the texture */
/* d3dd->set_context(d3dd); We need to set the context somehow.... */ /* 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; glThis->first_unlock = FALSE;
LEAVE_GL(); LEAVE_GL();
} }
} }
return D3D_OK; return ret_value;
} }
HRESULT WINAPI HRESULT WINAPI
...@@ -553,7 +555,7 @@ ULONG WINAPI ...@@ -553,7 +555,7 @@ ULONG WINAPI
Thunk_IDirect3DTextureImpl_2_Release(LPDIRECT3DTEXTURE2 iface) Thunk_IDirect3DTextureImpl_2_Release(LPDIRECT3DTEXTURE2 iface)
{ {
TRACE("(%p)->() thunking to IDirectDrawSurface7 interface.\n", 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 HRESULT WINAPI
...@@ -578,7 +580,7 @@ ULONG WINAPI ...@@ -578,7 +580,7 @@ ULONG WINAPI
Thunk_IDirect3DTextureImpl_1_Release(LPDIRECT3DTEXTURE iface) Thunk_IDirect3DTextureImpl_1_Release(LPDIRECT3DTEXTURE iface)
{ {
TRACE("(%p)->() thunking to IDirectDrawSurface7 interface.\n", 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 HRESULT WINAPI
......
...@@ -577,7 +577,10 @@ void DDRAW_dump_surface_to_disk(IDirectDrawSurfaceImpl *surface, FILE *f) ...@@ -577,7 +577,10 @@ void DDRAW_dump_surface_to_disk(IDirectDrawSurfaceImpl *surface, FILE *f)
{ {
int i; 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); fprintf(f, "P6\n%ld %ld\n255\n", surface->surface_desc.dwWidth, surface->surface_desc.dwHeight);
......
...@@ -227,8 +227,8 @@ void set_render_state(D3DRENDERSTATETYPE dwRenderStateType, ...@@ -227,8 +227,8 @@ void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
switch ((D3DTEXTUREBLEND) dwRenderState) { switch ((D3DTEXTUREBLEND) dwRenderState) {
case D3DTBLEND_MODULATE: case D3DTBLEND_MODULATE:
case D3DTBLEND_MODULATEALPHA: case D3DTBLEND_MODULATEALPHA:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
break; break;
default: default:
ERR("Unhandled texture environment %ld !\n",dwRenderState); ERR("Unhandled texture environment %ld !\n",dwRenderState);
} }
...@@ -239,13 +239,16 @@ void set_render_state(D3DRENDERSTATETYPE dwRenderStateType, ...@@ -239,13 +239,16 @@ void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
case D3DCULL_NONE: case D3DCULL_NONE:
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
break; break;
/* Not sure about these... The DirectX doc is, well, pretty unclear :-) */
case D3DCULL_CW: case D3DCULL_CW:
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glFrontFace(GL_CW); glFrontFace(GL_CW);
glCullFace(GL_BACK);
break; break;
case D3DCULL_CCW: case D3DCULL_CCW:
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW); glFrontFace(GL_CCW);
glCullFace(GL_BACK);
break; break;
default: default:
ERR("Unhandled cull mode %ld !\n",dwRenderState); ERR("Unhandled cull mode %ld !\n",dwRenderState);
...@@ -274,17 +277,23 @@ void set_render_state(D3DRENDERSTATETYPE dwRenderStateType, ...@@ -274,17 +277,23 @@ void set_render_state(D3DRENDERSTATETYPE dwRenderStateType,
break; break;
case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */ case D3DRENDERSTATE_ALPHABLENDENABLE: /* 27 */
if (dwRenderState) if (dwRenderState) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
else rs->alpha_blend_enable = TRUE;
} else {
glDisable(GL_BLEND); glDisable(GL_BLEND);
rs->alpha_blend_enable = FALSE;
}
break; break;
case D3DRENDERSTATE_FOGENABLE: /* 28 */ case D3DRENDERSTATE_FOGENABLE: /* 28 */
if (dwRenderState) if (dwRenderState) {
glEnable(GL_FOG); glEnable(GL_FOG);
else rs->fog_on = TRUE;
} else {
glDisable(GL_FOG); glDisable(GL_FOG);
rs->fog_on = FALSE;
}
break; break;
case D3DRENDERSTATE_SPECULARENABLE: /* 29 */ case D3DRENDERSTATE_SPECULARENABLE: /* 29 */
......
...@@ -67,6 +67,10 @@ typedef struct render_state { ...@@ -67,6 +67,10 @@ typedef struct render_state {
/* This is needed for the Alpha stuff */ /* This is needed for the Alpha stuff */
GLenum alpha_func; GLenum alpha_func;
GLclampf alpha_ref; 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; } RenderState;
/* Common functions defined in d3dcommon.c */ /* Common functions defined in d3dcommon.c */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment