]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/gpu/state/state.factor
use radix literals
[factor.git] / extra / gpu / state / state.factor
index 1a840ea0b4305e5c22196cb15a668ef4676c3d66..0f2ce7cb46e18c7c70cb8b1c2a54265e9d98c14c 100755 (executable)
@@ -1,29 +1,26 @@
 ! (c)2009 Joe Groff bsd license
 USING: accessors alien.c-types alien.data arrays byte-arrays
 combinators gpu kernel literals math math.rectangles opengl
-opengl.gl sequences variants specialized-arrays ;
+opengl.gl sequences typed variants specialized-arrays ;
 QUALIFIED-WITH: alien.c-types c
 FROM: math => float ;
-SPECIALIZED-ARRAY: int
+SPECIALIZED-ARRAY: c:int
 SPECIALIZED-ARRAY: c:float
 IN: gpu.state
 
-UNION: ?rect rect POSTPONE: f ;
-UNION: ?float float POSTPONE: f ;
-
 TUPLE: viewport-state
     { rect rect read-only } ;
 C: <viewport-state> viewport-state
 
 TUPLE: scissor-state
-    { rect ?rect read-only } ;
+    { rect maybe: rect read-only } ;
 C: <scissor-state> scissor-state
 
 TUPLE: multisample-state
     { multisample? boolean read-only }
     { sample-alpha-to-coverage? boolean read-only }
     { sample-alpha-to-one? boolean read-only }
-    { sample-coverage ?float read-only }
+    { sample-coverage maybe: float read-only }
     { invert-sample-coverage? boolean read-only } ;
 C: <multisample-state> multisample-state
 
@@ -37,22 +34,18 @@ VARIANT: stencil-op
     op-inc-sat op-dec-sat
     op-inc-wrap op-dec-wrap ;
 
-UNION: ?comparison comparison POSTPONE: f ;
-
 TUPLE: stencil-mode
     { value integer initial: 0 read-only }
-    { mask integer initial: HEX: FFFFFFFF read-only }
+    { mask integer initial: 0xFFFFFFFF read-only }
     { comparison comparison initial: cmp-always read-only }
     { stencil-fail-op stencil-op initial: op-keep read-only }
     { depth-fail-op stencil-op initial: op-keep read-only }
     { depth-pass-op stencil-op initial: op-keep read-only } ;
 C: <stencil-mode> stencil-mode
 
-UNION: ?stencil-mode stencil-mode POSTPONE: f ;
-
 TUPLE: stencil-state
-    { front-mode ?stencil-mode initial: f read-only }
-    { back-mode ?stencil-mode initial: f read-only } ;
+    { front-mode maybe: stencil-mode initial: f read-only }
+    { back-mode maybe: stencil-mode initial: f read-only } ;
 C: <stencil-state> stencil-state
 
 TUPLE: depth-range-state
@@ -61,7 +54,7 @@ TUPLE: depth-range-state
 C: <depth-range-state> depth-range-state
 
 TUPLE: depth-state
-    { comparison ?comparison initial: f read-only } ;
+    { comparison maybe: comparison initial: f read-only } ;
 C: <depth-state> depth-state
 
 VARIANT: blend-equation
@@ -86,19 +79,17 @@ TUPLE: blend-mode
     { dest-function blend-function initial: func-one-minus-source-alpha read-only } ;
 C: <blend-mode> blend-mode
 
-UNION: ?blend-mode blend-mode POSTPONE: f ;
-
 TUPLE: blend-state
     { constant-color sequence initial: f read-only }
-    { rgb-mode ?blend-mode read-only }
-    { alpha-mode ?blend-mode read-only } ;
+    { rgb-mode maybe: blend-mode read-only }
+    { alpha-mode maybe: blend-mode read-only } ;
 C: <blend-state> blend-state
 
 TUPLE: mask-state
     { color sequence initial: { t t t t } read-only }
     { depth boolean initial: t read-only }
-    { stencil-front integer initial: HEX: FFFFFFFF read-only }
-    { stencil-back integer initial: HEX: FFFFFFFF read-only } ;
+    { stencil-front integer initial: 0xFFFFFFFF read-only }
+    { stencil-back integer initial: 0xFFFFFFFF read-only } ;
 C: <mask-state> mask-state
 
 VARIANT: triangle-face
@@ -108,11 +99,9 @@ VARIANT: triangle-cull
 VARIANT: triangle-mode
     triangle-points triangle-lines triangle-fill ;
 
-UNION: ?triangle-cull triangle-cull POSTPONE: f ;
-    
 TUPLE: triangle-cull-state
     { front-face triangle-face initial: face-ccw read-only }
-    { cull ?triangle-cull initial: f read-only } ;
+    { cull maybe: triangle-cull initial: f read-only } ;
 C: <triangle-cull-state> triangle-cull-state
 
 TUPLE: triangle-state
@@ -125,7 +114,7 @@ VARIANT: point-sprite-origin
     origin-upper-left origin-lower-left ;
 
 TUPLE: point-state
-    { size ?float initial: 1.0 read-only }
+    { size maybe: float initial: 1.0 read-only }
     { sprite-origin point-sprite-origin initial: origin-upper-left read-only }
     { fade-threshold float initial: 1.0 read-only } ;
 C: <point-state> point-state
@@ -415,21 +404,19 @@ M: mask-state set-gpu-state*
     [ [ set-gpu-state* ] each ]
     [ set-gpu-state* ] if ; inline
 
-<PRIVATE
-
 : get-gl-bool ( enum -- value )
