summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfxutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/render/bgfxutil.cpp')
-rw-r--r--src/osd/modules/render/bgfxutil.cpp118
1 files changed, 93 insertions, 25 deletions
diff --git a/src/osd/modules/render/bgfxutil.cpp b/src/osd/modules/render/bgfxutil.cpp
index 5ba76cbd2a1..3d555bb60ad 100644
--- a/src/osd/modules/render/bgfxutil.cpp
+++ b/src/osd/modules/render/bgfxutil.cpp
@@ -7,42 +7,97 @@
//============================================================
// MAMEOS headers
-#include "emu.h"
#include "bgfxutil.h"
#include "copyutil.h"
+#include "emucore.h"
#include "render.h"
-const bgfx::Memory* bgfx_util::mame_texture_data_to_bgfx_texture_data(uint32_t format, int width, int height, int rowpixels, const rgb_t *palette, void *base)
+const bgfx::Memory* bgfx_util::mame_texture_data_to_bgfx_texture_data(bgfx::TextureFormat::Enum &dst_format, uint32_t src_format, int rowpixels, int width_margin, int height, const rgb_t *palette, void *base, uint16_t &out_pitch, int &width_div_factor, int &width_mul_factor)
{
- const bgfx::Memory* mem = bgfx::alloc(width * height * 4);
- uint32_t* data = reinterpret_cast<uint32_t*>(mem->data);
- uint16_t* src16 = reinterpret_cast<uint16_t*>(base);
- uint32_t* src32 = reinterpret_cast<uint32_t*>(base);
+ bgfx::TextureInfo info;
+ const bgfx::Memory *data = nullptr;
+ uint8_t *adjusted_base = (uint8_t *)base;
+
+ switch (src_format)
+ {
+ case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16):
+ dst_format = bgfx::TextureFormat::BGRA8;
+ 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);
+
+ if (width_margin)
+ {
+ adjusted_base -= width_margin * 2;
+ }
+ data = bgfx::copy(adjusted_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);
+
+ if (width_margin)
+ {
+ adjusted_base -= width_margin * 2;
+ }
+ data = bgfx::copy(adjusted_base, info.storageSize);
+ break;
+ case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32):
+ case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32):
+ dst_format = bgfx::TextureFormat::BGRA8;
+ width_div_factor = 1;
+ width_mul_factor = 1;
+ out_pitch = rowpixels * 4;
+ bgfx::calcTextureSize(info, rowpixels, height, 1, false, false, 1, dst_format);
+
+ if (width_margin)
+ {
+ adjusted_base -= width_margin * 4;
+ }
+ data = bgfx::copy(adjusted_base, info.storageSize);
+ break;
+ }
+
+ 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)
+{
+ const bgfx::Memory* mem = bgfx::alloc(rowpixels * height * 4);
+ auto* dst = reinterpret_cast<uint32_t*>(mem->data);
+ auto* src16 = reinterpret_cast<uint16_t*>(base);
+ auto* src32 = reinterpret_cast<uint32_t*>(base);
for (int y = 0; y < height; y++)
{
- uint32_t* dst_line = data + y * width;
- uint16_t* src_line16 = src16 + y * rowpixels;
- uint32_t* src_line32 = src32 + y * rowpixels;
- switch (format)
+ switch (src_format)
{
- case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16):
- copy_util::copyline_palette16(dst_line, src_line16, width, palette);
- break;
- case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16):
- copy_util::copyline_yuy16_to_argb(dst_line, src_line16, width, palette, 1);
- break;
- case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32):
- copy_util::copyline_argb32(dst_line, src_line32, width, palette);
- break;
- case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32):
- copy_util::copyline_rgb32(dst_line, src_line32, width, palette);
- break;
- default:
- break;
+ case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16):
+ copy_util::copyline_palette16_to_bgra(dst, src16, width, palette);
+ src16 += rowpixels;
+ break;
+ case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16):
+ copy_util::copyline_yuy16_to_bgra(dst, src16, width, palette, 1);
+ src16 += rowpixels;
+ break;
+ case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32):
+ copy_util::copyline_argb32_to_bgra(dst, src32, width, palette);
+ src32 += rowpixels;
+ break;
+ case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32):
+ copy_util::copyline_rgb32_to_bgra(dst, src32, width, palette);
+ src32 += rowpixels;
+ break;
+ default:
+ break;
}
+ dst += width;
}
return mem;
}
@@ -54,7 +109,8 @@ uint64_t bgfx_util::get_blend_state(uint32_t blend)
case BLENDMODE_ALPHA:
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
case BLENDMODE_RGB_MULTIPLY:
- return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO);
+ //return BGFX_STATE_BLEND_FUNC_SEPARATE(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_INV_SRC_COLOR, BGFX_STATE_BLEND_ONE, BGFX_STATE_BLEND_ZERO);
+ return BGFX_STATE_BLEND_FUNC_SEPARATE(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO, BGFX_STATE_BLEND_DST_ALPHA, BGFX_STATE_BLEND_ZERO);
case BLENDMODE_ADD:
return BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_ONE);
default:
@@ -62,3 +118,15 @@ uint64_t bgfx_util::get_blend_state(uint32_t blend)
}
return 0L;
}
+
+void bgfx_util::find_prescale_factor(uint16_t width, uint16_t height, uint16_t max_prescale_size, uint16_t &xprescale, uint16_t &yprescale)
+{
+ while (xprescale > 1 && width * xprescale > max_prescale_size)
+ {
+ xprescale--;
+ }
+ while (yprescale > 1 && height * yprescale > max_prescale_size)
+ {
+ yprescale--;
+ }
+}