1 ! Copyright (C) 2006, 2007 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types arrays kernel math namespaces cocoa
4 cocoa.messages cocoa.classes cocoa.types sequences
8 : NSOpenGLPFAAllRenderers 1 ;
9 : NSOpenGLPFADoubleBuffer 5 ;
10 : NSOpenGLPFAStereo 6 ;
11 : NSOpenGLPFAAuxBuffers 7 ;
12 : NSOpenGLPFAColorSize 8 ;
13 : NSOpenGLPFAAlphaSize 11 ;
14 : NSOpenGLPFADepthSize 12 ;
15 : NSOpenGLPFAStencilSize 13 ;
16 : NSOpenGLPFAAccumSize 14 ;
17 : NSOpenGLPFAMinimumPolicy 51 ;
18 : NSOpenGLPFAMaximumPolicy 52 ;
19 : NSOpenGLPFAOffScreen 53 ;
20 : NSOpenGLPFAFullScreen 54 ;
21 : NSOpenGLPFASampleBuffers 55 ;
22 : NSOpenGLPFASamples 56 ;
23 : NSOpenGLPFAAuxDepthStencil 57 ;
24 : NSOpenGLPFARendererID 70 ;
25 : NSOpenGLPFASingleRenderer 71 ;
26 : NSOpenGLPFANoRecovery 72 ;
27 : NSOpenGLPFAAccelerated 73 ;
28 : NSOpenGLPFAClosestPolicy 74 ;
29 : NSOpenGLPFARobust 75 ;
30 : NSOpenGLPFABackingStore 76 ;
31 : NSOpenGLPFAMPSafe 78 ;
32 : NSOpenGLPFAWindow 80 ;
33 : NSOpenGLPFAMultiScreen 81 ;
34 : NSOpenGLPFACompliant 83 ;
35 : NSOpenGLPFAScreenMask 84 ;
36 : NSOpenGLPFAPixelBuffer 90 ;
37 : NSOpenGLPFAVirtualScreenCount 128 ;
41 SYMBOL: +software-renderer+
45 : with-software-renderer ( quot -- )
46 t +software-renderer+ set
47 [ f +software-renderer+ set ]
50 : <PixelFormat> ( -- pixelfmt )
51 NSOpenGLPixelFormat -> alloc [
53 NSOpenGLPFADoubleBuffer ,
54 NSOpenGLPFADepthSize , 16 ,
55 +software-renderer+ get [ NSOpenGLPFARobust , ] when
57 ] { } make >c-int-array
58 -> initWithAttributes:
61 : <GLView> ( class dim -- view )
62 >r -> alloc 0 0 r> first2 <NSRect> <PixelFormat>
63 -> initWithFrame:pixelFormat:
64 dup 1 -> setPostsBoundsChangedNotifications:
65 dup 1 -> setPostsFrameChangedNotifications: ;
67 : view-dim ( view -- dim )
70 swap NSRect-h >fixnum 2array ;
72 : mouse-location ( view event -- loc )
74 -> locationInWindow f -> convertPoint:fromView:
75 dup NSPoint-x swap NSPoint-y
76 r> -> frame NSRect-h swap - 2array ;
81 : NSOpenGLCPSwapInterval 222 ;
86 TYPEDEF: void* CGLContextObj
87 TYPEDEF: int CGLContextParameter
89 FUNCTION: CGLError CGLSetParameter ( CGLContextObj ctx, CGLContextParameter pname, GLint* params ) ;