Commit 3b6aea59 authored by Roderick Colenbrander's avatar Roderick Colenbrander Committed by Alexandre Julliard

wined3d: Move palette uploading code over to arbfp blit_shader.

parent 513c7765
......@@ -6225,6 +6225,7 @@ struct arbfp_blit_priv {
GLenum uyvy_rect_shader, uyvy_2d_shader;
GLenum yv12_rect_shader, yv12_2d_shader;
GLenum p8_rect_shader, p8_2d_shader;
GLuint palette_texture;
};
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_2d_shader));
checkGLcall("Delete yuv and p8 programs");
if(priv->palette_texture) glDeleteTextures(1, &priv->palette_texture);
LEAVE_GL();
HeapFree(GetProcessHeap(), 0, device->blit_priv);
......@@ -6559,6 +6562,38 @@ static GLuint gen_p8_shader(IWineD3DDeviceImpl *device, GLenum textype)
}
/* 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. */
static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum complex_fixup yuv_fixup, GLenum textype)
{
GLenum shader;
......@@ -6715,19 +6750,19 @@ static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum complex_fixup yuv_
}
/* Context activation is done by the caller. */
static HRESULT arbfp_blit_set(IWineD3DDevice *iface, const struct wined3d_format_desc *format_desc,
GLenum textype, UINT width, UINT height)
static HRESULT arbfp_blit_set(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface)
{
GLenum shader;
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;
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");
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 */
ENTER_GL();
glEnable(textype);
......@@ -6736,7 +6771,7 @@ static HRESULT arbfp_blit_set(IWineD3DDevice *iface, const struct wined3d_format
return WINED3D_OK;
}
fixup = get_complex_fixup(format_desc->color_fixup);
fixup = get_complex_fixup(surface->resource.format_desc->color_fixup);
switch(fixup)
{
......@@ -6755,6 +6790,8 @@ static HRESULT arbfp_blit_set(IWineD3DDevice *iface, const struct wined3d_format
case COMPLEX_FIXUP_P8:
shader = textype == GL_TEXTURE_RECTANGLE_ARB ? priv->p8_rect_shader : priv->p8_2d_shader;
if (!shader) shader = gen_p8_shader(device, textype);
upload_palette(surface);
break;
default:
......
......@@ -2343,7 +2343,7 @@ HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_
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;
IWineD3DPaletteImpl *pal = This->palette;
......@@ -2867,7 +2867,6 @@ static void d3dfmt_p8_upload_palette(IWineD3DSurface *iface,
{
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
BYTE table[256][4];
IWineD3DDeviceImpl *device = This->resource.device;
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));
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)
......@@ -4103,8 +4077,7 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, const
dump_color_fixup_desc(Src->resource.format_desc->color_fixup);
}
myDevice->blitter->set_shader((IWineD3DDevice *) myDevice, Src->resource.format_desc,
Src->texture_target, Src->pow2Width, Src->pow2Height);
myDevice->blitter->set_shader((IWineD3DDevice *) myDevice, Src);
ENTER_GL();
......@@ -4739,10 +4712,14 @@ static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT
dst_rect = src_rect;
}
device->blitter->set_shader((IWineD3DDevice *) device, This);
ENTER_GL();
draw_textured_quad(This, &src_rect, &dst_rect, WINED3DTEXF_POINT);
LEAVE_GL();
device->blitter->set_shader((IWineD3DDevice *) device, This);
wglFlush(); /* Flush to ensure ordering across contexts. */
context_release(context);
......@@ -5143,12 +5120,11 @@ static HRESULT ffp_blit_alloc(IWineD3DDevice *iface) { return WINED3D_OK; }
static void ffp_blit_free(IWineD3DDevice *iface) { }
/* Context activation is done by the caller. */
static HRESULT ffp_blit_set(IWineD3DDevice *iface, const struct wined3d_format_desc *format_desc,
GLenum textype, UINT width, UINT height)
static HRESULT ffp_blit_set(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface)
{
ENTER_GL();
glEnable(textype);
checkGLcall("glEnable(textype)");
glEnable(surface->texture_target);
checkGLcall("glEnable(surface->texture_target)");
LEAVE_GL();
return WINED3D_OK;
}
......@@ -5229,8 +5205,7 @@ static void cpu_blit_free(IWineD3DDevice *iface)
}
/* Context activation is done by the caller. */
static HRESULT cpu_blit_set(IWineD3DDevice *iface, const struct wined3d_format_desc *format_desc,
GLenum textype, UINT width, UINT height)
static HRESULT cpu_blit_set(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface)
{
return WINED3D_OK;
}
......
......@@ -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,
* so there are no d3d texture settings to dirtify
*/
device->blitter->set_shader((IWineD3DDevice *) device, backbuffer->resource.format_desc,
backbuffer->texture_target, backbuffer->pow2Width,
backbuffer->pow2Height);
device->blitter->set_shader((IWineD3DDevice *) device, backbuffer);
glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter);
glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter);
......
......@@ -1173,8 +1173,7 @@ struct blit_shader
{
HRESULT (*alloc_private)(IWineD3DDevice *iface);
void (*free_private)(IWineD3DDevice *iface);
HRESULT (*set_shader)(IWineD3DDevice *iface, const struct wined3d_format_desc *format_desc,
GLenum textype, UINT width, UINT height);
HRESULT (*set_shader)(IWineD3DDevice *iface, IWineD3DSurfaceImpl *surface);
void (*unset_shader)(IWineD3DDevice *iface);
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);
......@@ -2237,6 +2236,7 @@ typedef enum {
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;
void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey) DECLSPEC_HIDDEN;
BOOL palette9_changed(IWineD3DSurfaceImpl *This) DECLSPEC_HIDDEN;
......
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