Add colour to the FPS Text, relocate vsync next to fps limit

if there are no limits on FPS it will remain white.
if vsync or fps limit are used and the fps is below the lower of the two limits then it will be coloured yellow, if we are at or above a limit then it will be green.
Clicking the fps text opens the preferences panel with limit framerate highlighted.
master
Beq 2024-11-08 22:33:08 +00:00
parent 3859398982
commit 49cd03d550
4 changed files with 104 additions and 30 deletions

View File

@ -315,7 +315,7 @@ void FSFloaterPerformance::draw()
args["FPSCAP"] = llformat("%02u", (U32)fpsCap);
args["FPSTARGET"] = llformat("%02u", (U32)targetFPS);
S32 refresh_rate = gViewerWindow->getWindow()->getRefreshRate();
args["VSYNCFREQ"] = llformat("%02d", (U32)refresh_rate);
args["VSYNCFREQ"] = llformat("%03d", (U32)refresh_rate);
auto textbox = getChild<LLTextBox>("fps_warning");
// Note: the ordering of these is important.
// 1) background_yield should override others

View File

@ -63,10 +63,12 @@
#include "llresmgr.h"
#include "llworld.h"
#include "llstatgraph.h"
#include "llurlaction.h"
#include "llviewermedia.h"
#include "llviewermenu.h" // for gMenuBarView
#include "llviewerparcelmgr.h"
#include "llviewerthrottle.h"
#include "llwindow.h"
#include "lluictrlfactory.h"
#include "lltoolmgr.h"
@ -304,6 +306,9 @@ bool LLStatusBar::postBuild()
mBoxBalance = getChild<LLTextBox>("balance");
mBoxBalance->setClickedCallback( &LLStatusBar::onClickBalance, this );
// <FS:Beq> show fpslimit reached in FPS status bar
getChild<LLTextBox>("FPSText")->setClickedCallback( std::bind(&LLUrlAction::executeSLURL, "secondlife:///app/openfloater/preferences?search=limit%20framerate", true));
mIconPresetsCamera = getChild<LLButton>( "presets_icon_camera" );
//mIconPresetsCamera->setMouseEnterCallback(boost::bind(&LLStatusBar::mIconPresetsCamera, this));
if (gSavedSettings.getBOOL("FSStatusBarMenuButtonPopupOnRollover"))
@ -483,7 +488,10 @@ bool LLStatusBar::postBuild()
mBalancePanel = getChild<LLPanel>("balance_bg");
mTimeMediaPanel = getChild<LLPanel>("time_and_media_bg");
// <FS:Beq> Make FPS a clickable button with contextual colour
mFPSText = getChild<LLTextBox>("FPSText");
// mFPSText = getChild<LLButton>("FPSText");
// </FS:Beq>
mVolumeIconsWidth = mBtnVolume->getRect().mRight - mStreamToggle->getRect().mLeft;
initParcelIcons();
@ -598,8 +606,60 @@ void LLStatusBar::refresh()
static LLCachedControl<bool> fsStatusBarShowFPS(gSavedSettings, "FSStatusBarShowFPS");
if (fsStatusBarShowFPS && mFPSUpdateTimer.getElapsedTimeF32() > 1.f)
{
static LLCachedControl<U32> max_fps(gSavedSettings, "FramePerSecondLimit");
static LLCachedControl<bool> limit_fps_enabled(gSavedSettings, "FSLimitFramerate");
static LLCachedControl<bool> vsync_enabled(gSavedSettings, "RenderVSyncEnable");
const auto FPS_below_limit_color = LLUIColorTable::instance().getColor( "Yellow" );
const auto FPS_limit_reached_color = LLUIColorTable::instance().getColor( "Green" );
const auto vsync_limit_reached_color = LLUIColorTable::instance().getColor( "Green" );
const auto FPS_uncapped_color = LLUIColorTable::instance().getColor( "White" );
const auto FPS_unfocussed_color = LLUIColorTable::instance().getColor( "Gray" );
mFPSUpdateTimer.reset();
mFPSText->setText(llformat("%.1f", LLTrace::get_frame_recording().getPeriodMedianPerSec(LLStatViewer::FPS)));
S32 vsync_freq=-1;
auto fps = LLTrace::get_frame_recording().getPeriodMedianPerSec(LLStatViewer::FPS);
if (gViewerWindow && gViewerWindow->getWindow())
{
vsync_freq = gViewerWindow->getWindow()->getRefreshRate();
}
mFPSText->setText(llformat("%.1f", fps ));
// if background, go grey, else go white unless we have a cap (checked next)
auto fps_color = FPS_uncapped_color;
if ((gViewerWindow && !gViewerWindow->getWindow()->getVisible())
|| !gFocusMgr.getAppHasFocus())
{
fps_color = FPS_unfocussed_color;
}
else
{
if (limit_fps_enabled && max_fps > 0)
{
if (fps >= max_fps-1) // allow a small undershoot
{
fps_color = FPS_limit_reached_color;
}
else
{
fps_color = FPS_below_limit_color;
}
}
// use vsync if enabled and the freq is lower than the max_fps
if (vsync_enabled && vsync_freq > 0)
{
if ( !limit_fps_enabled || (limit_fps_enabled && vsync_freq < (S32)max_fps) )
{
if (fps >= vsync_freq -1 )
{
fps_color = vsync_limit_reached_color;
}
else
{
fps_color = FPS_below_limit_color;
}
}
}
}
mFPSText->setColor(fps_color);
}
// </FS:Ansariel>

