Skip to content

Commit abc5748

Browse files
committed
Improvements to multiple layer support
1 parent e1b4101 commit abc5748

37 files changed

+722
-338
lines changed

doc/classes/RenderSceneBuffersConfiguration.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
Bias applied to mipmaps.
3838
</member>
3939
<member name="view_count" type="int" setter="set_view_count" getter="get_view_count" default="1">
40-
The number of views we're rendering.
40+
The number of views we're rendering. If larger than [code]1[/code] this will enable multiview rendering for stereoscopic or multiscopic views.
4141
</member>
4242
</members>
4343
</class>

doc/classes/RenderingServer.xml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3915,15 +3915,17 @@
39153915
<method name="viewport_get_render_target" qualifiers="const">
39163916
<return type="RID" />
39173917
<param index="0" name="viewport" type="RID" />
3918+
<param index="1" name="layer" type="int" default="0" />
39183919
<description>
3919-
Returns the render target for the viewport.
3920+
Returns the render target for the [param layer] of the viewport.
39203921
</description>
39213922
</method>
39223923
<method name="viewport_get_texture" qualifiers="const">
39233924
<return type="RID" />
39243925
<param index="0" name="viewport" type="RID" />
3926+
<param index="1" name="layer" type="int" default="0" />
39253927
<description>
3926-
Returns the viewport's last rendered frame.
3928+
Returns the viewport's last rendered frame for a [param layer].
39273929
</description>
39283930
</method>
39293931
<method name="viewport_get_update_mode" qualifiers="const">
@@ -4062,6 +4064,15 @@
40624064
Sets the viewport's global transformation matrix.
40634065
</description>
40644066
</method>
4067+
<method name="viewport_set_layer_count">
4068+
<return type="void" />
4069+
<param index="0" name="viewport" type="RID" />
4070+
<param index="1" name="layer_count" type="int" />
4071+
<description>
4072+
Sets the number of layers for this viewport. Each layer will be rendered separately.
4073+
[b]Note:[/b] This is an XR feature only, in other use cases the output of additional layers is discarded.
4074+
</description>
4075+
</method>
40654076
<method name="viewport_set_measure_render_time">
40664077
<return type="void" />
40674078
<param index="0" name="viewport" type="RID" />
@@ -4180,10 +4191,12 @@
41804191
<method name="viewport_set_size">
41814192
<return type="void" />
41824193
<param index="0" name="viewport" type="RID" />
4183-
<param index="1" name="width" type="int" />
4184-
<param index="2" name="height" type="int" />
4194+
<param index="1" name="layer" type="int" />
4195+
<param index="2" name="width" type="int" />
4196+
<param index="3" name="height" type="int" />
4197+
<param index="4" name="view_count" type="int" />
41854198
<description>
4186-
Sets the viewport's width and height in pixels.
4199+
Sets the viewport's [param width], [param height] in pixels and the [param view_count] for the specified [param layer].
41874200
</description>
41884201
</method>
41894202
<method name="viewport_set_snap_2d_transforms_to_pixel">

doc/classes/SubViewport.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
<member name="size_2d_override_stretch" type="bool" setter="set_size_2d_override_stretch" getter="is_size_2d_override_stretch_enabled" default="false">
3737
If [code]true[/code], the 2D size override affects stretch as well.
3838
</member>
39+
<member name="view_count" type="int" setter="set_view_count" getter="get_view_count" default="1">
40+
The number of views we're rendering. If larger than [code]1[/code] this will enable multiview rendering for stereoscopic or multiscopic views.
41+
</member>
3942
</members>
4043
<constants>
4144
<constant name="CLEAR_MODE_ALWAYS" value="0" enum="ClearMode">

