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

Migrate OSX to GLFW3+ #8348

Merged
merged 73 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
10741d3
Initial refactoring
Jhonnyg Dec 22, 2023
0965894
Update graphics tests
Jhonnyg Dec 6, 2023
ab0fe9f
Graphics test modifications
Jhonnyg Dec 22, 2023
9c3991b
Make graphics test render with opengl
Jhonnyg Dec 22, 2023
4817752
Move all glfw calls from hid
Jhonnyg Dec 23, 2023
e0790d7
Window resizing
Jhonnyg Dec 23, 2023
200fc4b
Vulkan support
Jhonnyg Dec 25, 2023
9d4e27a
More migration work
Jhonnyg Dec 25, 2023
fb6b30c
build fixes
Jhonnyg Dec 26, 2023
1c86c0d
Create aux context
Jhonnyg Dec 26, 2023
7f17d12
Android and ios build fixes
Jhonnyg Dec 27, 2023
a24893e
Fix vulkan linkage
Jhonnyg Dec 27, 2023
785947c
Web fixes
Jhonnyg Dec 28, 2023
3145f6b
Misc fixes
Jhonnyg Dec 28, 2023
c2cf261
Merge branch 'dev' into glfw3-support-for-osx
Jhonnyg Jan 4, 2024
239b260
Fixes
Jhonnyg Jan 5, 2024
9f2a054
Merge branch 'dev' into glfw3-support-for-osx
Jhonnyg Jan 22, 2024
2387eb0
Merge branch 'dev' into glfw3-support-for-osx
Jhonnyg Feb 5, 2024
bf97091
Merge branch 'dev' into glfw3-support-for-osx
Jhonnyg Feb 8, 2024
3c59edf
Vulkan fixes
Jhonnyg Feb 8, 2024
5b954a6
Fix building with setmarkedcallback
Jhonnyg Feb 8, 2024
619b6c8
Pre-review fixes
Jhonnyg Feb 8, 2024
7fc06e1
Remove vulkan-specific library from osx package
Jhonnyg Feb 9, 2024
b9c8d6b
Revert "Remove vulkan-specific library from osx package"
Jhonnyg Feb 9, 2024
331b99a
build.yaml fixes
Jhonnyg Feb 9, 2024
e9879f9
Manifest test
Jhonnyg Feb 9, 2024
9eb99da
Editor test fix
Jhonnyg Feb 9, 2024
cc3d301
Maybe this will work
Jhonnyg Feb 12, 2024
ab62ba9
Merge branch 'dev' into glfw3-support-for-osx
Jhonnyg Feb 12, 2024
0070124
Use 3.3.9
Jhonnyg Feb 13, 2024
b4e6dd5
Remove warning of swapinterval on vulkan
Jhonnyg Feb 13, 2024
2ae024f
Test with bundle activate/deactive code
Jhonnyg Feb 14, 2024
3292cd5
D'oh
Jhonnyg Feb 14, 2024
12aedaa
Update patch
Jhonnyg Feb 14, 2024
f8bdf45
Let's debug this2
Jhonnyg Feb 14, 2024
c534eb5
Merge branch 'dev' into glfw3-support-for-osx
Jhonnyg Mar 22, 2024
9d744f5
Merge branch 'dev' into glfw3-support-for-osx
Jhonnyg Apr 1, 2024
c3af962
Test fix
Jhonnyg Apr 1, 2024
49b8a02
Maybe now
Jhonnyg Apr 1, 2024
cec20f7
Test without focus patch
Jhonnyg Apr 1, 2024
894e46b
glfw3 + vulkan fixes
Jhonnyg Apr 1, 2024
63a1630
Please mr runner run this
Jhonnyg Apr 1, 2024
55e72d9
F it, build without test app for now..
Jhonnyg Apr 1, 2024
6df6236
One more try with different packages
Jhonnyg Apr 1, 2024
9fa91a1
Need to trigger a build..
Jhonnyg Apr 1, 2024
f829ecd
Goddamnit, one more time..
Jhonnyg Apr 2, 2024
3a42f74
Stash
Jhonnyg Apr 2, 2024
420e4a5
add launch log in the editor
AGulev May 3, 2024
e3202ea
add error log
AGulev May 3, 2024
ea4a3fa
Merge branch 'dev' into glfw3-support-for-osx
AGulev May 3, 2024
57c2dca
show error num
AGulev May 3, 2024
0963d31
add run parameters into log
AGulev May 3, 2024
7263ac8
Revert "add run parameters into log"
AGulev May 3, 2024
8e98472
Revert "add launch log in the editor"
AGulev May 3, 2024
ceb0412
use GLFW_COCOA_CHDIR_RESOURCES to prevent issues with building from t…
AGulev May 3, 2024
78dea47
Merge branch 'glfw3-support-for-osx' of github.com:defold/defold into…
Jhonnyg May 14, 2024
b712693
Merge branch 'dev' into glfw3-support-for-osx
Jhonnyg May 14, 2024
fe80378
Vulkan fixes
Jhonnyg May 14, 2024
ef09784
pre-review fixes
Jhonnyg May 14, 2024
7833374
Manifest updates
Jhonnyg May 14, 2024
6525e88
Remove wrong test content
Jhonnyg May 14, 2024
075fe0b
Upgrade to glfw 3.4
Jhonnyg May 14, 2024
9e01d79
Remove old glfw3 patch
Jhonnyg May 14, 2024
1739cc9
Manifest dummy fix
Jhonnyg May 14, 2024
8e00b19
Check support for first adapter in chain
Jhonnyg May 16, 2024
33cc206
Fix mouse input
Jhonnyg May 16, 2024
d1eeb46
Add patch for 3.4 again
Jhonnyg May 16, 2024
d8772f4
Add polling in null input library
Jhonnyg May 16, 2024
034d2e8
Merge branch 'dev' into glfw3-support-for-osx
Jhonnyg May 16, 2024
75e8fb4
pre review fixes
Jhonnyg May 16, 2024
c5237c2
Calculate display scale
Jhonnyg May 20, 2024
a340fa0
Review fix
Jhonnyg May 28, 2024
a05a79e
Use full bit mask for keyboard again
Jhonnyg May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions build_tools/waf_dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def platform_setup_vars(ctx, build_util):
def transform_runnable_path(platform, path):
return waf_dynamo_vendor.transform_runnable_path(platform, path)