View File

@ -1110,6 +1110,47 @@ If you do not understand the distinction then leave this control alone."
top_pad="6"
width="256"/>
<check_box
control_name="FSLimitFramerate"
height="16"
initial_value="true"
label="Limit Framerate"
layout="topleft"
left_delta="0"
name="FSLimitFramerate"
tool_tip="Limits the framerate to a user defined value. Can reduce GPU/CPU power consumption and heat."
top_pad="2"
width="256"/>
<slider
enabled_control="FSLimitFramerate"
control_name="FramePerSecondLimit"
decimal_digits="0"
follows="left|top"
height="16"
increment="1"
label="FPS:"
label_width="30"
layout="topleft"
max_val="360"
min_val="15"
name="MaxFPS"
left_delta="240"
mouse_opaque="true"
show_text="true"
width="200" />
<check_box
control_name="RenderVSyncEnable"
height="16"
initial_value="false"
label="Limit Framerate to monitor frequency (VSync)"
layout="topleft"
left="15"
top_pad="2"
name="vsync"
tool_tip="Synchronizes the frame rate to the refresh rate of the monitor, can result in increased stutter and input lag."
width="315" />
<text
type="string"
length="1"
@ -1294,33 +1335,6 @@ If you do not understand the distinction then leave this control alone."
name="RenderUnloadedAvatars"
top_pad="2"
width="256"/>
<check_box
control_name="FSLimitFramerate"
height="16"
initial_value="true"
label="Limit Framerate"
layout="topleft"
left_delta="0"
name="FSLimitFramerate"
top_pad="2"
width="256"/>
<slider
enabled_control="FSLimitFramerate"
control_name="FramePerSecondLimit"
decimal_digits="0"
follows="left|top"
height="16"
increment="1"
label="FPS:"
label_width="30"
layout="topleft"
max_val="360"
min_val="15"
name="MaxFPS"
left_delta="240"
mouse_opaque="true"
show_text="true"
width="200" />
<check_box
follows="top|left"
layout="topleft"

View File

@ -385,7 +385,7 @@
height="16"
width="42"
halign="center"
tool_tip="Frames per second"
tool_tip="Frames per second (click to adjust limit)"
wrap="false">
200.0
</text>