]> gitweb.factorcode.org Git - factor.git/commitdiff
frame-buffer: fix for retina using gl-scale-factor.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 22 Jan 2018 06:17:28 +0000 (22:17 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 22 Jan 2018 06:17:28 +0000 (22:17 -0800)
extra/frame-buffer/frame-buffer.factor

index 14ba367784e80b27df092538d3e9b961e2b5d2e0..e2b13b162b91888c0afcb8b48a84812a446fe1b7 100644 (file)
@@ -1,5 +1,5 @@
 USING: accessors alien.c-types alien.data combinators grouping
-kernel locals math math.vectors opengl.gl sequences
+kernel locals math math.vectors opengl opengl.gl sequences
 specialized-arrays ui.gadgets ui.render ;
 SPECIALIZED-ARRAY: uint
 IN: frame-buffer
@@ -11,11 +11,11 @@ TUPLE: frame-buffer < gadget pixels last-dim ;
 GENERIC: update-frame-buffer ( frame-buffer -- )
 
 : init-frame-buffer-pixels ( frame-buffer -- )
-  dup dim>> product 4 * uint <c-array> >>pixels
+  dup dim>> [ gl-scale ] map product >integer 4 * uint <c-array> >>pixels
   drop ;
 
 :: draw-pixels ( FRAME-BUFFER -- )
-    FRAME-BUFFER dim>> first2
+    FRAME-BUFFER dim>> first2 [ gl-scale >fixnum ] bi@
     GL_RGBA
     GL_UNSIGNED_INT
     FRAME-BUFFER pixels>>
@@ -24,7 +24,7 @@ GENERIC: update-frame-buffer ( frame-buffer -- )
 :: read-pixels ( FRAME-BUFFER -- )
     0
     0
-    FRAME-BUFFER dim>> first2
+    FRAME-BUFFER dim>> first2 [ gl-scale >fixnum ] bi@
     GL_RGBA
     GL_UNSIGNED_INT
     FRAME-BUFFER pixels>>
@@ -38,22 +38,20 @@ GENERIC: update-frame-buffer ( frame-buffer -- )
     [ [ drop { } ] [ 16 * <groups> ] if-zero ] 2bi@
     [ copy-row ] 2each ;
 
-: update-last-dim ( frame-buffer -- ) dup dim>> >>last-dim drop ;
-
 M:: frame-buffer layout* ( FRAME-BUFFER -- )
     FRAME-BUFFER last-dim>> [
         FRAME-BUFFER dim>> = [
             FRAME-BUFFER pixels>> :> OLD-PIXELS
-            FRAME-BUFFER last-dim>> first :> OLD-WIDTH
+            FRAME-BUFFER last-dim>> first gl-scale >fixnum :> OLD-WIDTH
             FRAME-BUFFER init-frame-buffer-pixels
-            FRAME-BUFFER update-last-dim
+            FRAME-BUFFER [ dim>> ] [ last-dim<< ] bi
             FRAME-BUFFER pixels>> :> NEW-PIXELS
-            FRAME-BUFFER last-dim>> first :> NEW-WIDTH
+            FRAME-BUFFER last-dim>> first gl-scale >fixnum :> NEW-WIDTH
             OLD-PIXELS OLD-WIDTH NEW-PIXELS NEW-WIDTH copy-pixels
         ] unless
     ] [
         FRAME-BUFFER init-frame-buffer-pixels
-        FRAME-BUFFER update-last-dim
+        FRAME-BUFFER [ dim>> ] [ last-dim<< ] bi
     ] if* ;
 
 M:: frame-buffer draw-gadget* ( FRAME-BUFFER -- )