X11 backend for pixel formats

db4
Joe Groff 2009-05-02 16:39:31 -05:00
parent 95f1ca3d9f
commit 623b16d048
4 changed files with 45 additions and 26 deletions

View File

@ -22,8 +22,6 @@ C: <offscreen-handle> offscreen-handle
SINGLETON: cocoa-ui-backend
<PRIVATE
PIXEL-FORMAT-ATTRIBUTE-TABLE: NSOpenGLPFA { } H{
{ double-buffered { $ NSOpenGLPFADoubleBuffer } }
{ stereo { $ NSOpenGLPFAStereo } }
@ -48,8 +46,6 @@ PIXEL-FORMAT-ATTRIBUTE-TABLE: NSOpenGLPFA { } H{
{ samples { $ NSOpenGLPFASamples } }
}
PRIVATE>
M: cocoa-ui-backend (make-pixel-format)
nip >NSOpenGLPFA-int-array
NSOpenGLPixelFormat -> alloc swap -> initWithAttributes: ;

View File

@ -7,7 +7,8 @@ namespaces opengl sequences strings x11 x11.xlib x11.events x11.xim
x11.glx x11.clipboard x11.constants x11.windows x11.io
io.encodings.string io.encodings.ascii io.encodings.utf8 combinators
command-line math.vectors classes.tuple opengl.gl threads
math.rectangles environment ascii ;
math.rectangles environment ascii
ui.pixel-formats ui.pixel-formats.private ;
IN: ui.backend.x11
SINGLETON: x11-ui-backend
@ -29,6 +30,40 @@ M: world configure-event
! In case dimensions didn't change
relayout-1 ;
PIXEL-FORMAT-ATTRIBUTE-TABLE: glx-visual { $ GLX_USE_GL $ GLX_RGBA } H{
{ double-buffered { $ GLX_DOUBLEBUFFER } }
{ stereo { $ GLX_STEREO } }
{ color-bits { $ GLX_BUFFER_SIZE } }
{ red-bits { $ GLX_RED_SIZE } }
{ green-bits { $ GLX_GREEN_SIZE } }
{ blue-bits { $ GLX_BLUE_SIZE } }
{ alpha-bits { $ GLX_ALPHA_SIZE } }
{ accum-red-bits { $ GLX_ACCUM_RED_SIZE } }
{ accum-green-bits { $ GLX_ACCUM_GREEN_SIZE } }
{ accum-blue-bits { $ GLX_ACCUM_BLUE_SIZE } }
{ accum-alpha-bits { $ GLX_ACCUM_ALPHA_SIZE } }
{ depth-bits { $ GLX_DEPTH_SIZE } }
{ stencil-bits { $ GLX_STENCIL_SIZE } }
{ aux-buffers { $ GLX_AUX_BUFFERS } }
{ sample-buffers { $ GLX_SAMPLE_BUFFERS } }
{ samples { $ GLX_SAMPLES } }
}
M: x11-ui-backend (make-pixel-format)
[ drop dpy get scr get ] dip
>glx-visual-int-array glXChooseVisual ;
M: x11-ui-backend (free-pixel-format)
handle>> XFree ;
M: x11-ui-backend (pixel-format-attribute)
[ dpy get ] 2dip
[ handle>> ] [ >glx-visual ] bi*
[ drop f ] [
first [ dpy get ] 2dip
0 <int> [ glXGetConfig drop ] keep *int
] if-empty ;
CONSTANT: modifiers
{
{ S+ HEX: 1 }
@ -187,7 +222,8 @@ M: world client-event
: gadget-window ( world -- )
dup
[ window-loc>> ] [ dim>> ] bi glx-window swap
[ [ [ window-loc>> ] [ dim>> ] bi ] dip handle>> glx-window ]
with-world-pixel-format swap
dup "Factor" create-xic
<x11-handle>
[ window>> register-window ] [ >>handle drop ] 2bi ;
@ -274,7 +310,9 @@ M: x11-pixmap-handle flush-gl-context ( handle -- )
drop ;
M: x11-ui-backend (open-offscreen-buffer) ( world -- )
dup dim>> glx-pixmap <x11-pixmap-handle> >>handle drop ;
dup [ [ dim>> ] [ handle>> ] bi* glx-pixmap ]
with-world-pixel-format
<x11-pixmap-handle> >>handle drop ;
M: x11-ui-backend (close-offscreen-buffer) ( handle -- )
dpy get swap
[ glx-pixmap>> glXDestroyGLXPixmap ]

View File

@ -95,17 +95,6 @@ CONSTANT: GLX_RGBA_FLOAT_BIT HEX: 0004
! GLX Events
! (also skipped for now. only has GLXPbufferClobberEvent, the rest is handled by xlib methinks)
: choose-visual ( flags -- XVisualInfo* )
[ dpy get scr get ] dip
[
%
GLX_RGBA ,
GLX_DEPTH_SIZE , 16 ,
0 ,
] int-array{ } make
glXChooseVisual
[ "Could not get a double-buffered GLX RGBA visual" throw ] unless* ;
: create-glx ( XVisualInfo* -- GLXContext )
[ dpy get ] dip f 1 glXCreateContext
[ "Failed to create GLX context" throw ] unless* ;

View File

@ -53,11 +53,8 @@ IN: x11.windows
dup
] dip auto-position ;
: glx-window ( loc dim -- window glx )
GLX_DOUBLEBUFFER 1array choose-visual
[ create-window ] keep
[ create-glx ] keep
XFree ;
: glx-window ( loc dim visual -- window glx )
[ create-window ] [ create-glx ] bi ;
: create-pixmap ( dim visual -- pixmap )
[ [ { 0 0 } swap ] dip create-window ] [
@ -74,9 +71,8 @@ IN: x11.windows
: create-glx-pixmap ( dim visual -- pixmap glx-pixmap )
[ create-pixmap ] [ (create-glx-pixmap) ] bi ;
: glx-pixmap ( dim -- glx pixmap glx-pixmap )
{ } choose-visual
[ nip create-glx ] [ create-glx-pixmap ] [ nip XFree ] 2tri ;
: glx-pixmap ( dim visual -- glx pixmap glx-pixmap )
[ nip create-glx ] [ create-glx-pixmap ] 2bi ;
: destroy-window ( win -- )
dpy get swap XDestroyWindow drop ;