mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-27 12:04:16 +01:00
core\frontend\framebuffer_layout: GetCardboardSettings: clean up floa… (#6399)
* core\frontend\framebuffer_layout: GetCardboardSettings: clean up float to u32 conversion warnings + style fixes * clang format * fix signedness
This commit is contained in:
parent
90bcf49db0
commit
a94acde519
@ -458,7 +458,7 @@ struct Values {
|
|||||||
SwitchableSetting<MonoRenderOption> mono_render_option{MonoRenderOption::LeftEye,
|
SwitchableSetting<MonoRenderOption> mono_render_option{MonoRenderOption::LeftEye,
|
||||||
"mono_render_option"};
|
"mono_render_option"};
|
||||||
|
|
||||||
Setting<s32> cardboard_screen_size{85, "cardboard_screen_size"};
|
Setting<u32> cardboard_screen_size{85, "cardboard_screen_size"};
|
||||||
Setting<s32> cardboard_x_shift{0, "cardboard_x_shift"};
|
Setting<s32> cardboard_x_shift{0, "cardboard_x_shift"};
|
||||||
Setting<s32> cardboard_y_shift{0, "cardboard_y_shift"};
|
Setting<s32> cardboard_y_shift{0, "cardboard_y_shift"};
|
||||||
|
|
||||||
|
@ -11,13 +11,13 @@
|
|||||||
|
|
||||||
namespace Layout {
|
namespace Layout {
|
||||||
|
|
||||||
static const float TOP_SCREEN_ASPECT_RATIO =
|
static constexpr float TOP_SCREEN_ASPECT_RATIO =
|
||||||
static_cast<float>(Core::kScreenTopHeight) / Core::kScreenTopWidth;
|
static_cast<float>(Core::kScreenTopHeight) / Core::kScreenTopWidth;
|
||||||
static const float BOT_SCREEN_ASPECT_RATIO =
|
static constexpr float BOT_SCREEN_ASPECT_RATIO =
|
||||||
static_cast<float>(Core::kScreenBottomHeight) / Core::kScreenBottomWidth;
|
static_cast<float>(Core::kScreenBottomHeight) / Core::kScreenBottomWidth;
|
||||||
static const float TOP_SCREEN_UPRIGHT_ASPECT_RATIO =
|
static constexpr float TOP_SCREEN_UPRIGHT_ASPECT_RATIO =
|
||||||
static_cast<float>(Core::kScreenTopWidth) / Core::kScreenTopHeight;
|
static_cast<float>(Core::kScreenTopWidth) / Core::kScreenTopHeight;
|
||||||
static const float BOT_SCREEN_UPRIGHT_ASPECT_RATIO =
|
static constexpr float BOT_SCREEN_UPRIGHT_ASPECT_RATIO =
|
||||||
static_cast<float>(Core::kScreenBottomWidth) / Core::kScreenBottomHeight;
|
static_cast<float>(Core::kScreenBottomWidth) / Core::kScreenBottomHeight;
|
||||||
|
|
||||||
u32 FramebufferLayout::GetScalingRatio() const {
|
u32 FramebufferLayout::GetScalingRatio() const {
|
||||||
@ -499,30 +499,31 @@ FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondar
|
|||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
FramebufferLayout GetCardboardSettings(FramebufferLayout layout) {
|
FramebufferLayout GetCardboardSettings(const FramebufferLayout& layout) {
|
||||||
FramebufferLayout newLayout = layout;
|
u32 top_screen_left = 0;
|
||||||
float top_screen_left = 0;
|
u32 top_screen_top = 0;
|
||||||
float top_screen_top = 0;
|
u32 bottom_screen_left = 0;
|
||||||
float bottom_screen_left = 0;
|
u32 bottom_screen_top = 0;
|
||||||
float bottom_screen_top = 0;
|
|
||||||
|
|
||||||
float cardboardScreenScale = Settings::values.cardboard_screen_size.GetValue() / 100.0f;
|
u32 cardboard_screen_scale = Settings::values.cardboard_screen_size.GetValue();
|
||||||
float top_screen_width = layout.top_screen.GetWidth() / 2.0f * cardboardScreenScale;
|
u32 top_screen_width = ((layout.top_screen.GetWidth() / 2) * cardboard_screen_scale) / 100;
|
||||||
float top_screen_height = layout.top_screen.GetHeight() / 2.0f * cardboardScreenScale;
|
u32 top_screen_height = ((layout.top_screen.GetHeight() / 2) * cardboard_screen_scale) / 100;
|
||||||
float bottom_screen_width = layout.bottom_screen.GetWidth() / 2.0f * cardboardScreenScale;
|
u32 bottom_screen_width =
|
||||||
float bottom_screen_height = layout.bottom_screen.GetHeight() / 2.0f * cardboardScreenScale;
|
((layout.bottom_screen.GetWidth() / 2) * cardboard_screen_scale) / 100;
|
||||||
|
u32 bottom_screen_height =
|
||||||
|
((layout.bottom_screen.GetHeight() / 2) * cardboard_screen_scale) / 100;
|
||||||
const bool is_swapped = Settings::values.swap_screen.GetValue();
|
const bool is_swapped = Settings::values.swap_screen.GetValue();
|
||||||
const bool is_portrait = layout.height > layout.width;
|
const bool is_portrait = layout.height > layout.width;
|
||||||
|
|
||||||
float cardboardScreenWidth;
|
u32 cardboard_screen_width;
|
||||||
float cardboardScreenHeight;
|
u32 cardboard_screen_height;
|
||||||
switch (Settings::values.layout_option.GetValue()) {
|
switch (Settings::values.layout_option.GetValue()) {
|
||||||
case Settings::LayoutOption::MobileLandscape:
|
case Settings::LayoutOption::MobileLandscape:
|
||||||
case Settings::LayoutOption::SideScreen:
|
case Settings::LayoutOption::SideScreen:
|
||||||
// If orientation is portrait, only use MobilePortrait
|
// If orientation is portrait, only use MobilePortrait
|
||||||
if (!is_portrait) {
|
if (!is_portrait) {
|
||||||
cardboardScreenWidth = top_screen_width + bottom_screen_width;
|
cardboard_screen_width = top_screen_width + bottom_screen_width;
|
||||||
cardboardScreenHeight = is_swapped ? bottom_screen_height : top_screen_height;
|
cardboard_screen_height = is_swapped ? bottom_screen_height : top_screen_height;
|
||||||
if (is_swapped)
|
if (is_swapped)
|
||||||
top_screen_left += bottom_screen_width;
|
top_screen_left += bottom_screen_width;
|
||||||
else
|
else
|
||||||
@ -535,50 +536,52 @@ FramebufferLayout GetCardboardSettings(FramebufferLayout layout) {
|
|||||||
default:
|
default:
|
||||||
if (!is_portrait) {
|
if (!is_portrait) {
|
||||||
// Default values when using LayoutOption::SingleScreen
|
// Default values when using LayoutOption::SingleScreen
|
||||||
cardboardScreenWidth = is_swapped ? bottom_screen_width : top_screen_width;
|
cardboard_screen_width = is_swapped ? bottom_screen_width : top_screen_width;
|
||||||
cardboardScreenHeight = is_swapped ? bottom_screen_height : top_screen_height;
|
cardboard_screen_height = is_swapped ? bottom_screen_height : top_screen_height;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
}
|
}
|
||||||
case Settings::LayoutOption::MobilePortrait:
|
case Settings::LayoutOption::MobilePortrait:
|
||||||
cardboardScreenWidth = top_screen_width;
|
cardboard_screen_width = top_screen_width;
|
||||||
cardboardScreenHeight = top_screen_height + bottom_screen_height;
|
cardboard_screen_height = top_screen_height + bottom_screen_height;
|
||||||
bottom_screen_left += (top_screen_width - bottom_screen_width) / 2.0f;
|
bottom_screen_left += (top_screen_width - bottom_screen_width) / 2;
|
||||||
if (is_swapped)
|
if (is_swapped)
|
||||||
top_screen_top += bottom_screen_height;
|
top_screen_top += bottom_screen_height;
|
||||||
else
|
else
|
||||||
bottom_screen_top += top_screen_height;
|
bottom_screen_top += top_screen_height;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
float cardboardMaxXShift = (layout.width / 2.0f - cardboardScreenWidth) / 2.0f;
|
s32 cardboard_max_x_shift = (layout.width / 2 - cardboard_screen_width) / 2;
|
||||||
float cardboardUserXShift =
|
s32 cardboard_user_x_shift =
|
||||||
(Settings::values.cardboard_x_shift.GetValue() / 100.0f) * cardboardMaxXShift;
|
(Settings::values.cardboard_x_shift.GetValue() * cardboard_max_x_shift) / 100;
|
||||||
float cardboardMaxYShift = ((float)layout.height - cardboardScreenHeight) / 2.0f;
|
s32 cardboard_max_y_shift = (layout.height - cardboard_screen_height) / 2;
|
||||||
float cardboardUserYShift =
|
s32 cardboard_user_y_shift =
|
||||||
(Settings::values.cardboard_y_shift.GetValue() / 100.0f) * cardboardMaxYShift;
|
(Settings::values.cardboard_y_shift.GetValue() * cardboard_max_y_shift) / 100;
|
||||||
|
|
||||||
// Center the screens and apply user Y shift
|
// Center the screens and apply user Y shift
|
||||||
newLayout.top_screen.left = top_screen_left + cardboardMaxXShift;
|
FramebufferLayout new_layout = layout;
|
||||||
newLayout.top_screen.top = top_screen_top + cardboardMaxYShift + cardboardUserYShift;
|
new_layout.top_screen.left = top_screen_left + cardboard_max_x_shift;
|
||||||
newLayout.bottom_screen.left = bottom_screen_left + cardboardMaxXShift;
|
new_layout.top_screen.top = top_screen_top + cardboard_max_y_shift + cardboard_user_y_shift;
|
||||||
newLayout.bottom_screen.top = bottom_screen_top + cardboardMaxYShift + cardboardUserYShift;
|
new_layout.bottom_screen.left = bottom_screen_left + cardboard_max_x_shift;
|
||||||
|
new_layout.bottom_screen.top =
|
||||||
|
bottom_screen_top + cardboard_max_y_shift + cardboard_user_y_shift;
|
||||||
|
|
||||||
// Set the X coordinates for the right eye and apply user X shift
|
// Set the X coordinates for the right eye and apply user X shift
|
||||||
newLayout.cardboard.top_screen_right_eye = newLayout.top_screen.left - cardboardUserXShift;
|
new_layout.cardboard.top_screen_right_eye = new_layout.top_screen.left - cardboard_user_x_shift;
|
||||||
newLayout.top_screen.left += cardboardUserXShift;
|
new_layout.top_screen.left += cardboard_user_x_shift;
|
||||||
newLayout.cardboard.bottom_screen_right_eye =
|
new_layout.cardboard.bottom_screen_right_eye =
|
||||||
newLayout.bottom_screen.left - cardboardUserXShift;
|
new_layout.bottom_screen.left - cardboard_user_x_shift;
|
||||||
newLayout.bottom_screen.left += cardboardUserXShift;
|
new_layout.bottom_screen.left += cardboard_user_x_shift;
|
||||||
newLayout.cardboard.user_x_shift = cardboardUserXShift;
|
new_layout.cardboard.user_x_shift = cardboard_user_x_shift;
|
||||||
|
|
||||||
// Update right/bottom instead of passing new variables for width/height
|
// Update right/bottom instead of passing new variables for width/height
|
||||||
newLayout.top_screen.right = newLayout.top_screen.left + top_screen_width;
|
new_layout.top_screen.right = new_layout.top_screen.left + top_screen_width;
|
||||||
newLayout.top_screen.bottom = newLayout.top_screen.top + top_screen_height;
|
new_layout.top_screen.bottom = new_layout.top_screen.top + top_screen_height;
|
||||||
newLayout.bottom_screen.right = newLayout.bottom_screen.left + bottom_screen_width;
|
new_layout.bottom_screen.right = new_layout.bottom_screen.left + bottom_screen_width;
|
||||||
newLayout.bottom_screen.bottom = newLayout.bottom_screen.top + bottom_screen_height;
|
new_layout.bottom_screen.bottom = new_layout.bottom_screen.top + bottom_screen_height;
|
||||||
|
|
||||||
return newLayout;
|
return new_layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<unsigned, unsigned> GetMinimumSizeFromLayout(Settings::LayoutOption layout,
|
std::pair<unsigned, unsigned> GetMinimumSizeFromLayout(Settings::LayoutOption layout,
|
||||||
|
@ -11,9 +11,9 @@ namespace Layout {
|
|||||||
|
|
||||||
/// Describes the horizontal coordinates for the right eye screen when using Cardboard VR
|
/// Describes the horizontal coordinates for the right eye screen when using Cardboard VR
|
||||||
struct CardboardSettings {
|
struct CardboardSettings {
|
||||||
float top_screen_right_eye;
|
u32 top_screen_right_eye;
|
||||||
float bottom_screen_right_eye;
|
u32 bottom_screen_right_eye;
|
||||||
float user_x_shift;
|
s32 user_x_shift;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Describes the layout of the window framebuffer (size and top/bottom screen positions)
|
/// Describes the layout of the window framebuffer (size and top/bottom screen positions)
|
||||||
@ -130,7 +130,7 @@ FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondar
|
|||||||
* @param layout frame layout to transform
|
* @param layout frame layout to transform
|
||||||
* @return layout transformed with the user cardboard settings
|
* @return layout transformed with the user cardboard settings
|
||||||
*/
|
*/
|
||||||
FramebufferLayout GetCardboardSettings(FramebufferLayout layout);
|
FramebufferLayout GetCardboardSettings(const FramebufferLayout& layout);
|
||||||
|
|
||||||
std::pair<unsigned, unsigned> GetMinimumSizeFromLayout(Settings::LayoutOption layout,
|
std::pair<unsigned, unsigned> GetMinimumSizeFromLayout(Settings::LayoutOption layout,
|
||||||
bool upright_screen);
|
bool upright_screen);
|
||||||
|
Loading…
Reference in New Issue
Block a user