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