2 USING: kernel alien.c-types combinators sequences splitting grouping
3 opengl.gl ui.gadgets ui.render
4 math math.vectors accessors ;
6 IN: ui.gadgets.frame-buffer
8 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10 TUPLE: frame-buffer action dim last-dim graft ungraft pixels ;
12 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14 : init-frame-buffer-pixels ( frame-buffer -- frame-buffer )
16 rect-dim product "uint[4]" <c-array>
19 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21 : <frame-buffer> ( -- frame-buffer )
22 frame-buffer construct-gadget
28 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30 : draw-pixels ( fb -- fb )
33 rect-dim first2 GL_RGBA GL_UNSIGNED_INT r> pixels>> glDrawPixels
36 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
38 : read-pixels ( fb -- fb )
42 0 0 r> rect-dim first2 GL_RGBA GL_UNSIGNED_INT r> pixels>> glReadPixels
45 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
47 M: frame-buffer pref-dim* dim>> ;
48 M: frame-buffer graft* graft>> call ;
49 M: frame-buffer ungraft* ungraft>> call ;
51 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
53 : copy-row ( old new -- )
54 2dup min-length swap >r head-slice 0 r> copy ;
56 ! : copy-pixels ( old-pixels old-width new-pixels new-width -- )
58 ! [ copy-row ] 2each ;
60 ! : copy-pixels ( old-pixels old-width new-pixels new-width -- )
62 ! [ copy-row ] 2each ;
64 : copy-pixels ( old-pixels old-width new-pixels new-width -- )
65 [ 16 * <sliced-groups> ] 2bi@
68 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
70 M: frame-buffer layout* ( fb -- )
73 [ dup last-dim>> f = ]
75 init-frame-buffer-pixels
82 [ dup [ rect-dim ] [ last-dim>> ] bi = not ]
84 dup [ pixels>> ] [ last-dim>> first ] bi
86 rot init-frame-buffer-pixels
87 dup rect-dim >>last-dim
89 [ pixels>> ] [ rect-dim first ] bi
98 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
100 M: frame-buffer draw-gadget* ( fb -- )
102 dup rect-dim { 0 1 } v* first2 glRasterPos2i