Fact-checked by Grok 2 weeks ago

Retained mode

Retained mode is a in where the application declaratively defines and maintains a , such as a , representing the graphical , while the graphics library automatically manages rendering, updates, and display in response to modifications. In contrast to immediate mode, where the application issues explicit procedural drawing commands for each frame and must resend all geometric data even for minor changes, retained mode stores the scene model in memory on the client or server side, minimizing redundant data transfers between the CPU and GPU. This approach allows the library to handle optimizations like incremental updates and automatic redrawing, reducing the developer's burden for low-level rendering details. Retained mode offers advantages in simplicity and efficiency for complex, dynamic scenes, as it abstracts away frame-by-frame command issuance and supports features like event handling for interactions without manual re-rendering. However, it can consume more due to the persistent scene representation and may limit fine-grained control over the rendering pipeline compared to immediate mode. Common examples include (SVG), where the browser retains and renders the scene description without per-frame commands, and Windows Presentation Foundation (WPF), which uses a retained-mode model for building and updating visual elements. Retained mode has been influential in graphical user interfaces (GUIs) and vector-based rendering systems, enabling scalable displays across platforms.

Fundamentals

Definition

Retained mode is a declarative in application programming interfaces () where the application constructs and maintains a persistent model, typically comprising data structures representing objects, transformations, and properties, which the graphics library utilizes for rendering. In this approach, the application specifies an entire that is built within the graphics system, allowing the library to store and manage this model across multiple frames rather than executing commands immediately. The core concept of retained mode involves the graphics library retaining control over the scene state, thereby automatically managing updates, view frustum culling, and redrawing operations in response to modifications in the model. This retention enables optimizations such as traversal for hierarchical relationships and efficient , as the library handles the rendering independently of per-frame application input. A representative example of retained mode involves constructing a scene using primitives like shapes, lines, or hierarchical nodes that persist beyond a single frame, as seen in APIs such as Windows Presentation Foundation (WPF), where the application adds, modifies, or removes elements from the maintained scene model. In contrast to immediate mode, retained mode emphasizes model persistence over procedural command issuance per frame.

Key Characteristics

Retained mode graphics systems maintain a persistent by storing and managing a hierarchical model of the scene, such as a (DAG), within the subsystem itself. This model persists across rendering cycles and is updated in response to application modifications, scene description from the act of rendering and enabling the system to handle display updates autonomously. Automatic optimization is a core feature, achieved through mechanisms like dirty flagging, which marks modified scene elements to facilitate partial updates rather than full re-renders. The system traverses the hierarchical structure to identify and process only affected regions, incorporating techniques such as and level-of-detail adjustments during rendering. Event-driven modifications further enhance efficiency by propagating changes through the structure and triggering optimizations only as needed. At its abstraction level, retained mode employs high-level declarative syntax, allowing developers to define the desired scene composition—such as adding or removing structural nodes—without specifying per-frame rendering commands. This paradigm shifts the burden of low-level details, like transformation matrices or drawing orders, to the graphics system, promoting and ease of scene manipulation.

Comparison to Immediate Mode

Core Differences

Retained mode and immediate mode represent two fundamental paradigms in graphics , differing primarily in their approach to scene description and rendering execution. Retained mode operates in a declarative manner, where the application constructs and maintains a persistent model of the scene—often structured as a —that encapsulates the , transformations, and other elements. This model is built once and subsequently updated incrementally as needed, allowing the graphics library to manage rendering based on the current state of the model. In contrast, immediate mode is imperative, requiring the application to issue a complete sequence of commands for every , effectively re-describing the entire scene from scratch without any retained structure. A core distinction lies in state handling between the two modes. In retained mode, the graphics library retains a full, persistent of the model, enabling efficient incremental modifications such as adding, removing, or altering elements without respecifying unaffected parts. This facilitates optimizations like or batching that the library can perform automatically on the stored data. Immediate mode, however, maintains no such persistent ; each command stream is stateless and self-contained, with the application bearing full responsibility for re-establishing all relevant states (e.g., transformations, materials) in every rendering pass, which can lead to redundant computations but ensures reproducibility across frames. Control flow also diverges significantly, affecting the level of and developer oversight. Retained mode delegates key rendering decisions—such as traversal order, optimization strategies, and even parallelization opportunities—to the graphics library, which analyzes the scene model to determine the most efficient execution path. This reduces application-side complexity but limits fine-grained control over the rendering . Conversely, immediate mode grants the application complete authority over the sequence and timing of commands, allowing direct manipulation of the rendering process for custom effects or algorithms, though at the cost of increased code verbosity and potential performance overhead from repeated state setups.