doc/classes/XRInterface.xml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
Returns a combination of [enum Capabilities] flags providing information about the capabilities of this interface.
2424
</description>
2525
</method>
26+
<method name="get_layer_count">
27+
<return type="int" />
28+
<description>
29+
Returns the number of layers we require for rendering. Each layer may have different resolution, view count and camera data.
30+
</description>
31+
</method>
2632
<method name="get_name" qualifiers="const">
2733
<return type="StringName" />
2834
<description>
@@ -37,16 +43,18 @@
3743
</method>
3844
<method name="get_projection_for_view">
3945
<return type="Projection" />
40-
<param index="0" name="view" type="int" />
41-
<param index="1" name="aspect" type="float" />
42-
<param index="2" name="near" type="float" />
43-
<param index="3" name="far" type="float" />
46+
<param index="0" name="layer" type="int" />
47+
<param index="1" name="view" type="int" />
48+
<param index="2" name="aspect" type="float" />
49+
<param index="3" name="near" type="float" />
50+
<param index="4" name="far" type="float" />
4451
<description>
4552
Returns the projection matrix for a view/eye.
4653
</description>
4754
</method>
4855
<method name="get_render_target_size">
4956
<return type="Vector2" />
57+
<param index="0" name="layer" type="int" default="0" />
5058
<description>
5159
Returns the resolution at which we should render our intermediate results before things like lens distortion are applied by the VR platform.
5260
</description>
@@ -72,8 +80,9 @@
7280
</method>
7381
<method name="get_transform_for_view">
7482
<return type="Transform3D" />
75-
<param index="0" name="view" type="int" />
76-
<param index="1" name="cam_transform" type="Transform3D" />
83+
<param index="0" name="layer" type="int" />
84+
<param index="1" name="view" type="int" />
85+
<param index="2" name="cam_transform" type="Transform3D" />
7786
<description>
7887
Returns the transform for a view/eye.
7988
[param view] is the view/eye index.
@@ -82,6 +91,7 @@
8291
</method>
8392
<method name="get_view_count">
8493
<return type="int" />
94+
<param index="0" name="layer" type="int" default="0" />
8595
<description>
8696
Returns the number of views that need to be rendered for this device. 1 for Monoscopic, 2 for Stereoscopic.
8797
</description>

doc/classes/XRInterfaceExtension.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,29 @@
4646
Return color texture into which to render (if applicable).
4747
</description>
4848
</method>
49+
<method name="_get_color_texture2" qualifiers="virtual">
50+
<return type="RID" />
51+
<param index="0" name="layer" type="int" />
52+
<description>
53+
</description>
54+
</method>
4955
<method name="_get_depth_texture" qualifiers="virtual">
5056
<return type="RID" />
5157
<description>
5258
Return depth texture into which to render (if applicable).
5359
</description>
5460
</method>
61+
<method name="_get_depth_texture2" qualifiers="virtual">
62+
<return type="RID" />
63+
<param index="0" name="layer" type="int" />
64+
<description>
65+
</description>
66+
</method>
67+
<method name="_get_layer_count" qualifiers="virtual">
68+
<return type="int" />
69+
<description>
70+
</description>
71+
</method>
5572
<method name="_get_name" qualifiers="virtual const">
5673
<return type="StringName" />
5774
<description>
@@ -86,6 +103,12 @@
86103
Returns the size of our render target for this interface, this overrides the size of the [Viewport] marked as the xr viewport.
87104
</description>
88105
</method>
106+
<method name="_get_render_target_size2" qualifiers="virtual">
107+
<return type="Vector2" />
108+
<param index="0" name="layer" type="int" />
109+
<description>
110+
</description>
111+
</method>
89112
<method name="_get_suggested_pose_names" qualifiers="virtual const">
90113
<return type="PackedStringArray" />
91114
<param index="0" name="tracker_name" type="StringName" />
@@ -125,12 +148,24 @@
125148
Return velocity texture into which to render (if applicable).
126149
</description>
127150
</method>
151+
<method name="_get_velocity_texture2" qualifiers="virtual">
152+
<return type="RID" />
153+
<param index="0" name="layer" type="int" />
154+
<description>
155+
</description>
156+
</method>
128157
<method name="_get_view_count" qualifiers="virtual">
129158
<return type="int" />
130159
<description>
131160
Returns the number of views this interface requires, 1 for mono, 2 for stereoscopic.
132161
</description>
133162
</method>
163+
<method name="_get_view_count2" qualifiers="virtual">
164+
<return type="int" />
165+
<param index="0" name="layer" type="int" />
166+
<description>
167+
</description>
168+
</method>
134169
<method name="_get_vrs_texture" qualifiers="virtual">
135170
<return type="RID" />
136171
<description>
@@ -239,11 +274,13 @@
239274
</method>
240275
<method name="get_color_texture">
241276
<return type="RID" />
277+
<param index="0" name="layer" type="int" default="0" />
242278
<description>
243279
</description>
244280
</method>
245281
<method name="get_depth_texture">
246282
<return type="RID" />
283+
<param index="0" name="layer" type="int" default="0" />
247284
<description>
248285
</description>
249286
</method>
@@ -256,6 +293,7 @@
256293
</method>
257294
<method name="get_velocity_texture">
258295
<return type="RID" />
296+
<param index="0" name="layer" type="int" default="0" />
259297
<description>
260298
</description>
261299
</method>

drivers/gles3/storage/texture_storage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ Size2i TextureStorage::render_target_get_size(RID p_render_target) const {
25482548
return rt->size;
25492549
}
25502550

