%% WebGL: MATLAB’s New Graphics Rendering System
%
% MATLAB Graphics and App Building Blog
% Guest Writer: Maddie Moon
% Maddie first worked with the Graphics and App Building team during her Engineering Development Group (EDG) internship in 2023. After graduating college, she joined MathWorks full-time and eventually found her way to the Advanced Support Group (ASG). Through her role in ASG, Maddie continues to work with the Graphics and App Building team to ensure long-term customer success through work with customers, technical support, and the development teams. When she's not working with these teams, Maddie enjoys crocheting (and knitting!) and running around with Lucy, her dog.
%
% As you probably know by now, MATLAB graphics just got a major upgrade—R2025a marks the full shift in rendering to WebGL, our most robust and stable renderer yet.
% If you’ve ever run into a graphics crash and been told to “use software OpenGL” without really knowing why, you’re not alone. Our Technical Support team has seen thousands of cases like this over the years. With WebGL now behind all MATLAB graphics, those issues and workarounds are becoming a thing of the past.
% Today I’ll walk you through what this transition means, why it matters, and how it improves your MATLAB experience—whether you're building apps, creating charts, or have previously experienced low-level graphics issues.
%% Background
% To understand why this change matters, let’s take a quick look back.
% Before WebGL became the default in R2025a, MATLAB graphics underwent another major transformation in R2014b, which introduced a new graphics system featuring improved rendering, anti-aliasing, and object-oriented graphics handles . As MATLAB evolved, we recognized the opportunity to deliver a more  consistent experience across desktop and web platforms by advancing our technology.
% We needed a more web-friendly alternative—and that’s where WebGL comes in.
%
% WebGL isn’t brand new in R2025a. If you’ve used recent releases of MATLAB such as R2024b, you’ve already seen it in action: WebGL has been the renderer of choice for uifigure for a while now. You can even confirm this yourself by calling rendererinfo on an axes generated in a regular figure and a uiaxes generated in a uifigure:
% rendererinfo(axes)
% rendererinfo(uiaxes)
%
% What’s new in R2025a is that WebGL is now the default renderer across the board—bringing us one step closer to a unified, modern graphics experience in MATLAB.
%% Benefits of WebGL
% Now that we’ve covered the history, let’s talk about the WebGL transition.
% First, the visual differences between OpenGL and WebGL are minimal. As mentioned earlier, if you’ve used uifigure in recent releases, you’ve already seen WebGL in action—so the transition in R2025a may even go unnoticed.
% Under the hood, however, there are two significant benefits: stability and robustness.
% Stability: WebGL has dramatically reduced the number of graphics-related crashes we’ve seen in Technical Support. Since its introduction, we’ve had zero (that’s right, none!) crash cases tied to WebGL rendering, compared to hundreds involving OpenGL.
% Robustness: You no longer need to worry about choosing the right renderer for performance. WebGL just works, whether you’re on a desktop or in a browser exploring MATLAB Online. And when hardware rendering isn’t available, WebGL still maintains graphics smoothing—whereas before, you might see noticeably pixelated outputs with software rendering. This means your plots and charts will look cleaner, even on systems without a dedicated GPU.
% A quick aside: here’s an example of graphics smoothing in action in R2025a, using a simple sine curve. When MATLAB defaults to software rendering, graphics smoothing is maintained meaning that the lines will not appear as pixelated and choppy as you might see without graphics smoothing.
%
% More importantly, WebGL supports our long-term goal of delivering a unified, modern graphics experience across all MATLAB environments.
%% Changes to opengl commands
% Prior to R2025a, the opengl command provided information and control over the graphics renderer. With WebGL, manually changing the renderer is no longer necessary.  This includes startup options including -softwareopengl, -nosoftwareopengl, -softwareopenglmesa, and -noopengl.  These commands and flags currently warn users that they have no effect and will be removed.
%% Tips and Tricks for Troubleshooting
% Even with a more stable renderer, graphics issues can still pop up—so here are a few tips to help you troubleshoot WebGL-related problems in R2025a:
%
% When should I use rendererinfo?
% Use rendererinfo to check the current MATLAB session’s renderer information (for example, which graphics device is in use). This replaces the older opengl info command and is especially helpful when reporting graphics issues.  Use rendererinfo(target) to return information for a specific axes or standalone visualization.
%
% I used to use commands to force MATLAB to use software rendering, will those still work?
% As of R2024b, OpenGL-related startup options give a warning in MATLAB. In R2025a, these startup options have no effect and will error in the future.
% Here is an example of how you can avoid these warnings in R2025a if you frequently switch between releases and want to specify software rendering in your startup script:
% if verLessThan('matlab','25')
%     opengl software
% end
% How can I improve performance if I can’t switch to hardware rendering?
% If you experience any performance issues, the documentation recommends updating to the latest versions of your graphics drivers to ensure the best quality and performance of graphics. In MATLAB Online, you can also try assessing the current WebGL support.
%% Conclusion
% The transition to WebGL in R2025a marks a major step forward for MATLAB graphics—bringing greater stability, fewer crashes, and a more consistent experience across desktop and web.
% We know that any change can come with questions, and we’re here to help. Whether you’re troubleshooting a display issue, reporting a bug, or have any questions about our new features, the MathWorks Support team is always just a click (or call) away.
%
% Thanks for joining me on this deep dive into WebGL. We look forward to seeing the new graphics system in your charts and apps!