Merge pull request #71848 from bruvzg/ios_gles

[iOS] Restore OpenGLES3 renderer support.
This commit is contained in:
Rémi Verschelde 2023-01-23 10:24:51 +01:00
commit 59dce77d4f
No known key found for this signature in database
GPG Key ID: C3336907360768E1
9 changed files with 84 additions and 42 deletions

View File

@ -1596,9 +1596,13 @@ void TextureStorage::_update_render_target(RenderTarget *rt) {
glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
#ifndef IOS_ENABLED
if (use_multiview) {
glFramebufferTextureMultiviewOVR(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, rt->color, 0, 0, rt->view_count);
} else {
#else
{
#endif
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->color, 0);
}
@ -1623,9 +1627,13 @@ void TextureStorage::_update_render_target(RenderTarget *rt) {
glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
#ifndef IOS_ENABLED
if (use_multiview) {
glFramebufferTextureMultiviewOVR(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, rt->depth, 0, 0, rt->view_count);
} else {
#else
{
#endif
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rt->depth, 0);
}

View File

@ -99,8 +99,8 @@ def configure(env: "Environment"):
if env["ios_simulator"]:
detect_darwin_sdk_path("iossimulator", env)
env.Append(ASFLAGS=["-mios-simulator-version-min=13.0"])
env.Append(CCFLAGS=["-mios-simulator-version-min=13.0"])
env.Append(ASFLAGS=["-mios-simulator-version-min=11.0"])
env.Append(CCFLAGS=["-mios-simulator-version-min=11.0"])
env.extra_suffix = ".simulator" + env.extra_suffix
else:
detect_darwin_sdk_path("ios", env)
@ -153,3 +153,11 @@ def configure(env: "Environment"):
if env["vulkan"]:
env.Append(CPPDEFINES=["VULKAN_ENABLED"])
if env["opengl3"]:
env.Append(CPPDEFINES=["GLES3_ENABLED"])
env.Prepend(
CPPPATH=[
"$IOS_SDK_PATH/System/Library/Frameworks/OpenGLES.framework/Headers",
]
)

View File

@ -33,7 +33,8 @@
@protocol DisplayLayer <NSObject>
- (void)renderDisplayLayer;
- (void)startRenderDisplayLayer;
- (void)stopRenderDisplayLayer;
- (void)initializeDisplayLayer;
- (void)layoutDisplayLayer;

View File

@ -60,7 +60,10 @@
- (void)layoutDisplayLayer {
}
- (void)renderDisplayLayer {
- (void)startRenderDisplayLayer {
}
- (void)stopRenderDisplayLayer {
}
@end
@ -76,8 +79,6 @@
}
- (void)initializeDisplayLayer {
// Get our backing layer
// Configure it so that it is opaque, does not retain the contents of the backbuffer when displayed, and uses RGBA8888 color.
self.opaque = YES;
self.drawableProperties = [NSDictionary
@ -87,8 +88,6 @@
kEAGLDrawablePropertyColorFormat,
nil];
// FIXME: Add Vulkan support via MoltenVK. Add fallback code back?
// Create GL ES 3 context
if (GLOBAL_GET("rendering/renderer/rendering_method") == "gl_compatibility") {
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
@ -115,8 +114,22 @@
[self createFramebuffer];
}
- (void)renderDisplayLayer {
- (void)startRenderDisplayLayer {
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
}
- (void)stopRenderDisplayLayer {
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
#ifdef DEBUG_ENABLED
GLenum err = glGetError();
if (err) {
NSLog(@"DrawView: %x error", err);
}
#endif
}
- (void)dealloc {
@ -154,11 +167,15 @@
return NO;
}
GLES3::TextureStorage::system_fbo = viewFramebuffer;
return YES;
}
// Clean up any buffers we have allocated.
- (void)destroyFramebuffer {
GLES3::TextureStorage::system_fbo = 0;
glDeleteFramebuffersOES(1, &viewFramebuffer);
viewFramebuffer = 0;
glDeleteRenderbuffersOES(1, &viewRenderbuffer);

View File

@ -47,6 +47,10 @@
#endif
#endif
#if defined(GLES3_ENABLED)
#include "drivers/gles3/rasterizer_gles3.h"
#endif // GLES3_ENABLED
#import <Foundation/Foundation.h>
#import <QuartzCore/CAMetalLayer.h>
@ -216,6 +220,7 @@ public:
virtual bool screen_is_kept_on() const override;
void resize_window(CGSize size);
virtual void swap_buffers() override {}
};
#endif // DISPLAY_SERVER_IOS_H

View File

@ -55,28 +55,7 @@ DisplayServerIOS::DisplayServerIOS(const String &p_rendering_driver, WindowMode
// Init TTS
tts = [[TTS_IOS alloc] init];
#if defined(GLES3_ENABLED)
if (rendering_driver == "opengl3") {
bool gl_initialization_error = false;
if (RasterizerGLES3::is_viable() == OK) {
RasterizerGLES3::register_config();
RasterizerGLES3::make_current();
} else {
gl_initialization_error = true;
}
if (gl_initialization_error) {
OS::get_singleton()->alert(
"Your device seems not to support the required OpenGL ES 3.0 version.\n\n",
"Unable to initialize OpenGL video driver");
}
}
#endif
#if defined(VULKAN_ENABLED)
rendering_driver = "vulkan";
context_vulkan = nullptr;
rendering_device_vulkan = nullptr;
@ -91,13 +70,14 @@ DisplayServerIOS::DisplayServerIOS(const String &p_rendering_driver, WindowMode
CALayer *layer = [AppDelegate.viewController.godotView initializeRenderingForDriver:@"vulkan"];
if (!layer) {
ERR_FAIL_MSG("Failed to create iOS rendering layer.");
ERR_FAIL_MSG("Failed to create iOS Vulkan rendering layer.");
}
Size2i size = Size2i(layer.bounds.size.width, layer.bounds.size.height) * screen_get_max_scale();
if (context_vulkan->window_create(MAIN_WINDOW_ID, p_vsync_mode, layer, size.width, size.height) != OK) {
memdelete(context_vulkan);
context_vulkan = nullptr;
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Failed to create Vulkan window.");
}
@ -108,6 +88,18 @@ DisplayServerIOS::DisplayServerIOS(const String &p_rendering_driver, WindowMode
}
#endif
#if defined(GLES3_ENABLED)
if (rendering_driver == "opengl3") {
CALayer *layer = [AppDelegate.viewController.godotView initializeRenderingForDriver:@"opengl3"];
if (!layer) {
ERR_FAIL_MSG("Failed to create iOS OpenGLES rendering layer.");
}
RasterizerGLES3::make_current();
}
#endif
bool keep_screen_on = bool(GLOBAL_GET("display/window/energy_saving/keep_screen_on"));
screen_set_keep_on(keep_screen_on);
@ -670,15 +662,18 @@ void DisplayServerIOS::resize_window(CGSize viewSize) {
void DisplayServerIOS::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) {
_THREAD_SAFE_METHOD_
#if defined(VULKAN_ENABLED)
context_vulkan->set_vsync_mode(p_window, p_vsync_mode);
if (context_vulkan) {
context_vulkan->set_vsync_mode(p_window, p_vsync_mode);
}
#endif
}
DisplayServer::VSyncMode DisplayServerIOS::window_get_vsync_mode(WindowID p_window) const {
_THREAD_SAFE_METHOD_
#if defined(VULKAN_ENABLED)
return context_vulkan->get_vsync_mode(p_window);
#else
return DisplayServer::VSYNC_ENABLED;
if (context_vulkan) {
return context_vulkan->get_vsync_mode(p_window);
}
#endif
return DisplayServer::VSYNC_ENABLED;
}

View File

@ -74,16 +74,20 @@ static const float earth_gravity = 9.80665;
CALayer<DisplayLayer> *layer;
if ([driverName isEqualToString:@"vulkan"]) {
#if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
if (@available(iOS 13, *)) {
layer = [GodotMetalLayer layer];
} else {
return nil;
}
#else
layer = [GodotMetalLayer layer];
#endif
} else if ([driverName isEqualToString:@"opengl3"]) {
if (@available(iOS 13, *)) {
NSLog(@"OpenGL ES is deprecated on iOS 13");
}
#if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
return nil;
#else
layer = [GodotOpenGLLayer layer];
#endif
} else {
return nil;
}
@ -238,7 +242,7 @@ static const float earth_gravity = 9.80665;
[self.displayLink setPaused:NO];
}
[self.renderingLayer renderDisplayLayer];
[self.renderingLayer startRenderDisplayLayer];
if (!self.renderer) {
return;
@ -258,6 +262,8 @@ static const float earth_gravity = 9.80665;
[self handleMotion];
[self.renderer renderOnView:self];
[self.renderingLayer stopRenderDisplayLayer];
}
- (BOOL)canRender {

View File

@ -230,7 +230,7 @@ def configure(env: "Environment"):
env.Append(LIBS=["pthread", "z"])
if env["opengl3"]:
env.Append(CPPDEFINES=["GLES_ENABLED", "GLES3_ENABLED"])
env.Append(CPPDEFINES=["GLES3_ENABLED"])
env.Append(LINKFLAGS=["-framework", "OpenGL"])
env.Append(LINKFLAGS=["-rpath", "@executable_path/../Frameworks", "-rpath", "@executable_path"])

View File

@ -3142,7 +3142,9 @@ ObjectID DisplayServerMacOS::window_get_attached_instance_id(WindowID p_window)
void DisplayServerMacOS::gl_window_make_current(DisplayServer::WindowID p_window_id) {
#if defined(GLES3_ENABLED)
gl_manager->window_make_current(p_window_id);
if (gl_manager) {
gl_manager->window_make_current(p_window_id);
}
#endif
}