{{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,<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, 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.<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.<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 is an alternative approach. Historically, retained mode has been the dominant style in GUI 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 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.<ref name="rm_vs_im" />
Some techniques to optimize rendering include:
* managing 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 by backface 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 (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.{{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, vertex buffers and index buffers, shaders, 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,<ref name="rm_vs_im" /> 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.
thumb|right|Schematic explanation of an immediate mode graphics API in contrast
==See also== * Compositing window manager * Scene graph
==References== {{Reflist}}
{{DEFAULTSORT:Retained Mode}} Category:Computer graphics Category:3D computer graphics