cocoa backend for offscreen world rendering
parent
14940bd7aa
commit
0b42f11683
|
@ -55,8 +55,11 @@ PRIVATE>
|
||||||
: with-multisample ( quot -- )
|
: with-multisample ( quot -- )
|
||||||
t +multisample+ pick with-variable ; inline
|
t +multisample+ pick with-variable ; inline
|
||||||
|
|
||||||
: <PixelFormat> ( -- pixelfmt )
|
|
||||||
|
|
||||||
|
: <PixelFormat> ( attributes -- pixelfmt )
|
||||||
NSOpenGLPixelFormat -> alloc [
|
NSOpenGLPixelFormat -> alloc [
|
||||||
|
%
|
||||||
NSOpenGLPFAWindow ,
|
NSOpenGLPFAWindow ,
|
||||||
NSOpenGLPFADoubleBuffer ,
|
NSOpenGLPFADoubleBuffer ,
|
||||||
NSOpenGLPFADepthSize , 16 ,
|
NSOpenGLPFADepthSize , 16 ,
|
||||||
|
@ -74,7 +77,7 @@ PRIVATE>
|
||||||
-> autorelease ;
|
-> autorelease ;
|
||||||
|
|
||||||
: <GLView> ( class dim -- view )
|
: <GLView> ( class dim -- view )
|
||||||
[ -> alloc 0 0 ] dip first2 <NSRect> <PixelFormat>
|
[ -> alloc 0 0 ] dip first2 <NSRect> { } <PixelFormat>
|
||||||
-> initWithFrame:pixelFormat:
|
-> initWithFrame:pixelFormat:
|
||||||
dup 1 -> setPostsBoundsChangedNotifications:
|
dup 1 -> setPostsBoundsChangedNotifications:
|
||||||
dup 1 -> setPostsFrameChangedNotifications: ;
|
dup 1 -> setPostsFrameChangedNotifications: ;
|
||||||
|
|
|
@ -17,11 +17,15 @@ HOOK: (open-window) ui-backend ( world -- )
|
||||||
|
|
||||||
HOOK: (close-window) ui-backend ( handle -- )
|
HOOK: (close-window) ui-backend ( handle -- )
|
||||||
|
|
||||||
|
HOOK: (open-offscreen-buffer) ui-backend ( world -- )
|
||||||
|
|
||||||
|
HOOK: (close-offscreen-buffer) ui-backend ( handle -- )
|
||||||
|
|
||||||
HOOK: raise-window* ui-backend ( world -- )
|
HOOK: raise-window* ui-backend ( world -- )
|
||||||
|
|
||||||
HOOK: select-gl-context ui-backend ( handle -- )
|
GENERIC: select-gl-context ( handle -- )
|
||||||
|
|
||||||
HOOK: flush-gl-context ui-backend ( handle -- )
|
GENERIC: flush-gl-context ( handle -- )
|
||||||
|
|
||||||
HOOK: beep ui-backend ( -- )
|
HOOK: beep ui-backend ( -- )
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,19 @@ command-line kernel memory namespaces cocoa.messages
|
||||||
cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
|
cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
|
||||||
cocoa.windows cocoa.classes cocoa.application sequences system
|
cocoa.windows cocoa.classes cocoa.application sequences system
|
||||||
ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
|
ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
|
||||||
ui.cocoa.views core-foundation threads math.geometry.rect fry ;
|
ui.cocoa.views core-foundation threads math.geometry.rect fry
|
||||||
|
libc generalizations ;
|
||||||
IN: ui.cocoa
|
IN: ui.cocoa
|
||||||
|
|
||||||
TUPLE: handle view window ;
|
TUPLE: handle ;
|
||||||
|
TUPLE: window-handle < handle view window ;
|
||||||
|
TUPLE: offscreen-handle < handle context buffer ;
|
||||||
|
|
||||||
C: <handle> handle
|
C: <window-handle> window-handle
|
||||||
|
C: <offscreen-handle> offscreen-handle
|
||||||
|
|
||||||
|
M: offscreen-handle window>> f ;
|
||||||
|
M: offscreen-handle view>> f ;
|
||||||
|
|
||||||
SINGLETON: cocoa-ui-backend
|
SINGLETON: cocoa-ui-backend
|
||||||
|
|
||||||
|
@ -38,7 +45,8 @@ M: pasteboard set-clipboard-contents
|
||||||
: gadget-window ( world -- )
|
: gadget-window ( world -- )
|
||||||
dup <FactorView>
|
dup <FactorView>
|
||||||
2dup swap world>NSRect <ViewWindow>
|
2dup swap world>NSRect <ViewWindow>
|
||||||
[ [ -> release ] [ install-window-delegate ] bi* ] [ <handle> ] 2bi
|
[ [ -> release ] [ install-window-delegate ] bi* ]
|
||||||
|
[ <window-handle> ] 2bi
|
||||||
>>handle drop ;
|
>>handle drop ;
|
||||||
|
|
||||||
M: cocoa-ui-backend set-title ( string world -- )
|
M: cocoa-ui-backend set-title ( string world -- )
|
||||||
|
@ -87,11 +95,36 @@ M: cocoa-ui-backend raise-window* ( world -- )
|
||||||
NSApp 1 -> activateIgnoringOtherApps:
|
NSApp 1 -> activateIgnoringOtherApps:
|
||||||
] when* ;
|
] when* ;
|
||||||
|
|
||||||
M: cocoa-ui-backend select-gl-context ( handle -- )
|
: pixel-size ( pixel-format -- size )
|
||||||
view>> -> openGLContext -> makeCurrentContext ;
|
0 <int> [ NSOpenGLPFAColorSize 0 -> getValues:forAttribute:forVirtualScreen: ]
|
||||||
|
keep *int -3 shift ;
|
||||||
|
|
||||||
M: cocoa-ui-backend flush-gl-context ( handle -- )
|
: offscreen-buffer ( world pixel-format -- alien w h pitch )
|
||||||
view>> -> openGLContext -> flushBuffer ;
|
[ dim>> first2 ] [ pixel-size ] bi*
|
||||||
|
{ [ * * malloc ] [ 2drop ] [ drop nip ] [ nip * ] } cleave ;
|
||||||
|
|
||||||
|
: gadget-offscreen-context ( world -- context buffer )
|
||||||
|
{ NSOpenGLPFAOffscreen } <PixelFormat>
|
||||||
|
[ NSOpenGLContext -> alloc swap f -> initWithFormat:shareContext: ]
|
||||||
|
[ offscreen-buffer ] bi
|
||||||
|
4 npick [ setOffScreen:width:height:rowbytes: ] dip ;
|
||||||
|
|
||||||
|
M: cocoa-ui-backend (open-offscreen-buffer) ( world -- )
|
||||||
|
dup gadget-offscreen-context <offscreen-handle> >>handle drop ;
|
||||||
|
|
||||||
|
M: cocoa-ui-backend (close-offscreen-buffer) ( handle -- )
|
||||||
|
[ context>> -> release ]
|
||||||
|
[ buffer>> free ] bi ;
|
||||||
|
|
||||||
|
GENERIC: gl-context ( handle -- context )
|
||||||
|
M: window-handle gl-context view>> -> openGLContext ;
|
||||||
|
M: offscreen-handle gl-context context>> ;
|
||||||
|
|
||||||
|
M: handle select-gl-context ( handle -- )
|
||||||
|
gl-context -> makeCurrentContext ;
|
||||||
|
|
||||||
|
M: handle flush-gl-context ( handle -- )
|
||||||
|
gl-context -> flushBuffer ;
|
||||||
|
|
||||||
M: cocoa-ui-backend beep ( -- )
|
M: cocoa-ui-backend beep ( -- )
|
||||||
NSBeep ;
|
NSBeep ;
|
||||||
|
|
Loading…
Reference in New Issue