2551-
void TextureStorage::render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture, RID p_velocity_depth_texture) {
2551+
void TextureStorage::render_target_set_override(RID p_render_target, int p_index, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture, RID p_velocity_depth_texture) {
25522552
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
25532553
ERR_FAIL_NULL(rt);
25542554
ERR_FAIL_COND(rt->direct_to_screen);

drivers/gles3/storage/texture_storage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ class TextureStorage : public RendererTextureStorage {
689689
virtual void render_target_set_vrs_texture(RID p_render_target, RID p_texture) override {}
690690
virtual RID render_target_get_vrs_texture(RID p_render_target) const override { return RID(); }
691691

692-
virtual void render_target_set_override(RID p_render_target, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture, RID p_velocity_depth_texture) override;
692+
virtual void render_target_set_override(RID p_render_target, int p_index, RID p_color_texture, RID p_depth_texture, RID p_velocity_texture, RID p_velocity_depth_texture) override;
693693
virtual RID render_target_get_override_color(RID p_render_target) const override;
694694
virtual RID render_target_get_override_depth(RID p_render_target) const override;
695695
virtual RID render_target_get_override_velocity(RID p_render_target) const override;

editor/editor_interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Vector<Ref<Texture2D>> EditorInterface::make_mesh_previews(const Vector<Ref<Mesh
148148
RID viewport = RS::get_singleton()->viewport_create();
149149
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_ALWAYS);
150150
RS::get_singleton()->viewport_set_scenario(viewport, scenario);
151-
RS::get_singleton()->viewport_set_size(viewport, size, size);
151+
RS::get_singleton()->viewport_set_size(viewport, 0, size, size, 1);
152152
RS::get_singleton()->viewport_set_transparent_background(viewport, true);
153153
RS::get_singleton()->viewport_set_active(viewport, true);
154154
RID viewport_texture = RS::get_singleton()->viewport_get_texture(viewport);

editor/plugins/animation_player_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ void AnimationPlayerEditor::_allocate_onion_layers() {
16831683
// Each capture is a viewport with a canvas item attached that renders a full-size rect with the contents of the main viewport.
16841684
onion.captures[i] = RS::get_singleton()->viewport_create();
16851685

1686-
RS::get_singleton()->viewport_set_size(onion.captures[i], capture_size.width, capture_size.height);
1686+
RS::get_singleton()->viewport_set_size(onion.captures[i], 0, capture_size.width, capture_size.height, 1);
16871687
RS::get_singleton()->viewport_set_update_mode(onion.captures[i], RS::VIEWPORT_UPDATE_ALWAYS);
16881688
RS::get_singleton()->viewport_set_transparent_background(onion.captures[i], !is_present);
16891689
RS::get_singleton()->viewport_attach_canvas(onion.captures[i], onion.capture.canvas);

editor/plugins/editor_preview_plugins.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
360360
viewport = RS::get_singleton()->viewport_create();
361361
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_DISABLED);
362362
RS::get_singleton()->viewport_set_scenario(viewport, scenario);
363-
RS::get_singleton()->viewport_set_size(viewport, 128, 128);
363+
RS::get_singleton()->viewport_set_size(viewport, 0, 128, 128, 1);
364364
RS::get_singleton()->viewport_set_transparent_background(viewport, true);
365365
RS::get_singleton()->viewport_set_active(viewport, true);
366366
viewport_texture = RS::get_singleton()->viewport_get_texture(viewport);
@@ -775,7 +775,7 @@ EditorMeshPreviewPlugin::EditorMeshPreviewPlugin() {
775775
viewport = RS::get_singleton()->viewport_create();
776776
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_DISABLED);
777777
RS::get_singleton()->viewport_set_scenario(viewport, scenario);
778-
RS::get_singleton()->viewport_set_size(viewport, 128, 128);
778+
RS::get_singleton()->viewport_set_size(viewport, 0, 128, 128, 1);
779779
RS::get_singleton()->viewport_set_transparent_background(viewport, true);
780780
RS::get_singleton()->viewport_set_active(viewport, true);
781781
viewport_texture = RS::get_singleton()->viewport_get_texture(viewport);
@@ -890,7 +890,7 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate(const Ref<Resource> &p_from, co
890890
EditorFontPreviewPlugin::EditorFontPreviewPlugin() {
891891
viewport = RS::get_singleton()->viewport_create();
892892
RS::get_singleton()->viewport_set_update_mode(viewport, RS::VIEWPORT_UPDATE_DISABLED);
893-
RS::get_singleton()->viewport_set_size(viewport, 128, 128);
893+
RS::get_singleton()->viewport_set_size(viewport, 0, 128, 128, 1);
894894
RS::get_singleton()->viewport_set_active(viewport, true);
895895
viewport_texture = RS::get_singleton()->viewport_get_texture(viewport);
896896

0 commit comments

Comments
 (0)