summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd
diff options
context:
space:
mode:
author MooglyGuy <MooglyGuy@users.noreply.github.com>2021-09-04 15:02:10 +0200
committer GitHub <noreply@github.com>2021-09-04 09:02:10 -0400
commitcbc2489dfc3a3f6b99f2537dcd2a2708b2dc2ba5 (patch)
tree7c2e0ec3d4560605c259b92874096c9516f5fbd0 /src/osd
parentb790bb64c91a8b36c3b4cfe6488f1f852943b2e9 (diff)
-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)
Diffstat (limited to 'src/osd')
-rw-r--r--src/osd/modules/render/bgfx/chainmanager.cpp7
-rw-r--r--src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_palette16.sc25
-rw-r--r--src/osd/modules/render/bgfx/target.h3
-rw-r--r--src/osd/modules/render/bgfx/texture.cpp17
-rw-r--r--src/osd/modules/render/bgfx/texture.h8
-rw-r--r--src/osd/modules/render/bgfx/texturehandleprovider.h3
-rw-r--r--src/osd/modules/render/bgfx/texturemanager.cpp24
-rw-r--r--src/osd/modules/render/bgfxutil.cpp22
-rw-r--r--src/osd/modules/render/bgfxutil.h2
-rw-r--r--src/osd/modules/render/drawbgfx.cpp7
10 files changed, 75 insertions, 43 deletions
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 / 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 / convert_stride, height, 1, false, false, 1, dst_format);
+ 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::vector<std::vector<rectangle_packer
m_hash_to_entry[rect.hash()] = rect;
bgfx::TextureFormat::Enum dst_format = bgfx::TextureFormat::BGRA8;
uint16_t pitch = rect.width();
- int convert_stride = 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, convert_stride);
- bgfx::updateTexture2D(m_texture_cache->texture(), 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);
}
}
}