Commit 4710c4b5 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Store color keys in textures instead of in surfaces.

parent d412eb56
......@@ -4611,7 +4611,8 @@ static HRESULT WINAPI ddraw_surface7_SetColorKey(IDirectDrawSurface7 *iface, DWO
return DDERR_INVALIDPARAMS;
}
}
ctx.ret = wined3d_surface_set_color_key(This->wined3d_surface, Flags, ctx.color_key);
if (This->wined3d_texture)
ctx.ret = wined3d_texture_set_color_key(This->wined3d_texture, Flags, ctx.color_key);
ddraw_surface7_EnumAttachedSurfaces(iface, &ctx, SetColorKeyEnum);
wined3d_mutex_unlock();
......@@ -5897,6 +5898,19 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
root->is_complex_root = TRUE;
texture->root = root;
if (desc->dwFlags & DDSD_CKDESTOVERLAY)
wined3d_texture_set_color_key(wined3d_texture, DDCKEY_DESTOVERLAY,
(struct wined3d_color_key *)&desc->u3.ddckCKDestOverlay);
if (desc->dwFlags & DDSD_CKDESTBLT)
wined3d_texture_set_color_key(wined3d_texture, DDCKEY_DESTBLT,
(struct wined3d_color_key *)&desc->ddckCKDestBlt);
if (desc->dwFlags & DDSD_CKSRCOVERLAY)
wined3d_texture_set_color_key(wined3d_texture, DDCKEY_SRCOVERLAY,
(struct wined3d_color_key *)&desc->ddckCKSrcOverlay);
if (desc->dwFlags & DDSD_CKSRCBLT)
wined3d_texture_set_color_key(wined3d_texture, DDCKEY_SRCBLT,
(struct wined3d_color_key *)&desc->ddckCKSrcBlt);
for (i = 0; i < layers; ++i)
{
attach = &root->complex_array[layers - 1 - i];
......@@ -5987,6 +6001,19 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
last->wined3d_texture = wined3d_texture;
texture->root = last;
if (desc->dwFlags & DDSD_CKDESTOVERLAY)
wined3d_texture_set_color_key(wined3d_texture, DDCKEY_DESTOVERLAY,
(struct wined3d_color_key *)&desc->u3.ddckCKDestOverlay);
if (desc->dwFlags & DDSD_CKDESTBLT)
wined3d_texture_set_color_key(wined3d_texture, DDCKEY_DESTBLT,
(struct wined3d_color_key *)&desc->ddckCKDestBlt);
if (desc->dwFlags & DDSD_CKSRCOVERLAY)
wined3d_texture_set_color_key(wined3d_texture, DDCKEY_SRCOVERLAY,
(struct wined3d_color_key *)&desc->ddckCKSrcOverlay);
if (desc->dwFlags & DDSD_CKSRCBLT)
wined3d_texture_set_color_key(wined3d_texture, DDCKEY_SRCBLT,
(struct wined3d_color_key *)&desc->ddckCKSrcBlt);
*attach = last;
attach = &last->complex_array[0];
}
......@@ -6070,26 +6097,6 @@ HRESULT ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw, s
surface->surface_desc.u1.lPitch = wined3d_surface_get_pitch(wined3d_surface);
}
if (desc->dwFlags & DDSD_CKDESTOVERLAY)
{
wined3d_surface_set_color_key(wined3d_surface, DDCKEY_DESTOVERLAY,
(struct wined3d_color_key *)&desc->u3.ddckCKDestOverlay);
}
if (desc->dwFlags & DDSD_CKDESTBLT)
{
wined3d_surface_set_color_key(wined3d_surface, DDCKEY_DESTBLT,
(struct wined3d_color_key *)&desc->ddckCKDestBlt);
}
if (desc->dwFlags & DDSD_CKSRCOVERLAY)
{
wined3d_surface_set_color_key(wined3d_surface, DDCKEY_SRCOVERLAY,
(struct wined3d_color_key *)&desc->ddckCKSrcOverlay);
}
if (desc->dwFlags & DDSD_CKSRCBLT)
{
wined3d_surface_set_color_key(wined3d_surface, DDCKEY_SRCBLT,
(struct wined3d_color_key *)&desc->ddckCKSrcBlt);
}
if (desc->dwFlags & DDSD_LPSURFACE)
{
UINT pitch = 0;
......
......@@ -7116,7 +7116,7 @@ static void upload_palette(const struct wined3d_surface *surface, struct wined3d
struct wined3d_device *device = surface->resource.device;
const struct wined3d_gl_info *gl_info = context->gl_info;
struct arbfp_blit_priv *priv = device->blit_priv;
BOOL colorkey = (surface->CKeyFlags & WINEDDSD_CKSRCBLT) != 0;
BOOL colorkey = !!(surface->container->color_key_flags & WINEDDSD_CKSRCBLT);
d3dfmt_p8_init_palette(surface, table, colorkey);
......
......@@ -603,7 +603,7 @@ static void device_load_logo(struct wined3d_device *device, const char *filename
color_key.color_space_low_value = 0;
color_key.color_space_high_value = 0;
wined3d_surface_set_color_key(surface, WINEDDCKEY_SRCBLT, &color_key);
wined3d_texture_set_color_key(device->logo_texture, WINEDDCKEY_SRCBLT, &color_key);
}
else
{
......
......@@ -531,19 +531,15 @@ static void state_alpha(struct wined3d_context *context, const struct wined3d_st
TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
/* Find out if the texture on the first stage has a ckey set
* The alpha state func reads the texture settings, even though alpha and texture are not grouped
* together. This is to avoid making a huge alpha+texture+texture stage+ckey block due to the hardly
* used WINED3D_RS_COLORKEYENABLE state(which is d3d <= 3 only). The texture function will call alpha
* in case it finds some texture+colorkeyenable combination which needs extra care.
*/
if (state->textures[0])
{
struct wined3d_surface *surface = surface_from_resource(state->textures[0]->sub_resources[0]);
if (surface->CKeyFlags & WINEDDSD_CKSRCBLT)
enable_ckey = TRUE;
}
/* Find out if the texture on the first stage has a ckey set. The alpha
* state func reads the texture settings, even though alpha and texture
* are not grouped together. This is to avoid making a huge alpha +
* texture + texture stage + ckey block due to the hardly used
* WINED3D_RS_COLORKEYENABLE state(which is d3d <= 3 only). The texture
* function will call alpha in case it finds some texture + colorkeyenable
* combination which needs extra care. */
if (state->textures[0] && (state->textures[0]->color_key_flags & WINEDDSD_CKSRCBLT))
enable_ckey = TRUE;
if (enable_ckey || context->last_was_ckey)
context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP));
......@@ -3220,9 +3216,7 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st
if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
{
struct wined3d_surface *surf = surface_from_resource(texture->sub_resources[0]);
if (surf->CKeyFlags & WINEDDSD_CKSRCBLT && !surf->resource.format->alpha_size)
if (texture->color_key_flags & WINEDDSD_CKSRCBLT && !texture->resource.format->alpha_size)
{
/* Color keying needs to pass alpha values from the texture through to have the alpha test work
* properly. On the other hand applications can still use texture combiners apparently. This code
......
......@@ -623,6 +623,67 @@ enum wined3d_texture_filter_type CDECL wined3d_texture_get_autogen_filter_type(c
return texture->filter_type;
}
HRESULT CDECL wined3d_texture_set_color_key(struct wined3d_texture *texture,
DWORD flags, const struct wined3d_color_key *color_key)
{
TRACE("texture %p, flags %#x, color_key %p.\n", texture, flags, color_key);
if (flags & WINEDDCKEY_COLORSPACE)
{
FIXME("Unhandled flags %#x.\n", flags);
return WINED3DERR_INVALIDCALL;
}
if (color_key)
{
switch (flags & ~WINEDDCKEY_COLORSPACE)
{
case WINEDDCKEY_DESTBLT:
texture->dst_blt_color_key = *color_key;
texture->color_key_flags |= WINEDDSD_CKDESTBLT;
break;
case WINEDDCKEY_DESTOVERLAY:
texture->dst_overlay_color_key = *color_key;
texture->color_key_flags |= WINEDDSD_CKDESTOVERLAY;
break;
case WINEDDCKEY_SRCOVERLAY:
texture->src_overlay_color_key = *color_key;
texture->color_key_flags |= WINEDDSD_CKSRCOVERLAY;
break;
case WINEDDCKEY_SRCBLT:
texture->src_blt_color_key = *color_key;
texture->color_key_flags |= WINEDDSD_CKSRCBLT;
break;
}
}
else
{
switch (flags & ~WINEDDCKEY_COLORSPACE)
{
case WINEDDCKEY_DESTBLT:
texture->color_key_flags &= ~WINEDDSD_CKDESTBLT;
break;
case WINEDDCKEY_DESTOVERLAY:
texture->color_key_flags &= ~WINEDDSD_CKDESTOVERLAY;
break;
case WINEDDCKEY_SRCOVERLAY:
texture->color_key_flags &= ~WINEDDSD_CKSRCOVERLAY;
break;
case WINEDDCKEY_SRCBLT:
texture->color_key_flags &= ~WINEDDSD_CKSRCBLT;
break;
}
}
return WINED3D_OK;
}
void CDECL wined3d_texture_generate_mipmaps(struct wined3d_texture *texture)
{
/* TODO: Implement filters using GL_SGI_generate_mipmaps. */
......
......@@ -3324,9 +3324,7 @@ void gen_ffp_frag_op(const struct wined3d_context *context, const struct wined3d
if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
{
struct wined3d_surface *surf = surface_from_resource(texture->sub_resources[0]);
if (surf->CKeyFlags & WINEDDSD_CKSRCBLT && !surf->resource.format->alpha_size)
if (texture->color_key_flags & WINEDDSD_CKSRCBLT && !texture->resource.format->alpha_size)
{
if (aop == WINED3D_TOP_DISABLE)
{
......
......@@ -222,7 +222,6 @@
@ cdecl wined3d_surface_preload(ptr)
@ cdecl wined3d_surface_releasedc(ptr ptr)
@ cdecl wined3d_surface_restore(ptr)
@ cdecl wined3d_surface_set_color_key(ptr long ptr)
@ cdecl wined3d_surface_set_overlay_position(ptr long long)
@ cdecl wined3d_surface_set_palette(ptr ptr)
@ cdecl wined3d_surface_set_priority(ptr long)
......@@ -260,6 +259,7 @@
@ cdecl wined3d_texture_incref(ptr)
@ cdecl wined3d_texture_preload(ptr)
@ cdecl wined3d_texture_set_autogen_filter_type(ptr long)
@ cdecl wined3d_texture_set_color_key(ptr long ptr)
@ cdecl wined3d_texture_set_lod(ptr long)
@ cdecl wined3d_texture_set_priority(ptr long)
......
......@@ -2082,6 +2082,13 @@ struct wined3d_texture
const struct min_lookup *min_mip_lookup;
const GLenum *mag_lookup;
GLenum target;
/* Color keys for DDraw */
struct wined3d_color_key dst_blt_color_key;
struct wined3d_color_key src_blt_color_key;
struct wined3d_color_key dst_overlay_color_key;
struct wined3d_color_key src_overlay_color_key;
DWORD color_key_flags;
};
static inline struct wined3d_texture *wined3d_texture_from_resource(struct wined3d_resource *resource)
......@@ -2212,13 +2219,6 @@ struct wined3d_surface
HDC hDC;
void *getdc_map_mem;
/* Color keys for DDraw */
struct wined3d_color_key dst_blt_color_key;
struct wined3d_color_key src_blt_color_key;
struct wined3d_color_key dst_overlay_color_key;
struct wined3d_color_key src_overlay_color_key;
DWORD CKeyFlags;
struct wined3d_color_key gl_color_key;
struct list renderbuffers;
......
......@@ -2311,8 +2311,6 @@ HRESULT __cdecl wined3d_surface_map(struct wined3d_surface *surface,
void __cdecl wined3d_surface_preload(struct wined3d_surface *surface);
HRESULT __cdecl wined3d_surface_releasedc(struct wined3d_surface *surface, HDC dc);
HRESULT __cdecl wined3d_surface_restore(struct wined3d_surface *surface);
HRESULT __cdecl wined3d_surface_set_color_key(struct wined3d_surface *surface,
DWORD flags, const struct wined3d_color_key *color_key);
HRESULT __cdecl wined3d_surface_set_overlay_position(struct wined3d_surface *surface, LONG x, LONG y);
void __cdecl wined3d_surface_set_palette(struct wined3d_surface *surface, struct wined3d_palette *palette);
DWORD __cdecl wined3d_surface_set_priority(struct wined3d_surface *surface, DWORD new_priority);
......@@ -2370,6 +2368,8 @@ ULONG __cdecl wined3d_texture_incref(struct wined3d_texture *texture);
void __cdecl wined3d_texture_preload(struct wined3d_texture *texture);
HRESULT __cdecl wined3d_texture_set_autogen_filter_type(struct wined3d_texture *texture,
enum wined3d_texture_filter_type filter_type);
HRESULT __cdecl wined3d_texture_set_color_key(struct wined3d_texture *texture,
DWORD flags, const struct wined3d_color_key *color_key);
DWORD __cdecl wined3d_texture_set_lod(struct wined3d_texture *texture, DWORD lod);
DWORD __cdecl wined3d_texture_set_priority(struct wined3d_texture *texture, DWORD priority);
......
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