Rendering Processes

In retained mode rendering, the process begins with traversing the , a hierarchical representing the graphical elements, to determine the visible components for output. During traversal, transformations such as rotations, scales, and translations are applied hierarchically from parent to child nodes, inheriting coordinate systems to position elements accurately. Invisible elements are culled through optimizations like view-frustum culling or occlusion culling to exclude them from further processing, followed by the remaining primitives into the final image. Updates to the scene propagate via change notifications, where modifications to the graph trigger selective re-traversals and re-renders rather than full rebuilds. In contrast, immediate mode rendering involves issuing a sequence of draw calls directly to the for each frame, specifying vertices, attributes, and primitives on-the-fly without maintaining any persistent scene representation. Commands such as glBegin and glEnd in legacy enclose vertex data, which is processed immediately through the pipeline stages including , clipping, and rasterization, resulting in output to the . Since no state or geometry is retained between frames, the entire visual content must be recreated from application logic in every rendering cycle, leading to repeated command issuance. These procedural differences yield distinct performance implications: retained mode facilitates batched updates by leveraging the for efficient change detection and partial re-renders, optimizing for complex, static scenes. Immediate mode, however, provides low-overhead execution suitable for dynamic scenarios, as it avoids the cost of graph maintenance and allows direct control over per-frame drawing without intermediate storage.

Historical Development

Origins in Early Graphics

The concept of retained mode graphics originated in the early 1960s with pioneering interactive systems designed to overcome the constraints of contemporary hardware, such as limited memory and processing power on machines like the TX-2 computer. Ivan Sutherland's system, developed in 1963 as part of his doctoral thesis, introduced a foundational retained structure through its use of a "display file" to store spot coordinates for vector-based drawings. This file, occupying up to 32,000 words in memory, held graphical primitives like lines and circles as sequences of display spots, enabling the system to regenerate the image incrementally without requiring full recomputation from the source data each time. The retained approach was essential for interactivity, as it allowed real-time manipulation via a —users could select and modify elements, with the ring-structured topological data (linking points, lines, and constraints) automatically updating connected parts of the scene. During the , retained mode concepts evolved in response to growing demands for handling more complex scenes in resource-constrained environments, where constant redrawing would overwhelm slow CPUs and vector displays. Systems built on Sketchpad's ideas, such as those in and applications, emphasized retaining scene descriptions to support editing and reuse, minimizing redraw cycles on hardware with display rates limited to around 100,000 spots per second. This motivation stemmed from the need to manage interactive efficiently, as immediate redrawing of entire scenes was impractical given memory sizes under 64K words and the absence of dedicated graphics accelerators. By the 1980s, these early innovations influenced standardized libraries like the (GKS), formalized as ISO 7942 in 1985, which incorporated retained structures through workstation-independent segment storage. GKS allowed graphical output primitives to be grouped into reusable segments, stored separately from immediate output commands, facilitating device-independent portability and efficient updates for complex 2D across varying hardware. This was followed by the Programmer's Hierarchical Interactive Graphics System (PHIGS), published as ISO/IEC 9592 in 1989, which introduced retained hierarchies for 3D scenes, enabling structured storage and traversal for interactive 3D graphics.

Evolution in Modern APIs

