From a9f739df25f57ce2ceecbbf3b3ec1efe9c6e42e9 Mon Sep 17 00:00:00 2001 From: "therealmogminer@gmail.com" Date: Mon, 31 Oct 2016 11:03:42 +0100 Subject: [PATCH] Hopefully fix the D3D9 issues people are having (nw) --- src/osd/modules/render/d3d/d3dcomm.h | 1 + src/osd/modules/render/drawd3d.cpp | 144 +++++++++++++++++++++------ 2 files changed, 113 insertions(+), 32 deletions(-) diff --git a/src/osd/modules/render/d3d/d3dcomm.h b/src/osd/modules/render/d3d/d3dcomm.h index 3452d0322a3..2d048e627c6 100644 --- a/src/osd/modules/render/d3d/d3dcomm.h +++ b/src/osd/modules/render/d3d/d3dcomm.h @@ -155,6 +155,7 @@ private: vec2f m_rawdims; // raw dims of the texture int m_type; // what type of texture are we? int m_xprescale, m_yprescale; // X/Y prescale factor + int m_xborderpix, m_yborderpix; // X/Y border pixels int m_cur_frame; // what is our current frame? IDirect3DTexture9 * m_d3dtex; // Direct3D texture pointer IDirect3DSurface9 * m_d3dsurface; // Direct3D offscreen plain surface pointer diff --git a/src/osd/modules/render/drawd3d.cpp b/src/osd/modules/render/drawd3d.cpp index a02ecb27a6c..8b172b9e299 100644 --- a/src/osd/modules/render/drawd3d.cpp +++ b/src/osd/modules/render/drawd3d.cpp @@ -2150,7 +2150,26 @@ void texture_info::compute_size(int texwidth, int texheight) int finalheight = texheight; int finalwidth = texwidth; - bool shaders_enabled = m_renderer->get_shaders()->enabled(); + m_xborderpix = 0; + m_yborderpix = 0; + + bool shaders_enabled = m_renderer->get_shaders()->enabled(); + bool wrap_texture = (m_flags & PRIMFLAG_TEXWRAP_MASK) == PRIMFLAG_TEXWRAP_MASK; + + // skip border when shaders are enabled + if (!shaders_enabled) + { + // if we're not wrapping, add a 1-2 pixel border on all sides + if (!wrap_texture) + { + // note we need 2 pixels in X for YUY textures + m_xborderpix = (PRIMFLAG_GET_TEXFORMAT(m_flags) == TEXFORMAT_YUY16) ? 2 : 1; + m_yborderpix = 1; + } + } + + finalwidth += 2 * m_xborderpix; + finalheight += 2 * m_yborderpix; // take texture size as given when shaders are enabled if (!shaders_enabled) @@ -2163,6 +2182,9 @@ void texture_info::compute_size(int texwidth, int texheight) finalheight = texheight; finalwidth = texwidth; + m_xborderpix = 0; + m_yborderpix = 0; + compute_size_subroutine(finalwidth, finalheight, &finalwidth, &finalheight); } } @@ -2176,10 +2198,10 @@ void texture_info::compute_size(int texwidth, int texheight) } // compute the U/V scale factors - m_start.c.x = 0.0f; - m_start.c.y = 0.0f; - m_stop.c.x = float(texwidth) / float(finalwidth); - m_stop.c.y = float(texheight) / float(finalheight); + m_start.c.x = (float)m_xborderpix / (float)finalwidth; + m_start.c.y = (float)m_yborderpix / (float)finalheight; + m_stop.c.x = (float)(texwidth + m_xborderpix) / (float)finalwidth; + m_stop.c.y = (float)(texheight + m_yborderpix) / (float)finalheight; // set the final values m_rawdims.c.x = finalwidth; @@ -2187,14 +2209,33 @@ void texture_info::compute_size(int texwidth, int texheight) } +//============================================================ +// copyline_palette16 +//============================================================ + +static inline void copyline_palette16(uint32_t *dst, const uint16_t *src, int width, const rgb_t *palette, int xborderpix) +{ + if (xborderpix) + *dst++ = 0xff000000 | palette[*src]; + for (int x = 0; x < width; x++) + *dst++ = 0xff000000 | palette[*src++]; + if (xborderpix) + *dst++ = 0xff000000 | palette[*--src]; +} + + //============================================================ // copyline_palettea16 //============================================================ -static inline void copyline_palettea16(uint32_t *dst, const uint16_t *src, int width, const rgb_t *palette) +static inline void copyline_palettea16(uint32_t *dst, const uint16_t *src, int width, const rgb_t *palette, int xborderpix) { + if (xborderpix) + *dst++ = palette[*src]; for (int x = 0; x < width; x++) *dst++ = palette[*src++]; + if (xborderpix) + *dst++ = palette[*--src]; } @@ -2202,19 +2243,34 @@ static inline void copyline_palettea16(uint32_t *dst, const uint16_t *src, int w // copyline_rgb32 //============================================================ -static inline void copyline_rgb32(uint32_t *dst, const uint32_t *src, int width, const rgb_t *palette) +static inline void copyline_rgb32(uint32_t *dst, const uint32_t *src, int width, const rgb_t *palette, int xborderpix) { if (palette != nullptr) { + if (xborderpix) + { + rgb_t srcpix = *src; + *dst++ = 0xff000000 | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; + } for (int x = 0; x < width; x++) { rgb_t srcpix = *src++; - *dst++ = palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; + *dst++ = 0xff000000 | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; + } + if (xborderpix) + { + rgb_t srcpix = *--src; + *dst++ = 0xff000000 | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; } } else { - memcpy(dst, src, sizeof(uint32_t) * width); + if (xborderpix) + *dst++ = 0xff000000 | *src; + for (int x = 0; x < width; x++) + *dst++ = 0xff000000 | *src++; + if (xborderpix) + *dst++ = 0xff000000 | *--src; } } @@ -2223,19 +2279,35 @@ static inline void copyline_rgb32(uint32_t *dst, const uint32_t *src, int width, // copyline_argb32 //============================================================ -static inline void copyline_argb32(uint32_t *dst, const uint32_t *src, int width, const rgb_t *palette) +static inline void copyline_argb32(uint32_t *dst, const uint32_t *src, int width, const rgb_t *palette, int xborderpix) { if (palette != nullptr) { + if (xborderpix) + { + rgb_t srcpix = *src; + *dst++ = (srcpix & 0xff000000) | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; + } for (int x = 0; x < width; x++) { rgb_t srcpix = *src++; *dst++ = (srcpix & 0xff000000) | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; } + if (xborderpix) + { + rgb_t srcpix = *--src; + *dst++ = (srcpix & 0xff000000) | palette[0x200 + srcpix.r()] | palette[0x100 + srcpix.g()] | palette[srcpix.b()]; + } } else { + if (xborderpix) + *dst++ = *src; memcpy(dst, src, sizeof(uint32_t) * width); + dst += width; + src += width; + if (xborderpix) + *dst++ = *--src; } } @@ -2357,39 +2429,47 @@ void texture_info::set_data(const render_texinfo *texsource, uint32_t flags) // loop over Y int tex_format = PRIMFLAG_GET_TEXFORMAT(flags); - if ((tex_format == TEXFORMAT_RGB32 || tex_format == TEXFORMAT_ARGB32) && texsource->palette == nullptr && texsource->width == texsource->rowpixels) + if (tex_format == TEXFORMAT_ARGB32 && texsource->palette == nullptr && texsource->width == texsource->rowpixels && m_xborderpix == 0 && m_yborderpix == 0) { memcpy((BYTE *)rect.pBits, texsource->base, sizeof(uint32_t) * texsource->width * texsource->height); } else { - for (int y = 0; y < texsource->height; y++) - { - void *dst = (BYTE *)rect.pBits + y * rect.Pitch; + int miny = 0 - m_yborderpix; + int tex_format = PRIMFLAG_GET_TEXFORMAT(flags); + int maxy = texsource->height + m_yborderpix; - // switch off of the format and - switch (PRIMFLAG_GET_TEXFORMAT(flags)) + for (int dsty = miny; dsty < maxy; dsty++) + { + int srcy = (dsty < 0) ? 0 : (dsty >= texsource->height) ? texsource->height - 1 : dsty; + + void *dst = (BYTE *)rect.pBits + (dsty + m_yborderpix) * rect.Pitch; + + switch (tex_format) { case TEXFORMAT_PALETTE16: + copyline_palette16((uint32_t *)dst, (uint16_t *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); + break; + case TEXFORMAT_PALETTEA16: - copyline_palettea16((uint32_t *)dst, (uint16_t *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette); + copyline_palettea16((uint32_t *)dst, (uint16_t *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); break; case TEXFORMAT_RGB32: - copyline_rgb32((uint32_t *)dst, (uint32_t *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette); + copyline_rgb32((uint32_t *)dst, (uint32_t *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); break; case TEXFORMAT_ARGB32: - copyline_argb32((uint32_t *)dst, (uint32_t *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette); + copyline_argb32((uint32_t *)dst, (uint32_t *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix); break; case TEXFORMAT_YUY16: if (m_texture_manager->get_yuv_format() == D3DFMT_YUY2) - copyline_yuy16_to_yuy2((uint16_t *)dst, (uint16_t *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette); + copyline_yuy16_to_yuy2((uint16_t *)dst, (uint16_t *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette); else if (m_texture_manager->get_yuv_format() == D3DFMT_UYVY) - copyline_yuy16_to_uyvy((uint16_t *)dst, (uint16_t *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette); + copyline_yuy16_to_uyvy((uint16_t *)dst, (uint16_t *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette); else - copyline_yuy16_to_argb((uint32_t *)dst, (uint16_t *)texsource->base + y * texsource->rowpixels, texsource->width, texsource->palette); + copyline_yuy16_to_argb((uint32_t *)dst, (uint16_t *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette); break; default: @@ -2442,8 +2522,8 @@ void texture_info::prescale() // set the source bounds RECT source; source.left = source.top = 0; - source.right = m_texinfo.width; - source.bottom = m_texinfo.height; + source.right = m_texinfo.width + 2 * m_xborderpix; + source.bottom = m_texinfo.height + 2 * m_yborderpix; // set the target bounds RECT dest; @@ -2494,22 +2574,22 @@ void texture_info::prescale() // configure the X/Y coordinates on the target surface lockedbuf[0].x = -0.5f; lockedbuf[0].y = -0.5f; - lockedbuf[1].x = (float)((m_texinfo.width) * m_xprescale) - 0.5f; + lockedbuf[1].x = (float)((m_texinfo.width + 2 * m_xborderpix) * m_xprescale) - 0.5f; lockedbuf[1].y = -0.5f; lockedbuf[2].x = -0.5f; - lockedbuf[2].y = (float)((m_texinfo.height) * m_yprescale) - 0.5f; - lockedbuf[3].x = (float)((m_texinfo.width) * m_xprescale) - 0.5f; - lockedbuf[3].y = (float)((m_texinfo.height) * m_yprescale) - 0.5f; + lockedbuf[2].y = (float)((m_texinfo.height + 2 * m_yborderpix) * m_yprescale) - 0.5f; + lockedbuf[3].x = (float)((m_texinfo.width + 2 * m_xborderpix) * m_xprescale) - 0.5f; + lockedbuf[3].y = (float)((m_texinfo.height + 2 * m_yborderpix) * m_yprescale) - 0.5f; // configure the U/V coordintes on the source texture lockedbuf[0].u0 = 0.0f; lockedbuf[0].v0 = 0.0f; - lockedbuf[1].u0 = (float)(m_texinfo.width) / (float)m_rawdims.c.x; + lockedbuf[1].u0 = (float)(m_texinfo.width + 2 * m_xborderpix) / (float)m_rawdims.c.x; lockedbuf[1].v0 = 0.0f; lockedbuf[2].u0 = 0.0f; - lockedbuf[2].v0 = (float)(m_texinfo.height) / (float)m_rawdims.c.y; - lockedbuf[3].u0 = (float)(m_texinfo.width) / (float)m_rawdims.c.x; - lockedbuf[3].v0 = (float)(m_texinfo.height) / (float)m_rawdims.c.y; + lockedbuf[2].v0 = (float)(m_texinfo.height + 2 * m_yborderpix) / (float)m_rawdims.c.y; + lockedbuf[3].u0 = (float)(m_texinfo.width + 2 * m_xborderpix) / (float)m_rawdims.c.x; + lockedbuf[3].v0 = (float)(m_texinfo.height + 2 * m_yborderpix) / (float)m_rawdims.c.y; // reset the remaining vertex parameters for (i = 0; i < 4; i++)