Skip to content

Commit

Permalink
Allow Angle backend selection, add initial iOS Angle support.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruvzg committed Jan 30, 2024
1 parent 9ab5ced commit ed40c75
Show file tree
Hide file tree
Showing 21 changed files with 390 additions and 54 deletions.
12 changes: 12 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,18 @@
<member name="rendering/environment/volumetric_fog/volume_size" type="int" setter="" getter="" default="64">
Base size used to determine size of froxel buffer in the camera X-axis and Y-axis. The final size is scaled by the aspect ratio of the screen, so actual values may differ from what is set. Set a larger size for more detailed fog, set a smaller size for better performance.
</member>
<member name="rendering/gl_compatibility/angle_backend" type="String" setter="" getter="">
Angle render backend.
</member>
<member name="rendering/gl_compatibility/angle_backend.ios" type="String" setter="" getter="">
iOS override for [member rendering/gl_compatibility/angle_backend].
</member>
<member name="rendering/gl_compatibility/angle_backend.macos" type="String" setter="" getter="">
macOS override for [member rendering/gl_compatibility/angle_backend].
</member>
<member name="rendering/gl_compatibility/angle_backend.windows" type="String" setter="" getter="">
Windows override for [member rendering/gl_compatibility/angle_backend].
</member>
<member name="rendering/gl_compatibility/driver" type="String" setter="" getter="">
Sets the driver to be used by the renderer when using the Compatibility renderer. This property can not be edited directly, instead, set the driver using the platform-specific overrides.
</member>
Expand Down
2 changes: 1 addition & 1 deletion drivers/gl_context/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Import("env")

if env["platform"] in ["macos", "windows", "linuxbsd"]:
if env["platform"] in ["ios", "macos", "windows", "linuxbsd"]:
# Thirdparty source files
thirdparty_dir = "#thirdparty/glad/"
thirdparty_sources = ["gl.c"]
Expand Down
12 changes: 9 additions & 3 deletions drivers/gles3/rasterizer_canvas_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_
#else
// On Desktop and mobile we map the memory without synchronizing for maximum speed.
void *ubo = glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(LightUniform) * light_count, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
memcpy(ubo, state.light_uniforms, sizeof(LightUniform) * light_count);
if (ubo) {
memcpy(ubo, state.light_uniforms, sizeof(LightUniform) * light_count);
}
glUnmapBuffer(GL_UNIFORM_BUFFER);
#endif

