Texture2D
- Last UpdatedNov 25, 2025
- 8 minute read
Use a Texture2D node to render 2D-based interfaces into engine objects (3D and 2D) as normal textures.
-
Only RectBase2D objects can be rendered into a Texture2D.
-
A RectBase2D declares to be rendered into a Texture2D explicitly by the renderToTexture2D parameter.
-
RectBase2D opacity is not supported inside Texture2D.
Platform support
This node is fully supported on XR-Windows platform.
It is partially supported on XR-Portable Windows, XR-Portable iOS, XR-Portable Android, and XR-P WASM platforms.
|
XR-WIN |
XR-P-WIN |
XR-P-IOS |
XR-P-AND |
XR-P-WASM |
|---|---|---|---|---|
|
Full support |
Partial support |
Partial support |
Partial support |
Partial support |
|
|
|
|
|
|
Nodes supporting Texture2D contents
To use a Texture2D as a texture inside a node, it must have the syntax: internal:Texture2D.
These nodes support internal use.
|
Node |
Field |
|---|---|
|
image |
|
|
images |
|
|
texture2D |
Event system
Texture2D has an event system that is used together with Rect2D and ItemMonitor to manage and propagate interaction events to embedded RectBase2D derived nodes. These nodes should not be managed directly by script code.
Sensor management
Some RectBase2D node type behaviors are based on the a sensor system that prevents the node from updating and propagating events when not visible.
When the Texture2D is rendered into an ItemMonitor, a Rect (Legacy), or a PanelTexture2D, the visibility is managed by the container node and propagated to the Texture2D so that the sensor system works properly. When the texture is rendered into a generic mesh, the visibility check may not work as expected. This could prevent the sensor system from working properly and lead to strange RectBase2D type node behaviors.
The sensorActive field enables you to manage the sensor activation/deactivation for the Texture2D content. Specify as auto when the texture is rendered into a node that can properly manage visibility. Specify as yes and no to control manually when rendering into a generic mesh.
Virtualizing texture size
Depending on the GPU specs, there is a limit in the dimension of texture that can be created in memory. When using Texture2D in rect2d mode to display lists of items, it can happen that the desired texture dimension is higher than what is supported by GPU.
In these cases, if the actual area of the texture to be displayed is smaller then the full required dimension, the texture size can be made virtual by use of the rect2DOffset field.

