]> gitweb.factorcode.org Git - factor.git/commitdiff
change gpu VERTEX-STRUCT: to make a struct class
authorJoe Groff <arcata@gmail.com>
Mon, 31 Aug 2009 04:06:15 +0000 (23:06 -0500)
committerJoe Groff <arcata@gmail.com>
Mon, 31 Aug 2009 04:06:15 +0000 (23:06 -0500)
extra/gpu/demos/bunny/bunny.factor
extra/gpu/shaders/shaders-docs.factor
extra/gpu/shaders/shaders.factor

index 05baf6e8fe2e2effdb3cee1b26bb0b9e74876948..44ce63692e403a9ee50b46707e39352a3d5460a9 100755 (executable)
@@ -1,11 +1,11 @@
 ! (c)2009 Joe Groff bsd license
-USING: accessors alien.c-types arrays combinators combinators.short-circuit
-game-worlds gpu gpu.buffers gpu.util.wasd gpu.framebuffers gpu.render
-gpu.shaders gpu.state gpu.textures gpu.util grouping http.client images
-images.loader io io.encodings.ascii io.files io.files.temp
-kernel math math.matrices math.parser math.vectors
-method-chains sequences specialized-arrays.float specialized-vectors.uint splitting
-struct-vectors threads ui ui.gadgets ui.gadgets.worlds
+USING: accessors alien.c-types arrays classes.struct combinators
+combinators.short-circuit game-worlds gpu gpu.buffers gpu.util.wasd
+gpu.framebuffers gpu.render gpu.shaders gpu.state gpu.textures gpu.util
+grouping http.client images images.loader io io.encodings.ascii io.files
+io.files.temp kernel math math.matrices math.parser math.vectors
+method-chains sequences specialized-arrays.float specialized-vectors.uint
+splitting struct-vectors threads ui ui.gadgets ui.gadgets.worlds
 ui.pixel-formats ;
 IN: gpu.demos.bunny
 
@@ -73,9 +73,8 @@ UNIFORM-TUPLE: loading-uniforms
     " " split [ string>number ] map sift ;
 
 : <bunny-vertex> ( vertex -- struct )
-    >float-array
-    "bunny-vertex-struct" <c-object>
-    [ set-bunny-vertex-struct-vertex ] keep ;
+    bunny-vertex-struct <struct>
+        swap >float-array >>vertex ; inline
 
 : (parse-bunny-model) ( vs is -- vs is )
     readln [
@@ -87,7 +86,7 @@ UNIFORM-TUPLE: loading-uniforms
     ] when* ;
 
 : parse-bunny-model ( -- vertexes indexes )
-    100000 "bunny-vertex-struct" <struct-vector>
+    100000 bunny-vertex-struct <struct-vector>
     100000 <uint-vector>
     (parse-bunny-model) ;
 
@@ -98,23 +97,15 @@ UNIFORM-TUPLE: loading-uniforms
 
 : calc-bunny-normal ( vertexes indexes -- )
     swap
-    [ [ nth bunny-vertex-struct-vertex ] curry { } map-as normal ]
-    [
-        [
-            nth [ bunny-vertex-struct-normal v+ ] keep
-            set-bunny-vertex-struct-normal
-        ] curry with each
-    ] 2bi ;
+    [ [ nth vertex>> ] curry { } map-as normal ]
+    [ [ nth [ v+ ] change-normal drop ] curry with each ] 2bi ;
 
 : calc-bunny-normals ( vertexes indexes -- )
     3 <groups>
     [ calc-bunny-normal ] with each ;
 
 : normalize-bunny-normals ( vertexes -- )
-    [
-        [ bunny-vertex-struct-normal normalize ] keep
-        set-bunny-vertex-struct-normal
-    ] each ;
+    [ [ normalize ] change-normal drop ] each ;
 
 : bunny-data ( filename -- vertexes indexes )
     ascii [ parse-bunny-model ] with-file-reader
