LWJGL Forum

Archive => Resolved Bugs/RFE => Topic started by: void256 on July 22, 2011, 21:41:30

Title: [FIXED] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: void256 on July 22, 2011, 21:41:30
Apple finally woke up and allows at least OpenGL 3.2 Core Profile on Mac OS X Lion!  :D

It must be explicitly enabled when creating the NSOpenGLPixelFormat using the following two NSOpenGLPixelFormatAttributes:

Code: [Select]
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core
I was able to confirm that this works on my Mac Pro with an ATI Radeon HD 4870 using the following code:

Code: [Select]
NSOpenGLPixelFormatAttribute attributes [] = {
  NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, // enable OpenGL 3.2
  NSOpenGLPFADoubleBuffer, // double buffered
  NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
  (NSOpenGLPixelFormatAttribute)nil
};
return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];

Without the Core Profile I get:

Code: [Select]
GL_VERSION = "2.1 ATI-7.2.9"
GL_SHADING_LANGUAGE_VERSION = "1.20"
GL_RENDERER = "ATI Radeon HD 4870 OpenGL Engine"

and with the Core Profile enabled:

Code: [Select]
GL_VERSION = "3.2 ATI-7.2.9"
GL_SHADING_LANGUAGE_VERSION = "1.50"
GL_RENDERER = "ATI Radeon HD 4870 OpenGL Engine"

;D

LWJGL should support this as well.

When the Core Profile is requested from LWJGL then somewhere in http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/native/macosx/context.m?revision=3598&view=markup (http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/native/macosx/context.m?revision=3598&view=markup) should be the two magic NSOpenGLPixelFormatAttributes added.

The only problem I see so far is, that this would only work on Mac OS X 10.7 so there would be an additional #ifdef:

Code: [Select]
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
necessary to compile it correctly.

Would that be possible? Please? Pretty Please?  ;)
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: spasi on July 22, 2011, 23:00:25
This is unfortunate. They made it a PixelFormat attribute instead of something similar to ARB_create_context. It will require some hackery to add support for this.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: Estraven on August 01, 2011, 11:12:45
Hi,

I can't tell you how happy I am to see someone actualy getting an OpenGL 3.2 Core Context enabled on Lion. Thank you Void256 !
I would definitivelly be happier if LWJGL could enable it.  ;D

as Void256 said : "Would that be possible? Please? Pretty Please? "  ;)

Estraven
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: kappa on August 01, 2011, 11:36:03
This is unfortunate. They made it a PixelFormat attribute instead of something similar to ARB_create_context. It will require some hackery to add support for this.

Yeh agreed, also means that the nightly build server will need to be updated to OS X Lion 10.7 to use the new API's, poor old Endolf just recently finished updating it to 10.6. This also sets a silly trend of requiring new API's for future OpenGL releases which will again require a the nightly server to be updated.

I do wonder though, if the new API's are just constants, then we can just plug the values in without requiring dependencies on new API's.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: spasi on August 01, 2011, 13:38:27
Afaict adding the constants would be enough. Sorry that I can't be of more help, I don't have access to (or experience with) a Mac.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: Estraven on August 01, 2011, 14:47:49

I've a Mac (nvidia 330M) updated to Lion, but i've never compiled LWJGL.
Is there any doc on how to compile LWJGL natives on MacOS ?

