Retained mode
{{Short description|Graphics libraries API design pattern}}
{{More citations needed|date=September 2014}}
Retained mode in computer graphics is a major pattern of API design in graphics libraries,{{Cite book|last=Jin|first=Zhefan|title=2006 10th International Conference on Computer Supported Cooperative Work in Design |chapter=Retained-Mode Parallel Graphics Rendering for Cooperative Design Environments |date=May 2006|chapter-url=https://ieeexplore.ieee.org/document/4019178?section=abstract|pages=1–6|doi=10.1109/CSCWD.2006.253142|isbn=1-4244-0164-X|s2cid=5825966}} in which
- the graphics library, instead of the client, retains the scene (complete object model of the rendering primitives) to be rendered and
- the client calls into the graphics library do not directly cause actual rendering, but make use of extensive indirection to resources, managed{{snd}} thus retained{{snd}} by the graphics library.{{Cite web
| title = Retained Mode Versus Immediate Mode
| work = Win32 apps
| author = Quinn Radich
| publisher = Microsoft
| date = May 30, 2018
| access-date = 21 December 2019
| url = https://docs.microsoft.com/en-us/windows/win32/learnwin32/retained-mode-versus-immediate-mode
| quote =
}} It does not preclude the use of double-buffering.{{Cite web |last=stevewhims |title=Predication queries - Win32 apps |url=https://learn.microsoft.com/en-us/windows/win32/direct3d12/predication-queries |access-date=2022-12-09 |website=learn.microsoft.com |language=en-us}}
Immediate mode is an alternative approach. Historically, retained mode has been the dominant style in GUI libraries;{{Cite web
| title = GUI Programming
| first = Alex
| last = Feldmeier
| work = UWP Computer Science and Software Engineering Technical Report
| date = October 12, 2013
| access-date = 22 December 2019
| url = http://people.uwplatt.edu/~yangq/CSSE411/csse411-materials/f13/feldmeiera-gui%20_programming.doc
| language =
| quote = Retained mode has been the standard for years. Just about every GUI is in retained mode.
}} however, both can coexist in the same library and are not necessarily exclusionary in practice.{{Cite web|last=QuinnRadich|title=Retained Mode Versus Immediate Mode - Win32 apps|url=https://docs.microsoft.com/en-us/windows/win32/learnwin32/retained-mode-versus-immediate-mode|access-date=2020-08-21|website=docs.microsoft.com|language=en-us}}
Overview
File:Retail-mode-graphics-api.png
In retained mode the client calls do not directly cause actual rendering, but instead update an abstract internal model (typically a list of objects) which is maintained within the library's data space. This allows the library to optimize when actual rendering takes place along with the processing of related objects.
Some techniques to optimize rendering include:
- managing double buffering{{Cite web
| title = OpenGL double buffering
| access-date = 7 May 2020
| url = https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glXSwapBuffers.xml
| title = DirectX double buffering
| access-date = 7 May 2020
| url = https://docs.microsoft.com/en-us/windows-hardware/drivers/display/flipping
}}
- treatment of hidden surfaces by backface culling{{Cite web
| title = OpenGL face culling
| access-date = 7 May 2020
| url = https://www.khronos.org/opengl/wiki/Face_Culling
}}/occlusion culling (Z-buffering){{Cite web
| title = DirectX occlusion culling
| access-date = 7 May 2020
| url = https://docs.microsoft.com/en-us/windows/win32/direct3d12/predication-queries
}}
- only transferring data that has changed from one frame to the next from the application to the library
Example of coexistence with immediate mode in the same library is OpenGL.{{dubious|date=November 2021}}{{Failed verification|date=November 2021}}{{Cite web
| title = OpenGL
| access-date = 4 May 2020
| url = https://www.opengl.org/
}} OpenGL has immediate mode functions that can use previously defined server side objects (textures, vertex buffers and index buffers, shaders, etc.) without resending unchanged data.{{Cite web|date=2013-08-19|title=OpenGL Driver Support|url=https://developer.nvidia.com/opengl-driver|access-date=2020-08-21|website=NVIDIA Developer|language=en}}{{Cite web|date=2011-07-19|title=OpenGL - The Industry's Foundation for High Performance Graphics|url=https://www.khronos.org/opengl/|access-date=2020-08-21|website=The Khronos Group|language=en}}
Examples of retained mode rendering systems include Windows Presentation Foundation, SceneKit on macOS,{{Cite book
| title = iOS and macOS Performance Tuning: Cocoa, Cocoa Touch, Objective-C, and Swift
| first = Marcel
| last = Weiher
| publisher = Addison-Wesley Professional
| date = Feb 24, 2017
| access-date = 22 December 2019
| url = https://books.google.com/books?id=1kY2DgAAQBAJ&q=retained%20mode%20APIs
| language =
| quote = SceneKit and SpriteKit on the other hand are retained-mode APIs
| isbn = 9780133085532
}} and PHIGS.