[PATCH 2/5] wined3d: Convert from floating point to specific surface formats.
Henri Verbeet
hverbeet at codeweavers.com
Mon Aug 23 11:28:07 CDT 2010
Instead of from WINED3DFMT_B8G8R8A8_UNORM.
---
dlls/wined3d/device.c | 14 +++-----------
dlls/wined3d/surface.c | 10 +++++++---
dlls/wined3d/utils.c | 30 +++++++++++++++++++-----------
dlls/wined3d/wined3d_private.h | 5 ++---
4 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index bb793cd..e528296 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -5496,6 +5496,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DeletePatch(IWineD3DDevice *iface, UINT
static HRESULT WINAPI IWineD3DDeviceImpl_ColorFill(IWineD3DDevice *iface,
IWineD3DSurface *surface, const WINED3DRECT *pRect, WINED3DCOLOR color)
{
+ const WINED3DCOLORVALUE c = {D3DCOLOR_R(color), D3DCOLOR_G(color), D3DCOLOR_B(color), D3DCOLOR_A(color)};
IWineD3DSurfaceImpl *s = (IWineD3DSurfaceImpl *)surface;
WINEDDBLTFX BltFx;
@@ -5510,7 +5511,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_ColorFill(IWineD3DDevice *iface,
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
{
- const WINED3DCOLORVALUE c = {D3DCOLOR_R(color), D3DCOLOR_G(color), D3DCOLOR_B(color), D3DCOLOR_A(color)};
const RECT draw_rect = {0, 0, s->currentDesc.Width, s->currentDesc.Height};
return device_clear_render_targets((IWineD3DDeviceImpl *)iface, 1, &s,
@@ -5521,7 +5521,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_ColorFill(IWineD3DDevice *iface,
/* Just forward this to the DirectDraw blitting engine */
memset(&BltFx, 0, sizeof(BltFx));
BltFx.dwSize = sizeof(BltFx);
- BltFx.u5.dwFillColor = color_convert_argb_to_fmt(color, s->resource.format_desc->format);
+ BltFx.u5.dwFillColor = wined3d_format_convert_from_float(s->resource.format_desc, &c);
return IWineD3DSurface_Blt(surface, (const RECT *)pRect, NULL, NULL,
WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_POINT);
}
@@ -5560,19 +5560,11 @@ static void WINAPI IWineD3DDeviceImpl_ClearRendertargetView(IWineD3DDevice *ifac
else
{
WINEDDBLTFX BltFx;
- WINED3DCOLOR c;
-
- WARN("Converting to WINED3DCOLOR, this might give incorrect results\n");
-
- c = ((DWORD)(color->b * 255.0f));
- c |= ((DWORD)(color->g * 255.0f)) << 8;
- c |= ((DWORD)(color->r * 255.0f)) << 16;
- c |= ((DWORD)(color->a * 255.0f)) << 24;
/* Just forward this to the DirectDraw blitting engine */
memset(&BltFx, 0, sizeof(BltFx));
BltFx.dwSize = sizeof(BltFx);
- BltFx.u5.dwFillColor = color_convert_argb_to_fmt(c, surface->resource.format_desc->format);
+ BltFx.u5.dwFillColor = wined3d_format_convert_from_float(surface->resource.format_desc, color);
hr = IWineD3DSurface_Blt((IWineD3DSurface *)surface, NULL, NULL, NULL,
WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_POINT);
if (FAILED(hr))
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 06893ee..c210fdf 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -4923,13 +4923,17 @@ static BOOL cpu_blit_supported(const struct wined3d_gl_info *gl_info, enum blit_
return FALSE;
}
-static HRESULT cpu_blit_color_fill(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect, DWORD fill_color)
+static HRESULT cpu_blit_color_fill(IWineD3DDeviceImpl *device,
+ IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect, DWORD color)
{
+ const WINED3DCOLORVALUE c = {D3DCOLOR_R(color), D3DCOLOR_G(color), D3DCOLOR_B(color), D3DCOLOR_A(color)};
WINEDDBLTFX BltFx;
+
memset(&BltFx, 0, sizeof(BltFx));
BltFx.dwSize = sizeof(BltFx);
- BltFx.u5.dwFillColor = color_convert_argb_to_fmt(fill_color, dst_surface->resource.format_desc->format);
- return IWineD3DBaseSurfaceImpl_Blt((IWineD3DSurface*)dst_surface, dst_rect, NULL, NULL, WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_POINT);
+ BltFx.u5.dwFillColor = wined3d_format_convert_from_float(dst_surface->resource.format_desc, &c);
+ return IWineD3DBaseSurfaceImpl_Blt((IWineD3DSurface*)dst_surface, dst_rect,
+ NULL, NULL, WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_POINT);
}
const struct blit_shader cpu_blit = {
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index e3a0cb6..b6d7eab 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -2532,25 +2532,33 @@ BOOL getDepthStencilBits(const struct wined3d_format_desc *format_desc, short *d
return TRUE;
}
-DWORD color_convert_argb_to_fmt(DWORD color, WINED3DFORMAT destfmt)
+DWORD wined3d_format_convert_from_float(const struct wined3d_format_desc *format, const WINED3DCOLORVALUE *color)
{
+ WINED3DFORMAT destfmt = format->format;
unsigned int r, g, b, a;
DWORD ret;
- if (destfmt == WINED3DFMT_B8G8R8A8_UNORM
- || destfmt == WINED3DFMT_B8G8R8X8_UNORM
- || destfmt == WINED3DFMT_B8G8R8_UNORM)
- return color;
+ TRACE("Converting color {%.8e %.8e %.8e %.8e} to format %s.\n",
+ color->r, color->g, color->b, color->a, debug_d3dformat(destfmt));
- 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;
+ r = (DWORD)((color->r * 255.0f) + 0.5f);
+ g = (DWORD)((color->g * 255.0f) + 0.5f);
+ b = (DWORD)((color->b * 255.0f) + 0.5f);
+ a = (DWORD)((color->a * 255.0f) + 0.5f);
switch(destfmt)
{
+ case WINED3DFMT_B8G8R8A8_UNORM:
+ case WINED3DFMT_B8G8R8X8_UNORM:
+ case WINED3DFMT_B8G8R8_UNORM:
+ ret = b;
+ ret |= g << 8;
+ ret |= r << 16;
+ ret |= a << 24;
+ TRACE("Returning 0x%08x.\n", ret);
+ return ret;
+
+
case WINED3DFMT_B5G6R5_UNORM:
if(r == 0xff && g == 0xff && b == 0xff) return 0xffff;
r = (r * 32) / 256;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index ecb426c..c0ac388 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2620,9 +2620,6 @@ const char *debug_d3dtop(WINED3DTEXTUREOP d3dtop) DECLSPEC_HIDDEN;
void dump_color_fixup_desc(struct color_fixup_desc fixup) DECLSPEC_HIDDEN;
const char *debug_surflocation(DWORD flag) DECLSPEC_HIDDEN;
-/* Color conversion routines */
-DWORD color_convert_argb_to_fmt(DWORD color, WINED3DFORMAT destfmt) DECLSPEC_HIDDEN;
-
/* Routines for GL <-> D3D values */
GLenum StencilOp(DWORD op) DECLSPEC_HIDDEN;
GLenum CompareFunc(DWORD func) DECLSPEC_HIDDEN;
@@ -2998,6 +2995,8 @@ const struct wined3d_format_desc *getFormatDescEntry(WINED3DFORMAT fmt,
const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
UINT wined3d_format_calculate_size(const struct wined3d_format_desc *format,
UINT alignment, UINT width, UINT height) DECLSPEC_HIDDEN;
+DWORD wined3d_format_convert_from_float(const struct wined3d_format_desc *format,
+ const WINED3DCOLORVALUE *color) DECLSPEC_HIDDEN;
static inline BOOL use_vs(IWineD3DStateBlockImpl *stateblock)
{
--
1.7.1
More information about the wine-patches
mailing list