[FIXED] add OpenGL 3.2 Core support for Mac OS X Lion

Started by void256, July 22, 2011, 21:41:30

Previous topic - Next topic

Estraven

Yes of course.

Gave you the decimal value to avoid looking through all .h files...

I had no idea where to look, so I finaly made a "find -exec grep" on my entire disk :)


in : /Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSOpenGL.h


   NSOpenGLPFAOpenGLProfile      =  99,     /* specify an OpenGL Profile to use             */

and

   NSOpenGLProfileVersion3_2Core   = 0x3200    /* choose an OpenGL 3.2 Core Implementation      */

Estraven

pjohnsen

Here is my NSOpenGL.h (/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSOpenGL.h)

/*
        NSOpenGL.h
        Application Kit
        Copyright (c) 2000-2011, Apple Inc.
        All rights reserved.
*/

#import <Foundation/NSObject.h>
#import <OpenGL/gltypes.h>

@class NSData, NSView, NSScreen;

/*
** NSOpenGL current API version
*/
#define NSOPENGL_CURRENT_VERSION  1

/* Option names for NSOpenGLSetOption() and NSOpenGLGetOption() */
typedef enum {
	NSOpenGLGOFormatCacheSize  = 501,	/* Set the size of the pixel format cache        */
	NSOpenGLGOClearFormatCache = 502,	/* Reset the pixel format cache if true          */
	NSOpenGLGORetainRenderers  = 503,	/* Whether to retain loaded renderers in memory  */
	NSOpenGLGOUseBuildCache    = 506,	/* Enable the function compilation block cache.  Off by default.  Must be enabled at startup. */

    /* Deprecated Global Option Values */
	NSOpenGLGOResetLibrary     = 504	/* Deprecated in Mac OS X 10.4.  Do a soft reset of the CGL library if true    */
} NSOpenGLGlobalOption;


/*
** Library global options.
*/
extern void NSOpenGLSetOption(NSOpenGLGlobalOption pname, GLint param);
extern void NSOpenGLGetOption(NSOpenGLGlobalOption pname, GLint *param);

/*
** Library version.
*/
extern void NSOpenGLGetVersion(GLint *major, GLint *minor);


/*********************
** NSOpenGLPixelFormat
*********************/

/*
** Attribute names for [NSOpenGLPixelFormat initWithAttributes]
** and [NSOpenGLPixelFormat getValues:forAttribute:forVirtualScreen].
*/
enum {
	NSOpenGLPFAAllRenderers       =   1,	/* choose from all available renderers          */
	NSOpenGLPFATripleBuffer       =   3,	/* choose a triple buffered pixel format        */
	NSOpenGLPFADoubleBuffer       =   5,	/* choose a double buffered pixel format        */
	NSOpenGLPFAStereo             =   6,	/* stereo buffering supported                   */
	NSOpenGLPFAAuxBuffers         =   7,	/* number of aux buffers                        */
	NSOpenGLPFAColorSize          =   8,	/* number of color buffer bits                  */
	NSOpenGLPFAAlphaSize          =  11,	/* number of alpha component bits               */
	NSOpenGLPFADepthSize          =  12,	/* number of depth buffer bits                  */
	NSOpenGLPFAStencilSize        =  13,	/* number of stencil buffer bits                */
	NSOpenGLPFAAccumSize          =  14,	/* number of accum buffer bits                  */
	NSOpenGLPFAMinimumPolicy      =  51,	/* never choose smaller buffers than requested  */
	NSOpenGLPFAMaximumPolicy      =  52,	/* choose largest buffers of type requested     */
	NSOpenGLPFAOffScreen          =  53,	/* choose an off-screen capable renderer        */
	NSOpenGLPFAFullScreen         =  54,	/* choose a full-screen capable renderer        */
	NSOpenGLPFASampleBuffers      =  55,	/* number of multi sample buffers               */
	NSOpenGLPFASamples            =  56,	/* number of samples per multi sample buffer    */
	NSOpenGLPFAAuxDepthStencil    =  57,	/* each aux buffer has its own depth stencil    */
	NSOpenGLPFAColorFloat         =  58,	/* color buffers store floating point pixels    */
	NSOpenGLPFAMultisample        =  59,    /* choose multisampling                         */
	NSOpenGLPFASupersample        =  60,    /* choose supersampling                         */
	NSOpenGLPFASampleAlpha        =  61,    /* request alpha filtering                      */
	NSOpenGLPFARendererID         =  70,	/* request renderer by ID                       */
	NSOpenGLPFASingleRenderer     =  71,	/* choose a single renderer for all screens     */
	NSOpenGLPFANoRecovery         =  72,	/* disable all failure recovery systems         */
	NSOpenGLPFAAccelerated        =  73,	/* choose a hardware accelerated renderer       */
	NSOpenGLPFAClosestPolicy      =  74,	/* choose the closest color buffer to request   */
	NSOpenGLPFABackingStore       =  76,	/* back buffer contents are valid after swap    */
	NSOpenGLPFAWindow             =  80,	/* can be used to render to an onscreen window  */
	NSOpenGLPFACompliant          =  83,	/* renderer is opengl compliant                 */
	NSOpenGLPFAScreenMask         =  84,	/* bit mask of supported physical screens       */
	NSOpenGLPFAPixelBuffer        =  90,	/* can be used to render to a pbuffer           */
	NSOpenGLPFARemotePixelBuffer  =  91,	/* can be used to render offline to a pbuffer   */
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
	NSOpenGLPFAAllowOfflineRenderers = 96,  /* allow use of offline renderers               */
#endif
	NSOpenGLPFAAcceleratedCompute =  97,	/* choose a hardware accelerated compute device */
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
	NSOpenGLPFAOpenGLProfile      =  99,	/* specify an OpenGL Profile to use             */
#endif
	NSOpenGLPFAVirtualScreenCount = 128,	/* number of virtual screens in this format     */

