Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenGL renderer #53150

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
22fb0da
Godot 4 GLES2 2D renderer + linux display manager
lawnjelly Nov 18, 2020
5d7741a
Added GLES2 vsync support
lawnjelly Jan 11, 2021
6fc6fa5
GLES2 tidying, TIME and bootscreen
lawnjelly Jan 12, 2021
eee42cb
Add single threaded mode for EditorResourcePreview
lawnjelly Jan 15, 2021
13a49a6
Fixes for quarmin's worst possible project.
lawnjelly Jan 15, 2021
b368ce4
Rebasing and fixes to compile after a year gap.
lawnjelly Sep 26, 2021
695aa1f
Fix shader builder code generation for the latest `master` branch
Calinou Sep 26, 2021
9446ce2
Remove references to a nonexistent GLES3 renderer for now [ci skip]
Calinou Sep 27, 2021
32e0b15
Remove unused/deprecated code and references to Godot 3.x [ci skip]
Calinou Sep 27, 2021
08a4fab
Merge the `gles_common/` abstraction folder with `gles2/` [ci skip]
Calinou Sep 27, 2021
4919480
Rename GLES2 driver to OpenGL [ci skip]
Calinou Sep 27, 2021
2f7ef59
[WIP] Initialize OpenGL 3.3 / OpenGL ES 3.0 context [ci skip]
Calinou Sep 27, 2021
dc22558
Port 2D shader to GLSL ES 3.0 to fix shader compilation [ci skip]
Calinou Sep 27, 2021
6b1d1d1
Revert "Port 2D shader to GLSL ES 3.0 to fix shader compilation [ci s…
Calinou Sep 27, 2021
ef5270f
Update some more references to OpenGL
Calinou Sep 27, 2021
0bcfa9a
Support PI, TAU and E shader constants in OpenGL shaders
Calinou Sep 27, 2021
11669cd
Use OpenGL compatibility profile to fix rendering for now
Calinou Sep 27, 2021
16f812f
Fix code style issue reported by Black
Calinou Sep 27, 2021
d7a46e3
Update the VideoDriver enum value for the OpenGL renderer
Calinou Sep 27, 2021
d6b7e66
Rename all references to GLES2 to OpenGL
Calinou Sep 27, 2021
5ef6450
Replace use of `#pragma once`, remove commented out code in stubs
Calinou Sep 28, 2021
6f9fa74
Remove reliance on the Dummy rasterizers
Calinou Sep 28, 2021
d781c8e
Always accept title-case driver names to make the OpenGL project sett…
Calinou Sep 28, 2021
80361cf
Rename `GLES_<platform>_ENABLED` defines to `OPENGL_<platform>_ENABLED`
Calinou Oct 3, 2021
e724dbf
Replace platform-specific OpenGL defines with `OPENGL_ENABLED`
Calinou Oct 4, 2021
fc043bc
Fix OpenGL initialization on Windows
clayjohn Oct 4, 2021
1204e32
Update for latest `master` branch
Calinou Oct 10, 2021
32b3bf7
Use OpenGL 3.3 Core Profile (#7)
clayjohn Oct 26, 2021
d5c32e8
Remove outdated comment about OpenGL Compatibility Profile
Calinou Oct 26, 2021
7001781
Fix build error after editor toast error implementation
Calinou Oct 26, 2021
582c18a
Hide renderer selection dropdown until OpenGL support is more mature
Calinou Oct 27, 2021
34bf390
Remove commented out exporter code
Calinou Oct 27, 2021
d357e7f
Remove some OpenGL/DisplayServer-related debugging prints
Calinou Oct 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ from collections import OrderedDict
# Local
import methods
import glsl_builders
import opengl_builders
from platform_methods import run_in_subprocess

# Scan possible build platforms

Expand Down Expand Up @@ -706,6 +708,17 @@ if selected_platform in platform_list:
}
env.Append(BUILDERS=GLSL_BUILDERS)

if not env["platform"] == "server":
env.Append(
BUILDERS={
"OpenGL_GLSL": env.Builder(
action=run_in_subprocess(opengl_builders.build_opengl_headers),
suffix="glsl.gen.h",
src_suffix=".glsl",
)
}
)

