cocoa backend support for ui.pixel-formats; world-pixel-format-attributes generic

db4
Joe Groff 2009-05-01 09:09:38 -05:00
parent 87daa532a6
commit ba8abd6cad
5 changed files with 80 additions and 30 deletions

View File

@ -42,22 +42,10 @@ CONSTANT: NSOpenGLPFAAllowOfflineRenderers 96
CONSTANT: NSOpenGLPFAVirtualScreenCount 128 CONSTANT: NSOpenGLPFAVirtualScreenCount 128
CONSTANT: NSOpenGLCPSwapInterval 222 CONSTANT: NSOpenGLCPSwapInterval 222
: <PixelFormat> ( attributes -- pixelfmt ) : <GLView> ( class dim pixel-format -- view )
NSOpenGLPixelFormat -> alloc swap [ [ -> alloc ]
% [ [ 0 0 ] dip first2 <CGRect> ]
NSOpenGLPFADepthSize , 16 , [ handle>> ] tri*
! NSOpenGLPFARendererID , kCGLRendererGenericFloatID ,
! NSOpenGLPFASupersample ,
! NSOpenGLPFASampleBuffers , 1 ,
! NSOpenGLPFASamples , 8 ,
0 ,
] int-array{ } make
-> initWithAttributes:
-> autorelease ;
: <GLView> ( class dim -- view )
[ -> alloc 0 0 ] dip first2 <CGRect>
NSOpenGLPFAWindow NSOpenGLPFADoubleBuffer 2array <PixelFormat>
-> initWithFrame:pixelFormat: -> initWithFrame:pixelFormat:
dup 1 -> setPostsBoundsChangedNotifications: dup 1 -> setPostsBoundsChangedNotifications:
dup 1 -> setPostsFrameChangedNotifications: ; dup 1 -> setPostsFrameChangedNotifications: ;

View File

@ -1,14 +1,15 @@
! Copyright (C) 2006, 2009 Slava Pestov. ! Copyright (C) 2006, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors math arrays assocs cocoa cocoa.application USING: accessors math arrays assocs cocoa cocoa.application
command-line kernel memory namespaces cocoa.messages command-line kernel memory namespaces cocoa.messages classes
cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
cocoa.windows cocoa.classes cocoa.nibs sequences ui ui.private cocoa.windows cocoa.classes cocoa.nibs sequences ui ui.private
ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
ui.backend.cocoa.views core-foundation core-foundation.run-loop ui.backend.cocoa.views core-foundation core-foundation.run-loop
core-graphics.types threads math.rectangles fry libc core-graphics.types threads math.rectangles fry libc
generalizations alien.c-types cocoa.views generalizations alien.c-types cocoa.views
combinators io.thread locals ; combinators io.thread locals ui.pixel-formats
specialized-arrays.int literals core-graphics ;
IN: ui.backend.cocoa IN: ui.backend.cocoa
TUPLE: handle ; TUPLE: handle ;
@ -20,6 +21,57 @@ C: <offscreen-handle> offscreen-handle
SINGLETON: cocoa-ui-backend SINGLETON: cocoa-ui-backend
<PRIVATE
GENERIC: >NSOpenGLPFA ( attribute -- NSOpenGLPFAs )
CONSTANT: attribute>NSOpenGLPFA-map H{
{ double-buffered { $ NSOpenGLPFADoubleBuffer } }
{ stereo { $ NSOpenGLPFAStereo } }
{ offscreen { $ NSOpenGLPFAOffScreen } }
{ fullscreen { $ NSOpenGLPFAFullScreen } }
{ windowed { $ NSOpenGLPFAWindow } }
{ accelerated { $ NSOpenGLPFAAccelerated } }
{ software-rendered { $ NSOpenGLPFASingleRenderer $ kCGLRendererGenericFloatID } }
{ robust { $ NSOpenGLPFARobust } }
{ backing-store { $ NSOpenGLPFABackingStore } }
{ multisampled { $ NSOpenGLPFAMultisample } }
{ supersampled { $ NSOpenGLPFASupersample } }
{ sample-alpha { $ NSOpenGLPFASampleAlpha } }
{ color-float { $ NSOpenGLPFAColorFloat } }
{ color-bits { $ NSOpenGLPFAColorSize } }
{ alpha-bits { $ NSOpenGLPFAAlphaSize } }
{ accum-bits { $ NSOpenGLPFAAccumSize } }
{ depth-bits { $ NSOpenGLPFADepthSize } }
{ stencil-bits { $ NSOpenGLPFAStencilSize } }
{ aux-buffers { $ NSOpenGLPFAAuxBuffers } }
{ sample-buffers { $ NSOpenGLPFASampleBuffers } }
{ samples { $ NSOpenGLPFASamples } }
}
M: object >NSOpenGLPFA
drop { } ;
M: symbol >NSOpenGLPFA
attribute>NSOpenGLPFA-map at [ { } ] unless* ;
M: pixel-format-attribute >NSOpenGLPFA
dup class attribute>NSOpenGLPFA-map at
[ swap value>> suffix ]
[ drop { } ] if ;
PRIVATE>
M: cocoa-ui-backend (make-pixel-format)
[ >NSOpenGLPFA ] map concat >int-array
NSOpenGLPixelFormat -> alloc swap -> initWithAttributes: ;
M: cocoa-ui-backend (free-pixel-format)
-> release ;
M: cocoa-ui-backend (pixel-format-attribute)
attribute>NSOpenGLPFA-map at
[ first 0 <int> [ swap 0 -> getValues:forAttribute:forVirtualScreen: ] keep *int ]
[ f ] if* ;
TUPLE: pasteboard handle ; TUPLE: pasteboard handle ;
C: <pasteboard> pasteboard C: <pasteboard> pasteboard
@ -70,7 +122,7 @@ M: cocoa-ui-backend fullscreen* ( world -- ? )
handle>> view>> -> isInFullScreenMode zero? not ; handle>> view>> -> isInFullScreenMode zero? not ;
M:: cocoa-ui-backend (open-window) ( world -- ) M:: cocoa-ui-backend (open-window) ( world -- )
world dim>> <FactorView> :> view [ [ dim>> ] dip <FactorView> ] with-world-pixel-format :> view
view world world>NSRect <ViewWindow> :> window view world world>NSRect <ViewWindow> :> window
view -> release view -> release
world view register-window world view register-window
@ -97,18 +149,19 @@ M: cocoa-ui-backend raise-window* ( world -- )
] when* ; ] when* ;
: pixel-size ( pixel-format -- size ) : pixel-size ( pixel-format -- size )
0 <int> [ NSOpenGLPFAColorSize 0 -> getValues:forAttribute:forVirtualScreen: ] color-bits pixel-format-attribute -3 shift ;
keep *int -3 shift ;
: offscreen-buffer ( world pixel-format -- alien w h pitch ) : offscreen-buffer ( world pixel-format -- alien w h pitch )
[ dim>> first2 ] [ pixel-size ] bi* [ dim>> first2 ] [ pixel-size ] bi*
{ [ * * malloc ] [ 2drop ] [ drop nip ] [ nip * ] } 3cleave ; { [ * * malloc ] [ 2drop ] [ drop nip ] [ nip * ] } 3cleave ;
: gadget-offscreen-context ( world -- context buffer ) :: gadget-offscreen-context ( world -- context buffer )
NSOpenGLPFAOffScreen 1array <PixelFormat> world world-pixel-format-attributes offscreen suffix
[ nip NSOpenGLContext -> alloc swap f -> initWithFormat:shareContext: dup ] <pixel-format> [
[ offscreen-buffer ] 2bi :> pf
4 npick [ -> setOffScreen:width:height:rowbytes: ] dip ; NSOpenGLContext -> alloc pf handle>> f -> initWithFormat:shareContext:
dup world pf offscreen-buffer -> setOffScreen:width:height:rowbytes:
] with-disposal ;
M: cocoa-ui-backend (open-offscreen-buffer) ( world -- ) M: cocoa-ui-backend (open-offscreen-buffer) ( world -- )
dup gadget-offscreen-context <offscreen-handle> >>handle drop ; dup gadget-offscreen-context <offscreen-handle> >>handle drop ;

