Add support for Cocoa OpenGL screen in gfxlib2 and other compiler error fixes for macOS - #448
Markos-Th09 wants to merge 10 commits into
Conversation
|
Wow, nice! I'm not sure about frameworks, but I think it should be up to the user whether they want to link to a framework or to a dylib. For example you can either install SDL via homebrew or compile/download a framework. For system frameworks there's no need for a choice, Maybe a new directive to add a framework, with some way to disable it (do I remember that there's now a way to disable/remove libraries added by #inclib?) I'll want to look into the computed goto removal. clang does support computed gotos. Casting a label address to a function pointer and calling it seems very unsafe (or rather, x86-specific). |
|
Edit: I have traced it to a real llvm bug and I found a workaround for the error _useless:; void* _useless_label = &&_useless;Optionally the variable can be marked as static void FATALOUTOFMEMORY( void )
{
label$2:;
label$4:;
void* vr$0 = fb_ErrorThrowEx( 4, 10, (char*)"src/compiler/list.bas", (void*)0ull, (void*)0ull );
goto *vr$0;
label$5:;
label$3:;
}However, this use of computed goto is undefined behavior per GCC, as this only meant to be used with the addresses of label in this same function taken with
|
|
Also I forgot to mention that the profiler section name is a problem for mach-o binaries so I have disabled it for now, as I don't what is the best solution. |
|
@rversteegen Just to be sure when using gfxlib functions like |
069e50d to
d688658
Compare
@rversteegen given what I have found about computed gotos, how do you believe it would be best addressed? |
9bd0959 to
b461e2b
Compare
|
@rversteegen Since I personally haven't found any issues, I have now opened this for review. The issues highlighted above still remain open for discussion, as I am unsure what is the best way to resolve them. |
Apple's `uname -a` prefers to use `arm64` instead of the standard `aarch64`
Clang is the default C compiler on darwin. This addresses llvm bug 18658 for unused gotos and avoids any issues, using the workaround that already exists in the codebase.
a87066d to
59a561a
Compare
Plain ScreenRes now opens a real macOS window with all the 2D primitives, without XQuartz and without OpenGL (which is deprecated on macOS). Backends and the missing piece: - Upstream's only Darwin backend is X11 via XQuartz, and the Cocoa driver in freebasic#448 is OpenGL-only: its init returns -1 unless DRIVER_OPENGL is set, so a plain ScreenRes renders into the software framebuffer and never presents it (the author's open question about Line/Circle showing nothing). - This driver presents that software framebuffer instead: a refresh thread converts it with the gfxlib2 blitter (fb_hGetBlitter) into a CoreGraphics bitmap and publishes the image to the window's layer, and AppKit itself is only touched on the main thread, from the driver hooks the core calls (flip/unlock/poll_events/wait_vsync) since an FB program owns the main thread and there is no NSApplication run loop. Window/event/scancode scaffolding is adapted from freebasic#448 by Markos-Th09, including src/rtlib/darwin/fb_private_scancodes_cocoa.h; the software present path and the driver hooks are new. Supporting changes: - makefile: compile .m sources (OBJC, LIBFBGFX_M and its PIC/MT variants) - fbc: link -framework Cocoa -framework QuartzCore -framework CoreGraphics for Darwin programs that use gfx - gfx_unix.c: register the driver after X11, so a build with XQuartz keeps using X11 and falls back to Cocoa when no X server is reachable, while a build without XQuartz gets Cocoa as its only driver Verified on macOS 27 / Apple M5: ScreenRes 640,480,32 succeeds (err = 0, ScreenPtr valid), Point() readback matches the drawn colours, BSave is correct, and the window renders Circle/Line/Draw String in the right colours.
Plain ScreenRes now opens a real macOS window with the 2D primitives, without XQuartz and without OpenGL (which is deprecated on macOS). Ported from the freebasic/fbc work in #479/#480 onto this tree's CMake build. Backends: this tree's only Darwin backend is X11 via XQuartz, and the Cocoa driver in freebasic/fbc#448 is OpenGL-only -- its init returns -1 unless DRIVER_OPENGL is set, so a plain ScreenRes renders into the software framebuffer and never presents it. This driver presents that framebuffer instead: a refresh thread converts it with the gfxlib2 blitter (fb_hGetBlitter) into a CoreGraphics bitmap and publishes the image to the window's layer, and AppKit is only touched on the main thread from the driver hooks the core calls (flip/unlock/ poll_events/wait_vsync), since an FB program owns the main thread and there is no NSApplication run loop. - src/gfxlib2/darwin/gfx_driver_cocoa.m, fb_gfx_cocoa.h: the driver - src/rtlib/darwin/fb_private_scancodes_cocoa.h: scancodes (from #448) - gfx_unix.c: register the driver after X11, so an XQuartz build keeps using X11 and falls back to Cocoa when no X server is reachable, while a build without XQuartz gets Cocoa as its only driver - fbc.bas: link -framework Cocoa -framework QuartzCore -framework CoreGraphics for Darwin programs that use gfx - gfxlib2/CMakeLists.txt: the Objective-C driver is listed explicitly (the glob takes only .c) and the OBJC language is enabled on Darwin alone, so other hosts do not need an Objective-C compiler Verified on macOS arm64 with the CMake build: cmake --install ships libfbgfx.a containing the driver (_fb_gfxDriverCocoa defined), and a ScreenRes 320,240,32 program draws a red box and a green circle whose pixels BSave returns exactly.
Plain ScreenRes now opens a real macOS window with the 2D primitives, without XQuartz and without OpenGL (which is deprecated on macOS). Ported from the freebasic/fbc work in #479/#480 onto this tree's CMake build. Backends: this tree's only Darwin backend is X11 via XQuartz, and the Cocoa driver in freebasic/fbc#448 is OpenGL-only -- its init returns -1 unless DRIVER_OPENGL is set, so a plain ScreenRes renders into the software framebuffer and never presents it. This driver presents that framebuffer instead: a refresh thread converts it with the gfxlib2 blitter (fb_hGetBlitter) into a CoreGraphics bitmap and publishes the image to the window's layer, and AppKit is only touched on the main thread from the driver hooks the core calls (flip/unlock/ poll_events/wait_vsync), since an FB program owns the main thread and there is no NSApplication run loop. - src/gfxlib2/darwin/gfx_driver_cocoa.m, fb_gfx_cocoa.h: the driver - src/rtlib/darwin/fb_private_scancodes_cocoa.h: scancodes (from #448) - gfx_unix.c: register the driver after X11, so an XQuartz build keeps using X11 and falls back to Cocoa when no X server is reachable, while a build without XQuartz gets Cocoa as its only driver - fbc.bas: link -framework Cocoa -framework QuartzCore -framework CoreGraphics for Darwin programs that use gfx - gfxlib2/CMakeLists.txt: the Objective-C driver is listed explicitly (the glob takes only .c) and the OBJC language is enabled on Darwin alone, so other hosts do not need an Objective-C compiler Verified on macOS arm64 with the CMake build: cmake --install ships libfbgfx.a containing the driver (_fb_gfxDriverCocoa defined), and a ScreenRes 320,240,32 program draws a red box and a green circle whose pixels BSave returns exactly.
Plain ScreenRes now opens a real macOS window with the 2D primitives, without XQuartz and without OpenGL (which is deprecated on macOS). Ported from the freebasic/fbc work in #479/#480 onto this tree's CMake build. Backends: this tree's only Darwin backend is X11 via XQuartz, and the Cocoa driver in freebasic/fbc#448 is OpenGL-only -- its init returns -1 unless DRIVER_OPENGL is set, so a plain ScreenRes renders into the software framebuffer and never presents it. This driver presents that framebuffer instead: a refresh thread converts it with the gfxlib2 blitter (fb_hGetBlitter) into a CoreGraphics bitmap and publishes the image to the window's layer, and AppKit is only touched on the main thread from the driver hooks the core calls (flip/unlock/ poll_events/wait_vsync), since an FB program owns the main thread and there is no NSApplication run loop. - src/gfxlib2/darwin/gfx_driver_cocoa.m, fb_gfx_cocoa.h: the driver - src/rtlib/darwin/fb_private_scancodes_cocoa.h: scancodes (from #448) - gfx_unix.c: register the driver after X11, so an XQuartz build keeps using X11 and falls back to Cocoa when no X server is reachable, while a build without XQuartz gets Cocoa as its only driver - fbc.bas: link -framework Cocoa -framework QuartzCore -framework CoreGraphics for Darwin programs that use gfx - gfxlib2/CMakeLists.txt: the Objective-C driver is listed explicitly (the glob takes only .c) and the OBJC language is enabled on Darwin alone, so other hosts do not need an Objective-C compiler Verified on macOS arm64 with the CMake build: cmake --install ships libfbgfx.a containing the driver (_fb_gfxDriverCocoa defined), and a ScreenRes 320,240,32 program draws a red box and a green circle whose pixels BSave returns exactly.
This PR includes several changes to improve support for the macOS platform in fbc and its libraries. It also aims to add support for OpenGL screens using Cocoa instead of requiring XQuartz for X11 support, although at the time of writing this I haven't tested the implementation very thoroughly yet.
Currently some mechanism similar to
#inclibbut for macOS frameworks is missing. Since a lot of important system libraries contained within frameworks such as OpenGL, this would be useful for headers such asgl.biandglut.bibut also in general. How should this feature be implemented in FreeBASIC?