From 16fcd747afff2d693cfe200ae86ba8e5cc5f7299 Mon Sep 17 00:00:00 2001 From: Lionel Ulmer Date: Mon, 16 Dec 2002 23:09:23 +0000 Subject: [PATCH] - revert some optimisations breaking some games - added a new texture format (4444 ARGB) - fixed the computation of colors - added new render states and fog support (NOT handled yet for transformed vertices) --- dlls/ddraw/d3ddevice/mesa.c | 47 +++++++++++++++++++++--------------------- dlls/ddraw/d3dtexture.c | 50 ++++++++++++++++++++++++++++----------------- dlls/ddraw/ddraw/main.c | 10 ++++----- dlls/ddraw/mesa.c | 42 +++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 47 deletions(-) diff --git a/dlls/ddraw/d3ddevice/mesa.c b/dlls/ddraw/d3ddevice/mesa.c index fe119fd11d8..5f7a4e94469 100644 --- a/dlls/ddraw/d3ddevice/mesa.c +++ b/dlls/ddraw/d3ddevice/mesa.c @@ -733,23 +733,24 @@ inline static void draw_primitive(IDirect3DDeviceGLImpl *glThis, DWORD maxvert, D3DLVERTEX *vx = ((D3DLVERTEX *) lpvertex) + (index == 0 ? vx_index : index[vx_index]); DWORD col = vx->u4.color; - glColor3f(((col >> 16) & 0xFF) / 255.0, - ((col >> 8) & 0xFF) / 255.0, - ((col >> 0) & 0xFF) / 255.0); + glColor4ub((col >> 16) & 0xFF, + (col >> 8) & 0xFF, + (col >> 0) & 0xFF, + (col >> 24) & 0xFF); glVertex3f(vx->u1.x, vx->u2.y, vx->u3.z); - TRACE(" LV: %f %f %f (%02lx %02lx %02lx)\n", + TRACE(" LV: %f %f %f (%02lx %02lx %02lx %02lx)\n", vx->u1.x, vx->u2.y, vx->u3.z, - ((col >> 16) & 0xFF), ((col >> 8) & 0xFF), ((col >> 0) & 0xFF)); + ((col >> 16) & 0xFF), ((col >> 8) & 0xFF), ((col >> 0) & 0xFF), ((col >> 24) & 0xFF)); } break; case D3DVT_TLVERTEX: { D3DTLVERTEX *vx = ((D3DTLVERTEX *) lpvertex) + (index == 0 ? vx_index : index[vx_index]); DWORD col = vx->u5.color; - glColor4ub((col >> 24) & 0xFF, - (col >> 16) & 0xFF, + glColor4ub((col >> 16) & 0xFF, (col >> 8) & 0xFF, - (col >> 0) & 0xFF); + (col >> 0) & 0xFF, + (col >> 24) & 0xFF); glTexCoord2f(vx->u7.tu, vx->u8.tv); if (vx->u4.rhw < 0.01) glVertex3f(vx->u1.sx, @@ -760,9 +761,9 @@ inline static void draw_primitive(IDirect3DDeviceGLImpl *glThis, DWORD maxvert, vx->u2.sy / vx->u4.rhw, vx->u3.sz / vx->u4.rhw, 1.0 / vx->u4.rhw); - TRACE(" TLV: %f %f %f (%02lx %02lx %02lx) (%f %f) (%f)\n", + TRACE(" TLV: %f %f %f (%02lx %02lx %02lx %02lx) (%f %f) (%f)\n", vx->u1.sx, vx->u2.sy, vx->u3.sz, - ((col >> 16) & 0xFF), ((col >> 8) & 0xFF), ((col >> 0) & 0xFF), + ((col >> 16) & 0xFF), ((col >> 8) & 0xFF), ((col >> 0) & 0xFF), ((col >> 24) & 0xFF), vx->u7.tu, vx->u8.tv, vx->u4.rhw); } break; @@ -926,10 +927,10 @@ static void handle_specular(char *vertex, int offset, int extra) { } static void handle_diffuse(char *vertex, int offset, int extra) { DWORD color = *((DWORD *) (vertex + offset)); - glColor4ub((color >> 24) & 0xFF, - (color >> 16) & 0xFF, + glColor4ub((color >> 16) & 0xFF, (color >> 8) & 0xFF, - (color >> 0) & 0xFF); + (color >> 0) & 0xFF, + (color >> 24) & 0xFF); } static void handle_texture(char *vertex, int offset, int extra) { if (extra == 0xFF) { @@ -983,10 +984,10 @@ static void draw_primitive_7(IDirect3DDeviceImpl *This, for (index = 0; index < dwIndexCount; index++) { int i = (dwIndices == NULL) ? index : dwIndices[index]; - glColor4ub((vertices[i].diffuse >> 24) & 0xFF, - (vertices[i].diffuse >> 16) & 0xFF, + glColor4ub((vertices[i].diffuse >> 16) & 0xFF, (vertices[i].diffuse >> 8) & 0xFF, - (vertices[i].diffuse >> 0) & 0xFF); + (vertices[i].diffuse >> 0) & 0xFF, + (vertices[i].diffuse >> 24) & 0xFF); /* Todo : handle specular... */ glTexCoord2fv(&(vertices[i].tu1)); if (vertices[i].rhw < 0.00001) @@ -998,14 +999,14 @@ static void draw_primitive_7(IDirect3DDeviceImpl *This, 1.0 / vertices[i].rhw); TRACE(" %f %f %f %f / %02lx %02lx %02lx %02lx - %02lx %02lx %02lx %02lx (%f %f)\n", vertices[i].x, vertices[i].y, vertices[i].z, vertices[i].rhw, - (vertices[i].diffuse >> 24) & 0xFF, (vertices[i].diffuse >> 16) & 0xFF, (vertices[i].diffuse >> 8) & 0xFF, (vertices[i].diffuse >> 0) & 0xFF, - (vertices[i].specular >> 24) & 0xFF, + (vertices[i].diffuse >> 24) & 0xFF, (vertices[i].specular >> 16) & 0xFF, (vertices[i].specular >> 8) & 0xFF, (vertices[i].specular >> 0) & 0xFF, + (vertices[i].specular >> 24) & 0xFF, vertices[i].tu1, vertices[i].tv1); } } else if (((d3dvtVertexType & D3DFVF_POSITION_MASK) == D3DFVF_XYZ) || @@ -1144,23 +1145,23 @@ static void draw_primitive_strided_7(IDirect3DDeviceImpl *This, for (index = 0; index < dwIndexCount; index++) { int i = (dwIndices == NULL) ? index : dwIndices[index]; - glColor4ub((CPNT(diffuse,i,0,DWORD) >> 24) & 0xFF, - (CPNT(diffuse,i,0,DWORD) >> 16) & 0xFF, + glColor4ub((CPNT(diffuse,i,0,DWORD) >> 16) & 0xFF, (CPNT(diffuse,i,0,DWORD) >> 8) & 0xFF, - (CPNT(diffuse,i,0,DWORD) >> 0) & 0xFF); + (CPNT(diffuse,i,0,DWORD) >> 0) & 0xFF, + (CPNT(diffuse,i,0,DWORD) >> 24) & 0xFF); /* Todo : handle specular... */ glTexCoord2f(CPNT(textureCoords[1],i,0,D3DVALUE),CPNT(textureCoords[1],i,1,D3DVALUE)); glVertex3f(CPNT(position,i,0,D3DVALUE),CPNT(position,i,1,D3DVALUE),CPNT(position,i,2,D3DVALUE)); TRACE(" %f %f %f / %02lx %02lx %02lx %02lx - %02lx %02lx %02lx %02lx (%f %f)\n", CPNT(position,i,0,D3DVALUE),CPNT(position,i,1,D3DVALUE),CPNT(position,i,2,D3DVALUE), - (CPNT(diffuse,i,0,DWORD) >> 24) & 0xFF, (CPNT(diffuse,i,0,DWORD) >> 16) & 0xFF, (CPNT(diffuse,i,0,DWORD) >> 8) & 0xFF, (CPNT(diffuse,i,0,DWORD) >> 0) & 0xFF, - (CPNT(specular,i,0,DWORD) >> 24) & 0xFF, + (CPNT(diffuse,i,0,DWORD) >> 24) & 0xFF, (CPNT(specular,i,0,DWORD) >> 16) & 0xFF, (CPNT(specular,i,0,DWORD) >> 8) & 0xFF, (CPNT(specular,i,0,DWORD) >> 0) & 0xFF, + (CPNT(specular,i,0,DWORD) >> 24) & 0xFF, CPNT(textureCoords[0],i,0,D3DVALUE),CPNT(textureCoords[0],i,1,D3DVALUE)); } } diff --git a/dlls/ddraw/d3dtexture.c b/dlls/ddraw/d3dtexture.c index 2a9ee218a8e..488f431c00e 100644 --- a/dlls/ddraw/d3dtexture.c +++ b/dlls/ddraw/d3dtexture.c @@ -397,6 +397,37 @@ gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) { GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, src_d->lpSurface); + } else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x0000F000) { + /* Move the four Alpha bits... */ + WORD *surface = (WORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(WORD)); + DWORD i; + WORD *src = (WORD *) src_d->lpSurface, *dst = surface; + + for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) { + *dst++ = (((*src & 0xFFF0) >> 4) | + ((*src & 0x000F) << 12)); + src++; + } + + if (init_upload) + glTexImage2D(GL_TEXTURE_2D, + glThis->mipmap_level, + GL_RGBA, + src_d->dwWidth, src_d->dwHeight, + 0, + GL_RGBA, + GL_UNSIGNED_SHORT_4_4_4_4, + surface); + else + glTexSubImage2D(GL_TEXTURE_2D, + glThis->mipmap_level, + 0, 0, + src_d->dwWidth, src_d->dwHeight, + GL_RGBA, + GL_UNSIGNED_SHORT_4_4_4_4, + surface); + + HeapFree(GetProcessHeap(), 0, surface); } else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00008000) { /* Converting the 1555 format in 5551 packed */ WORD *surface = (WORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(WORD)); @@ -779,17 +810,6 @@ ICOM_VTABLE(IDirect3DTexture2) VTABLE_IDirect3DTexture2 = XCAST(Load) GL_IDirect3DTextureImpl_2_1T_Load, }; -ICOM_VTABLE(IDirect3DTexture2) STUB_VTABLE_IDirect3DTexture2 = -{ - ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE - XCAST(QueryInterface) Thunk_IDirect3DTextureImpl_2_QueryInterface, - XCAST(AddRef) Thunk_IDirect3DTextureImpl_2_AddRef, - XCAST(Release) Thunk_IDirect3DTextureImpl_2_Release, - XCAST(GetHandle) Main_IDirect3DTextureImpl_2_1T_GetHandle, - XCAST(PaletteChanged) Main_IDirect3DTextureImpl_2_1T_PaletteChanged, - XCAST(Load) Main_IDirect3DTextureImpl_2_1T_Load, -}; - #if !defined(__STRICT_ANSI__) && defined(__GNUC__) #undef XCAST #endif @@ -823,14 +843,6 @@ HRESULT d3dtexture_create(IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOL { IDirect3DTextureGLImpl *private; - if ((surf->surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_SYSTEMMEMORY)) != 0) { - /* If it is an offscreen texture, only create stub implementations. - Only the IUnknown interfaces should be used anyway. */ - ICOM_INIT_INTERFACE(surf, IDirect3DTexture, VTABLE_IDirect3DTexture); /* No special STUB one here as all functions are stubs */ - ICOM_INIT_INTERFACE(surf, IDirect3DTexture2, STUB_VTABLE_IDirect3DTexture2); - return DD_OK; - } - private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTextureGLImpl)); if (private == NULL) return DDERR_OUTOFMEMORY; diff --git a/dlls/ddraw/ddraw/main.c b/dlls/ddraw/ddraw/main.c index caee348993d..b076cb808ca 100644 --- a/dlls/ddraw/ddraw/main.c +++ b/dlls/ddraw/ddraw/main.c @@ -557,6 +557,11 @@ Main_DirectDraw_CreateSurface(LPDIRECTDRAW7 iface, LPDDSURFACEDESC2 pDDSD, /* create backbuffer surface */ hr = This->create_backbuffer(This, pDDSD, ppSurf, pUnkOuter, NULL); } + else if (pDDSD->ddsCaps.dwCaps & DDSCAPS_TEXTURE) + { + /* create texture */ + hr = create_texture(This, pDDSD, ppSurf, pUnkOuter); + } else if ((pDDSD->ddsCaps.dwCaps & DDSCAPS_OFFSCREENPLAIN) || (pDDSD->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)) /* No difference in Wine right now */ { @@ -568,11 +573,6 @@ Main_DirectDraw_CreateSurface(LPDIRECTDRAW7 iface, LPDDSURFACEDESC2 pDDSD, /* create z-buffer */ hr = This->create_zbuffer(This, pDDSD, ppSurf, pUnkOuter); } - else if (pDDSD->ddsCaps.dwCaps & DDSCAPS_TEXTURE) - { - /* create texture */ - hr = create_texture(This, pDDSD, ppSurf, pUnkOuter); - } else { /* Otherwise, assume offscreenplain surface */ diff --git a/dlls/ddraw/mesa.c b/dlls/ddraw/mesa.c index b205c152ef9..e955a3d597d 100644 --- a/dlls/ddraw/mesa.c +++ b/dlls/ddraw/mesa.c @@ -83,6 +83,7 @@ void set_render_state(D3DRENDERSTATETYPE dwRenderStateType, } } break; + case D3DRENDERSTATE_TEXTUREADDRESSU: /* 44 */ case D3DRENDERSTATE_TEXTUREADDRESSV: /* 45 */ case D3DRENDERSTATE_TEXTUREADDRESS: { /* 3 */ @@ -268,7 +269,34 @@ void set_render_state(D3DRENDERSTATETYPE dwRenderStateType, else glDisable(GL_BLEND); break; + + case D3DRENDERSTATE_FOGENABLE: /* 28 */ + if (dwRenderState) + glEnable(GL_FOG); + else + glDisable(GL_FOG); + break; + case D3DRENDERSTATE_SPECULARENABLE: /* 29 */ + if (dwRenderState) + ERR(" Specular Lighting not supported yet.\n"); + break; + + case D3DRENDERSTATE_SUBPIXEL: /* 31 */ + case D3DRENDERSTATE_SUBPIXELX: /* 32 */ + /* We do not support this anyway, so why protest :-) */ + break; + + case D3DRENDERSTATE_FOGCOLOR: { /* 34 */ + GLint color[4]; + color[0] = (dwRenderState >> 16) & 0xFF; + color[1] = (dwRenderState >> 8) & 0xFF; + color[2] = (dwRenderState >> 0) & 0xFF; + color[3] = (dwRenderState >> 24) & 0xFF; + glFogiv(GL_FOG_COLOR, color); + } break; + + case D3DRENDERSTATE_COLORKEYENABLE: /* 41 */ if (dwRenderState) glEnable(GL_BLEND); @@ -276,6 +304,20 @@ void set_render_state(D3DRENDERSTATETYPE dwRenderStateType, glDisable(GL_BLEND); break; + case D3DRENDERSTATE_ZBIAS: /* 47 */ + /* This is a tad bit hacky.. But well, no idea how to do it better in OpenGL :-/ */ + if (dwRenderState == 0) { + glDisable(GL_POLYGON_OFFSET_FILL); + glDisable(GL_POLYGON_OFFSET_LINE); + glDisable(GL_POLYGON_OFFSET_POINT); + } else { + glEnable(GL_POLYGON_OFFSET_FILL); + glEnable(GL_POLYGON_OFFSET_LINE); + glEnable(GL_POLYGON_OFFSET_POINT); + glPolygonOffset(1.0, dwRenderState * 1.0); + } + break; + case D3DRENDERSTATE_FLUSHBATCH: /* 50 */ break; -- 2.11.4.GIT