In OpenGL, the GPU has 2 rendering methods
- On-screen Rendering: Renders On the Screen buffer currently used for display
- Off-screen Rendering: Creates a new buffer outside the current Screen buffer for Rendering
Off-screen rendering is a performance drain
- Need to create a new buffer;
- In the whole process of off-screen rendering, the context needs to be changed several times, first from the current Screen (on-screen) to off-screen (off-screen); When the off-screen rendering is finished, the rendering results of the off-screen buffer are displayed on the screen, and the context needs to be switched from off-screen to the current screen.
What actions trigger an off-screen rendering?
- ShouldRasterize = YES;
- Mask, layer.mask;
- Rounded corners, and layer.masksToBounds = YES, layer.cornerRadius > 0;
- Consider using CoreGraphics to draw rounded corners, or ask an artist to provide rounded images.
- Shadow, layer.shadowxxx;
- If layer.shadowPath is set, off-screen rendering will not occur.