JME, LWJGL, OpenGL 3.2 Core Profile, and Mac OSX 10.7+, ContextAttribs issue

How do I specify the version on OpenGL I want JME to run with?



In order to use OpenGL 3.2 on a Mac OSX 10.7+ using LWJGL one must specify the version as per:



http://www.lwjgl.org/wiki/index.php?title=Version_selection



Please Note: the code at the bottom currently has a bug. As ContextAttribs is immutable as per:



http://lwjgl.org/forum/index.php?topic=4708.0



So:



[java]

ContextAttribs contextAtrributes = new ContextAttribs(3, 2);

contextAtrributes.withForwardCompatible(true);

contextAtrributes.withProfileCore(true);

[/java]



should be:



[java]

ContextAttribs contextAtrributes = new ContextAttribs(3, 2).withForwardCompatible(true).contextAtrributes.withProfileCore(true);

[/java]



Once you set your ContextAttribs as such you can work with OpenGL 3.2 as opposed to OpenGL 2.1 (default) on Mac OSX 10.7+.



It is not clear to me how to custom set these in JME3 without modifying LwjglDisplay:



http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/lwjgl/com/jme3/system/lwjgl/LwjglDisplay.java



Any ideas?



Thank you.

Ok so no mac love… I get it, but here is the deal: OpenGL 3.2 is supported under the core profile with OSX 10.7+ and I gots shaders that use it. In the LwjglContext if JME can’t find OpenGL 3.3 isn’t found then it will fall all the way back to OpenGL 2.whatever as the “else” case does not set the core profile nor try 3.2, 3.1, etc. So… maybe someone who has contrib access and a sense of the direction that JME is going in can find it in their heart to add a little bit more granularity here. Just because JME shaders don’t use OpenGL 3 or 4 features yet… does that mean it shouldn’t let others use those features? I would propose the changes myself, but I am not sure how you would like to add the finer granularity do to the coarseness of the LWJGL_OPENGLX constants in AppSettings. (I suppose you could go with LWJGL_OPENGL3_2 or something like that) This is not a problem just for the mac peeps as PC users who want OpenGL 4.x features are gonna be hard pressed to get at them without the same lovin. Or perhaps I’m missing something and could should stand for some correction which is all good. I have included the relevant snippets below.



From AppSettings.java:

[java]

/**

  • Set the graphics renderer to use, one of:<br>
  • <ul>
  • <li>AppSettings.LWJGL_OPENGL1 - Force OpenGL1.1 compatability</li>
  • <li>AppSettings.LWJGL_OPENGL2 - Force OpenGL2 compatability</li>
  • <li>AppSettings.LWJGL_OPENGL3 - Force OpenGL3.3 compatability</li>
  • <li>AppSettings.LWJGL_OPENGL_ANY - Choose an appropriate
  • OpenGL version based on system capabilities</li>
  • <li>null - Disable graphics rendering</li>
  • </ul>
  • @param renderer The renderer to set
  • (Default: AppSettings.LWJGL_OPENGL2)

    */

    public void setRenderer(String renderer) {

    putString("Renderer", renderer);

    }

    [/java]



    And from LwjglContext.java

    [java]

    protected ContextAttribs createContextAttribs(){

    if (settings.getBoolean("GraphicsDebug") || settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)){

    ContextAttribs attr;

    if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)){

    attr = new ContextAttribs(3, 3);

    attr = attr.withProfileCore(true).withForwardCompatible(true).withProfileCompatibility(false);

    }else{

    attr = new ContextAttribs();

    }

    if (settings.getBoolean("GraphicsDebug")){

    attr = attr.withDebug(true);

    }

    return attr;

    }else{

    return null;

    }

    }

    [/java]
1 Like

We are aware of this.

Wie, OGL3.2 support would be nice addition :slight_smile: waiting :stuck_out_tongue:

2 Likes

I think we can just make OpenGL3 mean 3.2 … or deprecate that constant and only leave OpenGL3_2.

Its better to have coarseness in this case since you don’t want somebody to take out every Mac user just by enabling OpenGL 3.3.

@jappinen: Can you make a diff patch for this?

In a perfect world it might be nice to default to the latest version the driver supports and to expose all of the settings so that the developer still retains control. The more I pour through the JME code though I realize that doing this would result in a fairly large and possibly backward incompatible patch. As such I agree with your (Mokomo_Fan) recommendation to let OpenGL3 mean 3.2 and move on until this problem can be more formally addressed. This does however make me wonder where JME is going with its development. I know you guys are heads down preparing for a release, but perhaps you guys already have a clear idea of where you are headed with the next release. If so, might you be willing to let loose on some of the details or point me to some existing discussions? As far as a patch goes… I will look at putting a simple patch together that simply changes 3.3 to 3.2.

@jappinen said:
In a perfect world it might be nice to default to the latest version the driver supports and to expose all of the settings so that the developer still retains control. The more I pour through the JME code though I realize that doing this would result in a fairly large and possibly backward incompatible patch. As such I agree with your (Mokomo_Fan) recommendation to let OpenGL3 mean 3.2 and move on until this problem can be more formally addressed. This does however make me wonder where JME is going with its development. I know you guys are heads down preparing for a release, but perhaps you guys already have a clear idea of where you are headed with the next release. If so, might you be willing to let loose on some of the details or point me to some existing discussions? As far as a patch goes... I will look at putting a simple patch together that simply changes 3.3 to 3.2.


As you might know if you ever did something at this scale yourself, its always a mixture of gut-feelings and thorough knowledge of the things one deals with so its hard to make such concise statements.

I apologize for not being very clear. I was just wondering if you guys have plans to add support for tessellation and geometry shaders, multi-pass shaders and the like in a future version. As such I think that exposing GL versioning, profile choice, and forward capability might be a good thing in the future and that pushing towards a release is most likely not the right time to totally revamp this stuff. In general, I appreciate all of your thorough knowledge and the scale at which you operate.

Yes sure we do plan to add all this but it should be as easy to handle as possible to the end user. Ideally it doesn’t matter what opengl version the client computer has and the shaders adapt dynamically. Large differences between the gl versions (and os-level handling in lwjgl) make this ideal not quite possible though. This is stuff thats not really at shader level as you rather check glsl versions there. Its more about how things are initialized from the engine side.

OpenGL 3.3 to 3.2 patch. Very simple. Merely changes docs in AppSettings.java and ContextAttribs hardcoded parameter in LwjglContext.java to specify OpenGL 3.2 instead of 3.3 so that Macs using OS 10.7+ can use 3.x features as well as they do not support OpenGL 3.3.



http://pastebin.com/RcVzjB3B

1 Like