wined3d: Move palette uploading code over to arbfp blit_shader.

This commit is contained in:
Roderick Colenbrander 2010-04-05 20:05:13 +02:00 committed by Alexandre Julliard
parent 513c77655a
commit 3b6aea5934
4 changed files with 56 additions and 46 deletions

View File

@ -6225,6 +6225,7 @@ struct arbfp_blit_priv {
GLenum uyvy_rect_shader, uyvy_2d_shader; GLenum uyvy_rect_shader, uyvy_2d_shader;
GLenum yv12_rect_shader, yv12_2d_shader; GLenum yv12_rect_shader, yv12_2d_shader;
GLenum p8_rect_shader, p8_2d_shader; GLenum p8_rect_shader, p8_2d_shader;
GLuint palette_texture;
}; };
static HRESULT arbfp_blit_alloc(IWineD3DDevice *iface) { static HRESULT arbfp_blit_alloc(IWineD3DDevice *iface) {
@ -6252,6 +6253,8 @@ static void arbfp_blit_free(IWineD3DDevice *iface) {
GL_EXTCALL(glDeleteProgramsARB(1, &priv->p8_rect_shader)); GL_EXTCALL(glDeleteProgramsARB(1, &priv->p8_rect_shader));
GL_EXTCALL(glDeleteProgramsARB(1, &priv->p8_2d_shader)); GL_EXTCALL(glDeleteProgramsARB(1, &priv->p8_2d_shader));
checkGLcall("Delete yuv and p8 programs"); checkGLcall("Delete yuv and p8 programs");
if(priv->palette_texture) glDeleteTextures(1, &priv->palette_texture);
LEAVE_GL(); LEAVE_GL();
HeapFree(GetProcessHeap(), 0, device->blit_priv); HeapFree(GetProcessHeap(), 0, device->blit_priv);
@ -6558,6 +6561,38 @@ static GLuint gen_p8_shader(IWineD3DDeviceImpl *device, GLenum textype)
return shader; return shader;
} }
/* Context activation is done by the caller. */
static void upload_palette(IWineD3DSurfaceImpl *surface)
{
BYTE table[256][4];
IWineD3DDeviceImpl *device = surface->resource.device;
struct arbfp_blit_priv *priv = device->blit_priv;
BOOL colorkey = (surface->CKeyFlags & WINEDDSD_CKSRCBLT) ? TRUE : FALSE;
d3dfmt_p8_init_palette(surface, table, colorkey);
ENTER_GL();
if (!priv->palette_texture)
glGenTextures(1, &priv->palette_texture);
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE1));
glBindTexture(GL_TEXTURE_1D, priv->palette_texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
/* Make sure we have discrete color levels. */
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
/* Upload the palette */
/* TODO: avoid unneeed uploads in the future by adding some SFLAG_PALETTE_DIRTY mechanism */
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, table);
/* Switch back to unit 0 in which the 2D texture will be stored. */
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0));
LEAVE_GL();
}
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum complex_fixup yuv_fixup, GLenum textype) static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum complex_fixup yuv_fixup, GLenum textype)
{ {
@ -6715,19 +6750,19 @@ static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum complex_fixup yuv_
} }
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
static HRESULT arbfp_blit_set(IWineD3DDevice *iface, const struct wined3d_format_desc *format_desc, static HRESULT arbfp_blit_set(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface)
GLenum textype, UINT width, UINT height)
{ {
GLenum shader; GLenum shader;
IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface; IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface;
float size[4] = {width, height, 1, 1}; float size[4] = {surface->pow2Width, surface->pow2Height, 1, 1};
struct arbfp_blit_priv *priv = device->blit_priv; struct arbfp_blit_priv *priv = device->blit_priv;
enum complex_fixup fixup; enum complex_fixup fixup;
GLenum textype = surface->texture_target;
if (!is_complex_fixup(format_desc->color_fixup)) if (!is_complex_fixup(surface->resource.format_desc->color_fixup))
{ {
TRACE("Fixup:\n"); TRACE("Fixup:\n");
dump_color_fixup_desc(format_desc->color_fixup); dump_color_fixup_desc(surface->resource.format_desc->color_fixup);
/* Don't bother setting up a shader for unconverted formats */ /* Don't bother setting up a shader for unconverted formats */
ENTER_GL(); ENTER_GL();
glEnable(textype); glEnable(textype);
@ -6736,7 +6771,7 @@ static HRESULT arbfp_blit_set(IWineD3DDevice *iface, const struct wined3d_format
return WINED3D_OK; return WINED3D_OK;
} }
fixup = get_complex_fixup(format_desc->color_fixup); fixup = get_complex_fixup(surface->resource.format_desc->color_fixup);
switch(fixup) switch(fixup)
{ {
@ -6755,6 +6790,8 @@ static HRESULT arbfp_blit_set(IWineD3DDevice *iface, const struct wined3d_format
case COMPLEX_FIXUP_P8: case COMPLEX_FIXUP_P8:
shader = textype == GL_TEXTURE_RECTANGLE_ARB ? priv->p8_rect_shader : priv->p8_2d_shader; shader = textype == GL_TEXTURE_RECTANGLE_ARB ? priv->p8_rect_shader : priv->p8_2d_shader;
if (!shader) shader = gen_p8_shader(device, textype); if (!shader) shader = gen_p8_shader(device, textype);
upload_palette(surface);
break; break;
default: default:

View File

@ -2343,7 +2343,7 @@ HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_
return WINED3D_OK; return WINED3D_OK;
} }
static void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey) void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey)
{ {
IWineD3DDeviceImpl *device = This->resource.device; IWineD3DDeviceImpl *device = This->resource.device;
IWineD3DPaletteImpl *pal = This->palette; IWineD3DPaletteImpl *pal = This->palette;
@ -2867,7 +2867,6 @@ static void d3dfmt_p8_upload_palette(IWineD3DSurface *iface,
{ {
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface; IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
BYTE table[256][4]; BYTE table[256][4];
IWineD3DDeviceImpl *device = This->resource.device;
d3dfmt_p8_init_palette(This, table, (convert == CONVERT_PALETTED_CK)); d3dfmt_p8_init_palette(This, table, (convert == CONVERT_PALETTED_CK));
@ -2879,31 +2878,6 @@ static void d3dfmt_p8_upload_palette(IWineD3DSurface *iface,
GL_EXTCALL(glColorTableEXT(This->texture_target, GL_RGBA, 256, GL_RGBA, GL_UNSIGNED_BYTE, table)); GL_EXTCALL(glColorTableEXT(This->texture_target, GL_RGBA, 256, GL_RGBA, GL_UNSIGNED_BYTE, table));
LEAVE_GL(); LEAVE_GL();
} }
else
{
/* Let a fragment shader do the color conversion by uploading the palette to a 1D texture.
* The 8bit pixel data will be used as an index in this palette texture to retrieve the final color. */
TRACE("Using fragment shaders for emulating 8-bit paletted texture support\n");
device->blitter->set_shader((IWineD3DDevice *) device, This->resource.format_desc,
This->texture_target, This->pow2Width, This->pow2Height);
ENTER_GL();
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE1));
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /* Make sure we have discrete color levels. */
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, table); /* Upload the palette */
/* Switch back to unit 0 in which the 2D texture will be stored. */
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0));
/* Rebind the texture because it isn't bound anymore */
glBindTexture(This->texture_target, This->texture_name);
LEAVE_GL();
}
} }
BOOL palette9_changed(IWineD3DSurfaceImpl *This) BOOL palette9_changed(IWineD3DSurfaceImpl *This)
@ -4103,8 +4077,7 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, const
dump_color_fixup_desc(Src->resource.format_desc->color_fixup); dump_color_fixup_desc(Src->resource.format_desc->color_fixup);
} }
myDevice->blitter->set_shader((IWineD3DDevice *) myDevice, Src->resource.format_desc, myDevice->blitter->set_shader((IWineD3DDevice *) myDevice, Src);
Src->texture_target, Src->pow2Width, Src->pow2Height);
ENTER_GL(); ENTER_GL();
@ -4739,10 +4712,14 @@ static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT
dst_rect = src_rect; dst_rect = src_rect;
} }
device->blitter->set_shader((IWineD3DDevice *) device, This);
ENTER_GL(); ENTER_GL();
draw_textured_quad(This, &src_rect, &dst_rect, WINED3DTEXF_POINT); draw_textured_quad(This, &src_rect, &dst_rect, WINED3DTEXF_POINT);
LEAVE_GL(); LEAVE_GL();
device->blitter->set_shader((IWineD3DDevice *) device, This);
wglFlush(); /* Flush to ensure ordering across contexts. */ wglFlush(); /* Flush to ensure ordering across contexts. */
context_release(context); context_release(context);
@ -5143,12 +5120,11 @@ static HRESULT ffp_blit_alloc(IWineD3DDevice *iface) { return WINED3D_OK; }
static void ffp_blit_free(IWineD3DDevice *iface) { } static void ffp_blit_free(IWineD3DDevice *iface) { }
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
static HRESULT ffp_blit_set(IWineD3DDevice *iface, const struct wined3d_format_desc *format_desc, static HRESULT ffp_blit_set(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface)
GLenum textype, UINT width, UINT height)
{ {
ENTER_GL(); ENTER_GL();
glEnable(textype); glEnable(surface->texture_target);
checkGLcall("glEnable(textype)"); checkGLcall("glEnable(surface->texture_target)");
LEAVE_GL(); LEAVE_GL();
return WINED3D_OK; return WINED3D_OK;
} }
@ -5229,8 +5205,7 @@ static void cpu_blit_free(IWineD3DDevice *iface)
} }
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
static HRESULT cpu_blit_set(IWineD3DDevice *iface, const struct wined3d_format_desc *format_desc, static HRESULT cpu_blit_set(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface)
GLenum textype, UINT width, UINT height)
{ {
return WINED3D_OK; return WINED3D_OK;
} }