View File

@ -365,8 +365,8 @@ CLASS: {
-> openGLContext -> CGLContextObj NSOpenGLCPSwapInterval 1 <int> -> openGLContext -> CGLContextObj NSOpenGLCPSwapInterval 1 <int>
CGLSetParameter drop ; CGLSetParameter drop ;
: <FactorView> ( dim -- view ) : <FactorView> ( dim pixel-format -- view )
FactorView swap <GLView> [ sync-refresh-to-screen ] keep ; [ FactorView ] 2dip <GLView> [ sync-refresh-to-screen ] keep ;
: save-position ( world window -- ) : save-position ( world window -- )
-> frame CGRect-top-left 2array >>window-loc drop ; -> frame CGRect-top-left 2array >>window-loc drop ;

View File

@ -4,7 +4,7 @@ USING: accessors arrays assocs continuations kernel math models
namespaces opengl opengl.textures sequences io combinators namespaces opengl opengl.textures sequences io combinators
combinators.short-circuit fry math.vectors math.rectangles cache combinators.short-circuit fry math.vectors math.rectangles cache
ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
ui.commands ; ui.commands ui.pixel-formats destructors ;
IN: ui.gadgets.worlds IN: ui.gadgets.worlds
TUPLE: world < track TUPLE: world < track
@ -149,3 +149,12 @@ M: world handle-gesture ( gesture gadget -- ? )
: close-global ( world global -- ) : close-global ( world global -- )
[ get-global find-world eq? ] keep '[ f _ set-global ] when ; [ get-global find-world eq? ] keep '[ f _ set-global ] when ;
GENERIC: world-pixel-format-attributes ( world -- attributes )
M: world world-pixel-format-attributes
{ windowed double-buffered T{ depth-bits { value 16 } } } ;
: with-world-pixel-format ( world quot -- )
[ dup world-pixel-format-attributes <pixel-format> ]
dip with-disposal ; inline

View File

@ -1,7 +1,7 @@
USING: destructors math ui.backend ; USING: destructors math ui.backend ;
IN: ui.pixel-formats IN: ui.pixel-formats
SINGLETONS: SYMBOLS:
double-buffered double-buffered
stereo stereo
offscreen offscreen