I tried your code to initialize a 3.2+ OpenGL context on MacOS but i get an IMA error at line 86 in the following code. Do you have an idea what's happening ? (PB 5.51 x86)
Code: Select all
EnableExplicit
; ** Attribute names For [NSOpenGLPixelFormat initWithAttributes]
; ** And [NSOpenGLPixelFormat getValues:forAttribute:forVirtualScreen].
Enumeration ;{
#NSOpenGLPFAAllRenderers = 1 ;, /* choose from all available renderers */
#NSOpenGLPFATripleBuffer = 3 ;, /* choose a triple buffered pixel format */
#NSOpenGLPFADoubleBuffer = 5 ;, /* choose a double buffered pixel format */
#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 */
#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 */
#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 */
#NSOpenGLPFAScreenMask = 84 ;, /* bit mask of supported physical screens */
#NSOpenGLPFAAllowOfflineRenderers = 96 ;, /* allow use of offline renderers */
#NSOpenGLPFAAcceleratedCompute = 97 ;, /* choose a hardware accelerated compute device */
#NSOpenGLPFAVirtualScreenCount = 128 ;, /* number of virtual screens in this format */
#NSOpenGLPFAOpenGLProfile = 99 ;, /* specify an OpenGL Profile To use */
EndEnumeration ;}
;/* NSOpenGLPFAOpenGLProfile values */
Enumeration ;{
#NSOpenGLProfileVersionLegacy = $1000 ;, /* choose a Legacy/Pre-OpenGL 3.0 Implementation */
#NSOpenGLProfileVersion3_2Core = $3200 ;, /* choose an OpenGL 3.2 Core Implementation */
#NSOpenGLProfileVersion4_1Core = $4100 ; /* choose an OpenGL 4.1 Core Implementation */
EndEnumeration ;}
; ...[ array9_t ]......................................................
Structure array9_t
v.l[9]
EndStructure
; ...[ NSOpenGLPixelFormatAttribute ]...................................
Macro NSOpenGLPixelFormatAttribute
array9_t
EndMacro
; ...[ NSOpenGLPixelFormat ]............................................
Macro NSOpenGLPixelFormat
i
EndMacro
; ...[ NSOpenGLContext ]................................................
Macro NSOpenGLContext
i
EndMacro
OpenWindow(0, 10, 10, 640, 480, "OpenGL demo")
OpenGLGadget(0, 10, 10, WindowWidth(0)-20 , WindowHeight(0)-20)
; ---[ Allocate Pixel Format Object ]---------------------------------
Define pfo.NSOpenGLPixelFormat = CocoaMessage( 0, 0, "NSOpenGLPixelFormat alloc" )
; ---[ Set Pixel Format Attributes ]----------------------------------
Define pfa.NSOpenGLPixelFormatAttribute
With pfa
\v[0] = #NSOpenGLPFAColorSize : \v[1] = 24
\v[2] = #NSOpenGLPFAAlphaSize : \v[3] = 8
\v[4] = #NSOpenGLPFAOpenGLProfile : \v[5] = #NSOpenGLProfileVersion3_2Core ; will give 4.1 version (or more recent) if available
\v[6] = #NSOpenGLPFADoubleBuffer
\v[7] = #NSOpenGLPFAAcceleratedCompute ; I also want OpenCL available
\v[8] = #Null
EndWith
; ---[ Choose Pixel Format ]------------------------------------------
CocoaMessage( 0, pfo, "initWithAttributes:", @pfa )
; ---[ Allocate OpenGL Context ]--------------------------------------
Define ctx.NSOpenGLContext = CocoaMessage( 0, 0, "NSOpenGLContext alloc" )
; ---[ Create OpenGL Context ]----------------------------------------
CocoaMessage( 0, ctx, "initWithFormat:", pfo, "shareContext:", #Null )
; ---[ Associate Context With OpenGLGadget NSView ]-------------------
CocoaMessage( 0, ctx, "setView:", GadgetID(0) ) ; oglcanvas_gadget is your OpenGLGadget#
; ---[ Set Current Context ]------------------------------------------
CocoaMessage( 0, ctx, "makeCurrentContext" )
; do your OpenGL drawing..
; ---[ Swap Buffers ]-------------------------------------------------
; CocoaMessage( 0, ctx, "flushBuffer" )
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow