-bgfx: Revised fs_blit_palette16 to not use pixel rounding. Fixes issues in carpolo, kncljoe, and others. [Ryan Holtz] (#8488)

This commit is contained in:
MooglyGuy 2021-08-24 16:33:47 +02:00 committed by Vas Crabb
parent 07f8452101
commit 95325c6400
8 changed files with 32 additions and 20 deletions

View File

@ -15,22 +15,7 @@ uniform vec4 u_inv_tex_size1;
void main()
{
// Logic taken from fs_blit_yuy16.sc - we need to do this, because
// the D3D9 BGFX backend claims to support RG8, but does so in
// a faulty way by using A8L8, which is not an appropriate format
// for representing an RG8 texture.
vec2 half_texel = u_inv_tex_size0.xy * vec2(0.5, 0.5);
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 + half_texel.x);
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;
vec4 srcpix = texture2D(s_tex, v_texcoord0.xy);
vec2 palette_uv = (srcpix.bg * vec2(256.0, 256.0)) * u_inv_tex_size1.xy;
gl_FragColor = vec4(texture2D(s_pal, palette_uv).rgb, 1.0) * v_color0;
//gl_FragColor = texture2D(s_tex, v_texcoord0) * v_color0;
}

View File

@ -17,23 +17,50 @@
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)
{
bgfx::TextureInfo info;
const bgfx::Memory *data = nullptr;
switch (src_format)
{
case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16):
case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16):
dst_format = bgfx::TextureFormat::BGRA8;
convert_stride = 2;
out_pitch = rowpixels * 2;
bgfx::calcTextureSize(info, rowpixels / convert_stride, height, 1, false, false, 1, dst_format);
data = bgfx::copy(base, info.storageSize);
break;
case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16):
{
dst_format = bgfx::TextureFormat::BGRA8;
convert_stride = 1;
out_pitch = rowpixels * 4;
bgfx::calcTextureSize(info, rowpixels / convert_stride, height, 1, false, false, 1, dst_format);
uint16_t *src = (uint16_t *)base;
uint16_t *dst_data = new uint16_t[rowpixels * 2 * height];
uint16_t *dst = dst_data;
for (int i = 0; i < rowpixels * height; i++, src++)
{
*dst++ = *src;
*dst++ = 0;
}
data = bgfx::copy(dst_data, info.storageSize);
delete [] dst_data;
break;
}
case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32):
case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32):
dst_format = bgfx::TextureFormat::BGRA8;
convert_stride = 1;
out_pitch = rowpixels * 4;
bgfx::calcTextureSize(info, rowpixels / convert_stride, height, 1, false, false, 1, dst_format);
data = bgfx::copy(base, info.storageSize);
break;
}
bgfx::calcTextureSize(info, rowpixels / convert_stride, height, 1, false, false, 1, dst_format);
return bgfx::copy(base, info.storageSize);
return data;
}
const bgfx::Memory* bgfx_util::mame_texture_data_to_bgra32(uint32_t src_format, int width, int height, int rowpixels, const rgb_t *palette, void *base)