Expand Down Expand Up @@ -648,7 +650,9 @@ void RasterizerCanvasGLES3::_render_items(RID p_to_render_target, int p_item_cou
#else
// On Desktop and mobile we map the memory without synchronizing for maximum speed.
void *buffer = glMapBufferRange(GL_ARRAY_BUFFER, state.last_item_index * sizeof(InstanceData), index * sizeof(InstanceData), GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
memcpy(buffer, state.instance_data_array, index * sizeof(InstanceData));
if (buffer) {
memcpy(buffer, state.instance_data_array, index * sizeof(InstanceData));
}
glUnmapBuffer(GL_ARRAY_BUFFER);
#endif

Expand Down Expand Up @@ -1506,7 +1510,9 @@ void RasterizerCanvasGLES3::_add_to_batch(uint32_t &r_index, bool &r_batch_broke
#else
// On Desktop and mobile we map the memory without synchronizing for maximum speed.
void *buffer = glMapBufferRange(GL_ARRAY_BUFFER, state.last_item_index * sizeof(InstanceData), r_index * sizeof(InstanceData), GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
memcpy(buffer, state.instance_data_array, r_index * sizeof(InstanceData));
if (buffer) {
memcpy(buffer, state.instance_data_array, r_index * sizeof(InstanceData));
}
glUnmapBuffer(GL_ARRAY_BUFFER);
#endif
_allocate_instance_buffer();
Expand Down
7 changes: 5 additions & 2 deletions drivers/gles3/rasterizer_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#endif

bool RasterizerGLES3::gles_over_gl = true;
bool RasterizerGLES3::use_egl = true;

void RasterizerGLES3::begin_frame(double frame_step) {
frame++;
Expand Down Expand Up @@ -231,9 +232,9 @@ RasterizerGLES3::RasterizerGLES3() {
// version global to see if it loaded for now though, otherwise we fall back to
// the generic loader below.
#if defined(EGL_STATIC)
bool has_egl = true;
bool has_egl = use_egl;
#else
bool has_egl = (eglGetProcAddress != nullptr);
bool has_egl = use_egl && (eglGetProcAddress != nullptr);
#endif

if (gles_over_gl) {
Expand Down Expand Up @@ -262,6 +263,7 @@ RasterizerGLES3::RasterizerGLES3() {
// or we need to actually test for this situation before constructing this.
ERR_FAIL_COND_MSG(!glad_loaded, "Error initializing GLAD.");

#ifdef CAN_DEBUG
if (gles_over_gl) {
if (OS::get_singleton()->is_stdout_verbose()) {
if (GLAD_GL_ARB_debug_output) {
Expand All @@ -273,6 +275,7 @@ RasterizerGLES3::RasterizerGLES3() {
}
}
}
#endif // CAN_DEBUG
#endif // GLAD_ENABLED

// For debugging
Expand Down
4 changes: 3 additions & 1 deletion drivers/gles3/rasterizer_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class RasterizerGLES3 : public RendererCompositor {
double time_total = 0.0;

static bool gles_over_gl;
static bool use_egl;

protected:
GLES3::Config *config = nullptr;
Expand Down Expand Up @@ -105,8 +106,9 @@ class RasterizerGLES3 : public RendererCompositor {
static bool is_gles_over_gl() { return gles_over_gl; }
static void clear_depth(float p_depth);

static void make_current(bool p_gles_over_gl) {
static void make_current(bool p_gles_over_gl, bool p_use_egl = true) {
gles_over_gl = p_gles_over_gl;
use_egl = p_use_egl;
_create_func = _create_current;
low_end = true;
}
Expand Down
7 changes: 6 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,14 +1804,19 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.linuxbsd", PROPERTY_HINT_ENUM, driver_hints_egl), default_driver);
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.web", PROPERTY_HINT_ENUM, driver_hints), default_driver);
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.android", PROPERTY_HINT_ENUM, driver_hints), default_driver);
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.ios", PROPERTY_HINT_ENUM, driver_hints), default_driver);
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.ios", PROPERTY_HINT_ENUM, driver_hints_angle), default_driver);
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/driver.macos", PROPERTY_HINT_ENUM, driver_hints_angle), default_driver);

GLOBAL_DEF_RST("rendering/gl_compatibility/nvidia_disable_threaded_optimization", true);
GLOBAL_DEF_RST("rendering/gl_compatibility/fallback_to_angle", true);
GLOBAL_DEF_RST("rendering/gl_compatibility/fallback_to_native", true);
GLOBAL_DEF_RST("rendering/gl_compatibility/fallback_to_gles", true);

GLOBAL_DEF_RST_NOVAL("rendering/gl_compatibility/angle_backend", "default");
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/angle_backend.windows", PROPERTY_HINT_ENUM, "dx11,opengl"), "dx11");
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/angle_backend.ios", PROPERTY_HINT_ENUM, "metal,opengl"), "metal");
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "rendering/gl_compatibility/angle_backend.macos", PROPERTY_HINT_ENUM, "metal,opengl"), "metal");

Array device_blocklist;

#define BLOCK_DEVICE(m_vendor, m_name) \
Expand Down
12 changes: 12 additions & 0 deletions misc/dist/ios_xcode/godot_ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
1FF8DBB11FBA9DE1009DE660 /* dummy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FF8DBB01FBA9DE1009DE660 /* dummy.cpp */; };
D07CD44E1C5D589C00B7FB28 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D07CD44D1C5D589C00B7FB28 /* Images.xcassets */; };
9039D3BE24C093AC0020482C /* MoltenVK.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9039D3BD24C093AC0020482C /* MoltenVK.xcframework */; };
9039D3BE24C093AC00204830 /* libANGLE.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9039D3BD24C093AC00204830 /* libANGLE.xcframework */; };
9039D3BE24C093AC00204831 /* libEGL.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9039D3BD24C093AC00204831 /* libEGL.xcframework */; };
9039D3BE24C093AC00204832 /* libGLES.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9039D3BD24C093AC00204832 /* libGLES.xcframework */; };
D0BCFE4618AEBDA2004A7AAE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D0BCFE4418AEBDA2004A7AAE /* InfoPlist.strings */; };
D0BCFE7818AEBFEB004A7AAE /* $binary.pck in Resources */ = {isa = PBXBuildFile; fileRef = D0BCFE7718AEBFEB004A7AAE /* $binary.pck */; };
$pbx_launch_screen_build_reference
Expand Down Expand Up @@ -41,6 +44,9 @@
1FF4C1881F584E6300A41E41 /* $binary.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "$binary.entitlements"; sourceTree = "<group>"; };
1FF8DBB01FBA9DE1009DE660 /* dummy.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = dummy.cpp; sourceTree = "<group>"; };
9039D3BD24C093AC0020482C /* MoltenVK.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MoltenVK; path = MoltenVK.xcframework; sourceTree = "<group>"; };
9039D3BD24C093AC00204830 /* libANGLE.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MoltenVK; path = libANGLE.xcframework; sourceTree = "<group>"; };
9039D3BD24C093AC00204831 /* libEGL.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MoltenVK; path = libEGL.xcframework; sourceTree = "<group>"; };
9039D3BD24C093AC00204832 /* libGLES.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MoltenVK; path = libGLES.xcframework; sourceTree = "<group>"; };
D07CD44D1C5D589C00B7FB28 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
D0BCFE3418AEBDA2004A7AAE /* $binary.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "$binary.app"; sourceTree = BUILT_PRODUCTS_DIR; };
D0BCFE4318AEBDA2004A7AAE /* $binary-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "$binary-Info.plist"; sourceTree = "<group>"; };
Expand All @@ -58,6 +64,9 @@
buildActionMask = 2147483647;
files = (
9039D3BE24C093AC0020482C /* MoltenVK.xcframework in Frameworks */,
9039D3BE24C093AC00204830 /* libANGLE.xcframework in Frameworks */,
9039D3BE24C093AC00204831 /* libEGL.xcframework in Frameworks */,
9039D3BE24C093AC00204832 /* libGLES.xcframework in Frameworks */,
DEADBEEF2F582BE20003B888 /* $binary.xcframework */,
$modules_buildphase
$additional_pbx_frameworks_build
Expand Down Expand Up @@ -91,6 +100,9 @@
isa = PBXGroup;
children = (
9039D3BD24C093AC0020482C /* MoltenVK.xcframework */,
9039D3BD24C093AC00204830 /* libANGLE.xcframework */,
9039D3BD24C093AC00204831 /* libEGL.xcframework */,
9039D3BD24C093AC00204832 /* libGLES.xcframework */,
DEADBEEF1F582BE20003B888 /* $binary.xcframework */,
$modules_buildgrp
$additional_pbx_frameworks_refs
Expand Down
1 change: 1 addition & 0 deletions platform/ios/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ios_lib = [
"godot_view.mm",
"tts_ios.mm",
"display_layer.mm",
"gl_manager_ios_angle.mm",
"godot_app_delegate.m",
"godot_view_renderer.mm",
"device_metrics.m",
Expand Down
5 changes: 5 additions & 0 deletions platform/ios/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def get_opts():
("IOS_SDK_PATH", "Path to the iOS SDK", ""),
BoolVariable("ios_simulator", "Build for iOS Simulator", False),
("ios_triple", "Triple for ios toolchain", ""),
("angle_libs", "Path to the ANGLE static libraries", ""),
]


Expand Down Expand Up @@ -156,6 +157,10 @@ def configure(env: "Environment"):

if env["opengl3"]:
env.Append(CPPDEFINES=["GLES3_ENABLED", "GLES_SILENCE_DEPRECATION"])
if env["angle_libs"] != "":
env.AppendUnique(CPPDEFINES=["EGL_STATIC"])
env.Prepend(CPPPATH=["#thirdparty/angle/include"])

env.Prepend(
CPPPATH=[
"$IOS_SDK_PATH/System/Library/Frameworks/OpenGLES.framework/Headers",
Expand Down
77 changes: 47 additions & 30 deletions platform/ios/display_layer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#import <OpenGLES/ES3/gl.h>
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>

Expand All @@ -59,14 +60,20 @@ - (void)initializeDisplayLayer {
}

- (void)layoutDisplayLayer {
DisplayServerIOS::get_singleton()->window_make_current();
}

- (void)startRenderDisplayLayer {
DisplayServerIOS::get_singleton()->window_make_current();
}

- (void)stopRenderDisplayLayer {
}

- (void)dealloc {
DisplayServerIOS::get_singleton()->window_release_current();
}

@end

@implementation GodotOpenGLLayer {
Expand All @@ -77,6 +84,7 @@ @implementation GodotOpenGLLayer {
EAGLContext *context;
GLuint viewRenderbuffer, viewFramebuffer;
GLuint depthRenderbuffer;
BOOL initialized;
}

- (void)initializeDisplayLayer {
Expand All @@ -103,34 +111,42 @@ - (void)initializeDisplayLayer {
NSLog(@"Failed to set EAGLContext!");
return;
}
if (![self createFramebuffer]) {
NSLog(@"Failed to create frame buffer!");
return;
}
initialized = NO;
}

- (void)layoutDisplayLayer {
[EAGLContext setCurrentContext:context];
[self destroyFramebuffer];
[self createFramebuffer];
if (initialized) {
[self destroyFramebuffer];
[self createFramebuffer];
}
}

- (void)startRenderDisplayLayer {
[EAGLContext setCurrentContext:context];

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
if (!initialized && RasterizerGLES3::get_singleton() != nullptr) {
if (![self createFramebuffer]) {
NSLog(@"Failed to create frame buffer!");
return;
}
}

glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
}

- (void)stopRenderDisplayLayer {
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
if (initialized) {
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER];

#ifdef DEBUG_ENABLED
GLenum err = glGetError();
if (err) {
NSLog(@"DrawView: %x error", err);
}
GLenum err = glGetError();
if (err) {
NSLog(@"DrawView: %x error", err);
}
#endif
}
}

- (void)dealloc {
Expand All @@ -144,31 +160,32 @@ - (void)dealloc {
}

- (BOOL)createFramebuffer {
glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);
glGenFramebuffers(1, &viewFramebuffer);
glGenRenderbuffers(1, &viewRenderbuffer);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
// This call associates the storage for the current render buffer with the EAGLDrawable (our CAself)
// allowing us to draw into a buffer that will later be rendered to screen wherever the layer is (which corresponds with our view).
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id<EAGLDrawable>)self];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(id<EAGLDrawable>)self];
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);

glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);

// For this sample, we also need a depth buffer, so we'll create and attach one via another renderbuffer.
glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
glGenRenderbuffers(1, &depthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, backingWidth, backingHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);

if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
return NO;
}

GLES3::TextureStorage::system_fbo = viewFramebuffer;
initialized = YES;

return YES;
}
Expand All @@ -177,13 +194,13 @@ - (BOOL)createFramebuffer {
- (void)destroyFramebuffer {
GLES3::TextureStorage::system_fbo = 0;

glDeleteFramebuffersOES(1, &viewFramebuffer);
glDeleteFramebuffers(1, &viewFramebuffer);
viewFramebuffer = 0;
glDeleteRenderbuffersOES(1, &viewRenderbuffer);
glDeleteRenderbuffers(1, &viewRenderbuffer);
viewRenderbuffer = 0;

if (depthRenderbuffer) {
glDeleteRenderbuffersOES(1, &depthRenderbuffer);
glDeleteRenderbuffers(1, &depthRenderbuffer);
depthRenderbuffer = 0;
}
}
Expand Down
Loading

0 comments on commit ed40c75

Please sign in to comment.