summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules')
-rw-r--r--src/osd/modules/render/bgfx/chain.cpp27
-rw-r--r--src/osd/modules/render/bgfx/chain.h4
-rw-r--r--src/osd/modules/render/bgfx/chainentry.cpp28
-rw-r--r--src/osd/modules/render/bgfx/chainentry.h6
-rw-r--r--src/osd/modules/render/bgfx/chainreader.cpp9
-rw-r--r--src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc14
-rw-r--r--src/osd/modules/render/d3d/d3dhlsl.cpp4
-rw-r--r--src/osd/modules/render/drawbgfx.h13
-rw-r--r--src/osd/modules/render/drawd3d.cpp2
9 files changed, 83 insertions, 24 deletions
diff --git a/src/osd/modules/render/bgfx/chain.cpp b/src/osd/modules/render/bgfx/chain.cpp
index 3cc6e022573..aa1c3739dbe 100644
--- a/src/osd/modules/render/bgfx/chain.cpp
+++ b/src/osd/modules/render/bgfx/chain.cpp
@@ -21,9 +21,10 @@
#include "chain.h"
-bgfx_chain::bgfx_chain(std::string name, std::string author, target_manager& targets, std::vector<bgfx_slider*> sliders, std::vector<bgfx_parameter*> params, std::vector<bgfx_chain_entry*> entries, std::vector<bgfx_target*> target_list, std::uint32_t screen_index)
+bgfx_chain::bgfx_chain(std::string name, std::string author, bool transform, target_manager& targets, std::vector<bgfx_slider*> sliders, std::vector<bgfx_parameter*> params, std::vector<bgfx_chain_entry*> entries, std::vector<bgfx_target*> target_list, std::uint32_t screen_index)
: m_name(name)
, m_author(author)
+ , m_transform(transform)
, m_targets(targets)
, m_sliders(sliders)
, m_params(params)
@@ -60,22 +61,34 @@ bgfx_chain::~bgfx_chain()
void bgfx_chain::process(render_primitive* prim, int view, int screen, texture_manager& textures, osd_window& window, uint64_t blend)
{
+ screen_device_iterator screen_iterator(window.machine().root_device());
+ screen_device* screen_device = screen_iterator.first();
+ for (int i = 0; i < screen; i++)
+ {
+ screen_device = screen_iterator.next();
+ }
+ render_container &screen_container = screen_device->container();
+
int current_view = view;
uint16_t screen_width(floor((prim->bounds.x1 - prim->bounds.x0) + 0.5f));
uint16_t screen_height(floor((prim->bounds.y1 - prim->bounds.y0) + 0.5f));
- uint32_t rotation_type = (window.target()->orientation() & ROT90) == ROT90 ?
- 1 : (window.target()->orientation() & ROT180) == ROT180 ?
- 2 : (window.target()->orientation() & ROT270) == ROT270 ?
- 3 : 0;
+ uint32_t rotation_type =
+ (window.target()->orientation() & ROT90) == ROT90 ? 1 :
+ (window.target()->orientation() & ROT180) == ROT180 ? 2 :
+ (window.target()->orientation() & ROT270) == ROT270 ? 3 : 0;
bool orientation_swap_xy = (window.machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
- bool rotation_swap_xy = (window.target()->orientation() & ROT90) == ROT90 || (window.target()->orientation() & ROT270) == ROT270;
+ bool rotation_swap_xy = (window.target()->orientation() & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
bool swap_xy = orientation_swap_xy ^ rotation_swap_xy;
+ float screen_scale_x = 1.0f / screen_container.xscale();
+ float screen_scale_y = 1.0f / screen_container.yscale();
+ float screen_offset_x = -screen_container.xoffset();
+ float screen_offset_y = -screen_container.yoffset();
for (bgfx_chain_entry* entry : m_entries)
{
if (!entry->skip())
{
- entry->submit(current_view, prim, textures, screen_width, screen_height, rotation_type, swap_xy, blend, screen);
+ entry->submit(current_view, prim, textures, screen_width, screen_height, screen_scale_x, screen_scale_y, screen_offset_x, screen_offset_y, rotation_type, swap_xy, blend, screen);
current_view++;
}
}
diff --git a/src/osd/modules/render/bgfx/chain.h b/src/osd/modules/render/bgfx/chain.h
index bc68d4d5af2..465e44fea85 100644
--- a/src/osd/modules/render/bgfx/chain.h
+++ b/src/osd/modules/render/bgfx/chain.h
@@ -28,7 +28,7 @@ class osd_window;
class bgfx_chain
{
public:
- bgfx_chain(std::string name, std::string author, target_manager& targets, std::vector<bgfx_slider*> sliders, std::vector<bgfx_parameter*> params, std::vector<bgfx_chain_entry*> entries, std::vector<bgfx_target*> target_list, uint32_t screen_index);
+ bgfx_chain(std::string name, std::string author, bool transform, target_manager& targets, std::vector<bgfx_slider*> sliders, std::vector<bgfx_parameter*> params, std::vector<bgfx_chain_entry*> entries, std::vector<bgfx_target*> target_list, uint32_t screen_index);
~bgfx_chain();
void process(render_primitive* prim, int view, int screen, texture_manager& textures, osd_window &window, uint64_t blend = 0L);
@@ -36,10 +36,12 @@ public:
// Getters
std::vector<bgfx_slider*>& sliders() { return m_sliders; }
uint32_t applicable_passes();
+ bool transform() { return m_transform; }
private:
std::string m_name;
std::string m_author;
+ bool m_transform;
target_manager& m_targets;
std::vector<bgfx_slider*> m_sliders;
std::vector<bgfx_parameter*> m_params;
diff --git a/src/osd/modules/render/bgfx/chainentry.cpp b/src/osd/modules/render/bgfx/chainentry.cpp
index 156bc435f09..fc97e909260 100644
--- a/src/osd/modules/render/bgfx/chainentry.cpp
+++ b/src/osd/modules/render/bgfx/chainentry.cpp
@@ -50,7 +50,7 @@ bgfx_chain_entry::~bgfx_chain_entry()
delete m_clear;
}
-void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, uint64_t blend, int32_t screen)
+void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager& textures, 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)
{
bgfx::setViewSeq(view, true);
@@ -68,7 +68,7 @@ void bgfx_chain_entry::submit(int view, render_primitive* prim, texture_manager&
put_screen_buffer(prim, &buffer);
bgfx::setVertexBuffer(&buffer);
- setup_auto_uniforms(prim, textures, screen_width, screen_height, rotation_type, swap_xy, screen);
+ setup_auto_uniforms(prim, textures, 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)
{
@@ -112,6 +112,26 @@ void bgfx_chain_entry::setup_screensize_uniforms(texture_manager& textures, uint
}
}
+void bgfx_chain_entry::setup_screenscale_uniforms(float screen_scale_x, float screen_scale_y)
+{
+ bgfx_uniform* screen_scale = m_effect->uniform("u_screen_scale");
+ if (screen_scale != nullptr)
+ {
+ float values[2] = { screen_scale_x, screen_scale_y };
+ screen_scale->set(values, sizeof(float) * 2);
+ }
+}
+
+void bgfx_chain_entry::setup_screenoffset_uniforms(float screen_offset_x, float screen_offset_y)
+{
+ bgfx_uniform* screen_offset = m_effect->uniform("u_screen_offset");
+ if (screen_offset != nullptr)
+ {
+ float values[2] = { screen_offset_x, screen_offset_y };
+ screen_offset->set(values, sizeof(float) * 2);
+ }
+}
+
void bgfx_chain_entry::setup_sourcesize_uniform(render_primitive* prim) const
{
bgfx_uniform* source_dims = m_effect->uniform("u_source_dims");
@@ -176,9 +196,11 @@ 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_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, int32_t screen)
+void bgfx_chain_entry::setup_auto_uniforms(render_primitive* prim, texture_manager& textures, 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_sourcesize_uniform(prim);
setup_targetsize_uniform(screen);
setup_rotationtype_uniform(rotation_type);
diff --git a/src/osd/modules/render/bgfx/chainentry.h b/src/osd/modules/render/bgfx/chainentry.h
index e9e5112bf1b..d6452861de2 100644
--- a/src/osd/modules/render/bgfx/chainentry.h
+++ b/src/osd/modules/render/bgfx/chainentry.h
@@ -37,15 +37,17 @@ public:
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();
- void submit(int view, render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, uint64_t blend, int32_t screen);
+ void submit(int view, render_primitive* prim, texture_manager& textures, 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);
// Getters
std::string name() const { return m_name; }
bool skip();
private:
- void setup_auto_uniforms(render_primitive* prim, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint32_t rotation_type, bool swap_xy, int32_t screen);
+ void setup_auto_uniforms(render_primitive* prim, texture_manager& textures, 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);
void setup_screensize_uniforms(texture_manager& textures, uint16_t screen_width, uint16_t screen_height, int32_t screen);
+ void setup_screenscale_uniforms(float screen_scale_x, float screen_scale_y);
+ void setup_screenoffset_uniforms(float screen_offset_x, float screen_offset_y);
void setup_sourcesize_uniform(render_primitive* prim) const;
void setup_targetsize_uniform(int32_t screen) const;
void setup_rotationtype_uniform(uint32_t rotation_type) const;
diff --git a/src/osd/modules/render/bgfx/chainreader.cpp b/src/osd/modules/render/bgfx/chainreader.cpp
index 332ba139fd0..9e79eb1f19d 100644
--- a/src/osd/modules/render/bgfx/chainreader.cpp
+++ b/src/osd/modules/render/bgfx/chainreader.cpp
@@ -53,6 +53,13 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, std::string prefix
}
}
+ // Parse whether the screen container is transformed by the chain's shaders
+ bool transform = false;
+ if (value.HasMember("transform"))
+ {
+ transform = value["transform"].GetBool();
+ }
+
// Map sliders
std::map<std::string, bgfx_slider*> slider_map;
for (bgfx_slider* slider : sliders)
@@ -116,7 +123,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, std::string prefix
}
}
- return new bgfx_chain(name, author, targets, sliders, parameters, entries, target_list, screen_index);
+ return new bgfx_chain(name, author, transform, targets, sliders, parameters, entries, target_list, screen_index);
}
bool chain_reader::validate_parameters(const Value& value, std::string prefix)
diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc
index e4a3a984e6b..68fe25a32cc 100644
--- a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc
+++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_post.sc
@@ -12,8 +12,8 @@ $input v_color0, v_texcoord0
uniform vec4 u_swap_xy;
uniform vec4 u_source_dims; // size of the guest machine
uniform vec4 u_quad_dims;
-uniform vec4 u_screen_scale; // TODO: Hook up ScreenScale code-side
-uniform vec4 u_screen_offset; // TODO: Hook up ScreenOffset code-side
+uniform vec4 u_screen_scale;
+uniform vec4 u_screen_offset;
// User-supplied
uniform vec4 u_scanline_alpha;
@@ -50,7 +50,7 @@ vec2 GetAdjustedCoords(vec2 coord, vec2 center_offset)
coord -= center_offset;
// apply screen scale
- //coord /= u_screen_scale.xy;
+ coord *= u_screen_scale.xy;
// un-center coordinates
coord += center_offset;
@@ -102,7 +102,7 @@ void main()
// Color
vec4 BaseColor = texture2D(s_tex, BaseCoord);
- if (BaseCoord.x < 0.0 || BaseCoord.y < 0.0)
+ if (BaseCoord.x < 0.0 || BaseCoord.y < 0.0 || BaseCoord.x > 1.0 || BaseCoord.y > 1.0)
{
BaseColor.rgb = vec3(0.0, 0.0, 0.0);
}
@@ -111,7 +111,7 @@ void main()
if (u_shadow_alpha.x > 0.0)
{
vec2 ShadowCoord = GetShadowCoord(v_texcoord0.xy, v_texcoord0.xy);
-
+
vec4 ShadowColor = texture2D(s_shadow, ShadowCoord);
vec3 ShadowMaskColor = mix(vec3(1.0, 1.0, 1.0), ShadowColor.rgb, u_shadow_alpha.xxx);
@@ -122,7 +122,7 @@ void main()
// Color Compression
// increasing the floor of the signal without affecting the ceiling
BaseColor.rgb = u_floor.rgb + (vec3(1.0, 1.0, 1.0) - u_floor.rgb) * BaseColor.rgb;
-
+
// Color Power
BaseColor.r = pow(BaseColor.r, u_power.r);
BaseColor.g = pow(BaseColor.g, u_power.g);
@@ -136,7 +136,7 @@ void main()
float ColorBrightness = 0.299 * BaseColor.r + 0.587 * BaseColor.g + 0.114 * BaseColor.b;
- float ScanCoord = v_texcoord0.y * u_source_dims.y * u_scanline_scale.x * 3.1415927;
+ float ScanCoord = BaseCoord.y * u_source_dims.y * u_scanline_scale.x * 3.1415927;
float ScanCoordJitter = u_scanline_jitter.x * u_jitter_amount.x * 1.618034;
float ScanSine = sin(ScanCoord + ScanCoordJitter);
float ScanlineWide = u_scanline_height.x + u_scanline_variation.x * max(1.0, u_scanline_height.x) * (1.0 - ColorBrightness);
diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp
index 497cde4ffaa..d8ce75c06db 100644
--- a/src/osd/modules/render/d3d/d3dhlsl.cpp
+++ b/src/osd/modules/render/d3d/d3dhlsl.cpp
@@ -1379,8 +1379,8 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly,
screen_device *screen = screen_iterator.byindex(curr_screen);
render_container &screen_container = screen->container();
- float xscale = screen_container.xscale();
- float yscale = screen_container.yscale();
+ float xscale = 1.0f / screen_container.xscale();
+ float yscale = 1.0f / screen_container.yscale();
float xoffset = -screen_container.xoffset();
float yoffset = -screen_container.yoffset();
diff --git a/src/osd/modules/render/drawbgfx.h b/src/osd/modules/render/drawbgfx.h
index a6f66a6eff3..1a21b5c8259 100644
--- a/src/osd/modules/render/drawbgfx.h
+++ b/src/osd/modules/render/drawbgfx.h
@@ -12,6 +12,8 @@
#include "binpacker.h"
#include "bgfx/vertex.h"
+#include "bgfx/chain.h"
+#include "bgfx/chainmanager.h"
#include "sliderdirtynotifier.h"
class texture_manager;
@@ -53,8 +55,19 @@ public:
virtual render_primitive_list *get_primitives() override
{
+ // determines whether the screen container is transformed by the chain's shaders
+ bool chain_transform = false;
+
+ // check the first chain
+ bgfx_chain* chain = this->m_chains->screen_chain(0);
+ if (chain != nullptr)
+ {
+ chain_transform = chain->transform();
+ }
+
osd_dim wdim = window().get_size();
window().target()->set_bounds(wdim.width(), wdim.height(), window().pixel_aspect());
+ window().target()->set_transform_container(!chain_transform);
return &window().target()->get_primitives();
}
diff --git a/src/osd/modules/render/drawd3d.cpp b/src/osd/modules/render/drawd3d.cpp
index fa5dc500e2e..e28c3e7928a 100644
--- a/src/osd/modules/render/drawd3d.cpp
+++ b/src/osd/modules/render/drawd3d.cpp
@@ -209,7 +209,7 @@ render_primitive_list *renderer_d3d9::get_primitives()
if (m_shaders != nullptr)
{
// do not transform primitives (scale, offset) if shaders are enabled, the shaders will handle the transformation
- window().target()->set_transform_primitives(!m_shaders->enabled());
+ window().target()->set_transform_container(!m_shaders->enabled());
}
return &window().target()->get_primitives();
}