MaxxAMillion
MaxxAMillion

Reputation: 128

OpenTK in Xamarin.Mac: How to obtain modern OpenGL graphics context? (e.g. OpenGL 3.3 / GLSL 330)

I am developing a cross-platform graphics application, which uses OpenTK. On Windows, I can reference OpenTK and OpenTK.GLControl dlls to initialize my rendering context like this, and in particular, request a specific [modern] OpenGL graphics context (in this case, OpenGL 3.3):

int major = 3;
int minor = 3;
var control = new OpenTK.GLControl(GraphicsMode.Default, major, minor, GraphicsContextFlags.Default);

There are some examples on the Xamarin website (Introduction to OpenTK and MonoMacGameView) and they demonstrate using OpenTK for Mac like this:

Game = new MonoMacGameView (ContentView.Frame);
ContentView = Game;
Game.Run();

However, when I do this, and then check the OpenGL version like this:

string version = GL.GetString(StringName.Version); // "2.1 INTEL-10.14.66"
string glsl = GL.GetString(StringName.ShadingLanguageVersion); // "1.20"

...I get what appears to be an obsolete context, and furthermore, I can't seem to specify that I want anything else. My system (OS X 10.11.5, Mac mini (Late 2014) Intel Iris) should be able to support OpenGL 4.1, according to this: https://support.apple.com/en-us/HT202823

Of greater concern, the Xamarin OpenTK examples use Immediate Mode (e.g. GL.Begin), which has long since been removed from the OpenGL core profile specification. So, my questions are:

  1. Is it possible to obtain a modern OpenGL context in OpenTK on Mac? If so, how?
  2. Is there an equivalent of OpenTK.GLControl for Mac other than MonoMacGameView, or is that the preferred (and only) option?
  3. When setting up my solution in Xamarin, I have a Portable Class Library (with all my platform-independent code), and then separate projects (one for Mac and one for Windows) that reference it. The Windows project references OpenTK dlls; and the Mac project references OpenTK via NuGet (as described in the Intro tutorial linked above). Is this a sensible way to structure a cross-platform (Windows/Mac) solution that depends on OpenTK? Is there any way to use the same OpenTK dll references for both Mac and Windows?
  4. If it's the case that OpenTK cannot be used with an OpenGL 3.3+ context on Mac, is there an alternative approach to accessing OpenGL in Xamarin on Mac?

Any help is greatly appreciated. Thanks.

Upvotes: 0

Views: 1009

Answers (1)

SurvivalMachine
SurvivalMachine

Reputation: 8356

You need to ask for a forward compatible profile, replace GraphicsContextFlags.Default with GraphicsContextFlags.ForwardCompatible.

I'm using OpenGL 3.3 with OpenTK on Mac by inheriting from GameWindow class and initializing the context in the constructor like this:

using OpenTK;
using OpenTK.Graphics;

class Program : GameWindow
{
    public Program() : 
        base( width, height, GraphicsMode.Default, "App Name", 0, DisplayDevice.Default, 3, 3, GraphicsContextFlags.ForwardCompatible )
    {
       ...

I use Xamarin Studio and downloaded OpenTK from its website, didn't use NuGet.

Upvotes: 2

Related Questions