# VRAM Upload Culling

#### <a class="anchor" id="bkmrk--1"></a>Description

This chapter briefly describes how to use scope masks for uploading only dedicated content to VRAM.

#### **VRAM Upload using Scope Masks**

content to VRAM in succeeding steps.

##### <a class="anchor" id="bkmrk--3"></a>VRAM Upload Policies

Refer to <span style="color: rgb(230, 126, 35);">[Startup and Asset Management](https://doc316en.candera.eu/books/candera/page/startup-and-asset-management-LUu)</span> for how to load scenes from assets and upload to VRAM with the default upload policy [Candera::ContentLoader::DefaultUploadPolicy](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_content_loader.html#aeac726ed65d6cdb88644422ec9c5b0d2a374ada9b6b3da92611ff8e707530b68f "creates scene data in System RAM and uploads the asset data to VRAM").

To implement VRAM upload culling with scopes, use [Candera::ContentLoader::NoVramUploadPolicy](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_content_loader.html#aeac726ed65d6cdb88644422ec9c5b0d2a8646da23e8199f2db5a21b82b1ae1978 "creates scene data in System RAM but does not upload anything to VRAM") and upload dedicated content based on scope masks later.

##### <a class="anchor" id="bkmrk--4"></a>Scoping Concept

Refer to <span style="color: rgb(230, 126, 35);">[Scoping](https://doc316en.candera.eu/books/scene-design/chapter/scoping)</span> how to use and configure scope masks in SceneComposer.

####   
**Code Example**

The following scene graph is a simple example where two parts of the scene have different scopes. Think about a use case where one part of the scene has to be displayed immediately after loading the scene and the second part has to be displayed only later in some special situations. To save time for uploading the content to VRAM not all of the content has to be uploaded immediately.

<div drawio-diagram="1944"><img src="https://doc316en.candera.eu/uploads/images/drawio/2023-02/drawing-4-1676867547.png" alt=""/></div>

<div class="contents" id="bkmrk--0"><div class="contents"><div class="textblock">  
</div></div></div>##### <a class="anchor" id="bkmrk--6"></a>Using NoVramUploadPolicy

Loading the scene from the asset has to be triggered without loading the content to VRAM.

```
using namespace Candera;

<a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_content_loader.html" title="Encapsulates routines for scene content handling.">ContentLoader</a>& contentLoader = <a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_content_loader.html#a8d2faf2ac0af84444a4de43845c2e03e">ContentLoader::GetInstance</a>();
<a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_content_loader.html#abcb5725d1db1cae643a7d2e9fed85b91">ContentLoader::BuildState</a> buildState = contentLoader.BuildSceneContext("Scene", <a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_content_loader.html#aeac726ed65d6cdb88644422ec9c5b0d2a8646da23e8199f2db5a21b82b1ae1978" title="creates scene data in System RAM but does not upload anything to VRAM">ContentLoader::NoVramUploadPolicy</a>);
if (buildState == <a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_content_loader.html#abcb5725d1db1cae643a7d2e9fed85b91ac464d449fddc8a968cacd4f660dbd097" title="Completed.">ContentLoader::Completed</a>) {
    <a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_scene_context.html" title="Encapsulates main objects that define a scene context an application can operate on. These objects are:">SceneContext</a>* sceneContext = contentLoader.GetSceneContext("Scene");
    <a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_scene.html" title="The class Scene represents a top level scene graph node. Multiple Scenes are allowed. A Scene can not be part of any other Scene. To render a Scene, at least one Camera must be part of this Scene and the Camera must have rendering enabled. A Scene can have more than one Camera. Note: Lights added to a Scene apply for that Scene only and do not affect 3D objects in any other Scene.">Scene</a>* scene = sceneContext-><a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_scene_context.html#a895f11e8ee586e4e10649838cfd12dd7">GetScene</a>();
}
```

##### <a class="anchor" id="bkmrk--7"></a>Upload Nodes with Scope 1

```
using namespace Candera;

<a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_scope_mask.html" title="The class ScopeMask allows scene graph nodes to form conceptual groups independent of the scene graph...">ScopeMask</a> scopeMask1(false);            // all scopes are disabled...
scopeMask1.SetScopeEnabled(1, true);    // ...and only scope 1 gets enabled.
scene-><a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_scene.html#a324480706f8e985675e5fea454381150">Upload</a>(scopeMask1);
```

The scene can be rendered now as long as those nodes with scope 2 are not needed (e.g. rendering is disabled).

##### <a class="anchor" id="bkmrk--8"></a>Deferred Upload of Nodes with Scope 2

```
using namespace Candera;

<a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_scope_mask.html" title="The class ScopeMask allows scene graph nodes to form conceptual groups independent of the scene graph...">ScopeMask</a> scopeMask2(false);
scopeMask2.SetScopeEnabled(2, true);
scene-><a class="code" href="http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_scene.html#a324480706f8e985675e5fea454381150">Upload</a>(scopeMask2);
```

Now the whole scene is uploaded to VRAM and can be rendered completely.

<div class="contents" id="bkmrk-in-that-simple-use-c"><div class="textblock"><dl class="note"><dt>  
</dt><dd><p class="callout info">In that simple use case the scopes are already set to the nodes e.g. during design phase in SceneComposer. The scopes can also be set during runtime by calling [Candera::Node::SetScopeMask()](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_node.html#a96af0d7869cd7b35b7f2a0a35a70a1f1) or [Candera::Node::SetScopeEnabled()](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_node.html#abefd359cba7184aec9f2ebd7b9ab31e0).</p>

<p class="callout info">This example is written for [Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]") 3D, for 2D please refer to [Candera::Scene2D::Upload()](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_scene2_d.html#a1d21f1e09ea51bd1ac741fc5ae8d2e3b), [Candera::Node2D::SetScopeMask()](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_node2_d.html#af111a4667a3507d78b01814c6e132281) and [Candera::Node2D::SetScopeEnabled()](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_node2_d.html#aaa166796aff943249b32e4c2ad7e20ae).</p>

</dd></dl></div></div>