summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/chainentry.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/render/bgfx/chainentry.cpp')
-rw-r--r--src/osd/modules/render/bgfx/chainentry.cpp126
1 files changed, 87 insertions, 39 deletions
diff --git a/src/osd/modules/render/bgfx/chainentry.cpp b/src/osd/modules/render/bgfx/chainentry.cpp
index d48e279e9d2..c3f3ee3a8e3 100644
--- a/src/osd/modules/render/bgfx/chainentry.cpp
+++ b/src/osd/modules/render/bgfx/chainentry.cpp
@@ -9,10 +9,11 @@
//
//============================================================
-#include "emu.h"
+#include "chainmanager.h"
#include <bgfx/bgfx.h>
#include <bx/math.h>
+#include <cmath>
#include "chainentry.h"
@@ -25,10 +26,12 @@
#include "vertex.h"
#include "suppressor.h"
+#include "emucore.h"
#include "render.h"
-bgfx_chain_entry::bgfx_chain_entry(std::string name, bgfx_effect* effect, clear_state* clear, std::vector<bgfx_suppressor*> suppressors, std::vector<bgfx_input_pair*> inputs, std::vector<bgfx_entry_uniform*> uniforms, target_manager& targets, std::string output)
+bgfx_chain_entry::bgfx_chain_entry(std::string name, bgfx_effect* effect, clear_state* clear, std::vector<bgfx_suppressor*> suppressors, std::vector<bgfx_input_pair*> inputs,
+ std::vector<bgfx_entry_uniform*> uniforms, target_manager& targets, std::string output, bool apply_tint)
: m_name(name)
, m_effect(effect)
, m_clear(clear)
@@ -37,6 +40,7 @@ bgfx_chain_entry::bgfx_chain_entry(std::string name, bgfx_effect* effect, clear_
, m_uniforms(uniforms)
, m_targets(targets)
, m_output(output)
+ , m_apply_tint(apply_tint)
{
}
@@ -52,12 +56,18 @@ bgfx_chain_entry::~bgfx_chain_entry()
delete uniform;
}
m_uniforms.clear();
- delete m_clear;
+ if (m_clear)
+ {
+ delete m_clear;
+ }
}
-void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager& textures, uint16_t screen_count, uint16_t screen_width, uint16_t screen_height, float screen_scale_x, float screen_scale_y, float screen_offset_x, float screen_offset_y, uint32_t rotation_type, bool swap_xy, uint64_t blend, int32_t screen)
+void bgfx_chain_entry::submit(int view, chain_manager::screen_prim &prim, texture_manager& textures, uint16_t screen_count, uint16_t screen_width, uint16_t screen_height,
+ float screen_scale_x, float screen_scale_y, float screen_offset_x, float screen_offset_y, uint32_t rotation_type, bool swap_xy, int32_t screen)
{
- if (!setup_view(view, screen_width, screen_height, screen))
+ uint16_t view_width = screen_width;
+ uint16_t view_height = screen_height;
+ if (!setup_view(textures, view, screen_width, screen_height, screen, view_width, view_height))
{
return;
}
@@ -67,11 +77,22 @@ void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager&
input->bind(m_effect, screen);
}
+ uint32_t tint = 0xffffffff;
+ if (m_apply_tint)
+ {
+ const uint8_t a = (uint8_t)std::round(prim.m_prim->color.a * 255);
+ const uint8_t r = (uint8_t)std::round(prim.m_prim->color.r * 255);
+ const uint8_t g = (uint8_t)std::round(prim.m_prim->color.g * 255);
+ const uint8_t b = (uint8_t)std::round(prim.m_prim->color.b * 255);
+ tint = (a << 24) | (b << 16) | (g << 8) | r;
+ }
+
bgfx::TransientVertexBuffer buffer;
- put_screen_buffer(prim, &buffer);
- bgfx::setVertexBuffer(0,&buffer);
+ put_screen_buffer(view_width, view_height, tint, &buffer);
+ bgfx::setVertexBuffer(0, &buffer);
- setup_auto_uniforms(prim, textures, screen_count, screen_width, screen_height, screen_scale_x, screen_scale_y, screen_offset_x, screen_offset_y, rotation_type, swap_xy, screen);
+ setup_auto_uniforms(prim, textures, screen_count, view_width, view_height, screen_width, screen_height, screen_scale_x, screen_scale_y, screen_offset_x, screen_offset_y,
+ rotation_type, swap_xy, screen);
for (bgfx_entry_uniform* uniform : m_uniforms)
{
@@ -81,7 +102,7 @@ void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager&
}
}
- m_effect->submit(view, blend);
+ m_effect->submit(view);
if (m_targets.target(screen, m_output) != nullptr)
{
@@ -89,6 +110,43 @@ void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager&
}
}
+void bgfx_chain_entry::setup_auto_uniforms(chain_manager::screen_prim &prim, texture_manager& textures, uint16_t screen_count, uint16_t view_width, uint16_t view_height,
+ uint16_t screen_width, uint16_t screen_height, float screen_scale_x, float screen_scale_y, float screen_offset_x, float screen_offset_y,
+ uint32_t rotation_type, bool swap_xy, int32_t screen)
+{
+ setup_viewsize_uniforms(view_width, view_height);
+ setup_screensize_uniforms(textures, screen_width, screen_height, screen);
+ setup_screenscale_uniforms(screen_scale_x, screen_scale_y);
+ setup_screenoffset_uniforms(screen_offset_x, screen_offset_y);
+ setup_screencount_uniforms(screen_count);
+ setup_sourcesize_uniform(prim);
+ setup_targetsize_uniform(screen);
+ setup_targetscale_uniform(screen);
+ setup_rotationtype_uniform(rotation_type);
+ setup_swapxy_uniform(swap_xy);
+ setup_quaddims_uniform(prim);
+ setup_screenindex_uniform(screen);
+}
+
+void bgfx_chain_entry::setup_viewsize_uniforms(uint16_t view_width, uint16_t view_height)
+{
+ float width(view_width);
+ float height(view_height);
+ bgfx_uniform* view_dims = m_effect->uniform("u_view_dims");
+ if (view_dims != nullptr)
+ {
+ float values[2] = { width, height };
+ view_dims->set(values, sizeof(float) * 2);
+ }
+
+ bgfx_uniform* inv_view_dims = m_effect->uniform("u_inv_view_dims");
+ if (inv_view_dims != nullptr)
+ {
+ float values[2] = { -1.0f / width, 1.0f / height };
+ inv_view_dims->set(values, sizeof(float) * 2);
+ }
+}
+
void bgfx_chain_entry::setup_screensize_uniforms(texture_manager& textures, uint16_t screen_width, uint16_t screen_height, int32_t screen)
{
float width = screen_width;
@@ -145,13 +203,12 @@ void bgfx_chain_entry::setup_screencount_uniforms(uint16_t screen_count)
}
}
-void bgfx_chain_entry::setup_sourcesize_uniform(render_primitive* prim) const
+void bgfx_chain_entry::setup_sourcesize_uniform(chain_manager::screen_prim &prim) const
{
bgfx_uniform* source_dims = m_effect->uniform("u_source_dims");
if (source_dims != nullptr)
{
- float values[2] = { float(prim->texture.width), float(prim->texture.height) };
- source_dims->set(values, sizeof(float) * 2);
+ source_dims->set(&prim.m_tex_width, sizeof(float) * 2);
}
}
@@ -203,12 +260,12 @@ void bgfx_chain_entry::setup_swapxy_uniform(bool swap_xy) const
}
}
-void bgfx_chain_entry::setup_quaddims_uniform(render_primitive* prim) const
+void bgfx_chain_entry::setup_quaddims_uniform(chain_manager::screen_prim &prim) const
{
bgfx_uniform* quad_dims_uniform = m_effect->uniform("u_quad_dims");
if (quad_dims_uniform != nullptr)
{
- float values[2] = { float(floor((prim->bounds.x1 - prim->bounds.x0) + 0.5f)), float(floor((prim->bounds.y1 - prim->bounds.y0) + 0.5f)) };
+ float values[2] = { float(prim.m_quad_width), float(prim.m_quad_height) };
quad_dims_uniform->set(values, sizeof(float) * 2);
}
}
@@ -223,22 +280,8 @@ void bgfx_chain_entry::setup_screenindex_uniform(int32_t screen) const
}
}
-void bgfx_chain_entry::setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_count, uint16_t screen_width, uint16_t screen_height, float screen_scale_x, float screen_scale_y, float screen_offset_x, float screen_offset_y, uint32_t rotation_type, bool swap_xy, int32_t screen)
-{
- setup_screensize_uniforms(textures, screen_width, screen_height, screen);
- setup_screenscale_uniforms(screen_scale_x, screen_scale_y);
- setup_screenoffset_uniforms(screen_offset_x, screen_offset_y);
- setup_screencount_uniforms(screen_count);
- setup_sourcesize_uniform(prim);
- setup_targetsize_uniform(screen);
- setup_targetscale_uniform(screen);
- setup_rotationtype_uniform(rotation_type);
- setup_swapxy_uniform(swap_xy);
- setup_quaddims_uniform(prim);
- setup_screenindex_uniform(screen);
-}
-
-bool bgfx_chain_entry::setup_view(int view, uint16_t screen_width, uint16_t screen_height, int32_t screen) const
+bool bgfx_chain_entry::setup_view(texture_manager &textures, int view, uint16_t screen_width, uint16_t screen_height, int32_t screen,
+ uint16_t &out_view_width, uint16_t &out_view_height) const
{
bgfx::FrameBufferHandle handle = BGFX_INVALID_HANDLE;
uint16_t width = screen_width;
@@ -257,18 +300,23 @@ bool bgfx_chain_entry::setup_view(int view, uint16_t screen_width, uint16_t scre
bgfx::setViewFrameBuffer(view, handle);
bgfx::setViewRect(view, 0, 0, width, height);
+ out_view_width = width;
+ out_view_height = height;
const bgfx::Caps* caps = bgfx::getCaps();
+ std::string name = m_inputs[0]->texture() + std::to_string(screen);
+ const float right_ratio = float(textures.provider(name)->width()) / textures.provider(name)->rowpixels();
+
float projMat[16];
- bx::mtxOrtho(projMat, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f, 0.0f, caps->homogeneousDepth);
+ bx::mtxOrtho(projMat, 0.0f, right_ratio, 1.0f, 0.0f, 0.0f, 100.0f, 0.0f, caps->homogeneousDepth);
bgfx::setViewTransform(view, nullptr, projMat);
m_clear->bind(view);
return true;
}
-void bgfx_chain_entry::put_screen_buffer(render_primitive* prim, bgfx::TransientVertexBuffer* buffer) const
+void bgfx_chain_entry::put_screen_buffer(uint16_t screen_width, uint16_t screen_height, uint32_t screen_tint, bgfx::TransientVertexBuffer* buffer) const
{
if (6 == bgfx::getAvailTransientVertexBuffer(6, ScreenVertex::ms_decl))
{
@@ -279,7 +327,7 @@ void bgfx_chain_entry::put_screen_buffer(render_primitive* prim, bgfx::Transient
return;
}
- ScreenVertex* vertex = reinterpret_cast<ScreenVertex*>(buffer->data);
+ auto* vertex = reinterpret_cast<ScreenVertex*>(buffer->data);
float x[4] = { 0, 1, 0, 1 };
float y[4] = { 0, 0, 1, 1 };
@@ -296,42 +344,42 @@ void bgfx_chain_entry::put_screen_buffer(render_primitive* prim, bgfx::Transient
vertex[0].m_x = x[0];
vertex[0].m_y = y[0];
vertex[0].m_z = 0;
- vertex[0].m_rgba = 0xffffffff;
+ vertex[0].m_rgba = screen_tint;
vertex[0].m_u = u[0];
vertex[0].m_v = v[0];
vertex[1].m_x = x[1];
vertex[1].m_y = y[1];
vertex[1].m_z = 0;
- vertex[1].m_rgba = 0xffffffff;
+ vertex[1].m_rgba = screen_tint;
vertex[1].m_u = u[1];
vertex[1].m_v = v[1];
vertex[2].m_x = x[3];
vertex[2].m_y = y[3];
vertex[2].m_z = 0;
- vertex[2].m_rgba = 0xffffffff;
+ vertex[2].m_rgba = screen_tint;
vertex[2].m_u = u[3];
vertex[2].m_v = v[3];
vertex[3].m_x = x[3];
vertex[3].m_y = y[3];
vertex[3].m_z = 0;
- vertex[3].m_rgba = 0xffffffff;
+ vertex[3].m_rgba = screen_tint;
vertex[3].m_u = u[3];
vertex[3].m_v = v[3];
vertex[4].m_x = x[2];
vertex[4].m_y = y[2];
vertex[4].m_z = 0;
- vertex[4].m_rgba = 0xffffffff;
+ vertex[4].m_rgba = screen_tint;
vertex[4].m_u = u[2];
vertex[4].m_v = v[2];
vertex[5].m_x = x[0];
vertex[5].m_y = y[0];
vertex[5].m_z = 0;
- vertex[5].m_rgba = 0xffffffff;
+ vertex[5].m_rgba = screen_tint;
vertex[5].m_u = u[0];
vertex[5].m_v = v[0];
}