def platform_glfw_version(platform):
if platform in ['x86_64-macos', 'arm64-macos']:
return 3
return 2

# Note that some of these version numbers are also present in build.py (TODO: put in a waf_versions.py or similar)
# The goal is to put the sdk versions in sdk.py
SDK_ROOT=sdk.SDK_ROOT
Expand Down Expand Up @@ -1838,10 +1843,14 @@ def detect(conf):
conf.env['STLIB_GRAPHICS_VULKAN'] = ['graphics_vulkan', 'graphics_transcoder_basisu', 'basis_transcoder']
conf.env['STLIB_GRAPHICS_NULL'] = ['graphics_null', 'graphics_transcoder_null']

conf.env['STLIB_PLATFORM'] = ['platform']
conf.env['STLIB_PLATFORM_NULL'] = ['platform_null']
conf.env['STLIB_PLATFORM'] = ['platform']
conf.env['STLIB_PLATFORM_VULKAN'] = ['platform_vulkan']
conf.env['STLIB_PLATFORM_NULL'] = ['platform_null']

conf.env['STLIB_DMGLFW'] = 'dmglfw'
if platform_glfw_version(platform) == 3:
conf.env['STLIB_DMGLFW'] = 'glfw3'
else:
conf.env['STLIB_DMGLFW'] = 'dmglfw'