Set the Texture2D size to the required display dimension. Place 2D elements in Texture2D to the position they belong. And finally, use rect2DOffset to move their position in the texture. This way, you can have a virtual texture of any dimension of which only a portion is displayed. Moreover, the elements that are out of the display area are not drawn, which saves in calculation.
Camera snapshots
Texture2D can be used to host the outcome of a camera render. To do this, the mode field must be set to capture at node definition.
Use the captureCamera field and assign it the name of a camera node to see the rendered image appear on the Texture2D.
Please observe when setting the captureCamera, that by default a single snapshot is taken. To set the automatic update of the texture to match camera view, use captureCameraRefreshTime. A value of 0 will disable the automatic update.
Note: When a Texture2D is set in capture mode, it will not show any Rect2D element attached to it.
Taking snapshots on mobile devices
Texture2D can be used to take snapshots from device camera (iOS or Android device camera) and renders the snapshot as its content. To do this, the mode field must be set to capture at node definition and the captureCamera field must be set to DEVICE value.
Note: The captureCameraRefreshTime field is not applicable in the case of Device camera snapshot because we don't support device camera preview streaming to the texture. XR takes the first snapshot and then updates the texture with taken snapshot from device camera.
Texture mirror
Texture2D can be used to mirror the content of another Texture2D node. The suggested way to achieve this is to use an sbinary field to store the content of the original Texture2D by using the texturetobinary command, and then update the mirror Texture2D with the content of the sbinary field by using the binarytotexture command.
In this scenario, the original Texture2D acting as the source can have its mode set to rect2d or capture, while the Texture2D acting as mirror must have its mode set to mirror.
Code example
The following code example is an implementation of the above scenario, in which the mirror Texture2D is automatically updated with the content displayed in the original Texture2D every time the graphics displayed in the original Texture2D changes, such as due to a user interaction.
For this example to work, it is assumed that the graphic context contains two Texture2D nodes named Texture2DOriginal and Texture2DMirror. The Texture2DOriginal node can have its mode set either to rect2d or capture, and the Texture2DMirror node must have its mode set to mirror.
<Var type="sbinary" name="mySBinary" />
<Command name="cmd_runTextureToBinary">
<texturetobinary name="mySBinary.value" texture="Texture2DOriginal" />
</Command>
<Command name="cmd_runBinaryToTexture">
<binarytotexture name="mySBinary.value" texture="Texture2DMirror" />
</Command>
<route from=" Texture2DOriginal.updated" to="cmd_runTextureToBinary.execute" />
<route from="mySBinary.value" to="cmd_runBinaryToTexture.execute" />
Save to image file
You can save the content of a Texture2D into a .tga,.bmp,.gif,.jpeg,.png, or.tiff image file by using the saveToFile field. The saved image will have the same size as the Texture2D. Transparency is also preserved.The saved image will have the same size as the Texture2D. When enableDataAccessRestrictions field in Application configuration file) is set to false, images can be saved in any existing folder; whereas, when enableDataAccessRestrictions is set to true, they can only be saved in the working directory or any of its existing subdirectories. Notice that the saveToFile field is not displayed in the editor.
Note: Only PNG and JPEG image files can be saved on portable platforms.
Code example
This code example shows how to save an image in the working directory, in a subdirectory of the working directory, or in a system folder.
<set name="Texture2D.saveToFile" value="image.png"/>
<set name="Texture2D.saveToFile" value=".\GameData\Folder\image.png"/>
<set name="Texture2D.saveToFile" value=”C:\Folder\image.png"/>
Referencing Texture2D internal texture
The Texture2D can be referenced as a node in a similar way as the PanelTexture2D.
Other nodes can use its internal name as any other image. The code to reference it as an image depends on the selected mode:
-
internal:Texture2DNodeName when the mode is set to RECT2D. For example: internal:aTexture.
-
internal:Texture2DNodeName_capture when the mode is set to capture. For example: internal:aTexture_capture.
Code example
This is a code example for Texture2D.
<Texture2D name="aTexture" templateInfo="Texture2D|aTexture"/>
Texture2D fields
These are the fields for Texture2D. Only the node-specific fields are indicated, not fields obtained by inheritance.
Field inheritance: NodeBase > Texture2D
|
Fields |
Type |
Use |
Default value |
Description |
|---|---|---|---|---|
|
active |
sbool |
Optional |
true |
When set to false, the texture is not redrawn or handled. |
|
captureCamera |
sstring |
Optional |
Set to a camera node name to perform a snapshot render from that camera and show it in the texture. Take care not to have any Rect2D based nodes assigned to the node otherwise the refresh will override the snapshot. Set to DEVICE to take snapshot from iOS and Android devices camera and show it in the texture. |
|
|
captureCameraRefreshTime |
sfloat |
Optional |
0 |
Sets the interval at which the captureCamera should capture and update the texture. Works only in Capture mode. (Interval mentioned is in seconds). When set to 0, the capture is not updated. |
|
clearColor |
svec4 |
Optional |
0 0 0 0 |
Texture background color. This is the color used to clear before drawing. |
|
eventLeft |
sbool |
Optional |
false |
When true, the left mouse-click event is propagated. |
|
eventRight |
sbool |
Optional |
false |
When true, the right mouse-click event is propagated. |
|
eventMiddle |
sbool |
Optional |
false |
When true, the wheel click-mouse event is propagated. |
|
eventType |
senum |
Optional |
mouse |
Specifies between mouse and custom event types. When set to mouse, input is taken from actual device. When set to custom, the event can be managed by script. |
|
gridSize |
svec2 |
Optional |
-1 -1 |
Texture resolution, in points (contents size refers to this). If set to -1 -1 is equal to size. |
|
mode |
senum |
Optional |
rect2d |
Texture2D supports the following modes:
This parameter can be changed at runtime. |
|
rect2DOffset |
svec2 |
Optional |
0 0 |
If mode is set to rect2D, this field enables you to move the content inside the texture area, thus allowing to represent bigger contents inside a smaller texture area. |
|
refreshTime |
sfloat |
Optional |
0.1 |
Texture refresh time. |
|
saveToFile |
sstring |
Optional |
Saves the texture into an image file. The filename must include an extension (.tga,.bmp,.gif,.jpeg,.png, or.tiff). |
|
|
sensorActive |
senum |
Optional |
auto |
Leave set to auto for the RectBase2D content sensor activation to be lead by Texture2D container. Use yes and no to control manually. |
|
setMousePosition |
sfunction |
Optional |
Not set |
Used to force mouse position in pixels on the texture when the texture is not directly interacting with mouse. When successful, returns OK. sstring setMousePosition.execute(svec2 pos) |
|
setMousePositionUV |
sfunction |
Optional |
Not set |
Used to force mouse position in uv space (0-1) on the texture when the texture is not directly interacting with mouse. When successful, returns OK. sstring setMousePositionUV.execute(svec2 posUV) |
|
size |
svec2 |
Optional |
256 256 |
Texture size, in pixels. |
|
updated |
sevent |
Read only |
Not set |
Marked as modified every time the texture is redrawn. This is useful to trigger routes when the texture graphic changes. |