How can I reduce uifigure lag when using software OpenGL?
12 次查看(过去 30 天)
显示 更早的评论
I am maintaining a MATLAB application with a figure-based UI. I want to transition to uifigures (for the better uitable support), but ran into a problem: on my laptop a uifigure-based UI runs fine, but on the production machine the uifigure version runs unbearably slowly.
I traced this to the production machine using software OpenGL. Here are reproduction steps:
- Start MATLAB 2020b with the -softwareopengl flag.
- Run the following code to create a uifigure window with an axes that you can zoom in and out of using the mouse scroll wheel:
fig = uifigure();
g = uigridlayout(fig);
g.RowHeight = {'1x'};
g.ColumnWidth = {'1x'};
ax = uiaxes(g);
ax.Interactions = [];
ax.Toolbar = [];
ax.Layout.Row = 1;
ax.Layout.Column = 1;
fig.WindowScrollWheelFcn = {@windowScrollCallback ax};
function windowScrollCallback(~, event, ax)
disp('windowScrollCallback')
xy = ax.CurrentPoint;
x = xy(1,1);
y = xy(1,2);
xl = ax.XLim;
yl = ax.YLim;
if xl(1) <= x && x <= xl(2) && yl(1) <= y && y <= yl(2)
zoomRatio = 1.2 ^ event.VerticalScrollCount;
xl = (xl - x) * zoomRatio + x;
ax.XLim = xl;
end
end
- Zoom in and out using the scroll wheel, while moving the mouse around in the axes.
I have noticed the following things that might help identify the cause of the lag:
- The lag is in between moving the scroll wheel and the callback running; after moving the mouse and scrolling a lot, it can take tens of seconds for the scroll events to finish arriving.
- I have noticed that keeping the mouse perfectly still does not cause lag, so it is definetly related to mouse movement.
- Running the profiler shows that ~95% of CPU time is spent in an internal function ObjectPicker.getHierarchy.
2 个评论
Dolon Mandal
2023-9-21
The issue you are experiencing with the slow performance of the uifigure-based UI on the production machine, specifically related to mouse scroll events, is likely due to the use of software OpenGL. This can cause performance degradation, especially when interacting with graphics-intensive components like axes.
To address this issue, you can try disabling hardware acceleration for the uifigure window by setting the 'Renderer' property to 'painters'. This will force MATLAB to use the software rendering pipeline, which might improve the performance on the production machine.
fig = uifigure('Renderer', 'painters');
Randy Miles
2024-4-2
What version of Matlab supports these options? I'm running 2020b, and get this error:
>> fig = uifigure('Renderer', 'painters');
Error using appwindowfactory
Functionality not supported with figures created with the uifigure function. For more information, see Graphics Support in App
Designer.
Error in matlab.ui.internal.uifigureImpl (line 47)
window = appwindowfactory('WindowStyle','normal',...
Error in uifigure (line 26)
window = matlab.ui.internal.uifigureImpl(varargin{:});
回答(1 个)
Jacob Mathew
2025-6-6
Hey,
In addition to @Dolon Mandal suggestion of changing the Open GL renderer option, I would also check out the following documentation guide that details graphics performances, requirements and how to set necessary settings too:
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!