From 02d924f1a5233430053ca729c9b3a16128cdd4e1 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 30 Aug 2009 23:06:15 -0500 Subject: [PATCH] change gpu VERTEX-STRUCT: to make a struct class --- extra/gpu/demos/bunny/bunny.factor | 35 ++++++++++----------------- extra/gpu/shaders/shaders-docs.factor | 4 +-- extra/gpu/shaders/shaders.factor | 26 +++++++++----------- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/extra/gpu/demos/bunny/bunny.factor b/extra/gpu/demos/bunny/bunny.factor index 05baf6e8fe..44ce63692e 100755 --- a/extra/gpu/demos/bunny/bunny.factor +++ b/extra/gpu/demos/bunny/bunny.factor @@ -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 ; : ( vertex -- struct ) - >float-array - "bunny-vertex-struct" - [ set-bunny-vertex-struct-vertex ] keep ; + bunny-vertex-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" + 100000 bunny-vertex-struct 100000 (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 [ 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 diff --git a/extra/gpu/shaders/shaders-docs.factor b/extra/gpu/shaders/shaders-docs.factor index 33b97d7a82..8ccc65da43 100755 --- a/extra/gpu/shaders/shaders-docs.factor +++ b/extra/gpu/shaders/shaders-docs.factor @@ -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 diff --git a/extra/gpu/shaders/shaders.factor b/extra/gpu/shaders/shaders.factor index 58633d4a71..a247158684 100755 --- a/extra/gpu/shaders/shaders.factor +++ b/extra/gpu/shaders/shaders.factor @@ -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 + { } ; : 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 }