Commit 39092157 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Remove d3dfmt_p8_init_palette.

parent 81a904e7
...@@ -7280,12 +7280,10 @@ static GLuint gen_p8_shader(struct arbfp_blit_priv *priv, ...@@ -7280,12 +7280,10 @@ static GLuint gen_p8_shader(struct arbfp_blit_priv *priv,
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
static void upload_palette(const struct wined3d_surface *surface, struct wined3d_context *context) static void upload_palette(const struct wined3d_surface *surface, struct wined3d_context *context)
{ {
BYTE table[256][4];
struct wined3d_device *device = surface->resource.device; struct wined3d_device *device = surface->resource.device;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
struct arbfp_blit_priv *priv = device->blit_priv; struct arbfp_blit_priv *priv = device->blit_priv;
const struct wined3d_palette *palette = surface->palette;
d3dfmt_p8_init_palette(surface, table);
if (!priv->palette_texture) if (!priv->palette_texture)
gl_info->gl_ops.gl.p_glGenTextures(1, &priv->palette_texture); gl_info->gl_ops.gl.p_glGenTextures(1, &priv->palette_texture);
...@@ -7299,9 +7297,19 @@ static void upload_palette(const struct wined3d_surface *surface, struct wined3d ...@@ -7299,9 +7297,19 @@ static void upload_palette(const struct wined3d_surface *surface, struct wined3d
/* Make sure we have discrete color levels. */ /* Make sure we have discrete color levels. */
gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
/* Upload the palette */
/* TODO: avoid unneeded uploads in the future by adding some SFLAG_PALETTE_DIRTY mechanism */ /* TODO: avoid unneeded uploads in the future by adding some SFLAG_PALETTE_DIRTY mechanism */
gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, table); if (palette)
{
gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 256, 0, GL_BGRA,
GL_UNSIGNED_INT_8_8_8_8_REV, palette->colors);
}
else
{
static const DWORD black;
FIXME("P8 surface loaded without a palette.\n");
gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 1, 0, GL_BGRA,
GL_UNSIGNED_INT_8_8_8_8_REV, &black);
}
/* Switch back to unit 0 in which the 2D texture will be stored. */ /* Switch back to unit 0 in which the 2D texture will be stored. */
context_active_texture(context, gl_info, 0); context_active_texture(context, gl_info, 0);
......
...@@ -3370,38 +3370,6 @@ static BOOL color_in_range(const struct wined3d_color_key *color_key, DWORD colo ...@@ -3370,38 +3370,6 @@ static BOOL color_in_range(const struct wined3d_color_key *color_key, DWORD colo
&& color <= color_key->color_space_high_value; && color <= color_key->color_space_high_value;
} }
void d3dfmt_p8_init_palette(const struct wined3d_surface *surface, BYTE table[256][4])
{
const struct wined3d_palette *pal = surface->palette;
unsigned int i;
if (!pal)
{
FIXME("No palette set.\n");
/* Guarantees that memory representation remains correct after sysmem<->texture transfers even if
* there's no palette at this time. */
for (i = 0; i < 256; i++)
table[i][3] = i;
}
else
{
TRACE("Using surface palette %p\n", pal);
for (i = 0; i < 256; ++i)
{
table[i][0] = pal->colors[i].rgbRed;
table[i][1] = pal->colors[i].rgbGreen;
table[i][2] = pal->colors[i].rgbBlue;
/* The palette index is stored in the alpha component. In case of a
* readback we can then read GL_ALPHA. Color keying is handled in
* surface_blt_to_drawable() using a GL_ALPHA_TEST using GL_NOT_EQUAL.
* In case of a P8 surface the color key itself is passed to
* glAlphaFunc in other cases the alpha component of pixels that
* should be masked away is set to 0. */
table[i][3] = i;
}
}
}
static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UINT width, UINT height, static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UINT width, UINT height,
UINT outpitch, enum wined3d_conversion_type conversion_type, struct wined3d_surface *surface) UINT outpitch, enum wined3d_conversion_type conversion_type, struct wined3d_surface *surface)
{ {
...@@ -3420,27 +3388,40 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI ...@@ -3420,27 +3388,40 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI
} }
case WINED3D_CT_PALETTED: case WINED3D_CT_PALETTED:
{ if (surface->palette)
BYTE table[256][4];
unsigned int x, y;
d3dfmt_p8_init_palette(surface, table);
for (y = 0; y < height; y++)
{ {
source = src + pitch * y; unsigned int x, y;
dest = dst + outpitch * y; const struct wined3d_palette *palette = surface->palette;
/* This is an 1 bpp format, using the width here is fine */ for (y = 0; y < height; y++)
for (x = 0; x < width; x++) { {
BYTE color = *source++; source = src + pitch * y;
*dest++ = table[color][0]; dest = dst + outpitch * y;
*dest++ = table[color][1]; for (x = 0; x < width; x++)
*dest++ = table[color][2]; {
*dest++ = table[color][3]; BYTE color = *source++;
*dest++ = palette->colors[color].rgbRed;
*dest++ = palette->colors[color].rgbGreen;
*dest++ = palette->colors[color].rgbBlue;
*dest++ = 0;
}
} }
} }
} else
break; {
/* This should probably use the system palette, but unless
* the X server is running in P8 mode there is no such thing.
* The probably best solution is to set the fixed 20 colors
* from the default windows palette and set the rest to black,
* white, or some ugly pink. For now use black for the entire
* palette. Don't use pink everywhere. Age of Empires 2 draws
* a front buffer filled with zeroes without a palette when
* starting and we don't want the screen to flash in an ugly
* color. */
FIXME("P8 surface loaded without a palette.\n");
memset(dst, 0, height * outpitch);
}
break;
case WINED3D_CT_CK_565: case WINED3D_CT_CK_565:
{ {
......
...@@ -2350,8 +2350,6 @@ enum wined3d_conversion_type ...@@ -2350,8 +2350,6 @@ enum wined3d_conversion_type
WINED3D_CT_CK_ARGB32, WINED3D_CT_CK_ARGB32,
}; };
void d3dfmt_p8_init_palette(const struct wined3d_surface *surface, BYTE table[256][4]) DECLSPEC_HIDDEN;
struct wined3d_sampler struct wined3d_sampler
{ {
LONG refcount; LONG refcount;
......
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