]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/opengl/opengl.factor
Updating code to use with-out-parameters
[factor.git] / basis / opengl / opengl.factor
index bb5847e734f84bdcff77c254311c26832e15696f..893a8dfbd69f2cfd3ba580f9fa1464d0ecf33585 100644 (file)
@@ -2,11 +2,15 @@
 ! Portions copyright (C) 2007 Eduardo Cavazos.
 ! Portions copyright (C) 2008 Joe Groff.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.c-types continuations kernel libc math macros
+USING: alien alien.c-types alien.data ascii calendar
+combinators.short-circuit continuations kernel libc math macros
 namespaces math.vectors math.parser opengl.gl combinators
-combinators.smart arrays sequences splitting words byte-arrays assocs
-colors colors.constants accessors generalizations locals fry
-specialized-arrays.float specialized-arrays.uint ;
+combinators.smart arrays sequences splitting words byte-arrays
+assocs vocabs colors colors.constants accessors generalizations
+sequences.generalizations locals fry specialized-arrays ;
+FROM: alien.c-types => float ;
+SPECIALIZED-ARRAY: float
+SPECIALIZED-ARRAY: uint
 IN: opengl
 
 : gl-color ( color -- ) >rgba-components glColor4d ; inline
@@ -28,12 +32,19 @@ IN: opengl
         { HEX: 0506 "Invalid framebuffer operation" }
     } at "Unknown error" or ;
 
-TUPLE: gl-error code string ;
+TUPLE: gl-error function code string ;
+
+: <gl-error> ( function code -- gl-error )
+    dup error>string \ gl-error boa ; inline
+
+: gl-error-code ( -- code/f )
+    glGetError dup 0 = [ drop f ] when ; inline
+
+: (gl-error) ( function -- )
+    gl-error-code [ <gl-error> throw ] [ drop ] if* ;
 
 : gl-error ( -- )
-    glGetError dup 0 = [ drop ] [
-        dup error>string \ gl-error boa throw
-    ] if ;
+    f (gl-error) ; inline
 
 : do-enabled ( what quot -- )
     over glEnable dip glDisable ; inline
@@ -45,7 +56,9 @@ TUPLE: gl-error code string ;
     [ ?execute ] map ;
 
 : (all-enabled) ( seq quot -- )
-    over [ glEnable ] each dip [ glDisable ] each ; inline
+    [ dup [ glEnable ] each ] dip
+    dip
+    [ glDisable ] each ; inline
 
 : (all-enabled-client-state) ( seq quot -- )
     [ dup [ glEnableClientState ] each ] dip
@@ -84,8 +97,8 @@ MACRO: all-enabled-client-state ( seq quot -- )
     #! We use GL_LINE_STRIP with a duplicated first vertex
     #! instead of GL_LINE_LOOP to work around a bug in Apple's
     #! X3100 driver.
-    loc first2 :> y :> x
-    dim first2 :> h :> w
+    loc first2 :> ( x y )
+    dim first2 :> ( w h )
     [
         x 0.5 +     y 0.5 +
         x w + 0.3 - y 0.5 +
@@ -104,8 +117,8 @@ MACRO: all-enabled-client-state ( seq quot -- )
     rect-vertices (gl-rect) ;
 
 :: (fill-rect-vertices) ( loc dim -- vertices )
-    loc first2 :> y :> x
-    dim first2 :> h :> w
+    loc first2 :> ( x y )
+    dim first2 :> ( w h )
     [
         x      y
         x w +  y
@@ -126,7 +139,7 @@ MACRO: all-enabled-client-state ( seq quot -- )
     swap glPushAttrib call glPopAttrib ; inline
 
 : (gen-gl-object) ( quot -- id )
-    [ 1 0 <uint> ] dip keep *uint ; inline
+    [ 1 { uint } ] dip [ ] with-out-parameters ; inline
 
 : (delete-gl-object) ( id quot -- )
     [ 1 swap <uint> ] dip call ; inline