viewport::render_direct_to_screen in Godot 3.2-alpha1

ZardosZardos Posts: 3Member
edited October 8 in 2D

Hello,

Godot 3.2 seems to have a new feature for a viewport: render_direct_to_screen.

According to the docs: https://github.com/godotengine/godot-docs/blob/master/classes/class_viewport.rst#id67

"If true, renders the Viewport directly to the screen instead of to the root viewport. Only available in GLES2. This is a low-level optimization and should not be used in most cases. If used, reading from the Viewport or from SCREEN_TEXTURE becomes unavailable. "

I'm experimenting with a split screen game, and because of weak performance this feature is exactly what I need.

But unfortunately if I enable it I only get a black rectangle for the viewport (I'm using GLES2).

I using this tutorial project for my experiments: http://kidscancode.org/blog/2018/07/godot3_splitscreen/

Can someone provide a working sample project for this new feature or can confirm this is a bug in the current 3.2-alpha1 (and master branch).

Thanks,
Ralf

Comments

  • MegalomaniakMegalomaniak Posts: 1,585Admin

    "If used, reading from the Viewport or from SCREEN_TEXTURE becomes unavailable. " - So not a bug.

  • ZardosZardos Posts: 3Member
    edited October 9

    @Megalomaniak said:
    "If used, reading from the Viewport or from SCREEN_TEXTURE becomes unavailable. " - So not a bug.

    But, I do not want to read from the viewport/screen texture. I just want things drawn (via two viewports) directly to the screen instead to textures first (... and then later the textures are drawn to the screen).

    The option sounds like it should accomplish exactly this, but currently only two black rectangle are visible if the option is checked.
    I looked at the C++ source of the GLES2 renderer: On a first glimp it should work as advertised, so either I'm missing something or ther is a bug.

  • MegalomaniakMegalomaniak Posts: 1,585Admin

    Drawing things via two viewports is reading from viewports.

  • ZardosZardos Posts: 3Member
    edited October 9

    @Megalomaniak said:
    Drawing things via two viewports is reading from viewports.

    Well, I probably should trust you, because I'm really new to Godot, but please take a moment and look at this code starting at line 430: https://github.com/godotengine/godot/blob/master/servers/visual/visual_server_viewport.cpp

    void VisualServerViewport::viewport_attach_to_screen(RID p_viewport, const Rect2 &p_rect, int p_screen) {
    
            Viewport *viewport = viewport_owner.getornull(p_viewport);
            ERR_FAIL_COND(!viewport);
    
            // If using GLES2 we can optimize this operation by rendering directly to system_fbo
            // instead of rendering to fbo and copying to system_fbo after
            if (VSG::rasterizer->is_low_end() && viewport->viewport_render_direct_to_screen) {
    
                VSG::storage->render_target_set_size(viewport->render_target, p_rect.size.x, p_rect.size.y);
                VSG::storage->render_target_set_position(viewport->render_target, p_rect.position.x, p_rect.position.y);
            }
    
            viewport->viewport_to_screen_rect = p_rect;
            viewport->viewport_to_screen = p_screen;
        }
    

    As you see there is code to render directly to a system fbo if ">viewport_render_direct_to_screen" is true.

    So I'm not convinced yet with your awnser. I will probably have to step through the code in the debugger to see why it does not work....

    But if you think it is not possible draw to a viewport if "viewport_render_direct_to_screen" is true. What is the use case for this option then?

    Thanks for your time, anyway!

    • Ralf
  • MegalomaniakMegalomaniak Posts: 1,585Admin
    edited October 9

    At best I'd expect one of your viewports/cameras to work, but for split-screen the other camera would still need a viewport/screen_texture afaik. Maybe if you try to directly script the VisualServer, you might be able to work around it, but using higher level scripting I'd expect problems.

    To be clear the use case is a very strict optimization for really low power hardware, and for games that don't need more than just one viewport(the direct output one), so a game where you have a single camera can benefit from this for an example.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file