    /* NSOpenGLPFARobust, NSOpenGLPFAMPSafe, and NSOpenGLPFAMultiScreen are deprecated.  Applications that specify these attributes will continue to work, but they are deprecated for new development.
    */
	NSOpenGLPFARobust             =  75,	/* renderer does not need failure recovery      */
	NSOpenGLPFAMPSafe             =  78,	/* renderer is multi-processor safe             */
	NSOpenGLPFAMultiScreen        =  81 	/* single window can span multiple screens      */
};
typedef uint32_t NSOpenGLPixelFormatAttribute;

#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
/* NSOpenGLPFAOpenGLProfile values */
enum {
	NSOpenGLProfileVersionLegacy    = 0x1000,   /* choose a Legacy/Pre-OpenGL 3.0 Implementation */
	NSOpenGLProfileVersion3_2Core   = 0x3200    /* choose an OpenGL 3.2 Core Implementation      */
};
#endif

/*
** NSOpenGLPixelFormat interface.
*/
typedef struct _CGLPixelFormatObject NSOpenGLPixelFormatAuxiliary;

@interface NSOpenGLPixelFormat : NSObject <NSCoding>
{
@private
    NSOpenGLPixelFormatAuxiliary* _pixelFormatAuxiliary;
    NSData*                       _pixelAttributes;
    NSInteger                         _reserved1;
    NSInteger                         _reserved2;
    NSInteger                         _reserved3;
}

- (id)initWithAttributes:(const NSOpenGLPixelFormatAttribute *)attribs;
- (id)initWithData:(NSData*)attribs;
- (id)initWithCGLPixelFormatObj:(void *)format NS_AVAILABLE_MAC(10_6);

- (NSData*)attributes;
- (void)setAttributes:(NSData*)attribs;

- (void)getValues:(GLint *)vals forAttribute:(NSOpenGLPixelFormatAttribute)attrib forVirtualScreen:(GLint)screen;
- (GLint)numberOfVirtualScreens;

- (void *)CGLPixelFormatObj;

@end

/*********************
** NSOpenGLPixelBuffer
*********************/

/* NOTE: PBuffers should be considered deprecated as of 10.7.  Use GL_EXT_framebuffer_object instead.
*/
@interface NSOpenGLPixelBuffer : NSObject
{
@private
    struct _CGLPBufferObject	*_pixelBufferAuxiliary;
    void			*_reserved1;
    void			*_reserved2;
}