In the 1990s, retained mode gained prominence in 3D graphics through its integration into APIs like Open Inventor, developed by Silicon Graphics Inc. (SGI) and released in 1991, which employed scene graphs to model and retain complex 3D scenes for efficient rendering and interaction. Similarly, , announced in 1996 and first released in 1998 by , adopted a retained mode approach using hierarchical scene graphs composed of nodes such as BranchGroup, TransformGroup, and Shape3D to manage persistent 3D objects and automate rendering updates. These APIs built on earlier concepts like those in GKS but emphasized object-oriented structures for higher-level abstraction in professional 3D applications. Parallel to advancements in , retained mode influenced paradigms during the same decade, as seen in Java Swing, introduced in 1997 as part of the Java Foundation Classes and fully integrated into 1.2 in 1998, where a of retained component objects (e.g., panels, buttons) is maintained by the to handle and repainting dynamically. , conceived in 1990 by Haavard and Eirik Chambe-Eng, with Trolltech founded in 1994, first publicly released in 1995, and reaching version 1.0 in 1996, similarly utilized a retained widget-based model to construct and persist UI elements across cross-platform applications. By the late 1990s, this approach extended to web technologies with the HTML Document Object Model (DOM), standardized by the W3C in 1998, serving as a retained for document representation that enabled dynamic updates via scripting for interactive web UIs. In recent trends, retained mode has evolved toward hybrid models in game engines, exemplified by , launched in 2005, which employs a retained of GameObjects and components to maintain persistent world states while incorporating immediate-mode elements, such as its legacy IMGUI system, to optimize performance in real-time rendering scenarios. This balance allows developers to leverage retained structures for complex scene management alongside immediate commands for lightweight, frame-specific overlays, addressing performance demands in interactive environments.

Implementation Approaches

Scene Graph Structures

In retained mode graphics systems, the primary is a hierarchical node-based model that organizes elements into a tree-like representation, where encapsulate individual objects such as , lights, and cameras. Each maintains parent-child relationships that propagate transformations, like translations, rotations, and scalings, from parent to child, enabling efficient management of complex spatial hierarchies. Nodes in this model serve as containers for various components, including properties such as , attributes, and behavioral scripts, which define how objects interact within the . Traversal algorithms, typically depth-first, navigate the to apply these components during rendering, accumulating state changes like transformation matrices as they descend the tree. A common variant of the basic is the (DAG), which permits nodes to have multiple parents, facilitating shared subgraphs for elements like repeated geometries in a . This DAG approach maintains acyclicity to prevent infinite loops while allowing modifications to shared nodes to propagate efficiently across instances.

API

Retained mode APIs leverage established patterns to enable developers to construct, modify, and interact with scene representations efficiently, often building upon an underlying structure. These patterns promote modularity, automation of updates, and abstraction from low-level rendering details, allowing applications to focus on high-level scene description rather than explicit rendering commands. The is frequently used in retained mode APIs for constructing complex scene hierarchies through sequential operations, such as or factory methods that create and assemble nodes. For instance, developers might invoke functions like createNode() to instantiate a graphical element and addChild() to attach it to a , progressively building the retained model without directly managing memory or rendering states. This approach separates the logic from the representation, facilitating reusable and readable code for scene assembly. The observer pattern supports change propagation in retained mode systems by establishing dependencies where modifications to the model automatically notify and update dependent components, eliminating the need for manual redraws. When an application alters a —such as updating its or properties—the API's observer detects the change and triggers library-managed refreshes, ensuring the displayed output remains with the retained data. This pattern is integral to event-driven updates, enhancing without burdening the developer with explicit . Encapsulation in retained mode API design hides implementation details of the scene model, exposing only high-level operations that abstract away complexities like traversal algorithms or optimization routines. Nodes encapsulate properties such as transformations or attributes with default values and provide methods like attachEvent() for adding , allowing developers to manipulate the scene declaratively while the API internally manages rendering and consistency. This principle ensures that changes to the underlying do not affect application code, promoting maintainability and portability across hardware.

Advantages and Limitations

Benefits

Retained mode graphics APIs offer significant efficiency advantages for handling complex scenes by maintaining a persistent in memory, which enables incremental updates rather than full redraws each frame. This approach reduces computational overhead, as the system can optimize rendering through techniques such as view-frustum culling and management, avoiding unnecessary processing of unchanged elements. For instance, in scenarios involving hierarchical structures like directed acyclic graphs (DAGs), the retained model allows the graphics system to store and manipulate data locally on , minimizing data transfer and enabling scalable performance for large-scale visualizations. The declarative nature of retained mode simplifies development by integrating application logic with graphical data structures, making it easier to implement animations, interactions, and dynamic changes without manual . Developers specify "what" the scene should look like rather than "how" to draw it, with the handling initialization, , and cleanup automatically, which lowers the complexity of code for building and modifying persistent objects. Built-in optimizations, such as automatic repair of scene hierarchies and support for picking operations, further streamline workflows in libraries like Open Inventor or . Retained mode is particularly well-suited for applications requiring long-lived scenes, such as simulations, editors, or interactive tools, where the maintained graphical supports efficient updates, rendering, and user interactions over extended sessions. By retaining the model, the system facilitates persistence across frames, reducing redundancy in data resubmission and enabling seamless modifications without rebuilding the entire representation. This persistence model is especially beneficial in environments with limited computational resources, as it leverages the graphics system's intelligence to manage scene evolution.