Do any of you would be available to help me through this ?
Otherwise, I can do tests if you compile with the new required constant (I guess you can compile on 10.6, and I'll test on 10.7)

Estraven
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: kappa on August 01, 2011, 15:44:05
Not difficult to compile on mac, just grab the xcode sdk from the apple site (xcode 3 one is free). Once downloaded and installed, run eclipse, check out LWJGL from svn and run the ant build.xml and it should compile LWJGL for you.

Do any of you would be available to help me through this ?
Otherwise, I can do tests if you compile with the new required constant (I guess you can compile on 10.6, and I'll test on 10.7)

What would help is if you could get the values of the new constants (NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core) from the *.h header files.

@Spasi - as I understand it opengl 3.2 needs to be called explicitly before you can use it, but since this is a pixelformat, how would users enable it? do we need to add some new mac specific api to LWJGL or something?
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: Estraven on August 01, 2011, 16:32:35
Ok, I'm just having trouble with xCode (had to reinstall after Lion upgrade, and something went wrong....)

I'll keep you posted.

Estraven
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: spasi on August 01, 2011, 18:37:00
@kappa: Yes, it has to be explicit. There's only support for the core profile so LWJGL cannot automatically enable it, even if it detected 10.7+.

I think the cleanest option API-wise would be to continue using ContextAttribs. We should require users to use new ContextAttribs(3, 2).withProfileCore(true). When LWJGL sees this on a Mac, it should enable a code path that passes the right value to the PixelFormat query. We should also add checks for any other usage patterns (withDebug, withProfileCompatibility, etc) and throw an exception on Macs. We may allow withForwardCompatible though, the pseudo-fc mode should work fine on a Mac.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: Estraven on August 01, 2011, 20:30:15
@Spasi : For what it worth, I agree with what you described.

Concerning the jnilib modification. I finally succeded in recompiling the library.

Has some trouble and I had to modify the ant build.xml for the MacOs native lib (matching the xCode 4.1 libs)
Anyway, I then added this in the choosepixelformat method :

Code: [Select]
   
    FILE * f = fopen("temp.txt","w");
    fprintf(f,"%d %d",NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
    fclose(f);

Sorry for the old & crappy  C code... gives me : 99 12800

I then tried to add :

Code: [Select]
putAttrib(&attribs, NSOpenGLPFAOpenGLProfile);
putAttrib(&attribs, NSOpenGLProfileVersion3_2Core);

to the attributes list...

but when i run my project in eclipse using it, i get :

2011-08-01 22:23:07.908 java[5893:10403] invalid pixel format attribute

What's next ? ;)

Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: Estraven on August 01, 2011, 20:37:02
   Hum :

I brutally replaced the choosepixelformat method with this code :

Quote
    NSOpenGLPixelFormatAttribute attributes[] = {
        NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
        NSOpenGLPFADoubleBuffer,
        NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)16,
        (NSOpenGLPixelFormatAttribute)nil
    };
    NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];


   if (fmt == nil) {
      throwException(env, "Could not create pixel format");
      return NULL;
   }
   return fmt;

   

GOT THE OPENGL 3.2 CORE CONTEXT =) =)

   
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: Estraven on August 02, 2011, 08:16:28
Hum.... except that i can't get anything rendered... the GLCanvas get the color defined by glClearColor, but no geometry is rendered....

I'll try to find  a correct pixel format initialisation. If you have any suggestions...

Estraven
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: Estraven on August 02, 2011, 11:26:49
Very very strange... I have a Open3.2 compliant performance test software.
It's supposed to run at 50 FPS on a 330M (as it does on Windows 7)

Turns out it does run at 60 FPS, and when mouse grabbing (i do some offscreen additionnal rendering) decrease to 45 FPS... (as it does on Windows...)
This suggest that the geometry is processed correctly by the shaders. I just don't see anything on screen....

Shader compilation logs and GPU loading logs are almost indentical (Windows vs MacOs)
I just get an additional warning on Mac when validating shaders (Warning : no vertex array object bound.)

Regarding the context.m file, I ended up to this :

Quote