/*
** size width and height must be powers of two for 1D or 2D or CUBE_MAP targets
** size width and height must also be equal for CUBE_MAP target
** target should be one of GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP or GL_TEXTURE_RECTANGLE_EXT
** internalFormat should be GL_RGB, GL_RGBA or GL_DEPTH_COMPONENT
** maxLevel specifies the desired maximum mipmap level, starting with 0.  Must be 0 for
** TEXTURE_RECTANGLE targets.
*/
- (id)initWithTextureTarget:(GLenum)target textureInternalFormat:(GLenum)format textureMaxMipMapLevel:(GLint)maxLevel pixelsWide:(GLsizei)pixelsWide pixelsHigh:(GLsizei)pixelsHigh;
- (id)initWithCGLPBufferObj:(void *)pbuffer NS_AVAILABLE_MAC(10_6);
- (void *)CGLPBufferObj NS_AVAILABLE_MAC(10_6);
- (GLsizei)pixelsWide;
- (GLsizei)pixelsHigh;
- (GLenum)textureTarget;
- (GLenum)textureInternalFormat;
- (GLint)textureMaxMipMapLevel;
@end


/*****************
** NSOpenGLContext
*****************/

/* Parameter names for NSOpenGLContext -setValues:forParameter: and -getValues:forParameter: */
typedef enum {
    NSOpenGLCPSwapInterval           = 222, /* 1 param.  0 -> Don't sync, 1 -> Sync to vertical retrace     */
    NSOpenGLCPSurfaceOrder           = 235, /* 1 param.  1 -> Above Window (default), -1 -> Below Window    */
    NSOpenGLCPSurfaceOpacity         = 236, /* 1 param.  1-> Surface is opaque (default), 0 -> non-opaque   */
    NSOpenGLCPSurfaceBackingSize     = 304, /* 2 params.  Width/height of surface backing size              */
    NSOpenGLCPReclaimResources       = 308, /* 0 params.                                                    */
    NSOpenGLCPCurrentRendererID      = 309, /* 1 param.   Retrieves the current renderer ID                 */
    NSOpenGLCPGPUVertexProcessing    = 310, /* 1 param.   Currently processing vertices with GPU (get)      */
    NSOpenGLCPGPUFragmentProcessing  = 311, /* 1 param.   Currently processing fragments with GPU (get)     */
    NSOpenGLCPHasDrawable            = 314, /* 1 param.   Boolean returned if drawable is attached          */
    NSOpenGLCPMPSwapsInFlight        = 315, /* 1 param.   Max number of swaps queued by the MP GL engine    */

    /* The following parameters are obsolete and deprecated for new development. */
    NSOpenGLCPSwapRectangle          = 200, /* 4 params.  Set or get the swap rectangle {x, y, w, h}        */
    NSOpenGLCPSwapRectangleEnable    = 201, /* Enable or disable the swap rectangle                         */
    NSOpenGLCPRasterizationEnable    = 221, /* Enable or disable all rasterization                          */
    NSOpenGLCPStateValidation        = 301, /* Validate state for multi-screen functionality                */
    NSOpenGLCPSurfaceSurfaceVolatile = 306  /* 1 param.   Surface volatile state                            */
} NSOpenGLContextParameter;


/*
** NSOpenGLContext interface.
*/
typedef struct _CGLContextObject NSOpenGLContextAuxiliary;

@interface NSOpenGLContext : NSObject
{
@private
	__weak NSView            *_view;
	NSOpenGLContextAuxiliary *_contextAuxiliary;
}

/* Context creation */
- (id)initWithFormat:(NSOpenGLPixelFormat *)format shareContext:(NSOpenGLContext *)share;
- (id)initWithCGLContextObj:(void *)context NS_AVAILABLE_MAC(10_6);

/* Drawable management */
- (void)setView:(NSView *)view;
- (NSView *)view;
- (void)setFullScreen;

/* Deprecated in 10.7.  The -setOffScreen:width:height:rowbytes: API forces use of the software rasterizer, which is much slower than GPU rendering.  It is generally much better nowadays to use a normal pixel format with either an off-screen window or an FBO (GL_EXT_framebuffer_object), and then call glReadPixels() to read the rendered result back to CPU memory (if that's where it is needed).
*/
- (void)setOffScreen:(void *)baseaddr width:(GLsizei)width height:(GLsizei)height rowbytes:(GLint)rowbytes;

- (void)clearDrawable;
- (void)update;

/* Flush draw buffer */
- (void)flushBuffer;

/* Current context control */
- (void)makeCurrentContext;
+ (void)clearCurrentContext;
+ (NSOpenGLContext *)currentContext;

