From 523a552f5cd266240ad1cd9d278238a239807513 Mon Sep 17 00:00:00 2001 From: "therealmogminer@gmail.com" Date: Sat, 26 Mar 2016 21:03:45 +0100 Subject: [PATCH] Adjust some minor things in bgfx, nw --- bgfx/chains/hlsl.json | 48 ++--- src/osd/modules/render/bgfx/chainentry.cpp | 2 +- src/osd/modules/render/drawbgfx.cpp | 227 +++++++++++++-------- src/osd/modules/render/drawbgfx.h | 12 +- 4 files changed, 180 insertions(+), 109 deletions(-) diff --git a/bgfx/chains/hlsl.json b/bgfx/chains/hlsl.json index f6064635850..17757bb8c38 100644 --- a/bgfx/chains/hlsl.json +++ b/bgfx/chains/hlsl.json @@ -17,7 +17,7 @@ // sliders (optional): The list of sliders used by all of the entries in this chain. Can be omitted if no entries use any sliders. "sliders": [ // type (required): The sliders's conceptual type. Is it a list of string selections? Is it a single floating-point value? Does it require RGB values, or XY values? - // values: "int_enum", "int", "float", "vec2", "color" + // values: "intenum", "int", "float", "vec2", "color" // // name (required): The internal name of the slider, used to attach it to entry uniforms. // value: Any valid ASCII string. @@ -27,7 +27,7 @@ // // default (required): The value that this slider should have upon creation. // type: Either a single integer value or an array of integer values corresponding to the size of the slider type: - // "int_enum": Single integer value + // "intenum": Single integer value // "int": Single integer value // "float": Single integer value // "vec2": Array of two integer values @@ -52,12 +52,12 @@ // values: "none", "raster", "vector", "crt", "vectorraster", "lcd", "nonvector", "lcdraster", "lcdvector", "any", "all" // "crt", "nonvector", and "all" are provided as aliases for "vectorraster", "lcdraster", and "any" // - // strings (optional): A list of strings to use with the "int_enum" type, to select from a list of text options instead of simply numbers. + // strings (optional): A list of strings to use with the "intenum" type, to select from a list of text options instead of simply numbers. // value: An array of 2 or more entries, with one entry per possible slider setting from "min" to "max" inclusive. - { "type": "int_enum", "name": "adjustments", "text": "Enable Adjustments", "default": 0, "max": 1, "min": 0, "step": 1, "scale": 1.0, "format": "%s", "screen": "any", "strings": [ "Off", "On" ] }, + { "type": "intenum", "name": "adjustments", "text": "Enable Adjustments", "default": 0, "max": 1, "min": 0, "step": 1, "scale": 1.0, "format": "%s", "screen": "any", "strings": [ "Off", "On" ] }, - { "type": "int_enum", "name": "ntsc", "text": "Enable NTSC", "default": 0, "max": 1, "min": 0, "step": 1, "scale": 1.0, "format": "%s", "screen": "any", "strings": [ "Off", "On" ] }, + { "type": "intenum", "name": "ntsc", "text": "Enable NTSC", "default": 0, "max": 1, "min": 0, "step": 1, "scale": 1.0, "format": "%s", "screen": "any", "strings": [ "Off", "On" ] }, { "type": "float", "name": "a_value", "text": "NTSC A Value", "default": 50, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "raster" }, { "type": "float", "name": "b_value", "text": "NTSC B Value", "default": 50, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "raster" }, { "type": "float", "name": "cc_value", "text": "NTSC Color Carrier (Hz)", "default": 35795454, "max": 36795454, "min": 34795454, "step": 100, "scale": 0.0000001, "format": "%1.7f", "screen": "raster" }, @@ -84,31 +84,31 @@ { "type": "vec2", "name": "radial_converge_green", "text": "Green Radial Convergence, ", "default": [ 0, 0 ], "max": [ 8000, 6000 ], "min": [ -8000, -6000 ], "step": 1, "scale": 0.1, "format": "%3.1f", "screen": "raster" }, { "type": "vec2", "name": "radial_converge_blue", "text": "Blue Radial Convergence, ", "default": [ 0, 0 ], "max": [ 8000, 6000 ], "min": [ -8000, -6000 ], "step": 1, "scale": 0.1, "format": "%3.1f", "screen": "raster" }, - { "type": "vec2", "name": "defocus", "text": "Defocus, ", "default": [ 5, 5 ], "max": [ 500, 500 ], "min": [ 0, 0 ], "step": 1, "scale": 0.1, "format": "%2.1f", "screen": "crt" }, + { "type": "vec2", "name": "defocus", "text": "Defocus, ", "default": [ 15, 15 ], "max": [ 500, 500 ], "min": [ 0, 0 ], "step": 1, "scale": 0.1, "format": "%2.1f", "screen": "crt" }, - { "type": "color", "name": "phosphor", "text": "Phosphor Persistence, ", "default": [ 45, 45, 45 ], "max": [ 100, 100, 100 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "color", "name": "phosphor", "text": "Phosphor Persistence, ", "default": [ 55, 55, 55 ], "max": [ 100, 100, 100 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "scanline_alpha", "text": "Scanline Amount", "default": 100, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "scanline_scale", "text": "Overall Scanline Scale", "default": 100, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "scanline_bright_scale", "text": "Scanline Brightness Scale", "default": 200, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "scanline_bright_offset", "text": "Scanline Brightness Offset", "default": 0, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "scanline_jitter_amount", "text": "Scanline Jitter Amount", "default": 0, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "scanline_height", "text": "Individual Scanline Scale", "default": 100, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "scanline_variation", "text": "Scanline Variation", "default": 100, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "shadow_alpha", "text": "Shadow Mask Amount", "default": 0, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "vec2", "name": "shadow_uv_size", "text": "Shadow Mask UV Size ", "default": [ 250, 333 ], "max": [ 1000, 1000 ], "min": [ 0, 0 ], "step": 1, "scale": 0.001, "format": "%1.4f", "screen": "crt" }, - { "type": "vec2", "name": "shadow_uv_offset", "text": "Shadow Mask UV Offset ", "default": [ 0, 0 ], "max": [ 1000, 1000 ], "min": [ 0, 0 ], "step": 1, "scale": 0.001, "format": "%1.4f", "screen": "crt" }, - { "type": "int_enum", "name": "shadow_tile_mode", "text": "Shadow Mask Tile Mode", "default": 0, "max": 1, "min": 0, "step": 1, "scale": 1.0, "format": "%s", "screen": "crt", "strings": [ "Screen", "Source" ] }, - { "type": "float", "name": "humbar_alpha", "text": "Hum Bar Amount", "default": 0, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "humbar_hertz_rate", "text": "Hum Bar Frequency", "default": 100, "max": 10000, "min": 0, "step": 1, "scale": 0.00001, "format": "%1.7f", "screen": "crt" }, - { "type": "color", "name": "floor", "text": "Signal Floor, ", "default": [ 0, 0, 0 ], "max": [ 100, 100, 100 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "color", "name": "power", "text": "Signal Exponent, ", "default": [ 100, 100, 100 ], "max": [ 400, 400, 400 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "scanline_alpha", "text": "Scanline Amount", "default": 0, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "scanline_scale", "text": "Overall Scanline Scale", "default": 100, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "scanline_bright_scale", "text": "Scanline Brightness Scale", "default": 200, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "scanline_bright_offset", "text": "Scanline Brightness Offset", "default": 0, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "scanline_jitter_amount", "text": "Scanline Jitter Amount", "default": 0, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "scanline_height", "text": "Individual Scanline Scale", "default": 100, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "scanline_variation", "text": "Scanline Variation", "default": 100, "max": 400, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "shadow_alpha", "text": "Shadow Mask Amount", "default": 0, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "vec2", "name": "shadow_uv_size", "text": "Shadow Mask UV Size ", "default": [ 250, 333 ], "max": [ 1000, 1000 ], "min": [ 0, 0 ], "step": 1, "scale": 0.001, "format": "%1.4f", "screen": "crt" }, + { "type": "vec2", "name": "shadow_uv_offset", "text": "Shadow Mask UV Offset ", "default": [ 0, 0 ], "max": [ 1000, 1000 ], "min": [ 0, 0 ], "step": 1, "scale": 0.001, "format": "%1.4f", "screen": "crt" }, + { "type": "intenum", "name": "shadow_tile_mode", "text": "Shadow Mask Tile Mode", "default": 0, "max": 1, "min": 0, "step": 1, "scale": 1.0, "format": "%s", "screen": "crt", "strings": [ "Screen", "Source" ] }, + { "type": "float", "name": "humbar_alpha", "text": "Hum Bar Amount", "default": 5, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "float", "name": "humbar_hertz_rate", "text": "Hum Bar Frequency", "default": 100, "max": 10000, "min": 0, "step": 1, "scale": 0.00001, "format": "%1.7f", "screen": "crt" }, + { "type": "color", "name": "floor", "text": "Signal Floor, ", "default": [ 5, 5, 5 ], "max": [ 100, 100, 100 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, + { "type": "color", "name": "power", "text": "Signal Exponent, ", "default": [ 100, 100, 100 ], "max": [ 400, 400, 400 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "curvature", "text": "Screen Curvature Amount", "default": 25, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "round_corner", "text": "Rounded Corner Amount", "default": 15, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "smooth_border", "text": "Smooth Border Amount", "default": 5, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, { "type": "float", "name": "vignetting", "text": "Vignetting Amount", "default": 20, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" }, - { "type": "float", "name": "reflection", "text": "Reflection Amount", "default": 30, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" } + { "type": "float", "name": "reflection", "text": "Reflection Amount", "default": 25, "max": 200, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "crt" } ], // parameters (optional): A list of procedurally-generated parameters that can be bound to entry uniforms. @@ -197,7 +197,7 @@ // // value (required): The value against which we are comparing to determine whether this disabler is active. // type: Either a single integer value or an array of integer values corresponding to the size of the slider's type: - // "int_enum": Single integer value + // "intenum": Single integer value // "int": Single integer value // "float": Single integer value // "vec2": Array of two integer values diff --git a/src/osd/modules/render/bgfx/chainentry.cpp b/src/osd/modules/render/bgfx/chainentry.cpp index ff56559e430..f3bbbb42378 100644 --- a/src/osd/modules/render/bgfx/chainentry.cpp +++ b/src/osd/modules/render/bgfx/chainentry.cpp @@ -179,7 +179,7 @@ bool bgfx_chain_entry::setup_view(int view, uint16_t screen_width, uint16_t scre bx::mtxOrtho(projMat, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f); bgfx::setViewTransform(view, nullptr, projMat); - bgfx::setViewClear(view, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00ff00ff, 1.0f, 0); + bgfx::setViewClear(view, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0); return true; } diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp index ab1985a6898..d955f8c76f2 100644 --- a/src/osd/modules/render/drawbgfx.cpp +++ b/src/osd/modules/render/drawbgfx.cpp @@ -61,6 +61,7 @@ const char* renderer_bgfx::WINDOW_PREFIX = "Window 0, "; //============================================================ #define GIBBERISH (0) +#define SCENE_VIEW (0) //============================================================ // STATICS @@ -300,8 +301,13 @@ void renderer_bgfx::put_packed_quad(render_primitive *prim, UINT32 hash, ScreenV v0 += 0.5f / float(CACHE_SIZE); UINT32 rgba = u32Color(prim->color.r * 255, prim->color.g * 255, prim->color.b * 255, prim->color.a * 255); - float x[4] = { prim->bounds.x0, prim->bounds.x1, prim->bounds.x0, prim->bounds.x1 }; - float y[4] = { prim->bounds.y0, prim->bounds.y0, prim->bounds.y1, prim->bounds.y1 }; + const float x0 = prim->bounds.x0; + const float x1 = prim->bounds.x1; + const float y0 = prim->bounds.y0; + const float y1 = prim->bounds.y1; + + float x[4] = { x0, x1, x0, x1 }; + float y[4] = { y0, y0, y1, y1 }; float u[4] = { u0, u1, u0, u1 }; float v[4] = { v0, v0, v1, v1 }; @@ -406,28 +412,6 @@ void renderer_bgfx::render_post_screen_quad(int view, render_primitive* prim, bg float u[4] = { prim->texcoords.tl.u, prim->texcoords.tr.u, prim->texcoords.bl.u, prim->texcoords.br.u }; float v[4] = { prim->texcoords.tl.v, prim->texcoords.tr.v, prim->texcoords.bl.v, prim->texcoords.br.v }; - if (false)//PRIMFLAG_GET_TEXORIENT(prim->flags) & ORIENTATION_SWAP_XY) - { - std::swap(u[1], u[2]); - std::swap(v[1], v[2]); - } - - if (false)//PRIMFLAG_GET_TEXORIENT(prim->flags) & ORIENTATION_FLIP_X) - { - std::swap(u[0], u[1]); - std::swap(v[0], v[1]); - std::swap(u[2], u[3]); - std::swap(v[2], v[3]); - } - - if (false)//PRIMFLAG_GET_TEXORIENT(prim->flags) & ORIENTATION_FLIP_Y) - { - std::swap(u[0], u[2]); - std::swap(v[0], v[2]); - std::swap(u[1], u[3]); - std::swap(v[1], v[3]); - } - vertex[0].m_x = x[0]; vertex[0].m_y = y[0]; vertex[0].m_z = 0; @@ -476,7 +460,7 @@ void renderer_bgfx::render_post_screen_quad(int view, render_primitive* prim, bg m_screen_effect[blend]->submit(view); } -void renderer_bgfx::render_textured_quad(int view, render_primitive* prim, bgfx::TransientVertexBuffer* buffer) +void renderer_bgfx::render_textured_quad(render_primitive* prim, bgfx::TransientVertexBuffer* buffer) { ScreenVertex* vertex = reinterpret_cast(buffer->data); @@ -543,7 +527,7 @@ void renderer_bgfx::render_textured_quad(int view, render_primitive* prim, bgfx: UINT32 blend = PRIMFLAG_GET_BLENDMODE(prim->flags); bgfx::setVertexBuffer(buffer); bgfx::setTexture(0, effects[blend]->uniform("s_tex")->handle(), texture); - effects[blend]->submit(view); + effects[blend]->submit(m_ui_view); bgfx::destroyTexture(texture); } @@ -843,63 +827,29 @@ int renderer_bgfx::draw(int update) s_current_view = 0; } - handle_screen_chains(); - int view_index = s_current_view; + m_ui_view = -1; // Set view 0 default viewport. osd_dim wdim = window().get_size(); m_width[window_index] = wdim.width(); m_height[window_index] = wdim.height(); - if (window_index == 0) + handle_screen_chains(); + + bool skip_frame = update_dimensions(); + if (skip_frame) { - if ((m_dimensions != osd_dim(m_width[window_index], m_height[window_index]))) - { - bgfx::reset(m_width[window_index], m_height[window_index], video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); - m_dimensions = osd_dim(m_width[window_index], m_height[window_index]); - } + return 0; } - else - { - if ((m_dimensions != osd_dim(m_width[window_index], m_height[window_index]))) - { - bgfx::reset(window().m_main->get_size().width(), window().m_main->get_size().height(), video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); - delete m_framebuffer; -#ifdef OSD_WINDOWS - m_framebuffer = m_targets->create_backbuffer(window().m_hwnd, m_width[window_index], m_height[window_index]); -#else - m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(window().sdl_window()), m_width[window_index], m_height[window_index]); -#endif - bgfx::setViewFrameBuffer(view_index, m_framebuffer->target()); - m_dimensions = osd_dim(m_width[window_index], m_height[window_index]); - bgfx::setViewClear(view_index - , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH - , 0x00ff00ff - , 1.0f - , 0 - ); - bgfx::touch(view_index); - bgfx::frame(); - return 0; - } - bgfx::setViewFrameBuffer(view_index, m_framebuffer->target()); + if (s_current_view > m_max_view) + { + m_max_view = s_current_view; + } + else + { + s_current_view = m_max_view; } - - bgfx::setViewSeq(view_index, true); - bgfx::setViewRect(view_index, 0, 0, m_width[window_index], m_height[window_index]); - - // Setup view transform. - float proj[16]; - bx::mtxOrtho(proj, 0.0f, m_width[window_index], m_height[window_index], 0.0f, 0.0f, 100.0f); - bgfx::setViewTransform(view_index, nullptr, proj); - - bgfx::setViewClear(view_index - , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH - , 0x000000ff - , 1.0f - , 0 - ); window().m_primlist->acquire_lock(); @@ -915,7 +865,7 @@ int renderer_bgfx::draw(int update) bgfx::TransientVertexBuffer buffer; allocate_buffer(prim, blend, &buffer); - int32_t screen = 0; + int32_t screen = -1; if (PRIMFLAG_GET_SCREENTEX(prim->flags)) { for (screen = 0; screen < screens.size(); screen++) @@ -931,13 +881,13 @@ int renderer_bgfx::draw(int update) } } - buffer_status status = buffer_primitives(view_index, atlas_valid, &prim, &buffer, screen); + buffer_status status = buffer_primitives(atlas_valid, &prim, &buffer, screen); if (status != BUFFER_EMPTY && status != BUFFER_SCREEN) { 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); + m_gui_effect[blend]->submit(m_ui_view); } if (status != BUFFER_DONE && status != BUFFER_PRE_FLUSH) @@ -950,7 +900,7 @@ int renderer_bgfx::draw(int update) // This dummy draw call is here to make sure that view 0 is cleared // if no other draw calls are submitted to view 0. - bgfx::touch(view_index); + bgfx::touch(s_current_view > 0 ? s_current_view - 1 : 0); // Advance to next frame. Rendering thread will be kicked to // process submitted rendering primitives. @@ -959,12 +909,113 @@ int renderer_bgfx::draw(int update) bgfx::frame(); } - s_current_view++; - return 0; } -renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atlas_valid, render_primitive** prim, bgfx::TransientVertexBuffer* buffer, int32_t screen) +bool renderer_bgfx::update_dimensions() +{ + const uint32_t window_index = window().m_index; + const uint32_t width = m_width[window_index]; + const uint32_t height = m_height[window_index]; + + if (window_index == 0) + { + if ((m_dimensions != osd_dim(width, height))) + { + bgfx::reset(width, height, video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); + m_dimensions = osd_dim(width, height); + } + } + else + { + if ((m_dimensions != osd_dim(width, height))) + { + bgfx::reset(window().m_main->get_size().width(), window().m_main->get_size().height(), video_config.waitvsync ? BGFX_RESET_VSYNC : BGFX_RESET_NONE); + m_dimensions = osd_dim(width, height); + + delete m_framebuffer; +#ifdef OSD_WINDOWS + m_framebuffer = m_targets->create_backbuffer(window().m_hwnd, width, height); +#else + m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(window().sdl_window()), width, height); +#endif + + bgfx::setViewFrameBuffer(s_current_view, m_framebuffer->target()); + bgfx::setViewClear(s_current_view, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x000000ff, 1.0f, 0); + bgfx::touch(s_current_view); + bgfx::frame(); + return true; + } + } + return false; +} + +void renderer_bgfx::setup_view(uint32_t view_index, bool screen) +{ + const uint32_t window_index = window().m_index; + const uint32_t width = m_width[window_index]; + const uint32_t height = m_height[window_index]; + + if (window_index != 0) + { + bgfx::setViewFrameBuffer(view_index, m_framebuffer->target()); + } + + bgfx::setViewSeq(view_index, true); + bgfx::setViewRect(view_index, 0, 0, width, height); + +#if SCENE_VIEW + if (view_index == m_max_view) +#endif + { + bgfx::setViewClear(view_index, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0); + } + + setup_matrices(view_index, screen); +} + +void renderer_bgfx::setup_matrices(uint32_t view_index, bool screen) +{ + const uint32_t window_index = window().m_index; + const uint32_t width = m_width[window_index]; + const uint32_t height = m_height[window_index]; + + float proj[16]; + float view[16]; + if (screen) + { + static float offset = 0.0f; + offset += 0.5f; + float up[3] = { 0.0f, -1.0f, 0.0f }; + float cam_z = width * 0.5f * (float(height) / float(width)); + cam_z *= 1.05f; + float eye_height = height * 0.5f * 1.05f; + float at[3] = { width * 0.5f, height * 0.5f, 0.0f }; + float eye[3] = { width * 0.5f, eye_height, cam_z }; + bx::mtxLookAt(view, eye, at, up); + + bx::mtxProj(proj, 90.0f, float(width) / float(height), 0.1f, 5000.0f); + } + else + { + bx::mtxIdentity(view); + bx::mtxOrtho(proj, 0.0f, width, height, 0.0f, 0.0f, 100.0f); + } + + bgfx::setViewTransform(view_index, view, proj); +} + +void renderer_bgfx::init_ui_view() +{ + if (m_ui_view < 0) + { + m_ui_view = s_current_view; + setup_view(m_ui_view, false); + s_current_view++; + } +} + +renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(bool atlas_valid, render_primitive** prim, bgfx::TransientVertexBuffer* buffer, int32_t screen) { int vertices = 0; @@ -974,6 +1025,7 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl switch ((*prim)->type) { case render_primitive::LINE: + init_ui_view(); 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; @@ -981,6 +1033,7 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl case render_primitive::QUAD: if ((*prim)->texture.base == nullptr) { + init_ui_view(); put_packed_quad(*prim, WHITE_HASH, (ScreenVertex*)buffer->data + vertices); vertices += 6; } @@ -989,6 +1042,7 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl const UINT32 hash = get_texture_hash(*prim); if (atlas_valid && (*prim)->packable(PACKABLE_SIZE) && hash != 0 && m_hash_to_entry[hash].hash()) { + init_ui_view(); put_packed_quad(*prim, hash, (ScreenVertex*)buffer->data + vertices); vertices += 6; } @@ -1001,12 +1055,21 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl if (PRIMFLAG_GET_SCREENTEX((*prim)->flags) && m_screen_chains.size() > window().m_index && screen < m_screen_chains[window().m_index].size()) { - render_post_screen_quad(view, *prim, buffer, screen); +#if SCENE_VIEW + setup_view(s_current_view, true); + render_post_screen_quad(s_current_view, *prim, buffer, screen); + s_current_view++; + m_ui_view = -1; +#else + init_ui_view(); + render_post_screen_quad(m_ui_view, *prim, buffer, screen); +#endif return BUFFER_SCREEN; } else { - render_textured_quad(view, *prim, buffer); + init_ui_view(); + render_textured_quad(*prim, buffer); return BUFFER_EMPTY; } } diff --git a/src/osd/modules/render/drawbgfx.h b/src/osd/modules/render/drawbgfx.h index 95cd613bb2f..823472f5c4a 100644 --- a/src/osd/modules/render/drawbgfx.h +++ b/src/osd/modules/render/drawbgfx.h @@ -30,6 +30,7 @@ public: renderer_bgfx(osd_window *w) : osd_renderer(w, FLAG_NONE) , m_dimensions(0, 0) + , m_max_view(0) { } virtual ~renderer_bgfx(); @@ -64,6 +65,11 @@ private: void parse_screen_chains(std::string chain_str); bgfx_chain* screen_chain(int32_t screen); + bool update_dimensions(); + void setup_view(uint32_t view_index, bool screen); + void init_ui_view(); + void setup_matrices(uint32_t view_index, bool screen); + void allocate_buffer(render_primitive *prim, UINT32 blend, bgfx::TransientVertexBuffer *buffer); enum buffer_status { @@ -73,10 +79,10 @@ private: BUFFER_EMPTY, BUFFER_DONE }; - buffer_status buffer_primitives(int view, bool atlas_valid, render_primitive** prim, bgfx::TransientVertexBuffer* buffer, int32_t screen); + buffer_status buffer_primitives(bool atlas_valid, render_primitive** prim, bgfx::TransientVertexBuffer* buffer, int32_t screen); void process_screen_quad(int view, render_primitive* prim); - void render_textured_quad(int view, render_primitive* prim, bgfx::TransientVertexBuffer* buffer); + void render_textured_quad(render_primitive* prim, bgfx::TransientVertexBuffer* buffer); void render_post_screen_quad(int view, render_primitive* prim, bgfx::TransientVertexBuffer* buffer, int32_t screen); void put_packed_quad(render_primitive *prim, UINT32 hash, ScreenVertex* vertex); @@ -117,6 +123,8 @@ private: uint32_t m_width[16]; uint32_t m_height[16]; uint32_t m_white[16*16]; + int32_t m_ui_view; + uint32_t m_max_view; static const uint16_t CACHE_SIZE; static const uint32_t PACKABLE_SIZE;