View File

@ -161,9 +161,7 @@ static void swapchain_blit(IWineD3DSwapChainImpl *This, struct wined3d_context *
/* Set up the texture. The surface is not in a IWineD3D*Texture container, /* Set up the texture. The surface is not in a IWineD3D*Texture container,
* so there are no d3d texture settings to dirtify * so there are no d3d texture settings to dirtify
*/ */
device->blitter->set_shader((IWineD3DDevice *) device, backbuffer->resource.format_desc, device->blitter->set_shader((IWineD3DDevice *) device, backbuffer);
backbuffer->texture_target, backbuffer->pow2Width,
backbuffer->pow2Height);
glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter); glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter);
glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter); glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter);

View File

@ -1173,8 +1173,7 @@ struct blit_shader
{ {
HRESULT (*alloc_private)(IWineD3DDevice *iface); HRESULT (*alloc_private)(IWineD3DDevice *iface);
void (*free_private)(IWineD3DDevice *iface); void (*free_private)(IWineD3DDevice *iface);
HRESULT (*set_shader)(IWineD3DDevice *iface, const struct wined3d_format_desc *format_desc, HRESULT (*set_shader)(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface);
GLenum textype, UINT width, UINT height);
void (*unset_shader)(IWineD3DDevice *iface); void (*unset_shader)(IWineD3DDevice *iface);
BOOL (*color_fixup_supported)(const struct wined3d_gl_info *gl_info, struct color_fixup_desc fixup); BOOL (*color_fixup_supported)(const struct wined3d_gl_info *gl_info, struct color_fixup_desc fixup);
HRESULT (*color_fill)(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect, DWORD fill_color); HRESULT (*color_fill)(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *dst_surface, const RECT *dst_rect, DWORD fill_color);
@ -2237,6 +2236,7 @@ typedef enum {
HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, GLenum *format, HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, GLenum *format,
GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp, BOOL srgb_mode) DECLSPEC_HIDDEN; GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp, BOOL srgb_mode) DECLSPEC_HIDDEN;
void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey) DECLSPEC_HIDDEN;
BOOL palette9_changed(IWineD3DSurfaceImpl *This) DECLSPEC_HIDDEN; BOOL palette9_changed(IWineD3DSurfaceImpl *This) DECLSPEC_HIDDEN;