Drawbacks

Retained mode approaches introduce significant overhead in simple or static scenarios, where maintaining a persistent model requires additional allocation and management complexity that may not be justified for basic rendering tasks. For instance, the need to store a general-purpose model can lead to higher requirements compared to immediate mode alternatives, which avoid such persistent data structures. This overhead becomes particularly evident in applications with minimal dynamic changes, where the retained system's adds unnecessary processing without proportional benefits. Debugging retained mode implementations poses challenges due to the opacity of the underlying library management, which often conceals low-level rendering details and state transitions from developers. In systems like 3D, the abstraction hides intricate stages and interactions, such as layer filtering and state sets, making it difficult to bottlenecks or issues in the retained state. This lack of transparency can prolong troubleshooting, as developers must rely on specialized profiling tools to uncover hidden inefficiencies rather than directly inspecting rendering commands. Retained mode offers less flexibility for fine-tuning low-level rendering, especially in performance-critical applications like games, where the API's imposed model restricts direct optimizations and hardware-specific adjustments. By encapsulating the and update logic, retained APIs limit developer control over immediate drawing commands, potentially hindering the achievement of high frame rates or custom rendering pipelines required for interactive simulations. This rigidity contrasts with the direct command issuance in immediate mode, which allows for targeted tweaks but at the cost of manual .

Applications and Examples

In 3D Graphics Libraries

In 3D graphics libraries, retained mode is employed to maintain persistent scene representations, allowing efficient management of complex geometries and transformations without recomputing them each frame. While low-level APIs like primarily operate in immediate mode, extensions such as display lists and vertex buffer objects (VBOs) introduce retained elements by storing and commands on the GPU for , reducing CPU overhead in rendering pipelines. For instance, display lists compile commands into a server-side list that can be called multiple times, providing a form of retained rendering for static scenes, though they were deprecated in modern core profiles in favor of more flexible VBOs. In contrast, higher-level libraries like Open Inventor fully embrace retained mode through a hierarchical structure, where nodes representing geometries, properties, and groups are retained and traversed for rendering, enabling easy manipulation of 3D models via C++ objects built atop . This approach supports shared instancing and dynamic updates to the graph without full redraws, making it suitable for interactive 3D applications. Game engines exemplify retained mode in practical 3D contexts, such as Unity's GameObject , which forms a retained for organizing assets, components, and behaviors like physics simulations and . Developers build and modify this persistent structure at , with the engine automatically handling , rendering, and updates to maintain in dynamic environments. Similarly, utilizes retained mode in its mesh drawing pipeline, preparing scene draws in advance via actor components that retain state for efficient GPU submission. In / applications, retained mode proves essential for persistent environments, as seen in Unreal Engine's components, which maintain models, interactions, and spatial data across frames to support immersive, experiences without latency-inducing recomputations. This retained persistence ensures stable tracking and rendering of virtual objects overlaid on real-world spaces, enhancing user immersion in scenarios like architectural visualization or training simulations.

In User Interface Frameworks

