change gpu VERTEX-STRUCT: to make a struct class
parent
472189452d
commit
02d924f1a5
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Reference in New Issue