-    0 <uchar> [ glGetBooleanv ] keep *uchar c-bool> ;
+    0 c:uchar <ref> [ glGetBooleanv ] keep c:uchar deref c-bool> ;
 : get-gl-int ( enum -- value )
-    0 <int> [ glGetIntegerv ] keep *int ;
+    0 c:int <ref> [ glGetIntegerv ] keep c:int deref ;
 : get-gl-float ( enum -- value )
-    0 <float> [ glGetFloatv ] keep *float ;
+    0 c:float <ref> [ glGetFloatv ] keep c:float deref ;
 
 : get-gl-bools ( enum count -- value )
     <byte-array> [ glGetBooleanv ] keep [ c-bool> ] { } map-as ;
 : get-gl-ints ( enum count -- value )
-    <int-array> [ glGetIntegerv ] keep ;
+    c:int <c-array> [ glGetIntegerv ] keep ;
 : get-gl-floats ( enum count -- value )
-    <float-array> [ glGetFloatv ] keep ;
+    c:float <c-array> [ glGetFloatv ] keep ;
 
 : get-gl-rect ( enum -- value )
     4 get-gl-ints first4 [ 2array ] 2bi@ <rect> ;
@@ -437,17 +424,15 @@ M: mask-state set-gpu-state*
 : gl-enabled? ( enum -- ? )
     glIsEnabled c-bool> ;
 
-PRIVATE>
-
-: get-viewport-state ( -- viewport-state )
+TYPED: get-viewport-state ( -- viewport-state: viewport-state )
     GL_VIEWPORT get-gl-rect <viewport-state> ;
 
-: get-scissor-state ( -- scissor-state )
+TYPED: get-scissor-state ( -- scissor-state: scissor-state )
     GL_SCISSOR_TEST get-gl-bool
     [ GL_SCISSOR_BOX get-gl-rect ] [ f ] if
     <scissor-state> ;
 
-: get-multisample-state ( -- multisample-state )
+TYPED: get-multisample-state ( -- multisample-state: multisample-state )
     GL_MULTISAMPLE gl-enabled?
     GL_SAMPLE_ALPHA_TO_COVERAGE gl-enabled?
     GL_SAMPLE_ALPHA_TO_ONE gl-enabled?
@@ -457,7 +442,7 @@ PRIVATE>
     ] [ f f ] if
     <multisample-state> ;
 
-: get-stencil-state ( -- stencil-state )
+TYPED: get-stencil-state ( -- stencil-state: stencil-state )
     GL_STENCIL_TEST gl-enabled? [
         GL_STENCIL_REF get-gl-int
         GL_STENCIL_VALUE_MASK get-gl-int
@@ -477,15 +462,15 @@ PRIVATE>
     ] [ f f ] if
     <stencil-state> ;
 
-: get-depth-range-state ( -- depth-range-state )
+TYPED: get-depth-range-state ( -- depth-range-state: depth-range-state )
     GL_DEPTH_RANGE 2 get-gl-floats first2 <depth-range-state> ;
 
-: get-depth-state ( -- depth-state )
+TYPED: get-depth-state ( -- depth-state: depth-state )
     GL_DEPTH_TEST gl-enabled?
     [ GL_DEPTH_FUNC get-gl-int gl-comparison> ] [ f ] if
     <depth-state> ;
 
-: get-blend-state ( -- blend-state )
+TYPED: get-blend-state ( -- blend-state: blend-state )
     GL_BLEND gl-enabled? [
         GL_BLEND_COLOR 4 get-gl-floats
 
@@ -501,34 +486,34 @@ PRIVATE>
     ] [ f f f ] if
     <blend-state> ;
 
-: get-mask-state ( -- mask-state )
+TYPED: get-mask-state ( -- mask-state: mask-state )
     GL_COLOR_WRITEMASK 4 get-gl-bools 
     GL_DEPTH_WRITEMASK get-gl-bool
     GL_STENCIL_WRITEMASK get-gl-int
     GL_STENCIL_BACK_WRITEMASK get-gl-int
     <mask-state> ;
 
-: get-triangle-cull-state ( -- triangle-cull-state )
+TYPED: get-triangle-cull-state ( -- triangle-cull-state: triangle-cull-state )
     GL_FRONT_FACE get-gl-int gl-triangle-face>
     GL_CULL_FACE gl-enabled?
     [ GL_CULL_FACE_MODE get-gl-int gl-triangle-cull> ]
     [ f ] if
     <triangle-cull-state> ;
 
-: get-triangle-state ( -- triangle-state )
+TYPED: get-triangle-state ( -- triangle-state: triangle-state )
     GL_POLYGON_MODE 2 get-gl-ints
     first2 [ gl-triangle-mode> ] bi@
     GL_POLYGON_SMOOTH gl-enabled?
     <triangle-state> ;
 
-: get-point-state ( -- point-state )
+TYPED: get-point-state ( -- point-state: point-state )
     GL_VERTEX_PROGRAM_POINT_SIZE gl-enabled?
     [ f ] [ GL_POINT_SIZE get-gl-float ] if
     GL_POINT_SPRITE_COORD_ORIGIN get-gl-int gl-point-sprite-origin> 
     GL_POINT_FADE_THRESHOLD_SIZE get-gl-float
     <point-state> ;
 
-: get-line-state ( -- line-state )
+TYPED: get-line-state ( -- line-state: line-state )
     GL_LINE_WIDTH get-gl-float
     GL_LINE_SMOOTH gl-enabled?
     <line-state> ;