In user interface frameworks, retained mode refers to a where the framework maintains a persistent, hierarchical representation of UI elements—typically as a of objects or nodes—that persists across rendering cycles. This model allows for efficient incremental updates, where changes to the UI trigger targeted re-renders rather than full redraws, contrasting with immediate mode approaches that require re-specifying the entire UI each frame. Retained mode is prevalent in modern UI frameworks because it simplifies developer workflows by handling , , and rendering optimizations internally, enabling complex, interactive applications with minimal boilerplate for visual persistence. Windows Presentation Foundation (WPF), Microsoft's vector-based framework for Windows desktop applications, exemplifies retained mode through its element tree structure. Developers define UI hierarchies using XAML markup or code-behind, creating a logical tree of elements that WPF retains in memory. This tree is traversed for layout, rendering, and input handling, with the framework automatically managing dirty regions for partial updates—such as repainting only affected areas during animations or data bindings. For instance, when a changes, WPF's property system notifies the layout engine, which recomputes and renders only the impacted subtree, leveraging via for high-performance visuals. This approach reduces developer overhead for tasks like hit-testing and scene management, making it suitable for data-driven applications like . Qt, a cross-platform C++ framework widely used for desktop and embedded UIs, employs retained mode in both its widget-based and declarative () modules. In Qt Widgets, UI components like buttons and panels form a persistent object hierarchy managed by the QApplication , where updates propagate through for incremental rendering via QPainter or native backends. , Qt's QML-based system for fluid, graphics-intensive interfaces, uses a retained : developers declare item trees in QML, and the framework builds a node-based (e.g., QSGGeometryNode for ) that persists between frames. This enables optimizations like batched draw calls—reducing state changes from dozens to a handful for lists or animations—and off-thread rendering for smoother performance on resource-constrained devices. Retained mode in Qt supports diverse applications, from automotive dashboards to productivity tools, by abstracting platform-specific rendering details. Other frameworks, such as Android's Jetpack Compose and Apple's , adapt retained mode principles in declarative paradigms. Jetpack Compose retains a composition tree of UI states, recomposing only changed nodes via a snapshot-based diffing process. Similarly, SwiftUI maintains a render tree derived from declarative view descriptions, preserving identity across updates to minimize redraws and support animations. These implementations prioritize reactivity, where changes automatically propagate through the retained structure, fostering scalable UIs for mobile and cross-platform development while inheriting the efficiency of partial rendering.

