From cbc2489dfc3a3f6b99f2537dcd2a2708b2dc2ba5 Mon Sep 17 00:00:00 2001 From: MooglyGuy Date: Sat, 4 Sep 2021 15:02:10 +0200 Subject: [PATCH] -bgfx: Switched fs_blit_palette16 to expand bitmap_ind16 contents to R8. Fixes vertical off-by-one shift in games with an odd pixel count along X. [Ryan Holtz] (#8528) --- .../dx11/chains/misc/fs_blit_palette16.bin | Bin 1032 -> 1360 bytes .../dx9/chains/misc/fs_blit_palette16.bin | Bin 805 -> 1045 bytes .../essl/chains/misc/fs_blit_palette16.bin | Bin 1109 -> 1704 bytes .../glsl/chains/misc/fs_blit_palette16.bin | Bin 1040 -> 1610 bytes .../metal/chains/misc/fs_blit_palette16.bin | Bin 1462 -> 2007 bytes .../spirv/chains/misc/fs_blit_palette16.bin | Bin 2608 -> 3392 bytes src/osd/modules/render/bgfx/chainmanager.cpp | 7 ++--- .../shaders/chains/misc/fs_blit_palette16.sc | 25 ++++++++++++------ src/osd/modules/render/bgfx/target.h | 3 ++- src/osd/modules/render/bgfx/texture.cpp | 17 +++++++----- src/osd/modules/render/bgfx/texture.h | 8 +++--- .../render/bgfx/texturehandleprovider.h | 3 ++- .../modules/render/bgfx/texturemanager.cpp | 24 ++++++++++------- src/osd/modules/render/bgfxutil.cpp | 22 ++++++++++----- src/osd/modules/render/bgfxutil.h | 2 +- src/osd/modules/render/drawbgfx.cpp | 7 ++--- 16 files changed, 75 insertions(+), 43 deletions(-) diff --git a/bgfx/shaders/dx11/chains/misc/fs_blit_palette16.bin b/bgfx/shaders/dx11/chains/misc/fs_blit_palette16.bin index fb94aeda64add997a02b0e90ae6633a2e1199dad..b657355a35de1d8c4755872e35fc0b8a9b39a80d 100644 GIT binary patch literal 1360 zcmdT@O=}ZT6umQNfr_}Ovv8xhNV5=e(M+3W+JJOQCXpyYG!U^;q_rQ2i#lp? zqxc(&+kp53T=@@#{s7$s*Fm@9Iq#!QgLLnOJMX@G&b{~D``(1{O2K(E{vnX86n1+% zgXg{N^%sLm86JmjDem^xpYBZ}rGF!HW$_J?-X_0-1Ud)yn-4cCj&rg<6aVaqEOi&_ zpJorP{@T0p{^y^U-}b*ey1;D2QdqA;51~iUX1u(*ftCIobPY-&pFTe5bb-#m#mzT9tZqJ8DV0(XB^OYe|L?YVr)s!J0nQ%4ALCXfL#u8*Ld5 zt{c#QTG+$b;Gw5`2@iZlV$SfKuG0{C z_Z7+Oof)xb3{BiW3Bin+a delta 438 zcmcb>)xj}ghFk_S1A|M1le4#Dp`78u4>gG~(o$#ZwLfR(Gr3eYL&Q z->bKWuSbJjD$T~-CZJOrD^Y2I0~jb?$(A>MO`iXRPT7kVvOL06G6N;)o+uJvYwS`9wB1>?8C% zm2iz*+zw#us#*4xGwz!&dvfa2 zdMNFPc25#6&heEwx!*L7l>XeKwwzlzupWS_bk_gE___3mmp4p&5%%OkESzGceEEuFk1Xd!7%}*t5-lvGh7nU>PVi z diff --git a/bgfx/shaders/essl/chains/misc/fs_blit_palette16.bin b/bgfx/shaders/essl/chains/misc/fs_blit_palette16.bin index 2e8dc0a04b3ea8900600816d29ccf9d900db6b9d..f2465371ee178ebb65be7e2e5bbdb9fd5bc4e8d8 100644 GIT binary patch literal 1704 zcmbtVOK#gR5LF7K3uVzO%u-5RLDa_|v|Y6by6*u5!KNJnl4a-@$$?irX|K=|bcQiS zN>+*hHVn(=4BxzY^GHAb`gwQr`|lqEU$@3>8CASBZVYoo|4_u0UEvzpo!LbniuXD^CIYB5R0$#yx3s8-Y46< z$e@g~L&^*92MF%d0c=7Av~pTIZ^Q?Uy(5Pq^E}x=7AJeKZ1cqgNb_gWo(IT-R~3)y zCc;EeoqJGa2W&a=Xjy)TZ(vzk*KiLSW2fzGTtVGD%X8crFvqoR1-ni2xRO}DhU*iq zh+0{`0ZW#1+8G3dp@9&(#0WHuz-b9ZZH3P=%@^Cxk-+INuTSd~JsmmJkV6eOko~z% z`2YUq8p50qMxI2v_kbvZn?4526$-kfAbyC1WQ)R|N&D~>P+r@H7aYyh%obF;pV~rn zj7XzZU9Y)D1_rJWvZBqay5Q((OPG45*o3(AqBZovgVcCo+fMshx;J`1!R3I{a+2wC zFj->C&a#b|iossNbSashfTtyYQ{L5p^lFmy>VmX4O`4`~jl3&KdddiFICJJsa>eDb z7yN0m*DB1=wXbG4k%saf3Zz$|@0aB5ZUtXY4mYQrb`2dr|(HQ(ul2xKn_BlWc+1Nq?WAO`kL*xoML8^La z(~U_K$riFrRlTZLud4g`+tn@{2M#$KIQ3 z)Z1Dl$L2pge8BviSymGjU2;4?6K?}(#5Pa!!uw!rW*^O1aGU4F4n6fT+2=(DWt5%L zxbVM#*ywS*r)@cvpv0u_dJ7c^gUx!9yYpBmJR-Dv#z|3kO1Px6;?obFit$!*x_^*PccvnTR6G~a X;WJ&$SVJ8u&Jm|>Y&>!o+qV7yPeM z1yHOsJ~OW@z9h9GzBscg)j+QTq@pY}*<^A(lf>jt%+ib|llfQ_lub1?K{5r2IjJQj zsqv*{@rFR%8X8c;%=9YCC%wfwJ=LzZZii7 zK#exnD+k&HG!sRvqOuAo3Uqf#X;G??i-JaRJkV`AC=Q$~#-<=_uArq*7N4A-lV4;2 K^g=Bc7Xttczgv0$ diff --git a/bgfx/shaders/metal/chains/misc/fs_blit_palette16.bin b/bgfx/shaders/metal/chains/misc/fs_blit_palette16.bin index 98684b4e571125449c238c77fca8b52f2332c451..a4c3d3f0d0936e8ad0c75fc08a9d6135c7de182b 100644 GIT binary patch delta 666 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 diff --git a/src/osd/modules/render/bgfx/chainmanager.cpp b/src/osd/modules/render/bgfx/chainmanager.cpp index 26cba0d4f94..2de2870fdd2 100644 --- a/src/osd/modules/render/bgfx/chainmanager.cpp +++ b/src/osd/modules/render/bgfx/chainmanager.cpp @@ -465,13 +465,14 @@ uint32_t chain_manager::update_screen_textures(uint32_t view, render_primitive * bgfx::TextureFormat::Enum dst_format = bgfx::TextureFormat::BGRA8; uint16_t pitch = prim.m_rowpixels; - int convert_stride = 1; + int width_div_factor = 1; + int width_mul_factor = 1; const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, prim.m_flags & PRIMFLAG_TEXFORMAT_MASK, - prim.m_rowpixels, tex_height, prim.m_prim->texture.palette, prim.m_prim->texture.base, pitch, convert_stride); + prim.m_rowpixels, tex_height, prim.m_prim->texture.palette, prim.m_prim->texture.base, pitch, width_div_factor, width_mul_factor); if (texture == nullptr) { - bgfx_texture *texture = new bgfx_texture(full_name, dst_format, tex_width, tex_height, mem, BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP | BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT | BGFX_SAMPLER_MIP_POINT, pitch, prim.m_rowpixels, convert_stride); + bgfx_texture *texture = new bgfx_texture(full_name, dst_format, tex_width, tex_height, mem, BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP | BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT | BGFX_SAMPLER_MIP_POINT, pitch, prim.m_rowpixels, width_div_factor, width_mul_factor); m_textures.add_provider(full_name, texture); if (prim.m_prim->texture.palette) diff --git a/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_palette16.sc b/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_palette16.sc index 98f13186663..6ecfbcb1a72 100644 --- a/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_palette16.sc +++ b/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_palette16.sc @@ -15,14 +15,23 @@ uniform vec4 u_inv_tex_size1; void main() { - vec2 original_uv = v_texcoord0.xy * u_tex_size0.xy; - float mod_val = mod(original_uv.x, 2.0); - vec2 rounded_uv = vec2(original_uv.x - mod_val, original_uv.y); - vec4 srcpix = texture2D(s_tex, rounded_uv * u_inv_tex_size0.xy + vec2(u_inv_tex_size0.x, 0.0)); + vec2 original_uv = v_texcoord0.xy * u_tex_size0.xy * vec2(2.0, 1.0); + float mod_val = mod(original_uv.x, 4.0); + vec2 rounded_uv = vec2(original_uv.x - mod_val, original_uv.y) * vec2(0.5, 1.0); - vec2 palette_uv = (srcpix.ra * vec2(256.0, 256.0)) * u_inv_tex_size1.xy; - if (mod_val < 1.0) - palette_uv = (srcpix.bg * vec2(256.0, 256.0)) * u_inv_tex_size1.xy; + float inv_width = u_inv_tex_size0.x * 0.5; - gl_FragColor = vec4(texture2D(s_pal, palette_uv).rgb, 1.0) * v_color0; + vec2 palette_uv = vec2(0.0, 0.0); + if (mod_val < 2.0) + { + palette_uv.x = texture2D(s_tex, rounded_uv * u_inv_tex_size0.xy + vec2(inv_width * 0.5, 0.0)).r; + palette_uv.y = texture2D(s_tex, rounded_uv * u_inv_tex_size0.xy + vec2(inv_width * 1.5, 0.0)).r; + } + else + { + palette_uv.x = texture2D(s_tex, rounded_uv * u_inv_tex_size0.xy + vec2(inv_width * 2.5, 0.0)).r; + palette_uv.y = texture2D(s_tex, rounded_uv * u_inv_tex_size0.xy + vec2(inv_width * 3.5, 0.0)).r; + } + + gl_FragColor = vec4(texture2D(s_pal, palette_uv * vec2(256.0, 256.0) * u_inv_tex_size1.xy).rgb, 1.0) * v_color0; } diff --git a/src/osd/modules/render/bgfx/target.h b/src/osd/modules/render/bgfx/target.h index 15a12731c4f..c00fc669337 100644 --- a/src/osd/modules/render/bgfx/target.h +++ b/src/osd/modules/render/bgfx/target.h @@ -49,7 +49,8 @@ public: virtual uint16_t width() const override { return m_width; } virtual uint16_t height() const override { return m_height; } virtual uint16_t rowpixels() const override { return m_width; } - virtual int convert_stride() const override { return 1; } + virtual int width_div_factor() const override { return 1; } + virtual int width_mul_factor() const override { return 1; } private: std::string m_name; diff --git a/src/osd/modules/render/bgfx/texture.cpp b/src/osd/modules/render/bgfx/texture.cpp index 34efd738679..a504c625415 100644 --- a/src/osd/modules/render/bgfx/texture.cpp +++ b/src/osd/modules/render/bgfx/texture.cpp @@ -16,7 +16,8 @@ bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, u , m_width(width) , m_height(height) , m_rowpixels(width) - , m_convert_stride(1) + , m_width_div_factor(1) + , m_width_mul_factor(1) { bgfx::TextureInfo info; bgfx::calcTextureSize(info, width, height, 1, false, false, 1, format); @@ -34,18 +35,20 @@ bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, u } } -bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, const bgfx::Memory* data, uint32_t flags, uint16_t pitch, uint16_t rowpixels, int convert_stride) +bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, const bgfx::Memory* data, uint32_t flags, uint16_t pitch, uint16_t rowpixels, int width_div_factor, int width_mul_factor) : m_name(name) , m_format(format) , m_width(width) , m_height(height) , m_rowpixels(rowpixels ? rowpixels : width) - , m_convert_stride(convert_stride) + , m_width_div_factor(width_div_factor) + , m_width_mul_factor(width_mul_factor) { + int adjusted_width = (m_rowpixels * m_width_mul_factor) / m_width_div_factor; bgfx::TextureInfo info; - bgfx::calcTextureSize(info, m_rowpixels / m_convert_stride, height, 1, false, false, 1, format); - m_texture = bgfx::createTexture2D(m_rowpixels / m_convert_stride, height, false, 1, format, flags, nullptr); - bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, m_rowpixels / m_convert_stride, height, data, pitch); + bgfx::calcTextureSize(info, adjusted_width, height, 1, false, false, 1, format); + m_texture = bgfx::createTexture2D(adjusted_width, height, false, 1, format, flags, nullptr); + bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, adjusted_width, height, data, pitch); } bgfx_texture::~bgfx_texture() @@ -55,5 +58,5 @@ bgfx_texture::~bgfx_texture() void bgfx_texture::update(const bgfx::Memory *data, uint16_t pitch) { - bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, m_rowpixels / m_convert_stride, m_height, data, pitch); + bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, (m_rowpixels * m_width_mul_factor) / m_width_div_factor, m_height, data, pitch); } diff --git a/src/osd/modules/render/bgfx/texture.h b/src/osd/modules/render/bgfx/texture.h index 4a5d6636f5b..75fedcd3129 100644 --- a/src/osd/modules/render/bgfx/texture.h +++ b/src/osd/modules/render/bgfx/texture.h @@ -21,7 +21,7 @@ class bgfx_texture : public bgfx_texture_handle_provider { public: bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, uint32_t flags, void* data); - bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, const bgfx::Memory* data, uint32_t flags = BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP, uint16_t pitch = UINT16_MAX, uint16_t rowpixels = 0, int convert_stride = 1); + bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, const bgfx::Memory* data, uint32_t flags = BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP, uint16_t pitch = UINT16_MAX, uint16_t rowpixels = 0, int width_div_factor = 1, int width_mul_factor = 1); virtual ~bgfx_texture(); // Getters @@ -34,7 +34,8 @@ public: virtual uint16_t width() const override { return m_width; } virtual uint16_t height() const override { return m_height; } virtual uint16_t rowpixels() const override { return m_rowpixels; } - virtual int convert_stride() const override { return m_convert_stride; } + virtual int width_div_factor() const override { return m_width_div_factor; } + virtual int width_mul_factor() const override { return m_width_mul_factor; } void update(const bgfx::Memory *data, uint16_t pitch = UINT16_MAX); @@ -44,7 +45,8 @@ protected: uint16_t m_width; uint16_t m_height; uint16_t m_rowpixels; - int m_convert_stride; + int m_width_div_factor; + int m_width_mul_factor; bgfx::TextureHandle m_texture; }; diff --git a/src/osd/modules/render/bgfx/texturehandleprovider.h b/src/osd/modules/render/bgfx/texturehandleprovider.h index 03387040d7c..14fb2fe892c 100644 --- a/src/osd/modules/render/bgfx/texturehandleprovider.h +++ b/src/osd/modules/render/bgfx/texturehandleprovider.h @@ -25,7 +25,8 @@ public: virtual uint16_t width() const = 0; virtual uint16_t height() const = 0; virtual uint16_t rowpixels() const = 0; - virtual int convert_stride() const = 0; + virtual int width_div_factor() const = 0; + virtual int width_mul_factor() const = 0; }; #endif // __DRAWBGFX_TEXTURE_HANDLE_PROVIDER__ diff --git a/src/osd/modules/render/bgfx/texturemanager.cpp b/src/osd/modules/render/bgfx/texturemanager.cpp index f03d66e051a..1fe6fe13b60 100644 --- a/src/osd/modules/render/bgfx/texturemanager.cpp +++ b/src/osd/modules/render/bgfx/texturemanager.cpp @@ -122,9 +122,10 @@ bgfx::TextureHandle texture_manager::create_or_update_mame_texture(uint32_t form { bgfx::TextureFormat::Enum dst_format = bgfx::TextureFormat::BGRA8; uint16_t pitch = width; - int convert_stride = 1; - const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, rowpixels, height, palette, base, pitch, convert_stride); - bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)(rowpixels / convert_stride), (uint16_t)height, mem, pitch); + int width_div_factor = 1; + int width_mul_factor = 1; + const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, rowpixels, height, palette, base, pitch, width_div_factor, width_mul_factor); + bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)((rowpixels * width_mul_factor) / width_div_factor), (uint16_t)height, mem, pitch); return handle; } } @@ -151,9 +152,10 @@ bgfx::TextureHandle texture_manager::create_or_update_mame_texture(uint32_t form { bgfx::TextureFormat::Enum dst_format = bgfx::TextureFormat::BGRA8; uint16_t pitch = width; - int convert_stride = 1; - const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, rowpixels, height, palette, base, pitch, convert_stride); - bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)(rowpixels / convert_stride), (uint16_t)height, mem, pitch); + int width_div_factor = 1; + int width_mul_factor = 1; + const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, rowpixels, height, palette, base, pitch, width_div_factor, width_mul_factor); + bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)((rowpixels * width_mul_factor) / width_div_factor), (uint16_t)height, mem, pitch); return handle; } } @@ -163,10 +165,12 @@ bgfx::TextureHandle texture_manager::create_or_update_mame_texture(uint32_t form bgfx::TextureFormat::Enum dst_format = bgfx::TextureFormat::BGRA8; uint16_t pitch = width; - int convert_stride = 1; - const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, rowpixels, height, palette, base, pitch, convert_stride); - handle = bgfx::createTexture2D(width, height, false, 1, dst_format, flags, nullptr); - bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)(rowpixels / convert_stride), (uint16_t)height, mem, pitch); + int width_div_factor = 1; + int width_mul_factor = 1; + const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, rowpixels, height, palette, base, pitch, width_div_factor, width_mul_factor); + const uint16_t adjusted_width = (uint16_t)((rowpixels * width_mul_factor) / width_div_factor); + handle = bgfx::createTexture2D(adjusted_width, height, false, 1, dst_format, flags, nullptr); + bgfx::updateTexture2D(handle, 0, 0, 0, 0, adjusted_width, (uint16_t)height, mem, pitch); m_mame_textures[key] = { handle, seqid, width, height }; return handle; diff --git a/src/osd/modules/render/bgfxutil.cpp b/src/osd/modules/render/bgfxutil.cpp index a147e8c2c1c..4fa4b8fbd07 100644 --- a/src/osd/modules/render/bgfxutil.cpp +++ b/src/osd/modules/render/bgfxutil.cpp @@ -14,7 +14,7 @@ #include "render.h" -const bgfx::Memory* bgfx_util::mame_texture_data_to_bgfx_texture_data(bgfx::TextureFormat::Enum &dst_format, uint32_t src_format, int rowpixels, int height, const rgb_t *palette, void *base, uint16_t &out_pitch, int &convert_stride) +const bgfx::Memory* bgfx_util::mame_texture_data_to_bgfx_texture_data(bgfx::TextureFormat::Enum &dst_format, uint32_t src_format, int rowpixels, int height, const rgb_t *palette, void *base, uint16_t &out_pitch, int &width_div_factor, int &width_mul_factor) { bgfx::TextureInfo info; const bgfx::Memory *data = nullptr; @@ -22,20 +22,30 @@ const bgfx::Memory* bgfx_util::mame_texture_data_to_bgfx_texture_data(bgfx::Text switch (src_format) { case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16): - case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16): dst_format = bgfx::TextureFormat::BGRA8; - convert_stride = 2; + width_div_factor = 2; + width_mul_factor = 1; out_pitch = rowpixels * 2; - bgfx::calcTextureSize(info, rowpixels / convert_stride, height, 1, false, false, 1, dst_format); + bgfx::calcTextureSize(info, rowpixels / width_div_factor, height, 1, false, false, 1, dst_format); + + data = bgfx::copy(base, info.storageSize); + break; + case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16): + dst_format = bgfx::TextureFormat::R8; + width_div_factor = 1; + width_mul_factor = 2; + out_pitch = rowpixels * 2; + bgfx::calcTextureSize(info, rowpixels * width_mul_factor, height, 1, false, false, 1, dst_format); data = bgfx::copy(base, info.storageSize); break; case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32): case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32): dst_format = bgfx::TextureFormat::BGRA8; - convert_stride = 1; + width_div_factor = 1; + width_mul_factor = 1; out_pitch = rowpixels * 4; - bgfx::calcTextureSize(info, rowpixels / convert_stride, height, 1, false, false, 1, dst_format); + bgfx::calcTextureSize(info, rowpixels, height, 1, false, false, 1, dst_format); data = bgfx::copy(base, info.storageSize); break; diff --git a/src/osd/modules/render/bgfxutil.h b/src/osd/modules/render/bgfxutil.h index 010321bd6bd..e1b683cd024 100644 --- a/src/osd/modules/render/bgfxutil.h +++ b/src/osd/modules/render/bgfxutil.h @@ -11,7 +11,7 @@ class bgfx_util { public: - static const bgfx::Memory* mame_texture_data_to_bgfx_texture_data(bgfx::TextureFormat::Enum &dst_format, uint32_t format, int rowpixels, int height, const rgb_t *palette, void *base, uint16_t &out_pitch, int &convert_stride); + static const bgfx::Memory* mame_texture_data_to_bgfx_texture_data(bgfx::TextureFormat::Enum &dst_format, uint32_t format, int rowpixels, int height, const rgb_t *palette, void *base, uint16_t &out_pitch, int &width_div_factor, int &width_mul_factor); static const bgfx::Memory* mame_texture_data_to_bgra32(uint32_t src_format, int width, int height, int rowpixels, const rgb_t *palette, void *base); static uint64_t get_blend_state(uint32_t blend); }; diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp index 3f99bfc09f0..1e34cb1ee7e 100644 --- a/src/osd/modules/render/drawbgfx.cpp +++ b/src/osd/modules/render/drawbgfx.cpp @@ -1168,9 +1168,10 @@ void renderer_bgfx::process_atlas_packs(std::vectortexture(), 0, 0, rect.x(), rect.y(), rect.width() / convert_stride, rect.height(), mem, pitch); + int width_div_factor = 1; + int width_mul_factor = 1; + const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, rect.format(), rect.rowpixels(), rect.height(), rect.palette(), rect.base(), pitch, width_div_factor, width_mul_factor); + bgfx::updateTexture2D(m_texture_cache->texture(), 0, 0, rect.x(), rect.y(), (rect.width() * width_mul_factor) / width_div_factor, rect.height(), mem, pitch); } } }