NSOpenGLPixelFormat *choosePixelFormat(JNIEnv *env, jobject pixel_format, bool use_display_bpp, bool support_window, bool support_pbuffer, bool double_buffered) {
   
   
    int bpp;
    jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
    //if (use_display_bpp)
    //    bpp = CGDisplayBitsPerPixel(kCGDirectMainDisplay);
    //else
        bpp = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "bpp", "I"));
   
    int alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "alpha", "I"));
    int depth = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "depth", "I"));
    int stencil = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stencil", "I"));
    int samples = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "samples", "I"));
    int num_aux_buffers = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "num_aux_buffers", "I"));
    int accum_bpp = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_bpp", "I"));
    int accum_alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_alpha", "I"));
    bool stereo = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stereo", "Z"));
    bool floating_point = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "floating_point", "Z"));
    // TODO: Add floating_point_packed attribute below
       bool floating_point_packed = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "floating_point_packed", "Z"));
    // TODO: Add sRGB attribute below
       bool sRGB = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "sRGB", "Z"));

    attrib_list_t attribs;
    jboolean allow_software_acceleration = getBooleanProperty(env, "org.lwjgl.opengl.Display.allowSoftwareOpenGL");
    initAttribList(&attribs);
   
    putAttrib(&attribs, NSOpenGLPFAOpenGLProfile); // ADDED LINE
    putAttrib(&attribs, NSOpenGLProfileVersion3_2Core); // ADDED LINE

   
    if (support_window) // DISPLACED HERE -
        putAttrib(&attribs, NSOpenGLPFAWindow);
   
   
    if (support_pbuffer)  // DISPLACED HERE -
        putAttrib(&attribs, NSOpenGLPFAPixelBuffer);
   
    if (!allow_software_acceleration)
        putAttrib(&attribs, NSOpenGLPFAAccelerated);
    if (double_buffered)
        putAttrib(&attribs, NSOpenGLPFADoubleBuffer);
    putAttrib(&attribs, NSOpenGLPFAMinimumPolicy);
   
    putAttrib(&attribs, NSOpenGLPFAColorSize); putAttrib(&attribs, bpp);
    putAttrib(&attribs, NSOpenGLPFAAlphaSize); putAttrib(&attribs, alpha);
    putAttrib(&attribs, NSOpenGLPFADepthSize); putAttrib(&attribs, depth);
    putAttrib(&attribs, NSOpenGLPFAStencilSize); putAttrib(&attribs, stencil);
    putAttrib(&attribs, NSOpenGLPFAAccumSize); putAttrib(&attribs, accum_bpp + accum_alpha);
   
    putAttrib(&attribs, NSOpenGLPFASampleBuffers); putAttrib(&attribs, samples > 0 ? 1 : 0);
    putAttrib(&attribs, NSOpenGLPFASamples); putAttrib(&attribs, samples);
    putAttrib(&attribs, NSOpenGLPFAAuxBuffers); putAttrib(&attribs, num_aux_buffers);
   
 
   
   
    if (stereo)
        putAttrib(&attribs, NSOpenGLPFAStereo);
   
    if (floating_point)
        putAttrib(&attribs, NSOpenGLPFAColorFloat);
   
    putAttrib(&attribs, 0);
   
    NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs.attribs];

    if (fmt == nil) {
        throwException(env, "Could not create pixel format");
        return NULL;
    }
    return fmt;
}

Very few modifications.

I can't find any more test to do... Please anyone help me.

Estraven
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: Estraven on August 03, 2011, 08:02:39
Oups... My Bad. OpenGL 3.2 Core REQUIRES the use of VAOs (not just VBOs...)
I added VAO instructions, now It work perfectly !

Thus, the context.m i posted above works on Lion,

I'll be using this tweeked native libs until you come up with a more flexible release of LWJGL.
Meanwhile, if any other MacOs user wants this lib, i can provide it. I only changed the "liblwjgl.jnilib"

Thanks for your help.

Estraven
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: kappa on August 03, 2011, 08:41:21
nice work.

Would it be possible that you can get the constant values of both NSOpenGLPFAOpenGLProfile and NSOpenGLProfileVersion3_2Core? These can be found in the *.h file they are from. Just open it and copy and paste the two lines that specify the two. This would allow adding support for those without requiring Lion to compile LWJGL.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: Estraven on August 03, 2011, 09:24:11
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
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: pjohnsen on August 27, 2011, 15:50:42
Here is my NSOpenGL.h (/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSOpenGL.h)

