diff options
Diffstat (limited to 'src/osd/modules/render/drawbgfx.cpp')
| -rw-r--r-- | src/osd/modules/render/drawbgfx.cpp | 253 |
1 files changed, 49 insertions, 204 deletions
diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp index 539c9ee4d14..4d305983ff0 100644 --- a/src/osd/modules/render/drawbgfx.cpp +++ b/src/osd/modules/render/drawbgfx.cpp @@ -23,6 +23,7 @@ // MAMEOS headers #include "emu.h" #include "window.h" +#include "rendutil.h" #include <bgfx/bgfxplatform.h> #include <bgfx/bgfx.h> @@ -31,6 +32,7 @@ #include <algorithm> #include "drawbgfx.h" +#include "copyutil.h" #include "bgfx/texturemanager.h" #include "bgfx/targetmanager.h" #include "bgfx/shadermanager.h" @@ -62,7 +64,6 @@ const char* renderer_bgfx::WINDOW_PREFIX = "Window 0, "; //============================================================ #define GIBBERISH (0) -#define USE_NEW_SHADERS (1) //============================================================ // INLINES @@ -164,16 +165,17 @@ int renderer_bgfx::create() m_screen_effect[2] = m_effects->effect("screen_multiply"); m_screen_effect[3] = m_effects->effect("screen_add"); -#if USE_NEW_SHADERS m_chains = new chain_manager(options, *m_textures, *m_targets, *m_effects, m_width[window().m_index], m_height[window().m_index]); m_screen_chain = m_chains->chain(options.bgfx_screen_chain(), window().machine(), window().m_index); m_sliders_dirty = true; -#endif uint32_t flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT; m_texture_cache = m_textures->create_texture("#cache", bgfx::TextureFormat::RGBA8, CACHE_SIZE, CACHE_SIZE, nullptr, flags); - memset(m_white, 0xff, sizeof(uint32_t) * 16 * 16); + uint32_t shadow_flags = 0;//BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT; + m_textures->create_png_texture(window().machine().options().art_path(), options.bgfx_shadow_mask(), "shadow", shadow_flags); + + memset(m_white, 0xff, sizeof(uint32_t) * 16 * 16); m_texinfo.push_back(rectangle_packer::packable_rectangle(WHITE_HASH, PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32), 16, 16, 16, nullptr, m_white)); return 0; @@ -186,9 +188,7 @@ int renderer_bgfx::create() renderer_bgfx::~renderer_bgfx() { // Cleanup. -#if USE_NEW_SHADERS delete m_chains; -#endif delete m_effects; delete m_shaders; delete m_textures; @@ -325,25 +325,15 @@ void renderer_bgfx::process_screen_quad(int view, render_primitive* prim) m_textures->add_provider("screen", texture); m_targets->update_guest_targets(tex_width, tex_height); - m_screen_chain->process(prim, view, *m_textures, window().get_size().width(), window().get_size().height(), get_blend_state(PRIMFLAG_GET_BLENDMODE(prim->flags))); + m_screen_chain->process(prim, view, *m_textures, window(), get_blend_state(PRIMFLAG_GET_BLENDMODE(prim->flags))); m_textures->add_provider("screen", nullptr); delete texture; } -void renderer_bgfx::render_post_screen_quad(int view, render_primitive* prim) +void renderer_bgfx::render_post_screen_quad(int view, render_primitive* prim, bgfx::TransientVertexBuffer* buffer) { - bgfx::TransientVertexBuffer buffer; - if (bgfx::checkAvailTransientVertexBuffer(6, ScreenVertex::ms_decl)) - { - bgfx::allocTransientVertexBuffer(&buffer, 6, ScreenVertex::ms_decl); - } - else - { - return; - } - - ScreenVertex* vertex = reinterpret_cast<ScreenVertex*>(buffer.data); + ScreenVertex* vertex = reinterpret_cast<ScreenVertex*>(buffer->data); vertex[0].m_x = prim->bounds.x0; vertex[0].m_y = prim->bounds.y0; @@ -388,7 +378,7 @@ void renderer_bgfx::render_post_screen_quad(int view, render_primitive* prim) vertex[5].m_v = prim->texcoords.tl.v; UINT32 blend = PRIMFLAG_GET_BLENDMODE(prim->flags); - bgfx::setVertexBuffer(&buffer); + bgfx::setVertexBuffer(buffer); bgfx::setTexture(0, m_screen_effect[blend]->uniform("s_tex")->handle(), m_targets->target(m_screen_chain->output())->texture()); m_screen_effect[blend]->submit(view); } @@ -654,176 +644,6 @@ uint32_t renderer_bgfx::u32Color(uint32_t r, uint32_t g, uint32_t b, uint32_t a return (a << 24) | (b << 16) | (g << 8) | r; } -//============================================================ -// copyline_palette16 -//============================================================ - -static inline void copyline_palette16(UINT32 *dst, const UINT16 *src, int width, const rgb_t *palette) -{ - for (int x = 0; x < width; x++) - { - rgb_t srcpixel = palette[*src++]; - *dst++ = 0xff000000 | (srcpixel.b() << 16) | (srcpixel.g() << 8) | srcpixel.r(); - } -} - - -//============================================================ -// copyline_palettea16 -//============================================================ - -static inline void copyline_palettea16(UINT32 *dst, const UINT16 *src, int width, const rgb_t *palette) -{ - for (int x = 0; x < width; x++) - { - rgb_t srcpixel = palette[*src++]; - *dst++ = (srcpixel.a() << 24) | (srcpixel.b() << 16) | (srcpixel.g() << 8) | srcpixel.r(); - } -} - - -//============================================================ -// copyline_rgb32 -//============================================================ - -static inline void copyline_rgb32(UINT32 *dst, const UINT32 *src, int width, const rgb_t *palette) -{ - int x; - - // palette (really RGB map) case - if (palette != nullptr) - { - for (x = 0; x < width; x++) - { - rgb_t srcpix = *src++; - *dst++ = 0xff000000 | palette[0x200 + srcpix.b()] | palette[0x100 + srcpix.g()] | palette[srcpix.r()]; - } - } - - // direct case - else - { - for (x = 0; x < width; x++) - { - rgb_t srcpix = *src++; - *dst++ = 0xff000000 | (srcpix.b() << 16) | (srcpix.g() << 8) | srcpix.r(); - } - } -} - - -//============================================================ -// copyline_argb32 -//============================================================ - -static inline void copyline_argb32(UINT32 *dst, const UINT32 *src, int width, const rgb_t *palette) -{ - int x; - // palette (really RGB map) case - if (palette != nullptr) - { - for (x = 0; x < width; x++) - { - rgb_t srcpix = *src++; - *dst++ = (srcpix & 0xff000000) | palette[0x200 + srcpix.b()] | palette[0x100 + srcpix.g()] | palette[srcpix.r()]; - } - } - - // direct case - else - { - for (x = 0; x < width; x++) - { - rgb_t srcpix = *src++; - *dst++ = (srcpix.a() << 24) | (srcpix.b() << 16) | (srcpix.g() << 8) | srcpix.r(); - } - } -} - -static inline UINT32 ycc_to_rgb(UINT8 y, UINT8 cb, UINT8 cr) -{ - /* original equations: - - C = Y - 16 - D = Cb - 128 - E = Cr - 128 - - R = clip(( 298 * C + 409 * E + 128) >> 8) - G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8) - B = clip(( 298 * C + 516 * D + 128) >> 8) - - R = clip(( 298 * (Y - 16) + 409 * (Cr - 128) + 128) >> 8) - G = clip(( 298 * (Y - 16) - 100 * (Cb - 128) - 208 * (Cr - 128) + 128) >> 8) - B = clip(( 298 * (Y - 16) + 516 * (Cb - 128) + 128) >> 8) - - R = clip(( 298 * Y - 298 * 16 + 409 * Cr - 409 * 128 + 128) >> 8) - G = clip(( 298 * Y - 298 * 16 - 100 * Cb + 100 * 128 - 208 * Cr + 208 * 128 + 128) >> 8) - B = clip(( 298 * Y - 298 * 16 + 516 * Cb - 516 * 128 + 128) >> 8) - - R = clip(( 298 * Y - 298 * 16 + 409 * Cr - 409 * 128 + 128) >> 8) - G = clip(( 298 * Y - 298 * 16 - 100 * Cb + 100 * 128 - 208 * Cr + 208 * 128 + 128) >> 8) - B = clip(( 298 * Y - 298 * 16 + 516 * Cb - 516 * 128 + 128) >> 8) - */ - int r, g, b, common; - - common = 298 * y - 298 * 16; - r = (common + 409 * cr - 409 * 128 + 128) >> 8; - g = (common - 100 * cb + 100 * 128 - 208 * cr + 208 * 128 + 128) >> 8; - b = (common + 516 * cb - 516 * 128 + 128) >> 8; - - if (r < 0) r = 0; - else if (r > 255) r = 255; - if (g < 0) g = 0; - else if (g > 255) g = 255; - if (b < 0) b = 0; - else if (b > 255) b = 255; - - return 0xff000000 | (b << 16) | (g << 8) | r; -} - -//============================================================ -// copyline_yuy16_to_argb -//============================================================ - -static inline void copyline_yuy16_to_argb(UINT32 *dst, const UINT16 *src, int width, const rgb_t *palette, int xprescale) -{ - int x; - - assert(width % 2 == 0); - - // palette (really RGB map) case - if (palette != nullptr) - { - for (x = 0; x < width / 2; x++) - { - UINT16 srcpix0 = *src++; - UINT16 srcpix1 = *src++; - UINT8 cb = srcpix0 & 0xff; - UINT8 cr = srcpix1 & 0xff; - for (int x2 = 0; x2 < xprescale; x2++) - *dst++ = ycc_to_rgb(palette[0x000 + (srcpix0 >> 8)], cb, cr); - for (int x2 = 0; x2 < xprescale; x2++) - *dst++ = ycc_to_rgb(palette[0x000 + (srcpix1 >> 8)], cb, cr); - } - } - - // direct case - else - { - for (x = 0; x < width; x += 2) - { - UINT16 srcpix0 = *src++; - UINT16 srcpix1 = *src++; - UINT8 cb = srcpix0 & 0xff; - UINT8 cr = srcpix1 & 0xff; - for (int x2 = 0; x2 < xprescale; x2++) - *dst++ = ycc_to_rgb(srcpix0 >> 8, cb, cr); - for (int x2 = 0; x2 < xprescale; x2++) - *dst++ = ycc_to_rgb(srcpix1 >> 8, cb, cr); - } - } -} - const bgfx::Memory* renderer_bgfx::mame_texture_data_to_bgfx_texture_data(UINT32 format, int width, int height, int rowpixels, const rgb_t *palette, void *base) { const bgfx::Memory* mem = bgfx::alloc(width * height * 4); @@ -832,19 +652,19 @@ const bgfx::Memory* renderer_bgfx::mame_texture_data_to_bgfx_texture_data(UINT32 switch (format) { case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16): - copyline_palette16((UINT32*)mem->data + y * width, (UINT16*)base + y * rowpixels, width, palette); + copy_util::copyline_palette16((UINT32*)mem->data + y * width, (UINT16*)base + y * rowpixels, width, palette); break; case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTEA16): - copyline_palettea16((UINT32*)mem->data + y * width, (UINT16*)base + y * rowpixels, width, palette); + copy_util::copyline_palettea16((UINT32*)mem->data + y * width, (UINT16*)base + y * rowpixels, width, palette); break; case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16): - copyline_yuy16_to_argb((UINT32*)mem->data + y * width, (UINT16*)base + y * rowpixels, width, palette, 1); + copy_util::copyline_yuy16_to_argb((UINT32*)mem->data + y * width, (UINT16*)base + y * rowpixels, width, palette, 1); break; case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32): - copyline_argb32((UINT32*)mem->data + y * width, (UINT32*)base + y * rowpixels, width, palette); + copy_util::copyline_argb32((UINT32*)mem->data + y * width, (UINT32*)base + y * rowpixels, width, palette); break; case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32): - copyline_rgb32((UINT32*)mem->data + y * width, (UINT32*)base + y * rowpixels, width, palette); + copy_util::copyline_rgb32((UINT32*)mem->data + y * width, (UINT32*)base + y * rowpixels, width, palette); break; default: break; @@ -972,6 +792,7 @@ int renderer_bgfx::draw(int update) if (status != BUFFER_EMPTY) { + //printf("Drawing with gui effect\n"); fflush(stdout); bgfx::setVertexBuffer(&buffer); bgfx::setTexture(0, m_gui_effect[blend]->uniform("s_tex")->handle(), m_texture_cache->texture()); m_gui_effect[blend]->submit(view_index); @@ -982,6 +803,7 @@ int renderer_bgfx::draw(int update) prim = prim->next(); } } + //printf("Done\n\n\n"); fflush(stdout); window().m_primlist->release_lock(); @@ -1009,6 +831,7 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl switch ((*prim)->type) { case render_primitive::LINE: + //printf("Putting a line at vertex index %d, vertices now %d\n", vertices, vertices + 30); fflush(stdout); put_line((*prim)->bounds.x0, (*prim)->bounds.y0, (*prim)->bounds.x1, (*prim)->bounds.y1, 1.0f, u32Color((*prim)->color.r * 255, (*prim)->color.g * 255, (*prim)->color.b * 255, (*prim)->color.a * 255), (ScreenVertex*)buffer->data + vertices, 1.0f); vertices += 30; break; @@ -1017,6 +840,7 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl if ((*prim)->texture.base == nullptr) { put_packed_quad(*prim, WHITE_HASH, (ScreenVertex*)buffer->data + vertices); + //printf("Putting a blank quad at vertex index %d, vertices now %d\n", vertices, vertices + 6); fflush(stdout); vertices += 6; } else @@ -1025,23 +849,29 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl if (atlas_valid && (*prim)->packable(PACKABLE_SIZE) && hash != 0 && m_hash_to_entry[hash].hash()) { put_packed_quad(*prim, hash, (ScreenVertex*)buffer->data + vertices); + //printf("Putting a packable quad at vertex index %d, vertices now %d\n", vertices, vertices + 6); fflush(stdout); vertices += 6; } else { -#if USE_NEW_SHADERS + if (vertices > 0) + { + //printf("Pre-flushing buffer\n"); + return BUFFER_PRE_FLUSH; + } + if (PRIMFLAG_GET_SCREENTEX((*prim)->flags)) { //render_screen_quad(view, *prim); - render_post_screen_quad(view, *prim); + //printf("Rendering a screen quad at vertex index %d\n", vertices); fflush(stdout); + render_post_screen_quad(view, *prim, buffer); } else { + //printf("Rendering an unpackable quad at vertex index %d\n", vertices); fflush(stdout); render_textured_quad(view, *prim, buffer); } -#else - render_textured_quad(*view, *prim, buffer); -#endif + //printf("Ignored %d vertices\n", vertices); fflush(stdout); return BUFFER_EMPTY; } } @@ -1060,6 +890,7 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl *prim = (*prim)->next(); } + //printf("Rendered %d vertices\n", vertices); fflush(stdout); if (*prim == nullptr) { return BUFFER_DONE; @@ -1202,7 +1033,7 @@ bool renderer_bgfx::check_for_dirty_atlas() void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::TransientVertexBuffer *buffer) { int vertices = 0; - + //printf("Allocating buffer\n"); bool mode_switched = false; while (prim != nullptr && !mode_switched) { @@ -1210,6 +1041,7 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx:: { case render_primitive::LINE: vertices += 30; + //printf("Encountered a line, vertices now %d\n", vertices); break; case render_primitive::QUAD: @@ -1218,19 +1050,33 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx:: if (prim->texture.base == nullptr) { vertices += 6; + //printf("Encountered a blank quad, vertices now %d\n", vertices); } else { - mode_switched = true; if (vertices == 0) { vertices += 6; + if (!PRIMFLAG_GET_SCREENTEX(prim->flags)) + { + //printf("Encountered a screen quad, vertices now %d\n", vertices); + } + else + { + //printf("Encountered an unpackable quad, vertices now %d\n", vertices); + } + } + else + { + //printf("Encountered an unpackable/screen quad with %d vertices left in the buffer, ending loop.\n", vertices); } + mode_switched = true; } } else { vertices += 6; + //printf("Encountered a packable quad, vertices now %d\n", vertices); } break; default: @@ -1248,6 +1094,7 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx:: if (vertices > 0 && bgfx::checkAvailTransientVertexBuffer(vertices, ScreenVertex::ms_decl)) { + //printf("Allocating %d transient vertices\n", vertices); bgfx::allocTransientVertexBuffer(buffer, vertices, ScreenVertex::ms_decl); } } @@ -1255,7 +1102,6 @@ void renderer_bgfx::allocate_buffer(render_primitive *prim, UINT32 blend, bgfx:: slider_state* renderer_bgfx::get_slider_list() { slider_state *listhead = nullptr; -#if USE_NEW_SHADERS slider_state **tailptr = &listhead; std::vector<bgfx_slider*> sliders = m_screen_chain->sliders(); for (bgfx_slider* slider : sliders) @@ -1272,6 +1118,5 @@ slider_state* renderer_bgfx::get_slider_list() } (*tailptr)->next = nullptr; m_sliders_dirty = false; -#endif return listhead; } |
