]> gitweb.factorcode.org Git - factor.git/commitdiff
X11 backend for pixel formats
authorJoe Groff <arcata@gmail.com>
Sat, 2 May 2009 21:39:31 +0000 (16:39 -0500)
committerJoe Groff <arcata@gmail.com>
Sat, 2 May 2009 21:39:31 +0000 (16:39 -0500)
basis/ui/backend/cocoa/cocoa.factor
basis/ui/backend/x11/x11.factor
basis/x11/glx/glx.factor
basis/x11/windows/windows.factor

index a4dbf670e2d2fcb7b0883ac1db9b6673debd361f..dd207aa4f9ba3b4b9ec591bc001839e2105541cd 100755 (executable)
@@ -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: ;
index fb78abe917bacc41710a3df294639cb34c792000..5192fa1075977e892abf18c207b6e798b732492c 100755 (executable)
@@ -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 ]
index b459b55f4612bda7e3f33cf58bef7d92cc773b66..67ac0e8cc1ac1e6aeec3b1bd0a2c8f8107c6d39a 100644 (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* ;
index 37da51e9b8dcd7b79c01acd92517d8f48e013fd3..54cf205c144e8bb2a0bf96268208fcad1a5c08e7 100644 (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 ;