godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.62k stars 20.77k forks source link

`OS.get_cmdline_args()` does not include `--rendering-method` CLI argument #81080

Open GameBeastProductions opened 1 year ago

GameBeastProductions commented 1 year ago

Godot version

v4.1.1.stable.official [bd6af8e0e]

System information

Godot v4.1.1.stable - Manjaro Linux - Vulkan (Mobile) - integrated AMD Radeon Vega 10 Graphics (RADV RAVEN) - AMD Ryzen 7 3700U

Issue description

I am trying to determine if the rendering method has been overridden on the command line, like this:

./game --rendering-method gl_compatibility

I am printing the result of OS.get_cmdline_args(), so the expected behaviour when I run the game is that the printed array contains something like this:

["--rendering-method", "gl_compatibility"]

However, when just this argument is set, I get an empty array. I've tried using OS.get_cmdline_user_args() and running the game from the editor with the argument set in editor/run/main_run_args, but these give the same result.

If this is intentional, I can't find mention of it in the docs. Other CLI arguments might also be affected by this.

Steps to reproduce

  1. Create a simple project with a Node2D and this script attached:
    
    extends Node2D

func _ready(): print(OS.get_cmdline_args())


2. Set `editor/run/main_run_args` in the Project Settings to `--rendering-method gl_compatibility`
3. Run the game from the editor.  Only the main scene argument is in the printed array
4. Export the project, and run it with the above argument.  The printed array is empty

### Minimal reproduction project

N/A
GameBeastProductions commented 1 year ago

I know the option I gave it must be valid because I see this in the output as well:

OpenGL API 4.6 (Core Profile) Mesa 23.1.5 - Compatibility

So it has set the rendering method to gl_compatibility.

AThousandShips commented 1 year ago

Note that there's a note in the documentation about the engine modifying or stripping args here

GameBeastProductions commented 1 year ago

Note that there's a note in the documentation about the engine modifying or stripping args here

When I run the game with -- --rendering-method gl_compatibility, I see that the argument appears in OS.get_cmdline_user_args() but the rendering method is not applied correctly.

The reason I want to determine this is that my game now supports either method, but I need to know which is enabled so I can substitute some graphical effects.

Calinou commented 1 year ago

The reason I want to determine this is that my game now supports either method, but I need to know which is enabled so I can substitute some graphical effects.

We should expose a method to get the current rendering method and driver without relying on CLI arguments. This will also account for fallbacks once these are implemented. We had that in 3.x, but it's missing in 4.x for some reason.

There's already a RenderingDriver enum exposed in the OS singleton, but no methods in the engine use it (not even in C++).

As a workaround, you can read the result of RenderingServer.get_video_adapter_api_version() and infer whether it's Vulkan or OpenGL based on the reported version number. If the version number is 3.0.0 or greater (to account for GLES 3.0 in mobile), it's OpenGL, otherwise, it's Vulkan. This will break once Vulkan reaches version 3.0.0, but I don't see that happening until a decade or so :slightly_smiling_face: