Building for macOS is broken, glatter doesn't support macOS

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Building for macOS is broken, glatter doesn't support macOS

Postby FSA » Tue Jul 16, 2024 12:26 pm

I'm trying to build on macOS 14.5 (M1 Pro ARMv8), however the glatter lib doesn't support macOS at all:
glatter_platform_headers.h
Code: Select all
#if defined(_WIN32)
    #ifndef NOMINMAX
    #define NOMINMAX
    #endif
    #ifndef WIN32_LEAN_AND_MEAN
    #define WIN32_LEAN_AND_MEAN
    #endif
    #include <Windows.h>
#elif defined (__linux__)
    #include <pthread.h>
    #include <dlfcn.h>
#else
    #error This platform is not supported
#endif


Also it seems like SSE3 is required and enabled by default. However my CPU (ARMv8 M1 Pro) doesn't support Intel intrinsics.

An update to miniz is also required. The currently used miniz.c version in Newton has a bug, that causes incorrect #defines for apple.
This can be fixed by replacing line 2986 in miniz.c with
Code: Select all
#elif defined(__GNUC__) && _LARGEFILE64_SOURCE && !defined(__APPLE__)
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Building for macOS is broken, glatter doesn't support ma

Postby Julio Jerez » Tue Jul 16, 2024 6:03 pm

ok I fixed this
"The currently used miniz.c version in Newton has a bug, that causes incorrect #defines for apple.
This can be fixed by replacing line 2986 in miniz.c with"

and the sse3 part by adding this to the cmake scrips

if (APPLE OR NEWTON_SCALAR_VECTOR_CLASS)
add_definitions(-DD_SCALAR_VECTOR_CLASS)
endif()

this will exclude all the x86 simd code and only use scalar classes.
on OS 10 there is no much advantage of using neon since it is 128 bit wide, and simd on x86 is only advantageous when using avx and avx2. however the clang compiler are very good at generation neon code.
in fact, I am considering to get rid of all the explicit intrinsics simd code for some future version of the engine. Visual Studio 2019 and 2022 are incredibly good at generating optimized simd code from cpp. In many cases better I can write using explicit intrinsics.

The third one is much harder, because Apple not longer support openGL, therefore my guess is that this is glatter fail, that library is only a wrapper to load the driver function opengl function pointers but if teh drive not loge provide them, it will never work.

at least I think that's the reason.
you can still build the libraries, you are just not going to be anle to build the demos.
if you
Julio Jerez
Moderator
Moderator
 
Posts: 12425
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Building for macOS is broken, glatter doesn't support ma

Postby FSA » Wed Jul 17, 2024 12:01 pm

Yes Apple deprecated OpenGL >=4.2, but you can still use it on newer macOS versions. To silence the deprecation warnings, one can use this:
Code: Select all
#define GL_SILENCE_DEPRECATION

As far as I know, using OpenGL works with a translation layer in between, to translate to METAL. The ANGLE lib could be of interest: https://github.com/google/angle
However since OpenGL is starting to get deprecated on Linux too, maybe it should be considered moving to a newer API. Metal is actually I suprinsgly simple API, but only on Apple systems of course.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Building for macOS is broken, glatter doesn't support ma

Postby Julio Jerez » Wed Jul 17, 2024 1:59 pm

I am trying to migrate to Vulkan, but that is a slow process.

I have a local when I try to migrate to vulkan but the I stopped, and decide that to easy the learning am first trying using vulkan compute for deep learning.

but the problem now is that it seems apply support vulkan even less than OpenGL.
last time I try to build newton on my Mac mini, I could not get pass anything.
I abandoned it.
It seems Apple is perfectly content with their user base and they are weeding out anything that is not apple.

So, other tha adding #define GL_SILENCE_DEPRECATION
what do I have to do to get open gl building on OSx, is there a site or a doc?
will the code compile?

My probloem wi th apple is that I have been burn so many times.
I put to of work on Objective C, just to find out that after OSX 5. they deprecated, and soon after that code didn't even run.
I had a Mac Pro, that I paid 6 grand, it has dual Ceon quad cores, and after El Capitan, Apple said thought luck, you can only use this compute for browsing the internet, and read emails, every day one by one application stop running.
I was an apply fan, I have a Imac with a G5, and apply said will always support G5 and Intel, they that decided to cut the G5, then the Cut Intel,
so I decided I will not invest any time on Apple development. They can have their Cake and eat it.

I still has to deal with Apply because of my work, but if it was me, the smugness of Apple toward their use base is just not acceptable.

those are just few of my experiences, I haven't even mention they ask you to pay for the privilege to develop for Mac product. or the horror stories of people using Iphones.
Julio Jerez
Moderator
Moderator
 
Posts: 12425
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Building for macOS is broken, glatter doesn't support ma

Postby Julio Jerez » Wed Jul 17, 2024 2:14 pm

I will see if I can link that Angle library over the weekend.
Julio Jerez
Moderator
Moderator
 
Posts: 12425
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Building for macOS is broken, glatter doesn't support ma

Postby FSA » Wed Jul 17, 2024 2:21 pm

There shouldn't be much to do as far as I understood it. Considering a different loading lib: https://www.khronos.org/opengl/wiki/OpenGL_Loading_Library

Here is a short example to use OpenGL on M1 Mac: https://carette.xyz/posts/opengl_and_cpp_on_m1_mac/

Apparently macOS doesn't need a loading lib. The functions are exposed directly with the included header.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Building for macOS is broken, glatter doesn't support ma

