wined3d: Convert the colors to the surface format for colorfill.

This commit is contained in:
Stefan Dösinger 2007-08-31 20:58:35 +02:00 committed by Alexandre Julliard
parent 29be901376
commit 3b07663b90
1 changed files with 111 additions and 2 deletions

View File

@ -5659,6 +5659,113 @@ static void color_fill_fbo(IWineD3DDevice *iface, IWineD3DSurface *surface, CONS
}
}
static inline DWORD argb_to_fmt(DWORD color, WINED3DFORMAT destfmt) {
unsigned int r, g, b, a;
DWORD ret;
if(destfmt == WINED3DFMT_A8R8G8B8 || destfmt == WINED3DFMT_X8R8G8B8 ||
destfmt == WINED3DFMT_R8G8B8)
return color;
TRACE("Converting color %08x to format %s\n", color, debug_d3dformat(destfmt));
a = (color & 0xff000000) >> 24;
r = (color & 0x00ff0000) >> 16;
g = (color & 0x0000ff00) >> 8;
b = (color & 0x000000ff) >> 0;
switch(destfmt)
{
case WINED3DFMT_R5G6B5:
if(r == 0xff && g == 0xff && b == 0xff) return 0xffff;
r = (r * 32) / 256;
g = (g * 64) / 256;
b = (b * 32) / 256;
ret = r << 11;
ret |= g << 5;
ret |= b;
TRACE("Returning %08x\n", ret);
return ret;
case WINED3DFMT_X1R5G5B5:
case WINED3DFMT_A1R5G5B5:
a = (a * 2) / 256;
r = (r * 32) / 256;
g = (g * 32) / 256;
b = (b * 32) / 256;
ret = a << 15;
ret |= r << 10;
ret |= g << 5;
ret |= b << 0;
TRACE("Returning %08x\n", ret);
return ret;
case WINED3DFMT_A8:
TRACE("Returning %08x\n", a);
return a;
case WINED3DFMT_X4R4G4B4:
case WINED3DFMT_A4R4G4B4:
a = (a * 16) / 256;
r = (r * 16) / 256;
g = (g * 16) / 256;
b = (b * 16) / 256;
ret = a << 12;
ret |= r << 8;
ret |= g << 4;
ret |= b << 0;
TRACE("Returning %08x\n", ret);
return ret;
case WINED3DFMT_R3G3B2:
r = (r * 8) / 256;
g = (g * 8) / 256;
b = (b * 4) / 256;
ret = r << 5;
ret |= g << 2;
ret |= b << 0;
TRACE("Returning %08x\n", ret);
return ret;
case WINED3DFMT_X8B8G8R8:
case WINED3DFMT_A8B8G8R8:
ret = a << 24;
ret |= b << 16;
ret |= g << 8;
ret |= r << 0;
TRACE("Returning %08x\n", ret);
return ret;
case WINED3DFMT_A2R10G10B10:
a = (a * 4) / 256;
r = (r * 1024) / 256;
g = (g * 1024) / 256;
b = (b * 1024) / 256;
ret = a << 30;
ret |= r << 20;
ret |= g << 10;
ret |= b << 0;
TRACE("Returning %08x\n", ret);
return ret;
case WINED3DFMT_A2B10G10R10:
a = (a * 4) / 256;
r = (r * 1024) / 256;
g = (g * 1024) / 256;
b = (b * 1024) / 256;
ret = a << 30;
ret |= b << 20;
ret |= g << 10;
ret |= r << 0;
TRACE("Returning %08x\n", ret);
return ret;
default:
FIXME("Add a COLORFILL conversion for format %s\n", debug_d3dformat(destfmt));
return 0;
}
}
static HRESULT WINAPI IWineD3DDeviceImpl_ColorFill(IWineD3DDevice *iface, IWineD3DSurface *pSurface, CONST WINED3DRECT* pRect, WINED3DCOLOR color) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *) pSurface;
@ -5677,7 +5784,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_ColorFill(IWineD3DDevice *iface, IWineD
/* Just forward this to the DirectDraw blitting engine */
memset(&BltFx, 0, sizeof(BltFx));
BltFx.dwSize = sizeof(BltFx);
BltFx.u5.dwFillColor = color;
BltFx.u5.dwFillColor = argb_to_fmt(color, surface->resource.format);
return IWineD3DSurface_Blt(pSurface, (RECT *) pRect, NULL, NULL, WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_NONE);
}
}
@ -5794,8 +5901,10 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetDepthStencilSurface(IWineD3DDevice
if(*ppZStencilSurface != NULL) {
/* Note inc ref on returned surface */
IWineD3DSurface_AddRef(*ppZStencilSurface);
return WINED3D_OK;
} else {
return WINED3DERR_NOTFOUND;
}
return WINED3D_OK;
}
/* TODO: Handle stencil attachments */