Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Support OpenGL 3.2 on Mac OS X Lion #84

Closed
mantognini opened this Issue Aug 11, 2011 · 15 comments

Comments

Projects
None yet
9 participants
Owner

mantognini commented Aug 11, 2011

Because (source)

The OpenGL 3.2 core profile is defined by Khronos and explicitly removes removes deprecated features described in earlier versions of the OpenGL specification; further the core profile prohibits these functions from being added back into OpenGL using extensions. OpenGL 3.2 core represents a complete break from the fixed function pipeline of OpenGL 1.x in favor of a clean, lean shader-based pipeline.

OpenGL context version 3.2 will be supported in SFML 2.x only. (SFML 2.0 still uses such deprecated functions so using OpenGL 3.2 will completely break SFML 2.0.)

This update should be in two part :

  • Cmake script must be updated to build SFML via an option for Snow Leopard on Lion for backward compatibility;
  • SFContext class must be updated to support new OpenGL features.

The first point is similar to what is done for compiling SFML for Leopard on Snow Leopard. The cmake script (root CMakeLists.txt) should be updated in two places. First the options part :

# Mac OS X specific options
if (MACOSX)
    if (MACOSX_VERSION EQUAL 6)
        # add an option to build against 10.5 SDK if current OS X version is 10.6
        set(BUILD_LEOPARD FALSE CACHE BOOL "TRUE to build SFML for OS X 10.5, FALSE to compile with default SDK")
    elseif(MACOSX_VERSION EQUAL 7)
        # add an option to build against 10.6 SDK if current OS X version is 10.7
        set(BUILD_SNOW_LEOPARD FALSE CACHE BOOL "TRUE to build SFML for OS X 10.6, FALSE to compile with default SDK")
    endif()
endif()

Then the configuration part :

# Setup Mac OS X multi arch/SDK support.
if (MACOSX)
    [snip]

    # use 10.5, 10.6 or default SDK ?
    if (BUILD_LEOPARD)
        # Use 10.5 SDK : override default value
        set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.5.sdk")
        set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5")
    elseif (BUILD_SNOW_LEOPARD)
        # Use 10.6 SDK : override default value
        set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.6.sdk")
        set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6")
    else()
        # Default SDK, let either the user or CMake decide which one to use.
    endif()
endif()

The second point is an update for sf::priv::SFContext::CreateContext :

    // Choose the attributs of OGL context.
    std::vector<NSOpenGLPixelFormatAttribute> attrs;
    attrs.reserve(20); // max attributs (estimation).

    // These casts are safe. C++ is much more strict than Obj-C.

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070

    // Add support for OpenGL 3.2 on Mac OS X Lion and later
    if (settings.MajorVersion > 3 || (settings.MajorVersion == 3 && settings.MinorVersion >= 2)) {
        attrs.push_back(NSOpenGLPFAOpenGLProfile);
        attrs.push_back(NSOpenGLProfileVersion3_2Core);
    } else {
        attrs.push_back(NSOpenGLPFAOpenGLProfile);
        attrs.push_back(NSOpenGLProfileVersionLegacy);
    }

#endif

Note that for OpenGL 2.1 setting NSOpenGLPFAOpenGLProfile to NSOpenGLProfileVersionLegacy is apparently not required (maybe it's its default value) : SFML currently works fine on Mac OS X Lion without it.

@ghost ghost assigned mantognini Aug 11, 2011

Kylllyk commented Dec 27, 2011

That path works just fine.
Thanks.

why isn't this still in the code?

Owner

mantognini commented Aug 31, 2012

I'm not sure why you're asking this.. Have you read the issue description ?

um, yeah, and in the latest pull of sfml the opengl 3.2 support (core profile support, since you can't get 3.2 opengl support in OSX without it) isn't in any more. On further research it's probably because someone said somewhere that SFML still has parts that are still dependent on deprecated functionality. Is it just the matrix control? I might find some free time if I know where to focus it^^

Owner

mantognini commented Sep 1, 2012

On further research

Like reading the description above ?

Anyway, don't lose your time implementing anything here. Laurent will probably remove those deprecated function calls differently than what you'll come up. And this task will be implemented in 2.x so not before months.

Thanks for being so helpful! Maybe I'll look into it, maybe I wont it'll all depend on what looks to be the best solution to my problem. Good luck!

Does anyone know approximately how long it will be until the OpenGL 3.2 Core profile will be supported by sfml 2?

Owner

mantognini commented Oct 18, 2012

It's planned for 2.x – i.e. no date is given.

What parts of SFML use the deprecated function calls? Essentially all I need from SFML is the event handling and for it to set up an OpenGL context and window...I'm not using any of the SFML graphics stuff, I've got my own code for that.

@cjameshuff feel free to use my fork https://github.com/mclark4386/SFML/tree/OSX-3.2Changes then if you would like (note that is a branch) where I've done all that I needed... and it sounds like our needs were the same^^

As a side note, I'll be happy to help move over the deprecated functions when I have time... then we can add this to the main line^^;

Any updates on this? It's been 2 years, SFML 2.1's been released, and it appears you still can't get a 3.2 context on OS X without patching SFML.

Are the deprecated functions really that much of a problem? If so, what needs to be fixed or avoided? And why does this require refusing even minimal OpenGL 3.2 support on OS X, but not on Linux or Windows?

And why does this require refusing even minimal OpenGL 3.2 support on OS X, but not on Linux or Windows?

Because on Linux and Windows you can create an OpenGL 3.2 compatibility profile context, which allows for deprecated functions, whereas on a Mac you can only get an OpenGL 3.2 core profile context.
Thus, until the entirety of the Graphics module can use the OpenGL 3.2 core context, there would be little incentive for SFML to provide a core context. Rewriting all of that takes a lot of time. VBOs have to be created to do all rendering. Basic shaders have to be setup as well. Everything which is handled automatically by the fixed function pipeline will have to be handled manually by SFML, which is no easy task.
However, I see nothing wrong with the Window module allowing you to create a core context anyway, with a big scary warning that you won't be able to use any of the Graphics module.

I see nothing wrong with the Window module allowing you to create a core context anyway, with a big scary warning that you won't be able to use any of the Graphics module.

+1, would this be easy to implement? It seems like it should be pretty straight forward.

mjbshaw commented Aug 15, 2013

I might suggest that OpenGL 4.0 be supported on Mac OS X Mavericks (when it's released in the near future), and not just 3.2.

@mantognini mantognini modified the milestones: 2.2, 2.x Apr 13, 2014

Owner

mantognini commented Apr 15, 2014

For the record, this support of OpenGL 3.2 is still partial: you cannot use 3.2 context with the graphics module.

@mantognini mantognini removed their assignment Apr 30, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment