gl/vk: Fix clip region scaling for overlay elements

This commit is contained in:
kd-11 2019-01-31 14:31:32 +03:00 committed by kd-11
parent 3653c2eb0d
commit 9e39e2d2c4
2 changed files with 24 additions and 3 deletions

View File

@ -348,13 +348,15 @@ namespace gl
"layout(location=0) out vec2 tc0;\n"
"layout(location=1) out vec4 clip_rect;\n"
"uniform vec4 ui_scale;\n"
"uniform vec2 viewport;\n"
"uniform vec4 clip_bounds;\n"
"\n"
"void main()\n"
"{\n"
" tc0.xy = in_pos.zw;\n"
" clip_rect = (clip_bounds * ui_scale.zwzw);\n"
" clip_rect.yw = ui_scale.yy - clip_rect.wy; //invert y axis\n"
" clip_rect = clip_bounds;\n"
" clip_rect.yw = ui_scale.yy - clip_rect.wy; // Invert y axis\n"
" clip_rect *= (ui_scale.zwzw * viewport.xyxy) / ui_scale.xyxy; // Normalize and convert to window coords\n"
" vec4 pos = vec4((in_pos.xy * ui_scale.zw) / ui_scale.xy, 0., 1.);\n"
" pos.y = (1. - pos.y); //invert y axis\n"
" gl_Position = (pos + pos) - 1.;\n"
@ -581,6 +583,7 @@ namespace gl
void run(u16 w, u16 h, GLuint target, rsx::overlays::overlay& ui)
{
program_handle.uniforms["viewport"] = color2f(f32(w), f32(h));
program_handle.uniforms["ui_scale"] = color4f((f32)ui.virtual_width, (f32)ui.virtual_height, 1.f, 1.f);
program_handle.uniforms["time"] = (f32)(get_system_time() / 1000) * 0.005f;
for (auto &cmd : ui.get_compiled().draw_commands)

View File

@ -472,6 +472,7 @@ namespace vk
bool m_clip_enabled;
int m_texture_type;
areaf m_clip_region;
size2f m_viewport_size;
std::vector<std::unique_ptr<vk::image>> resources;
std::unordered_map<u64, std::unique_ptr<vk::image>> font_cache;
@ -499,7 +500,8 @@ namespace vk
" color = regs[1];\n"
" parameters = regs[2];\n"
" parameters2 = regs[4];\n"
" clip_rect = regs[3] * regs[0].zwzw;\n"
" clip_rect = (regs[3] * regs[0].zwzw) / regs[0].xyxy; // Normalized coords\n"
" clip_rect *= regs[5].xyxy; // Window coords\n"
" vec4 pos = vec4((in_pos.xy * regs[0].zw) / regs[0].xy, 0.5, 1.);\n"
" gl_Position = (pos + pos) - 1.;\n"
"}\n"
@ -728,23 +730,38 @@ namespace vk
{
m_ubo_offset = (u32)m_ubo.alloc<256>(128);
auto dst = (f32*)m_ubo.map(m_ubo_offset, 128);
// regs[0] = scaling parameters
dst[0] = m_scale_offset.r;
dst[1] = m_scale_offset.g;
dst[2] = m_scale_offset.b;
dst[3] = m_scale_offset.a;
// regs[1] = color
dst[4] = m_color.r;
dst[5] = m_color.g;
dst[6] = m_color.b;
dst[7] = m_color.a;
// regs[2] = fs config parameters
dst[8] = m_time;
dst[9] = m_pulse_glow? 1.f : 0.f;
dst[10] = m_skip_texture_read? 0.f : (f32)m_texture_type;
dst[11] = m_clip_enabled ? 1.f : 0.f;
// regs[3] = clip rect
dst[12] = m_clip_region.x1;
dst[13] = m_clip_region.y1;
dst[14] = m_clip_region.x2;
dst[15] = m_clip_region.y2;
// regs[4] = fs config parameters 2
dst[16] = m_blur_strength;
// regs[5] = viewport size
dst[20] = m_viewport_size.width;
dst[21] = m_viewport_size.height;
m_ubo.unmap();
}
@ -766,6 +783,7 @@ namespace vk
{
m_scale_offset = color4f((f32)ui.virtual_width, (f32)ui.virtual_height, 1.f, 1.f);
m_time = (f32)(get_system_time() / 1000) * 0.005f;
m_viewport_size = { f32(w), f32(h) };
for (auto &command : ui.get_compiled().draw_commands)
{