wined3d: Add WINED3DFMT_P8_UINT support to wined3d_format_convert_from_float().

This commit is contained in:
Henri Verbeet 2011-08-02 21:42:15 +02:00 committed by Alexandre Julliard
parent cf1c641cbb
commit 111e8fe77c
3 changed files with 38 additions and 3 deletions

View File

@ -7355,7 +7355,7 @@ static HRESULT cpu_blit_color_fill(struct wined3d_device *device, struct wined3d
memset(&BltFx, 0, sizeof(BltFx)); memset(&BltFx, 0, sizeof(BltFx));
BltFx.dwSize = sizeof(BltFx); BltFx.dwSize = sizeof(BltFx);
BltFx.u5.dwFillColor = wined3d_format_convert_from_float(dst_surface->resource.format, color); BltFx.u5.dwFillColor = wined3d_format_convert_from_float(dst_surface, color);
return wined3d_surface_blt(dst_surface, dst_rect, NULL, NULL, return wined3d_surface_blt(dst_surface, dst_rect, NULL, NULL,
WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_POINT); WINEDDBLT_COLORFILL, &BltFx, WINED3DTEXF_POINT);
} }

View File

@ -2622,7 +2622,7 @@ BOOL getDepthStencilBits(const struct wined3d_format *format, BYTE *depthSize, B
/* Note: It's the caller's responsibility to ensure values can be expressed /* Note: It's the caller's responsibility to ensure values can be expressed
* in the requested format. UNORM formats for example can only express values * in the requested format. UNORM formats for example can only express values
* in the range 0.0f -> 1.0f. */ * in the range 0.0f -> 1.0f. */
DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, const WINED3DCOLORVALUE *color) DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface, const WINED3DCOLORVALUE *color)
{ {
static const struct static const struct
{ {
@ -2653,6 +2653,7 @@ DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, con
{WINED3DFMT_B10G10R10A2_UNORM, 1023.0f, 1023.0f, 1023.0f, 3.0f, 20, 10, 0, 30}, {WINED3DFMT_B10G10R10A2_UNORM, 1023.0f, 1023.0f, 1023.0f, 3.0f, 20, 10, 0, 30},
{WINED3DFMT_R10G10B10A2_UNORM, 1023.0f, 1023.0f, 1023.0f, 3.0f, 0, 10, 20, 30}, {WINED3DFMT_R10G10B10A2_UNORM, 1023.0f, 1023.0f, 1023.0f, 3.0f, 0, 10, 20, 30},
}; };
const struct wined3d_format *format = surface->resource.format;
unsigned int i; unsigned int i;
TRACE("Converting color {%.8e %.8e %.8e %.8e} to format %s.\n", TRACE("Converting color {%.8e %.8e %.8e %.8e} to format %s.\n",
@ -2674,6 +2675,40 @@ DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, con
return ret; return ret;
} }
if (format->id == WINED3DFMT_P8_UINT)
{
PALETTEENTRY *e;
BYTE r, g, b, a;
if (!surface->palette)
{
WARN("Surface doesn't have a palette, returning 0.\n");
return 0;
}
r = (BYTE)((color->r * 255.0f) + 0.5f);
g = (BYTE)((color->g * 255.0f) + 0.5f);
b = (BYTE)((color->b * 255.0f) + 0.5f);
a = (BYTE)((color->a * 255.0f) + 0.5f);
e = &surface->palette->palents[a];
if (e->peRed == r && e->peGreen == g && e->peBlue == b)
return a;
WARN("Alpha didn't match index, searching full palette.\n");
for (i = 0; i < 256; ++i)
{
e = &surface->palette->palents[i];
if (e->peRed == r && e->peGreen == g && e->peBlue == b)
return i;
}
FIXME("Unable to convert color to palette index.\n");
return 0;
}
FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format->id)); FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format->id));
return 0; return 0;

View File

@ -2805,7 +2805,7 @@ const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl
enum wined3d_format_id format_id) DECLSPEC_HIDDEN; enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT wined3d_format_calculate_size(const struct wined3d_format *format,
UINT alignment, UINT width, UINT height) DECLSPEC_HIDDEN; UINT alignment, UINT width, UINT height) DECLSPEC_HIDDEN;
DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface,
const WINED3DCOLORVALUE *color) DECLSPEC_HIDDEN; const WINED3DCOLORVALUE *color) DECLSPEC_HIDDEN;
static inline BOOL use_vs(const struct wined3d_state *state) static inline BOOL use_vs(const struct wined3d_state *state)