]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/opengl/opengl.factor
use radix literals
[factor.git] / basis / opengl / opengl.factor
index 7884890ebfac47f0f3223480aa9af73a122602e1..a8b04eafbc6b03aa5cd18ee1e218bb2a8b82c047 100644 (file)
@@ -2,13 +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 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 vocabs
-colors colors.constants accessors generalizations locals fry
-specialized-arrays.float specialized-arrays.uint
-tools.annotations tools.annotations.private compiler.units ;
+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 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
@@ -20,62 +22,29 @@ IN: opengl
 
 : error>string ( n -- string )
     H{
-        { HEX: 0 "No error" }
-        { HEX: 0501 "Invalid value" }
-        { HEX: 0500 "Invalid enumerant" }
-        { HEX: 0502 "Invalid operation" }
-        { HEX: 0503 "Stack overflow" }
-        { HEX: 0504 "Stack underflow" }
-        { HEX: 0505 "Out of memory" }
-        { HEX: 0506 "Invalid framebuffer operation" }
+        { 0x0 "No error" }
+        { 0x0501 "Invalid value" }
+        { 0x0500 "Invalid enumerant" }
+        { 0x0502 "Invalid operation" }
+        { 0x0503 "Stack overflow" }
+        { 0x0504 "Stack underflow" }
+        { 0x0505 "Out of memory" }
+        { 0x0506 "Invalid framebuffer operation" }
     } at "Unknown error" or ;
 
-TUPLE: gl-error code string ;
+TUPLE: gl-error function code string ;
 
-TUPLE: gl-error-log
-    { function word initial: t }
-    { error gl-error }
-    { timestamp timestamp } ;
-
-gl-error-log [ V{ } clone ] initialize
-
-: <gl-error> ( code -- gl-error )
+: <gl-error> ( function code -- gl-error )
     dup error>string \ gl-error boa ; inline
 
-: <gl-error-log> ( function code -- gl-error-log )
-    <gl-error> now gl-error-log boa ;
-
 : gl-error-code ( -- code/f )
     glGetError dup 0 = [ drop f ] when ; inline
 
-: gl-error ( -- )
-    gl-error-code [ <gl-error> throw ] [ ] if* ;
-
-: log-gl-error ( function -- )
-    gl-error-code [ <gl-error-log> gl-error-log get push ] [ drop ] if* ;
-
-: gl-function? ( word -- ? )
-    name>> { [ "glGetError" = not ] [ "gl" head? ] [ third LETTER? ] } 1&& ;
-
-: gl-functions ( -- words )
-    "opengl.gl" vocab words [ gl-function? ] filter ;
+: (gl-error) ( function -- )
+    gl-error-code [ <gl-error> throw ] [ drop ] if* ;
 
-: annotate-gl-functions ( quot -- )
-    [
-        [ gl-functions ] dip [ [ dup ] dip curry (annotate) ] curry each
-    ] with-compilation-unit ;
-
-: reset-gl-functions ( -- )
-    [ gl-functions [ (reset) ] each ] with-compilation-unit ;
-
-: clear-gl-error-log ( -- )
-    V{ } clone gl-error-log set ;
-
-: throw-gl-errors ( -- )
-    [ drop '[ @ gl-error ] ] annotate-gl-functions ;
-
-: log-gl-errors ( -- )
-    [ '[ @ _ log-gl-error ] ] annotate-gl-functions ;
+: gl-error ( -- )
+    f (gl-error) ; inline
 
 : do-enabled ( what quot -- )
     over glEnable dip glDisable ; inline
@@ -87,7 +56,9 @@ gl-error-log [ V{ } clone ] initialize
     [ ?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
@@ -126,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 +
@@ -146,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
@@ -168,10 +139,10 @@ 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
+    [ 1 swap uint <ref> ] dip call ; inline
 
 : gen-gl-buffer ( -- id )
     [ glGenBuffers ] (gen-gl-object) ;
@@ -212,7 +183,7 @@ MACRO: all-enabled-client-state ( seq quot -- )
     glActiveTexture swap glBindTexture gl-error ;
 
 : (set-draw-buffers) ( buffers -- )
-    [ length ] [ >uint-array ] bi glDrawBuffers ;
+    [ length ] [ uint >c-array ] bi glDrawBuffers ;
 
 MACRO: set-draw-buffers ( buffers -- )
     words>values '[ _ (set-draw-buffers) ] ;
@@ -229,7 +200,7 @@ MACRO: set-draw-buffers ( buffers -- )
 : with-translation ( loc quot -- )
     [ [ gl-translate ] dip call ] do-matrix ; inline
 
-: fix-coordinates ( point1 point2 -- x1 y2 x2 y2 )
+: fix-coordinates ( point1 point2 -- x1 y1 x2 y2 )
     [ first2 [ >fixnum ] bi@ ] bi@ ;
 
 : gl-set-clip ( loc dim -- )