index 33b97d7a8268e274e9901d49a5e61c4dab8cb6a5..8ccc65da43b6a55ceb5aa564d063455084b73a1e 100755 (executable)
@@ -1,5 +1,5 @@
 ! (c)2009 Joe Groff bsd license
-USING: alien.syntax classes gpu.buffers help.markup help.syntax
+USING: classes classes.struct gpu.buffers help.markup help.syntax
 images kernel math multiline quotations sequences strings ;
 IN: gpu.shaders
 
@@ -51,7 +51,7 @@ HELP: VERTEX-FORMAT:
 
 HELP: VERTEX-STRUCT:
 { $syntax <" VERTEX-STRUCT: struct-name format-name "> }
-{ $description "Defines a struct C type (like " { $link POSTPONE: C-STRUCT: } ") with the same binary format and component types as the given " { $link vertex-format } "." } ;
+{ $description "Defines a struct class (like " { $link POSTPONE: STRUCT: } ") with the same binary format and component types as the given " { $link vertex-format } "." } ;
 
 { POSTPONE: GLSL-PROGRAM: POSTPONE: GLSL-SHADER-FILE: POSTPONE: GLSL-SHADER: } related-words
 
index 58633d4a7171f95aa1270c88ce0334a10bcc5c8a..a247158684841a142aa16bcdb204625e42847656 100755 (executable)
@@ -1,7 +1,7 @@
 ! (c)2009 Joe Groff bsd license
 USING: accessors alien alien.c-types alien.strings
-alien.structs arrays assocs byte-arrays classes.mixin
-classes.parser classes.singleton combinators
+arrays assocs byte-arrays classes.mixin classes.parser
+classes.singleton classes.struct combinators
 combinators.short-circuit definitions destructors
 generic.parser gpu gpu.buffers hashtables images
 io.encodings.ascii io.files io.pathnames kernel lexer literals
@@ -238,8 +238,8 @@ M: f (verify-feedback-format)
         { uint-integer-components [ "uint" ] }
     } case ;
 
-: c-array-dim ( dim -- string )
-    dup 1 = [ drop "" ] [ number>string "[" "]" surround ] if ;
+: c-array-dim ( type dim -- type' )
+    dup 1 = [ drop ] [ 2array ] if ;
 
 SYMBOL: padding-no
 padding-no [ 0 ] initialize
@@ -250,11 +250,10 @@ padding-no [ 0 ] initialize
     "(" ")" surround
     padding-no inc ;
 
-: vertex-attribute>c-type ( vertex-attribute -- {type,name} )
-    [
-        [ component-type>> component-type>c-type ]
-        [ dim>> c-array-dim ] bi append
-    ] [ name>> [ padding-name ] unless* ] bi 2array ;
+: vertex-attribute>struct-slot ( vertex-attribute -- struct-slot-spec )
+    [ name>> [ padding-name ] unless* ]
+    [ [ component-type>> component-type>c-type ] [ dim>> c-array-dim ] bi ] bi
+    { } <struct-slot-spec> ;
 
 : shader-filename ( shader/program -- filename )
     dup filename>> [ nip ] [ name>> where first ] if* file-name ;
@@ -303,13 +302,12 @@ SYNTAX: VERTEX-FORMAT:
     [ first4 vertex-attribute boa ] map
     define-vertex-format ;
 
-: define-vertex-struct ( struct-name vertex-format -- )
-    [ current-vocab ] dip
-    "vertex-format-attributes" word-prop [ vertex-attribute>c-type ] map
-    define-struct ;
+: define-vertex-struct ( class vertex-format -- )
+    "vertex-format-attributes" word-prop [ vertex-attribute>struct-slot ] map
+    define-struct-class ;
 
 SYNTAX: VERTEX-STRUCT:
-    scan scan-word define-vertex-struct ;
+    CREATE-CLASS scan-word define-vertex-struct ;
 
 TUPLE: vertex-array < gpu-object
     { program-instance program-instance read-only }