Postby Julio Jerez » Wed Jul 17, 2024 4:35 pm

I see if I can follow this, https://carette.xyz/posts/opengl_and_cpp_on_m1_mac
this weekend.
thanks for the link
Julio Jerez
Moderator
Moderator
 
Posts: 12425
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Building for macOS is broken, glatter doesn't support ma

Postby Julio Jerez » Thu Aug 15, 2024 10:41 am

oh, I know this is late, but after investigation more, I found keep that trying using opengl on max os is a fool errand.
Even if for some reason you get it to work, you are still at the mercy of apply next release.
the further away you get the less the more support is removed.

I also check those other libraries like Angle or MoltenVulkam and I found that both are ridiculous complex for what this is supposed to be.

In fact I am not so sure Molet Vulkan will survive few versions of Mac OS, my perception is that apple will also deprecated it.

anyway th3 was I see I can try tow options.

1-write a native swift demo using metal, which seem just a s complex as Vulkan.
2-using a third-party lightweight library. I am now looking at SDL2

it seems simple enough, has cmake script and Xcode support already.
most important the demos can be test on many platforms provided they work.
but the huge problem with sdl is that is has zero support for 3d graphics.

It is so shameful that there not easy way to put a simple demo together on apple systems.

the only option they let is to use native metal, which is not a essay thing.
It required learning many things.
Julio Jerez
Moderator
Moderator
 
Posts: 12425
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Building for macOS is broken, glatter doesn't support ma

Postby Julio Jerez » Mon Aug 19, 2024 12:18 pm

ok after struggling for few days trying to adapt cmake to generate a valid xcode project.
I find the task quite difficult. No impossible I actually have a project, but there are few things that are still impossible, one is the bridging between CPP and Switf.
I could not find a way to generate a project that links without errors. It looks like xcode create some special in the project, that can only be does using xcode.
It seems xcode is a moving target.

so I decided to make manual libraries in xcode.

I am surprice there are no samples of how to integrate cpp and xcode. not even on the Apple support sites. most of them are contradictory and misleading. they mention cpp interoperability, but it is a baith and switch, the interoperability is an Apple version of cpp they call objective cpp.

I did find a minimal sample CppInteropInlineExample and that the one I am using.

Any way I am adding the library and mange to link them with a switf project, that can instanciate the word, but even in switf every thing is is changing.

here is an example in this file. (created but xcode id and edicted)

Code: Select all
import SwiftUI

struct ContentView: View {
    let number = myFavoriteNumber()
    let newton = UnsafeMutablePointer<Void>(CreateWorld())
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, No. \(number)!")
        }
        .padding()
    }
}


the line that instanciate the engine is this
let newton = UnsafeMutablePointer<Void>(CreateWorld())

but xcode is unhappy and generate a warning saying to use UnsafeMutableRawPointer
instead of UnsafeMutablePointer

but I could not find a simple example of how to use that. and if my pass experience with xcode and apply, is correct when they issues a warning, it means that next time you open the project your code will not compiled because apple just removed it.

I found the integration between Switf and native C++ too difficult and incomplete on Apple,
and I get the impression that Apple is also on its way to flush out Cpp from their system,
the solution they are providing seem to be a really bad band aid.

anyway I will add all the libraries and see if I figure out how to run at least a simple test.
but if it turns out that I will have to write c or objective c glue code, that no something I want to spend time on.

In their video that claim it is possible to make call to cpp classes, but they talk of objective cpp

right now, I am stuck on how to insatiate a cpp class and them how to make call to member functions of the class.
Julio Jerez
Moderator
Moderator
 
Posts: 12425
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Building for macOS is broken, glatter doesn't support ma

Postby Julio Jerez » Sun Jun 22, 2025 10:27 pm

I go around to build the mac to see if it compiles opencl, and now I see so cool stuff.
It seems they are now supporting openGL again.

    Found GLFW library
    Found OpenGL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks/OpenGL.framework
    Found OpenGL library

last time those searched failed. I see if I can get the libraries working

I can' get the GLFW form the apple system, it seems you have to use the homebrew bull s-hit
so, I am using the source version that I use for windows.
It seems apple does no need any Glatter, they add their one loader.

not I have to copy with imgui, see how that goes.
There are too of deprecation warning, which means even if I can get it going it is at the mercy of apples next OS release.

anyway, I still try to see if I can get it build and link.
Julio Jerez
Moderator
Moderator
 
Posts: 12425
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Building for macOS is broken, glatter doesn't support ma

Postby Julio Jerez » Mon Jun 23, 2025 6:09 pm

well I give up. the newton libraries are compiling right, but for some reason I can't get it to link

message ("linking required Apple frameworks")
add_definitions(-DGL_SILENCE_DEPRECATION)

target_link_libraries(${projectName} PUBLIC glfw)
#target_link_libraries(${projectName} PUBLIC glfw glut)

#target_link_libraries(${projectName} PRIVATE "-framework IOKit")
#target_link_libraries(${projectName} PRIVATE "-framework CoreGraphics")
#target_link_libraries(${projectName}Foundation" "-framework AppKit")

target_link_libraries(${projectName} PUBLIC "-framework OpenGL")
target_link_libraries(${projectName} PRIVATE "-framework CoreFoundation")
#set_target_properties(${projectName} PROPERTIES LINK_FLAGS "-Wl,-F/Library/Frameworks") PRIVATE "-framework CoreGraphics" "-framework
Julio Jerez
Moderator
Moderator
 
Posts: 12425
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 1 guest

cron