OpenGL floating-point framebuffer

Discussion in 'Mac Programming' started by Columbo X, Nov 22, 2008.

  1. Columbo X macrumors member

    Joined:
    Jun 10, 2007
    Location:
    UK
    #1
    I'm currently porting a library of effects (depth of field, glow, HDR etc.) from Windows to Mac OS and am looking to create floating point framebuffers in Cocoa. The documentation seems straightforward and I've setup and validated a hardware accelerated pixel format as follows...

    // ID of main display - running MBP mid-late 07 with 8600M GT GPU with Leopard 5.5
    CGDirectDisplayID display = CGMainDisplayID();

    GLuint attributes[] =
    {
    NSOpenGLPFAScreenMask, (NSOpenGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display),
    NSOpenGLPFAWindow,
    NSOpenGLPFANoRecovery,
    NSOpenGLPFAAccelerated,
    NSOpenGLPFADoubleBuffer,
    NSOpenGLPFAColorFloat,
    NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)64,
    NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
    NSOpenGLPFAMinimumPolicy,
    0
    };

    NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: (NSOpenGLPixelFormatAttribute*)attributes];

    if (fmt) {

    printf("pixel format VALID!\n");

    // check details of returned pixel format
    GLint noofVirtualScreens = [fmt numberOfVirtualScreens];

    GLint colourFloatBuffer, colourSize, alphaSize;
    [fmt getValues:&colourFloatBuffer forAttribute:NSOpenGLPFAColorFloat forVirtualScreen:0];
    [fmt getValues:&colourSize forAttribute:NSOpenGLPFAColorSize forVirtualScreen:0];
    [fmt getValues:&alphaSize forAttribute:NSOpenGLPFAAlphaSize forVirtualScreen:0];

    printf("number of virtual screens = %d\n", noofVirtualScreens);
    printf("Colour Buffer = %d\n", colourFloatBuffer); // 1=okay
    printf("colour size = %d\n", colourSize);
    printf("alpha size = %d\n", alphaSize);

    }
    else
    {
    printf("pixel format not valid!\n");
    }


    I seem to get a valid pixel format with a 64 bit colour buffer setup okay. However, on rendering into a subclass of NSView I get nothing at all - just a white b/ground as if the context is not bound to the view. If I remove the NSOpenGLPFAColorFloat flag and set the colour size to 32 I get output as normal.

    Has anyone else tried using floating point buffers on the 8600M and run into similar problems? I'm wondering if there are properies of the NSView that need to be changed?

    Thanks in advance.

    C
     
  2. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    If you're using Cocoa, shouldn't you be rendering into an NSOpenGLView? And using NSOpenGLPixelBuffer and NSOpenGLContext?
     
  3. Columbo X thread starter macrumors member

    Joined:
    Jun 10, 2007
    Location:
    UK
    #3
    Yes, I've tried sub-classing NSOpenGLView and setting the pixel format properties in Interface Builder. But I get the same behaviour. My sub-class of NSView (based on Apple's examples of setting up your own OpenGL view) has essentially the same functionality of NSOpenGLView and maintains it's own NSOpenGLPixelFormat and NSOpenGLContext.
     
  4. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #4
    Hi,

    I tried using your attributes and it worked for me on my iMac (using the example CocoaGL project).

    b e n
     
  5. Columbo X thread starter macrumors member

    Joined:
    Jun 10, 2007
    Location:
    UK
    #5
    Hi lazydog,

    I also tried this - I ran one of the OpenGL demos from Apple and it worked fine until I added the NSOpenGLPFAColorFloat attributes to the initWithFrame: method - after which nothing gets rendered.

    Do you have an nVidia GPU in your iMac? I'll have to test this on our iMacs at work to see if I get more luck.

    Thanks,

    C
     
  6. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #6
    Hi Columbo

    I think it's an ati chipset. Have you looked at the supported formats? You can do this using the Open GL Driver Monitor app in the developers directory. For example, on my Powerbook 64 and 128 bit float argb is supported.

    b e n
     
  7. Columbo X thread starter macrumors member

    Joined:
    Jun 10, 2007
    Location:
    UK
    #7
    Yeah, I checked this just now - the 64 and 128 bit floating point formats are supported in hardware. I'll try this out on our ATI-based iMacs tomorrow.

    ---

    Update: The code worked fine on an ATI 2600 iMac - time for a bug report to Apple I think.

    Cheers,
    C
     

Share This Page