# Retained mode

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Retained_mode
> Markdown URL: https://mediated.wiki/source/Retained_mode.md
> Source: https://en.wikipedia.org/wiki/Retained_mode
> Source revision: 1319304654
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{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](/source/application_programming_interface) in graphics libraries,<ref>{{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}}</ref> in which

* the [graphics library](/source/graphics_library), instead of the [client](/source/Client_(computing)), retains the scene (complete [object model](/source/object_model) of the [rendering primitive](/source/rendering_primitive)s) to be [rendered](/source/Rendering_(computer_graphics)) and
* the [client](/source/Client_(computing)) calls into the [graphics library](/source/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](/source/graphics_library).<ref name="rm_vs_im">{{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 = 
}}</ref> It does not preclude the use of [double-buffering](/source/Multiple_buffering).<ref>{{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}}</ref>

[Immediate mode](/source/Immediate_mode_(computer_graphics)) is an alternative approach. Historically, retained mode has been the dominant style in [GUI](/source/Graphical_user_interface) libraries;<ref name="feldmeier">{{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.
}}{{Dead link|date=October 2025 |bot=InternetArchiveBot }}</ref> however, both can coexist in the same library and are not necessarily exclusionary in practice.<ref>{{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}}</ref>

==Overview==
thumb|right|Schematic explanation of a retained mode graphics API

In retained mode the [client](/source/Client_(computing)) calls do not directly cause actual rendering, but instead update an [abstract internal model](/source/Abstract_data_type) (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.<ref name="rm_vs_im" />

Some techniques to optimize rendering include:

* managing [double buffering](/source/double_buffering)<ref>{{Cite web
| title = OpenGL double buffering
| access-date = 7 May 2020
| url = https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glXSwapBuffers.xml
}}</ref><ref>{{Cite web
| title = DirectX double buffering
| access-date = 7 May 2020
| url = https://docs.microsoft.com/en-us/windows-hardware/drivers/display/flipping
}}</ref>
* treatment of [hidden surfaces](/source/Hidden-surface_determination) by [backface culling](/source/Back-face_culling)<ref>{{Cite web
| title = OpenGL face culling
| access-date = 7 May 2020
| url = https://www.khronos.org/opengl/wiki/Face_Culling
}}</ref>/[occlusion culling](/source/occlusion_culling) ([Z-buffering](/source/Z-buffering))<ref>{{Cite web
| title = DirectX occlusion culling
| access-date = 7 May 2020
| url = https://docs.microsoft.com/en-us/windows/win32/direct3d12/predication-queries
}}</ref>
* 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](/source/OpenGL).{{dubious|date=November 2021}}{{Failed verification|date=November 2021}}<ref>{{Cite web
| title = OpenGL
| access-date = 4 May 2020
| url = https://www.opengl.org/
}}</ref> OpenGL has immediate mode functions that can use previously defined server side objects ([textures](/source/Texture_mapping), [vertex buffer](/source/Vertex_buffer_object)s and [index buffer](/source/index_buffer)s, [shader](/source/shader)s, etc.) without resending unchanged data.<ref>{{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}}</ref><ref>{{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}}</ref>

Examples of retained mode rendering systems include [Windows Presentation Foundation](/source/Windows_Presentation_Foundation),<ref name="rm_vs_im" /> [SceneKit](/source/SceneKit) on macOS,<ref name="book_iOS">{{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
}}</ref> and [PHIGS](/source/PHIGS).

thumb|right|Schematic explanation of an immediate mode graphics API in contrast

==See also==
* [Compositing window manager](/source/Compositing_window_manager)
* [Scene graph](/source/Scene_graph)

==References==
{{Reflist}}

{{DEFAULTSORT:Retained Mode}}
Category:Computer graphics
Category:3D computer graphics

---
Adapted from the Wikipedia article [Retained mode](https://en.wikipedia.org/wiki/Retained_mode) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Retained_mode?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