/* Copy attributes from another context */
- (void)copyAttributesFromContext:(NSOpenGLContext *)context withMask:(GLbitfield)mask;

/* Context Parameter handling */
- (void)setValues:(const GLint *)vals forParameter:(NSOpenGLContextParameter)param;
- (void)getValues:(GLint *)vals forParameter:(NSOpenGLContextParameter)param;


/* virtual screens */
- (void)setCurrentVirtualScreen:(GLint)screen;
- (GLint)currentVirtualScreen;

/* creating textures */
- (void)createTexture:(GLenum)target fromView:(NSView *)view internalFormat:(GLenum)format;


- (void *)CGLContextObj;

/*
** NOTE: PBuffers have been Deprecated as of 10.7.  Use GL_EXT_framebuffer_object instead.
**
** Attach context to an NSOpenGLPixelBuffer instance.
** For GL_CUBE_MAP target pixel buffers, face should be one of GL_TEXTURE_CUBE_MAP_POSITIVE_X, 
** GL_TEXTURE_CUBE_MAP_POSITIVE_Y, etc.  Otherwise it should be 0.
** Level specifies the desired mipmap level you want to render to.  It must less than or equal to the maxLevel
** parameter of the pixel buffer.
** If applicable, the virtual screen should be set to the same value as the current virtual screen you are using
** to render on-screen with.
*/
- (void)setPixelBuffer:(NSOpenGLPixelBuffer *)pixelBuffer cubeMapFace:(GLenum)face mipMapLevel:(GLint)level currentVirtualScreen:(GLint)screen;
- (NSOpenGLPixelBuffer *)pixelBuffer;
- (GLenum)pixelBufferCubeMapFace;
- (GLint)pixelBufferMipMapLevel;

/*
** NOTE: PBuffers have been Deprecated as of 10.7.  Use GL_EXT_framebuffer_object instead.
**
** This call is a mirror of CGLTexImagePBuffer.  This essentially "binds" the given pixel buffer's image data
** to the currently bound texture object.   Source specifies which of the PBuffer's color buffers should be used,
** and should be one of GL_FRONT, GL_BACK, GL_AUX0, etc.
*/
- (void)setTextureImageToPixelBuffer:(NSOpenGLPixelBuffer *)pixelBuffer colorBuffer:(GLenum)source;

@end

spasi

I've committed an implementation for this, but since I don't have access to a Mac, it's completely untested. Could you please download the latest nightly and try it out?

You need to use ContextAttribs in order to enable the NSOpenGLPFAOpenGLProfile path. Pass new ContextAttribs(3, 2).withProfileCore(true) to your context and it should work. Any other ContextAttribs configuration will be ignored.

kappa

reports comming in from multiple sources about the following failure on Mac OS X nightly builds

QuoteSCHWERWIEGEND: Failed to create display
java.lang.NullPointerException
at org.lwjgl.opengl.MacOSXPeerInfo.(MacOSXPeerInfo.java:51)
at org.lwjgl.opengl.MacOSXCanvasPeerInfo.(MacOSXCanvasPeerInfo.java:49)
at org.lwjgl.opengl.MacOSXDisplayPeerInfo.(MacOSXDisplayPeerInfo.java:48)
at org.lwjgl.opengl.MacOSXDisplay.createPeerInfo(MacOSXDisplay.java:245)
at org.lwjgl.opengl.DrawableGL.setPixelFormat(DrawableGL.java:61)
at org.lwjgl.opengl.Display.create(Display.java:897)
at org.lwjgl.opengl.Display.create(Display.java:808)
at com.jme3.system.lwjgl.LwjglDisplay.createContext(LwjglDisplay.java:140)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:113)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)
at java.lang.Thread.run(Thread.java:680)

Could this be something related to the above changes?

source1
source2

spasi

That NPE should not happen with the latest build. It was fixed 2 days ago, see this. This is the current code:

boolean gl32 = attribs != null && attribs.getMajorVersion() == 3 && attribs.getMinorVersion() == 2 && attribs.isProfileCore();

kappa

Quote from: spasi on September 07, 2011, 15:11:11
That NPE should not happen with the latest build. It was fixed 2 days ago, see this.