scons_cache_path = os.environ.get("SCONS_CACHE")
if scons_cache_path != None:
CacheDir(scons_cache_path)
Expand Down
2 changes: 1 addition & 1 deletion core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ void OS::_bind_methods() {
ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false);
ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900);

BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES2);
BIND_ENUM_CONSTANT(VIDEO_DRIVER_VULKAN);
BIND_ENUM_CONSTANT(VIDEO_DRIVER_OPENGL);

BIND_ENUM_CONSTANT(DAY_SUNDAY);
BIND_ENUM_CONSTANT(DAY_MONDAY);
Expand Down
2 changes: 1 addition & 1 deletion core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class OS : public Object {

public:
enum VideoDriver {
VIDEO_DRIVER_GLES2,
VIDEO_DRIVER_VULKAN,
VIDEO_DRIVER_OPENGL,
Calinou marked this conversation as resolved.
Show resolved Hide resolved
};

enum Weekday {
Expand Down
19 changes: 19 additions & 0 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ class OS {
bool restart_on_exit = false;
List<String> restart_commandline;

// for the user interface we keep a record of the current display driver
// so we can retrieve the rendering drivers available
int _display_driver_id = -1;
String _current_rendering_driver_name = "";

protected:
void _set_logger(CompositeLogger *p_logger);

Expand All @@ -81,20 +86,29 @@ class OS {
RENDER_SEPARATE_THREAD
};

enum RenderMainThreadMode {
RENDER_MAIN_THREAD_ONLY,
RENDER_ANY_THREAD,
};

protected:
friend class Main;
// Needed by tests to setup command-line args.
friend int test_main(int argc, char *argv[]);

HasServerFeatureCallback has_server_feature_callback = nullptr;
RenderThreadMode _render_thread_mode = RENDER_THREAD_SAFE;
RenderMainThreadMode _render_main_thread_mode = RENDER_ANY_THREAD;

// Functions used by Main to initialize/deinitialize the OS.
void add_logger(Logger *p_logger);

virtual void initialize() = 0;
virtual void initialize_joypads() = 0;

void set_current_rendering_driver_name(String p_driver_name) { _current_rendering_driver_name = p_driver_name; }
void set_display_driver_id(int p_display_driver_id) { _display_driver_id = p_display_driver_id; }

virtual void set_main_loop(MainLoop *p_main_loop) = 0;
virtual void delete_main_loop() = 0;

Expand All @@ -110,6 +124,9 @@ class OS {

static OS *get_singleton();

String get_current_rendering_driver_name() const { return _current_rendering_driver_name; }
int get_display_driver_id() const { return _display_driver_id; }

void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify = false, Logger::ErrorType p_type = Logger::ERR_ERROR);
void print(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
void printerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
Expand Down Expand Up @@ -241,6 +258,8 @@ class OS {
virtual uint64_t get_free_static_memory() const;

RenderThreadMode get_render_thread_mode() const { return _render_thread_mode; }
RenderMainThreadMode get_render_main_thread_mode() const { return _render_main_thread_mode; }
void set_render_main_thread_mode(RenderMainThreadMode p_thread_mode) { _render_main_thread_mode = p_thread_mode; }

virtual String get_locale() const;
String get_locale_language() const;
Expand Down
6 changes: 3 additions & 3 deletions doc/classes/Environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@
The bleed scale of the HDR glow.
</member>
<member name="glow_hdr_threshold" type="float" setter="set_glow_hdr_bleed_threshold" getter="get_glow_hdr_bleed_threshold" default="1.0">
The lower threshold of the HDR glow. When using the GLES2 renderer (which doesn't support HDR), this needs to be below [code]1.0[/code] for glow to be visible. A value of [code]0.9[/code] works well in this case.
The lower threshold of the HDR glow. When using the OpenGL renderer (which doesn't support HDR), this needs to be below [code]1.0[/code] for glow to be visible. A value of [code]0.9[/code] works well in this case.
</member>
<member name="glow_intensity" type="float" setter="set_glow_intensity" getter="get_glow_intensity" default="0.8">
The overall brightness multiplier of the glow effect. When using the GLES2 renderer, this should be increased to 1.5 to compensate for the lack of HDR rendering.
The overall brightness multiplier of the glow effect. When using the OpenGL renderer, this should be increased to 1.5 to compensate for the lack of HDR rendering.
</member>
<member name="glow_levels/1" type="float" setter="set_glow_level" getter="get_glow_level" default="0.0">
The intensity of the 1st level of glow. This is the most "local" level (least blurry).
Expand Down Expand Up @@ -160,7 +160,7 @@
If [code]true[/code], glow levels will be normalized so that summed together their intensities equal [code]1.0[/code].
</member>
<member name="glow_strength" type="float" setter="set_glow_strength" getter="get_glow_strength" default="1.0">
The strength of the glow effect. This applies as the glow is blurred across the screen and increases the distance and intensity of the blur. When using the GLES2 renderer, this should be increased to 1.3 to compensate for the lack of HDR rendering.
The strength of the glow effect. This applies as the glow is blurred across the screen and increases the distance and intensity of the blur. When using the OpenGL renderer, this should be increased to 1.3 to compensate for the lack of HDR rendering.
</member>
<member name="reflected_light_source" type="int" setter="set_reflection_source" getter="get_reflection_source" enum="Environment.ReflectionSource" default="0">
</member>
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/NinePatchRect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@
</constant>
<constant name="AXIS_STRETCH_MODE_TILE" value="1" enum="AxisStretchMode">
Repeats the center texture across the NinePatchRect. This won't cause any visible distortion. The texture must be seamless for this to work without displaying artifacts between edges.
[b]Note:[/b] Only supported when using the GLES3 renderer. When using the GLES2 renderer, this will behave like [constant AXIS_STRETCH_MODE_STRETCH].
[b]Note:[/b] Only supported when using the Vulkan renderer. When using the OpenGL renderer, this will behave like [constant AXIS_STRETCH_MODE_STRETCH].
</constant>
<constant name="AXIS_STRETCH_MODE_TILE_FIT" value="2" enum="AxisStretchMode">
Repeats the center texture across the NinePatchRect, but will also stretch the texture to make sure each tile is visible in full. This may cause the texture to be distorted, but less than [constant AXIS_STRETCH_MODE_STRETCH]. The texture must be seamless for this to work without displaying artifacts between edges.
[b]Note:[/b] Only supported when using the GLES3 renderer. When using the GLES2 renderer, this will behave like [constant AXIS_STRETCH_MODE_STRETCH].
[b]Note:[/b] Only supported when using the Vulkan renderer. When using the OpenGL renderer, this will behave like [constant AXIS_STRETCH_MODE_STRETCH].
</constant>
</constants>
</class>
8 changes: 4 additions & 4 deletions doc/classes/OS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,12 @@
</member>
</members>
<constants>
<constant name="VIDEO_DRIVER_GLES2" value="0" enum="VideoDriver">
The GLES2 rendering backend. It uses OpenGL ES 2.0 on mobile devices, OpenGL 2.1 on desktop platforms and WebGL 1.0 on the web.
</constant>
<constant name="VIDEO_DRIVER_VULKAN" value="1" enum="VideoDriver">
<constant name="VIDEO_DRIVER_VULKAN" value="0" enum="VideoDriver">
The Vulkan rendering backend.
</constant>
<constant name="VIDEO_DRIVER_OPENGL" value="1" enum="VideoDriver">
The OpenGL rendering backend. It uses OpenGL ES 3.0 on mobile devices, OpenGL 3.3 on desktop platforms and WebGL 2.0 on the web.
</constant>
<constant name="DAY_SUNDAY" value="0" enum="Weekday">
Sunday.
</constant>
Expand Down
42 changes: 42 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,18 @@
The number of fixed iterations per second. This controls how often physics simulation and [method Node._physics_process] methods are run.
[b]Note:[/b] This property is only read when the project starts. To change the physics FPS at runtime, set [member Engine.physics_ticks_per_second] instead.
</member>
<member name="rendering/2d/opengl/batching_send_null" type="int" setter="" getter="" default="0">
</member>
<member name="rendering/2d/opengl/batching_stream" type="int" setter="" getter="" default="0">
</member>
<member name="rendering/2d/opengl/legacy_orphan_buffers" type="int" setter="" getter="" default="0">
</member>
<member name="rendering/2d/opengl/legacy_stream" type="int" setter="" getter="" default="0">
</member>
<member name="rendering/2d/options/ninepatch_mode" type="int" setter="" getter="" default="1">
</member>
<member name="rendering/2d/options/use_software_skinning" type="bool" setter="" getter="" default="true">
</member>
<member name="rendering/2d/sdf/oversize" type="int" setter="" getter="" default="1">
</member>
<member name="rendering/2d/sdf/scale" type="int" setter="" getter="" default="1">
Expand Down Expand Up @@ -1504,6 +1516,32 @@
</member>
<member name="rendering/anti_aliasing/screen_space_roughness_limiter/limit" type="float" setter="" getter="" default="0.18">
</member>
<member name="rendering/batching/debug/diagnose_frame" type="bool" setter="" getter="" default="false">
</member>
<member name="rendering/batching/debug/flash_batching" type="bool" setter="" getter="" default="false">
</member>
<member name="rendering/batching/lights/max_join_items" type="int" setter="" getter="" default="32">
</member>
<member name="rendering/batching/lights/scissor_area_threshold" type="float" setter="" getter="" default="1.0">
</member>
<member name="rendering/batching/options/single_rect_fallback" type="bool" setter="" getter="" default="false">
</member>
<member name="rendering/batching/options/use_batching" type="bool" setter="" getter="" default="false">
</member>
<member name="rendering/batching/options/use_batching_in_editor" type="bool" setter="" getter="" default="false">
</member>
<member name="rendering/batching/parameters/batch_buffer_size" type="int" setter="" getter="" default="16384">
</member>
<member name="rendering/batching/parameters/colored_vertex_format_threshold" type="float" setter="" getter="" default="0.25">
</member>
<member name="rendering/batching/parameters/item_reordering_lookahead" type="int" setter="" getter="" default="4">
</member>
<member name="rendering/batching/parameters/max_join_item_commands" type="int" setter="" getter="" default="16">
</member>
<member name="rendering/batching/precision/uv_contract" type="bool" setter="" getter="" default="false">
</member>
<member name="rendering/batching/precision/uv_contract_amount" type="int" setter="" getter="" default="100">
</member>
<member name="rendering/camera/depth_of_field/depth_of_field_bokeh_quality" type="int" setter="" getter="" default="1">
Sets the quality of the depth of field effect. Higher quality takes more samples, which is slower but looks smoother.
</member>
Expand Down Expand Up @@ -1582,6 +1620,10 @@
</member>
<member name="rendering/environment/volumetric_fog/volume_size" type="int" setter="" getter="" default="64">
</member>
<member name="rendering/gles2/compatibility/disable_half_float" type="bool" setter="" getter="" default="false">
</member>
<member name="rendering/gles2/compatibility/enable_high_float.Android" type="bool" setter="" getter="" default="false">
</member>
<member name="rendering/global_illumination/gi/use_half_resolution" type="bool" setter="" getter="" default="false">
</member>
<member name="rendering/global_illumination/sdfgi/frames_to_converge" type="int" setter="" getter="" default="4">
Expand Down
4 changes: 4 additions & 0 deletions drivers/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ SConscript("winmidi/SCsub")
# Graphics drivers
if env["vulkan"]:
SConscript("vulkan/SCsub")
SConscript("opengl/SCsub")
SConscript("gl_context/SCsub")
else:
SConscript("dummy/SCsub")

# Core dependencies
SConscript("png/SCsub")
Expand Down
23 changes: 23 additions & 0 deletions drivers/gl_context/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python

Import("env")

if env["platform"] in ["haiku", "osx", "windows", "linuxbsd"]:
# Thirdparty source files
thirdparty_dir = "#thirdparty/glad/"
thirdparty_sources = [
"glad.c",
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]

env.Prepend(CPPPATH=[thirdparty_dir])

env.Append(CPPDEFINES=["GLAD_ENABLED"])
env.Append(CPPDEFINES=["GLES_OVER_GL"])

env_thirdparty = env.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(env.drivers_sources, thirdparty_sources)

# Godot source files
env.add_source_files(env.drivers_sources, "*.cpp")
7 changes: 7 additions & 0 deletions drivers/opengl/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python

Import("env")

env.add_source_files(env.drivers_sources, "*.cpp")

SConscript("shaders/SCsub")
Loading