if platform in ('x86_64-macos','arm64-macos'):
conf.env['STLIB_VULKAN'] = Options.options.with_vulkan_validation and 'vulkan' or 'MoltenVK'
Expand Down
2 changes: 2 additions & 0 deletions editor/src/clj/editor/app_manifest.clj
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@

(def vulkan-toggles
(concat
(exclude-libs-toggles [:x86_64-osx :arm64-osx] ["platform"])
(libs-toggles [:x86_64-osx :arm64-osx] ["platform_vulkan"])
(libs-toggles [:x86_64-osx :arm64-osx :arm64-ios] ["graphics_vulkan" "MoltenVK"])
(libs-toggles android ["graphics_vulkan"])
(libs-toggles windows ["graphics_vulkan" "vulkan"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
platforms:
arm64-osx:
context:
excludeLibs: ["graphics"]
excludeLibs: ["graphics", "platform"]
excludeSymbols: ["GraphicsAdapterOpenGL"]
symbols: ["GraphicsAdapterVulkan"]
libs: ["graphics_vulkan","MoltenVK"]
libs: ["graphics_vulkan", "platform_vulkan", "MoltenVK"]
frameworks: ["Metal","IOSurface","QuartzCore"]
linkFlags: []

x86_64-osx:
context:
excludeLibs: ["graphics"]
excludeLibs: ["graphics", "platform"]
excludeSymbols: ["GraphicsAdapterOpenGL"]
symbols: ["GraphicsAdapterVulkan"]
libs: ["graphics_vulkan","MoltenVK"]
libs: ["graphics_vulkan", "platform_vulkan", "MoltenVK"]
frameworks: ["Metal","IOSurface","QuartzCore"]
linkFlags: []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
platforms:
arm64-osx:
context:
excludeLibs: []
excludeLibs: ["platform"]
excludeSymbols: []
symbols: ["GraphicsAdapterVulkan"]
libs: ["graphics_vulkan","MoltenVK"]
libs: ["graphics_vulkan", "platform_vulkan", "MoltenVK"]
frameworks: ["Metal","IOSurface","QuartzCore"]
linkFlags: []

x86_64-osx:
context:
excludeLibs: []
excludeLibs: ["platform"]
excludeSymbols: []
symbols: ["GraphicsAdapterVulkan"]
libs: ["graphics_vulkan","MoltenVK"]
libs: ["graphics_vulkan", "platform_vulkan", "MoltenVK"]
frameworks: ["Metal","IOSurface","QuartzCore"]
linkFlags: []

Expand Down
26 changes: 17 additions & 9 deletions engine/engine/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,28 @@ def configure(conf):
architecture = build_util.get_target_architecture()

sound_lib = 'sound'
glfw_lib = 'dmglfw'
platform_lib = 'platform'

if operating_sys == 'macos':
conf.env.append_value('LINKFLAGS', ['-framework', 'Cocoa', '-framework', 'OpenGL', '-framework', 'OpenAL', '-framework', 'AGL', '-framework', 'IOKit', '-framework', 'Carbon', '-framework', 'CoreVideo', '-framework', 'QuartzCore'])

glfw_lib = "glfw3"

# For Vulkan/MoltenVK
if waflib.Options.options.with_vulkan and architecture == 'x86_64':
conf.env.append_value('LINKFLAGS', ['-framework', 'Metal', '-framework', 'Foundation', '-framework', 'IOSurface'])
if waflib.Options.options.with_vulkan:

platform_lib = "platform_vulkan"

# Link with vulkan.dylib if the flag has been set (see graphics/vulkan/README.md) for more information
conf.env.append_value('LINKFLAGS', ['-l', waflib.Options.options.with_vulkan_validation and 'vulkan' or 'MoltenVK'])
# JG: for now, we only support validation layers on macos for x86_64 archs. I'll fix this later when/if needed.
if architecture == 'x86_64':
conf.env.append_value('LINKFLAGS', ['-framework', 'Metal', '-framework', 'Foundation', '-framework', 'IOSurface'])

# Metal deps requires libc++ stdlib. Remove once we've updated to use libc++ std
conf.env.append_value('LINKFLAGS', ['-l', 'c++'])
# Link with vulkan.dylib if the flag has been set (see graphics/vulkan/README.md) for more information
conf.env.append_value('LINKFLAGS', ['-l', waflib.Options.options.with_vulkan_validation and 'vulkan' or 'MoltenVK'])

# Metal deps requires libc++ stdlib. Remove once we've updated to use libc++ std
conf.env.append_value('LINKFLAGS', ['-l', 'c++'])

elif operating_sys == 'ios':
conf.env.append_value('LINKFLAGS', ['-framework', 'UIKit', '-framework', 'OpenGLES', '-framework', 'QuartzCore', '-framework', 'CoreGraphics', '-framework', 'OpenAL', '-framework', 'AudioToolbox'])
Expand Down Expand Up @@ -113,10 +122,10 @@ def configure(conf):
conf.env['STLIB_GAMESYS'] = 'gamesys script_box2d'.split()
conf.env['STLIB_GAMEOBJECT'] = 'gameobject'
conf.env['STLIB_SCRIPT'] = 'script'
conf.env['STLIB_DMGLFW'] = 'dmglfw'
conf.env['STLIB_DMGLFW'] = glfw_lib
conf.env['STLIB_GUI'] = 'gui'
conf.env['STLIB_PARTICLE'] = 'particle'
conf.env['STLIB_PLATFORM'] = 'platform'
conf.env['STLIB_PLATFORM'] = platform_lib
conf.env['STLIB_PLATFORM_NULL'] = 'platform_null'
conf.env['STLIB_RIG'] = 'rig'
conf.env['STLIB_SOUND'] = sound_lib
Expand All @@ -127,7 +136,6 @@ def configure(conf):
conf.env['STLIB_HID_NULL'] = 'hid_null'
conf.env['STLIB_INPUT'] = 'input'
conf.env['STLIB_LIVEUPDATE'] = 'liveupdate'
conf.env['STLIB_PLATFORM_NULL'] = 'platform_null'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate


if operating_sys != "macos":
conf.env['STLIB_UNWIND'] = 'unwind'
Expand Down
3 changes: 2 additions & 1 deletion engine/graphics/src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ namespace dmGraphics

while(next)
{
if (next->m_Priority < selected->m_Priority && next->m_IsSupportedCb())
bool is_supported = next->m_IsSupportedCb();
if (next->m_Priority < selected->m_Priority && is_supported)
{
Comment on lines +75 to 77
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only link with one adapter we never actually do this check..

selected = next;
}
Expand Down
101 changes: 67 additions & 34 deletions engine/graphics/src/opengl/graphics_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,45 @@
#include <emscripten/html5.h>
#endif

#include <platform/platform_window_opengl.h>

#include "graphics_opengl_defines.h"
#include "../graphics_private.h"
#include "../graphics_native.h"
#include "../graphics_adapter.h"
#include "graphics_opengl_private.h"

#if defined(DM_PLATFORM_MACOS)
// Potential name clash with ddf. If included before ddf/ddf.h (TYPE_BOOL)
#include <Carbon/Carbon.h>
// Potential name clash with ddf. If included before ddf/ddf.h (TYPE_BOOL)
#include <Carbon/Carbon.h>
#endif

#include <glfw/glfw.h>
#include <glfw/glfw_native.h>
/* Include standard OpenGL headers: GLFW uses GL_FALSE/GL_TRUE, and it is
* convenient for the user to only have to include <GL/glfw.h>. This also
* solves the problem with Windows <GL/gl.h> and <GL/glu.h> needing some
* special defines which normally requires the user to include <windows.h>
* (which is not a nice solution for portable programs).
*/
#if defined(__APPLE_CC__)
#if defined(DM_PLATFORM_IOS)
#include <platform/platform_window_ios.h>
#include <OpenGLES/ES3/gl.h>
#else
#include <OpenGL/gl3.h>
#ifndef GLFW_NO_GLU
#include <OpenGL/glu.h>
#endif
#endif
#elif defined(ANDROID)
#include <platform/platform_window_android.h>
#include <EGL/egl.h>
#include <GLES/gl.h>
#else
#include <GL/gl.h>
#ifndef GLFW_NO_GLU
#include <GL/glu.h>
#endif
#endif

#if defined(__linux__) && !defined(ANDROID)
#include <GL/glext.h>
Expand Down Expand Up @@ -184,28 +210,30 @@ namespace dmGraphics
{
using namespace dmVMath;

static void LogGLError(GLint err, const char* fnname, int line)
{
#if defined(GL_ES_VERSION_2_0)
const char* error_str = "<unknown-gl-error>";
switch(err)
#define TO_STR_CASE(x) case x: return #x;
static const char* GetGLErrorLiteral(GLint err)
{
case GL_INVALID_ENUM:
error_str = "GL_INVALID_ENUM";
break;
case GL_INVALID_VALUE:
error_str = "GL_INVALID_VALUE";
break;
case GL_INVALID_OPERATION:
error_str = "GL_INVALID_OPERATION";
break;
default:break;
switch(err)
{
TO_STR_CASE(GL_NO_ERROR);
TO_STR_CASE(GL_INVALID_ENUM);
TO_STR_CASE(GL_INVALID_VALUE);
TO_STR_CASE(GL_INVALID_OPERATION);
TO_STR_CASE(GL_INVALID_FRAMEBUFFER_OPERATION);
TO_STR_CASE(GL_OUT_OF_MEMORY);
// These are not available by the gl headers we are using currently
// but left for posterity
// TO_STR_CASE(GL_STACK_UNDERFLOW);
// TO_STR_CASE(GL_STACK_OVERFLOW);
}
return "<unknown-gl-error>";
}
#undef TO_STR_CASE

static inline void LogGLError(GLint err, const char* fnname, int line)
{
dmLogError("%s(%d): gl error %d: %s\n", fnname, line, err, GetGLErrorLiteral(err));
}
dmLogError("%s(%d): gl error %d: %s\n", fnname, line, err, error_str);
#else
dmLogError("%s(%d): gl error %d: %s\n", fnname, line, err, gluErrorString(err));
#endif
}

// We use defines here so that we get a callstack from the correct function

Expand Down Expand Up @@ -237,7 +265,7 @@ static void LogGLError(GLint err, const char* fnname, int line)
LogGLError(err, __FUNCTION__, __LINE__); \
if (err == GL_OUT_OF_MEMORY) { \
dmLogWarning("Signs of surface being destroyed. skipping assert.");\
if (glfwAndroidVerifySurface()) { \
if (dmPlatform::AndroidVerifySurface(g_Context->m_Window)) { \
assert(0); \
} \
} else { \
Expand Down Expand Up @@ -344,7 +372,8 @@ static void LogFrameBufferError(GLenum status)
{
ChooseEAGLView() {
// Let's us choose the CAEAGLLayer
glfwSetViewType(GLFW_OPENGL_API);
// Note: We don't need a valid window here (and we don't have access to one)
dmPlatform::iOSSetViewTypeOpenGL((dmPlatform::HWindow) 0);
}
} g_ChooseEAGLView;
#endif
Expand Down Expand Up @@ -587,7 +616,7 @@ static void LogFrameBufferError(GLenum status)

static bool OpenGLIsSupported()
{
return (glfwInit() == GL_TRUE);
return true;
}
Jhonnyg marked this conversation as resolved.
Show resolved Hide resolved

static void OpenGLFinalize()
Expand Down Expand Up @@ -653,6 +682,8 @@ static void LogFrameBufferError(GLenum status)

static uintptr_t GetExtProcAddress(const char* name, const char* extension_name, const char* core_name, HContext context)
{
dmPlatform::HWindow window = GetWindow(context);

/*
Check in order
1) ARB - Extensions officially approved by the OpenGL Architecture Review Board
Expand All @@ -673,7 +704,7 @@ static void LogFrameBufferError(GLenum status)
continue;
l = dmStrlCpy(proc_str, name, 255);
dmStrlCpy(proc_str + l, proc_name_postfix_str[i], 256-l);
func = (uintptr_t) glfwGetProcAddress(proc_str);
func = dmPlatform::GetProcAddress(window, proc_str);
if(func != 0x0)
{
break;
Expand All @@ -683,7 +714,7 @@ static void LogFrameBufferError(GLenum status)
if(func == 0 && core_name)
{
// On OpenGL, optionally check for core driver support if extension wasn't found (i.e extension has become part of core OpenGL)
func = (uintptr_t) glfwGetProcAddress(core_name);
func = dmPlatform::GetProcAddress(window, core_name);
}
#endif

Expand Down Expand Up @@ -748,7 +779,7 @@ static void LogFrameBufferError(GLenum status)

glBindTexture(GL_TEXTURE_2D, 0);
CHECK_GL_ERROR;
glBindFramebuffer(GL_FRAMEBUFFER, glfwGetDefaultFramebuffer());
glBindFramebuffer(GL_FRAMEBUFFER, dmPlatform::OpenGLGetDefaultFramebufferId());
CHECK_GL_ERROR;
glDeleteFramebuffers(1, &osfb);
DeleteTexture(texture_handle);
Expand Down Expand Up @@ -956,6 +987,8 @@ static void LogFrameBufferError(GLenum status)
#if !(defined(__EMSCRIPTEN__) || defined(GL_ES_VERSION_2_0))
GLint n;
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
CHECK_GL_ERROR;

if (n > 0)
{
int max_len = 0;
Expand Down Expand Up @@ -1407,15 +1440,15 @@ static void LogFrameBufferError(GLenum status)
static void OpenGLBeginFrame(HContext context)
{
#if defined(ANDROID)
glfwAndroidBeginFrame();
dmPlatform::AndroidBeginFrame(((OpenGLContext*) context)->m_Window);
#endif
}

static void OpenGLFlip(HContext context)
{
DM_PROFILE(__FUNCTION__);
PostDeleteTextures((OpenGLContext*) context, false);
glfwSwapBuffers();
dmPlatform::SwapBuffers(((OpenGLContext*) context)->m_Window);
CHECK_GL_ERROR;
}

Expand Down Expand Up @@ -2532,7 +2565,7 @@ static void LogFrameBufferError(GLenum status)
}

CHECK_GL_FRAMEBUFFER_ERROR;
glBindFramebuffer(GL_FRAMEBUFFER, glfwGetDefaultFramebuffer());
glBindFramebuffer(GL_FRAMEBUFFER, dmPlatform::OpenGLGetDefaultFramebufferId());
CHECK_GL_ERROR;

return StoreAssetInContainer(context->m_AssetHandleContainer, rt, ASSET_TYPE_RENDER_TARGET);
Expand Down Expand Up @@ -2615,7 +2648,7 @@ static void LogFrameBufferError(GLenum status)
context->m_FrameBufferInvalidateAttachments = rt != NULL;
#endif
}
glBindFramebuffer(GL_FRAMEBUFFER, rt == NULL ? glfwGetDefaultFramebuffer() : rt->m_Id);
glBindFramebuffer(GL_FRAMEBUFFER, rt == NULL ? dmPlatform::OpenGLGetDefaultFramebufferId() : rt->m_Id);
CHECK_GL_ERROR;

#if __EMSCRIPTEN__
Expand Down