Yup can confirm now that both those sources have tried the latest nightly builds and confirmed that it works, odd though as they had the nightly builds from yesterday when it should have been fixed. I did a minor code change today (not related to any native code) which caused a rebuild on nightly server which caused nightlies to build correctly this time, could it be that the nightly build server is bundling OS X natives one version behind or something? anyway have bumped the native jni version now just to be sure.

spasi


kappa

Quote from: spasi on September 08, 2011, 08:06:39
Have we had any confirmation from a 10.7+ user?
void256 who opened the above RFE mentioned that he'll hopefully test it on the weekend and confirm whether it works.

pjohnsen

Hi guys,

I just tested latest nightly (#1330) on MBA with 10.7.1, and advanced applet is working fine for me in safari and ff (chrome has some weird stuff about loading it from local filesystem, but I think that is a chrome issue, nothing to do with lwjgl).

I'll try and get around to updating 3dviewr.com to use this build :)

-pjoe

pjohnsen

Hi again, 3dviewr.com is now running build #1330 ... and everything looks good  :)

Endolf

Does this mean I don't need to update the OSX node on the build farm? :)

Endolf

spasi


kappa

another thing to keep in mind is that OS X Lion 10.7 has dropped support for PPC compilation and its not possible without some hackage. So until we decide to drop PPC support sticking with 10.6 for the nightly builds might be a good idea.

jouvieje

The exception reported in Adopt new JAWT API on Mac OS X so that Plugin2 will work is indeed corrected in nightly #1327 and Lion and the 3d is now showing on my applets :)

I have another issue on mac (only tested with lion). The AWTGLCanvas seems to cover all the applet area no matter if some awt/swing components was in the applet layout. The side panel of my applet is not visible anymore on mac (but ok on win/linux).
EDIT: Just before the AWTGLCanvas shows up, I can see during a fraction of second all the awt/swing component and then the AWTGLCanvas cover them and take place on the entire applet area. Also, the mouse seem to respond to the expected area of the AWTGLCanvas.

Is there a limitation of the new plugin regarding the use of swing with lwjgl's AWTGLCanvas or is it a possible bug either in my applet or lwjgl ? Not sure if #1331 should resolve this, but I'll try monday when i'll have access to the mac.

BTW, thanks for all you hard work supporting applet on mac.

@pjohnsen: just in case you wish to support old hardware, there's many errors in your viewer with my old gen 1.5 card due to the use of 2.0 functions.

void256

Sorry for the delay! Here is what I did with 10.7:


Unfortunatly there seems to be a problem with the pixel format:

2011-09-13 15:16:59.455 java[25828:1903] invalid pixel format attribute
2011-09-13 15:16:59.456 java[25828:1903] invalid pixel format attribute
org.lwjgl.LWJGLException: Could not create pixel format
	at org.lwjgl.opengl.MacOSXPeerInfo.nChoosePixelFormat(Native Method)
	at org.lwjgl.opengl.MacOSXPeerInfo.choosePixelFormat(MacOSXPeerInfo.java:60)
	at org.lwjgl.opengl.MacOSXPeerInfo.<init>(MacOSXPeerInfo.java:55)
	at org.lwjgl.opengl.MacOSXCanvasPeerInfo.<init>(MacOSXCanvasPeerInfo.java:49)
	at org.lwjgl.opengl.MacOSXDisplayPeerInfo.<init>(MacOSXDisplayPeerInfo.java:48)
	at org.lwjgl.opengl.MacOSXDisplay.createPeerInfo(MacOSXDisplay.java:247)
	at org.lwjgl.opengl.DrawableGL.setPixelFormat(DrawableGL.java:61)
	at org.lwjgl.opengl.Display.create(Display.java:897)
	at org.lwjgl.opengl.Display.create(Display.java:848)
	at de.lessvoid.nifty.test.LwjglInitHelper.initGraphics(LwjglInitHelper.java:136)
	at de.lessvoid.nifty.test.LwjglInitHelper.initSubSystems(LwjglInitHelper.java:50)
	at de.lessvoid.nifty.test.Main.main(Main.java:25)
13.09.2011 15:16:59 de.lessvoid.nifty.test.LwjglInitHelper initGraphics
WARNUNG: Unable to create window!, exiting...


If I only use "Display.create(new PixelFormat())" it works but without the 3.2 support of course.

Anything else I'm missing?

PS: I'm now responding quicker because I'm back from vacation ... =)