Code: [Select]
/*
        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


Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: spasi on September 03, 2011, 19:56:32
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.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: kappa on September 07, 2011, 12:58:38
reports comming in from multiple sources about the following failure on Mac OS X nightly builds

Quote
SCHWERWIEGEND: 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 (http://jmonkeyengine.org/groups/jmonkeyplatform/forum/topic/display-is-not-created/#post-141448)
source2 (http://twitter.com/#!/john_ste/status/111341001796362240)
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: 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 (http://lwjgl.org/forum/index.php/topic,4023.msg22430.html#msg22430). This is the current code:

Code: [Select]
boolean gl32 = attribs != null && attribs.getMajorVersion() == 3 && attribs.getMinorVersion() == 2 && attribs.isProfileCore();
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: kappa on September 07, 2011, 21:43:59
That NPE should not happen with the latest build. It was fixed 2 days ago, see this (http://lwjgl.org/forum/index.php/topic,4023.msg22430.html#msg22430).

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.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: spasi on September 08, 2011, 08:06:39
Have we had any confirmation from a 10.7+ user?
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: kappa on September 08, 2011, 08:50:24
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.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: pjohnsen on September 08, 2011, 10:07:47
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
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: pjohnsen on September 08, 2011, 11:19:49
Hi again, 3dviewr.com is now running build #1330 ... and everything looks good  :)
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: Endolf on September 08, 2011, 16:42:35
Does this mean I don't need to update the OSX node on the build farm? :)

Endolf
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: spasi on September 08, 2011, 17:00:47
Yes, I've hard-coded the new token values.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: kappa on September 08, 2011, 18:07:18
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.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: jouvieje on September 09, 2011, 19:06:44
The exception reported in Adopt new JAWT API on Mac OS X so that Plugin2 will work (http://lwjgl.org/forum/index.php/topic,4023.15.html) 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.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: void256 on September 13, 2011, 13:19:51
Sorry for the delay! Here is what I did with 10.7:


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

Code: [Select]
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 ... =)
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: spasi on September 13, 2011, 18:09:38
Sounds like the new code works and the new attributes are being passed. This is the native code:

Code: [Select]
if (gl32) {
putAttrib(&attribs, 99); // NSOpenGLPFAOpenGLProfile
putAttrib(&attribs, 0x3200); // NSOpenGLProfileVersion3_2Core
}

I've no idea why it fails.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: void256 on September 13, 2011, 19:17:14
Hmm, when I understand the native code in context.m correctly there are some Pixelformat Attributes always set. Would it be possible - for an additional test - to only set the new attributes?

Using plain Obj-C it works with a minimal version:

Code: [Select]
+ (NSOpenGLPixelFormat*) basicPixelFormat
{
    NSOpenGLPixelFormatAttribute attributes [] = {
        NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
        (NSOpenGLPixelFormatAttribute)nil
    };
    return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
}

So, I'm curious what would happen when there would be no attribute set at all - besides the new NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core of course.

I understand that we want to specify some of the attributes of course. This would just be a test what would happen when we create exactly the same NSOpenGLPixelFormatAttribute[] I had luck with in the native example. Maybe something is conflicting with the new NSOpenGLPFAOpenGLProfile stuff?
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: kappa on September 13, 2011, 20:48:57
void256 would it be possible if you could just build lwjgl on your end? main issue here is lack of access to an OS X 10.7, should be as easy as checking out of svn and running build.xml to compile lwjgl. Would allow you to quickly test the different combinations to find the correct one.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: princec on September 14, 2011, 11:48:54
I've just got me 10.7 on my Mini - I should try and get a dev environment going on it to help you out...

Cas :)
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: void256 on September 15, 2011, 01:04:12
Ok, I've build LWJGL from svn which worked out quite well. Since 10.7 does not support building for ppc anymore I need to comment out a couple of lines in one of the build.xml files but after that I've got the jars and the native libs.

Unfortunatly when I try to use them I only get that - somewhat familiar :) - exception:

Code: [Select]
Exception in thread "main" java.lang.LinkageError: Version mismatch: jar version is '20', native library version is '19'
Usually you get that one when you're using the wrong jar with the wrong native libs. But I've double and triple ^^ checked my classpath and I think I'm using exactly the versions from my own build of LWJGL.

Is there some additional trick to align these version numbers somehow?
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: kappa on September 15, 2011, 08:54:40
That version check is a last line of defence to make sure your using the right natives with the correct jars.

If you look inside MacOSXSysImplementation.java (found in the org.lwjgl.* package), you'll see the line
Quote
private static final int JNI_VERSION = 20;
this value is obtained by the natives when compiling directly from the above java class using
Quote
org_lwjgl_MacOSXSysImplementation_JNI_VERSION
see org_lwjgl_opengl_Display.m (inside src/native/macosx).

So its either your compiler compiling with older lwjgl java classes or the natives you're running with are old (do quadruple check :), maybe try deleting any precompiled natives already in the lwjgl folder).
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: spasi on September 15, 2011, 09:03:59
Get in the LWJGL root directory and run this:

Code: [Select]
java -cp bin -Djava.library.path=libs/macosx org.lwjgl.test.opengl.VersionTest 3 2 core
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: void256 on September 15, 2011, 11:31:35
Ok, the quadruple check solved it ;) Somehow I ended up using the wrong native libs, oops :-[ but now it works!

With some testing it seems that Apple doesn't like the attribute:

Code: [Select]
if (support_window)
  putAttrib(&attribs, NSOpenGLPFAWindow);

Which is odd, because the doc says:

Code: [Select]
NSOpenGLPFAWindow

    A Boolean attribute. If present, this attribute indicates that only renderers that are capable of rendering to a window are considered. This attribute is implied if neither NSOpenGLPFAFullScreen nor NSOpenGLPFAOffScreen is specified.

    Available in Mac OS X v10.0 and later.

Without NSOpenGLPFAWindow my OpenGL implementation finally reported:

Code: [Select]
opengl version: 3.2 ATI-7.4.10
I still get a warning about some other invalid pixel format attribute though:

Code: [Select]
2011-09-15 13:19:44.054 java[3338:1903] invalid pixel format attribute
but the exception is gone. I've not yet tested if I can render anything but this looks pretty good so far.

From what I understand the support_window boolean is not accessible from the outside and is set to false when using MacOSXPbufferPeerInfo only and set to true when using MacOSXCanvasPeerInfo (or a subclass).

What are these PeerInfos? =)
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: void256 on September 15, 2011, 12:01:14
With brute force out commenting of the line "putAttrib(&attribs, NSOpenGLPFAWindow);" and then running:

Code: [Select]
java -cp bin -Djava.library.path=libs/macosx org.lwjgl.test.opengl.VersionTest 3 2 core
I've got that:

Code: [Select]
Setting display mode to: 1024 x 768 x 32 @85Hz
2011-09-15 14:01:00.429 java[3658:c07] invalid pixel format attribute

---------

Requested ContextAttribs: Version=3.2 - Layer=0 - Debug=false - ForwardCompatible=false - RobustAccess=false - Profile=Core

GL_VERSION returned : 3.2 ATI-7.4.10
Core profile: true
Compatibility profile: false
ARB_compatibility present: false
Deprecated functionality present: false

---------

Version 3.2 or greater is requested, the context returned may
implement any of the following versions:

1) The requested profile of the requested version.
true

2) The requested profile of any later version, so long as no
features have been removed from that later version and profile.
false

TEST SUCCEEDED

And just for the record - with the NSOpenGLPFAWindow line in place it looks like that:

Code: [Select]
Setting display mode to: 1024 x 768 x 32 @85Hz
2011-09-15 14:03:31.546 java[3768:c07] invalid pixel format attribute
2011-09-15 14:03:31.547 java[3768:c07] invalid pixel format attribute
The VersionTest program was terminated because an error occured.

Reason: Could not create pixel format
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: kappa on September 15, 2011, 12:59:01
oh nice work void256, guess as it stands we just need to change the code to something like:

Code: [Select]
if (support_window && !gl32)
  putAttrib(&attribs, NSOpenGLPFAWindow);
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: spasi on September 15, 2011, 13:05:03
If you don't mind, could you please comment out the other attributes one-by-one as well? So that we can get rid of the other "invalid pixel format attribute" message.
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: void256 on September 15, 2011, 16:15:21
Sure, here is it. With that commented out as well it does not complain anymore:

Code: [Select]
NSOpenGLPFAPixelBuffer

    A Boolean attribute. If present, this attribute indicates that rendering to a pixel buffer is enabled.

    Available in Mac OS X v10.3 and later.

Not sure if that makes sense but maybe PBOs are explicitly available when requesting the Core profile so it's not necessary to request support?
Title: Re: [RFE] add OpenGL 3.2 Core support for Mac OS X Lion
Post by: spasi on September 15, 2011, 17:23:39
That makes sense. It's the pbuffer flag and pbuffers have been deprecated in 10.7 in favor of FBOs. I have applied a fix now, try the next build to make sure it works please.