References

  1. [1]
    Retained Mode Versus Immediate Mode - Win32 apps
    Aug 23, 2019 · Retained-mode APIs store a scene model, while immediate-mode APIs do not. Retained-mode APIs are simpler but less flexible, and can have higher ...Missing: definition | Show results with:definition
  2. [2]
    None
    ### Summary of Retained Mode and Immediate Mode in Graphics APIs (from CS 418 WebGL Lecture Slides)
  3. [3]
    [PDF] Programming with WebGL Part 1: Background Objectives Retained ...
    Retained vs. Immediate Mode. Graphics. • Immediate. - Geometry is drawn when CPU sends it to GPU. - All data needs to be resent even if little changes.
  4. [4]
    The Design of a Parallel Graphics Interface - ACM Digital Library
    In a retained-mode API, the application first specifies an entire scene that is built on the graphics system and subsequently re- quests the scene to be ...
  5. [5]
    Gaming Graphics: The Road to Revolution - ACM Queue
    May 5, 2004 · • Retained-mode APIs implement a scenegraph or other organizing paradigm. A scenegraph encodes spatial or logical relationships and hierarchies ...
  6. [6]
    [PDF] The svgl toolkit: enabling fast rendering of rich 2D graphics - Hal-Inria
    We describe these two families of APIs in this section. 2.1 3D Retained-Mode Graphics APIs. Retained-mode graphics packages are defined in [8], p. 293: ”It ...
  7. [7]
    [PDF] The Design of a Parallel Graphics Interface
    In a retained-mode API, the application first specifies an entire scene that is built on the graphics system and subsequently re- quests the scene to be ...
  8. [8]
    [PDF] Distributed OpenSceneGraph - UiT Munin
    A scene graph is a hierarchical data structure used to store, organize and manipulate graphics' scenes in retained mode graphics toolkits. ... its DIRTY flag ...
  9. [9]
    [PDF] Retained Mode Graphics Two approaches to graphics
    Retained Mode Graphics. Two approaches to graphics. ❚ Say ´howµ. ❙ Immediate mode: explicit commands. ❚ Say ´whatµ. ❙ Retained mode: define and change model ...
  10. [10]
    Scene Graph Basics
    The Java 3D renderer incorporates all graphics state changes made in a direct path from a scene graph root to a leaf object in the drawing of that leaf object.
  11. [11]
    [PDF] The OpenGL Graphics System: A Specification - Khronos Registry
    For the most part, OpenGL provides an immediate-mode interface, meaning that specifying an object causes it to be drawn. A typical program that uses OpenGL ...
  12. [12]
    [PDF] IVAN EDWARD SUTHERLAND B.S., Carnegie Institute of ...
    Sketchpad also makes it easy to draw highly repetitive or highly accurate drawings and to change drawings previously- drawn with it. The many drawings in this.Missing: graphics | Show results with:graphics
  13. [13]
    [PDF] Sketchpad: A man-machine graphical communication system
    Ivan Sutherland's Sketchpad is one of the most influential computer pro- grams ever written by an individual, as recognized in his citation for the Tur-.
  14. [14]
    [PDF] graphical kernel system (GKS) - NIST Technical Series Publications
    The graphical kernel system (GKS) is a set of basic functions for computer graphics programming, used by many graphics applications.
  15. [15]
    [PDF] Open Inventor™ C++ Reference Manual - TechPubs
    Include files are in Courier font. Key to Scene Graph Diagrams. Figure I-1 shows the symbols used in the scene graph diagrams that appear throughout this guide.
  16. [16]
    [PDF] The Java 3D™ API Specification - Oracle
    Feb 8, 2011 · This license allows and is limited to the creation and distribution of clean-room implementa- tions of this specification that (i) are complete ...Missing: 1990s | Show results with:1990s
  17. [17]
    [PDF] Scene graph - UCSD CSE
    A scene graph is a data structure for constructing 3D scenes, using a tree structure to represent scenes, with nodes connected together.
  18. [18]
    [PDF] Hierarchical Modeling and Scene Graphs - UT Computer Science
    The position of the figure is determined by 11 joint angles (two for the head and one for each other part). Display of the tree requires a graph traversal.
  19. [19]
    [PDF] A General Design Pattern for Programs of Scene Graph and its ...
    This paper firstly focuses on the concept of the DPI design pattern in Section 2, presenting a three-layer structure and the connections between each layer.
  20. [20]
    Chapter 6. Creating Scene Graphs - TechPubs
    Scene Graph Traversals. A traversal is a method applied to (potentially) every node in a scene graph. Each node type responds in its own way by ...
  21. [21]
    [PDF] Graphics Pipeline in 2D - Cornell: Computer Science
    retained mode. •. Immediate mode: primitives drawn as they are specified. – advantages: simple, flexible. •. Retained mode: graphics system stores scene graph.<|control11|><|separator|>
  22. [22]
    [PDF] Advanced OpenGL Topics - UTK-EECS
    New images are created by reexecuting the display function and regenerating the primitives. • In retained mode, the primitives are stored in a display list. (in ...
  23. [23]
    GLU considered important - Page 2 - OpenGL - Khronos Forums
    Jan 24, 2010 · I thought that things would really go away, and, for my money, display lists are the best way to do retained mode graphics, and I rather like ...
  24. [24]
    [PDF] OpenGL 4.3 (Compatibility Profile) - February 14, 2013
    May 1, 2025 · ... display of framebuffer contents on a physical display device (including the transformation of individual framebuffer values by such ...
  25. [25]
    Scene Graphs - Open Inventor
    A scene graph consists of one or more nodes, each of which represents a geometry, property, or grouping object. Hierarchical scenes are created by adding ...Missing: SGI retained mode
  26. [26]
    Coin: Coin - Coin3D
    Coin is an OpenGL based, retained mode 3D graphics rendering library. It is implemented in C++ and publicly released with the source code open for your perusal.
  27. [27]
    Mesh Drawing Pipeline in Unreal Engine - Epic Games Developers
    The Mesh Drawing Pipeline is based around a concept of retained mode, where all scene draws are prepared in advance instead of building them every frame.<|separator|>
  28. [28]
    What is Windows Presentation Foundation - WPF
    ### Summary: WPF Rendering and Retained Mode
  29. [29]
  30. [30]
    Qt Quick Scene Graph - Qt Documentation
    Using a scene graph for graphics rather than the traditional imperative painting systems (QPainter and similar), means the scene to be rendered can be retained ...
  31. [31]
    SwiftUI is not an immediate-mode toolkit. In fact it's the exact ...
    Aug 26, 2023 · A retained mode GUI could technically be much faster, even if I have yet to see one in the wild.