SPECIALIZED-VECTOR: uint
IN: gpu.demos.bunny
+VERTEX-FORMAT: bunny-vertex
+ { "vertex" float-components 3 f }
+ { f float-components 1 f }
+ { "normal" float-components 3 f }
+ { f float-components 1 f } ;
+
+STRUCT: bunny-vertex-struct
+ { vertex float-4 }
+ { normal float-4 } ;
+
GLSL-SHADER-FILE: bunny-vertex-shader vertex-shader "bunny.v.glsl"
GLSL-SHADER-FILE: bunny-fragment-shader fragment-shader "bunny.f.glsl"
GLSL-PROGRAM: bunny-program
- bunny-vertex-shader bunny-fragment-shader ;
+ bunny-vertex-shader bunny-fragment-shader
+ bunny-vertex ;
GLSL-SHADER-FILE: window-vertex-shader vertex-shader "window.v.glsl"
GLSL-SHADER-FILE: sobel-fragment-shader fragment-shader "sobel.f.glsl"
GLSL-PROGRAM: sobel-program
- window-vertex-shader sobel-fragment-shader ;
+ window-vertex-shader sobel-fragment-shader
+ window-vertex ;
GLSL-SHADER-FILE: loading-fragment-shader fragment-shader "loading.f.glsl"
GLSL-PROGRAM: loading-program
- window-vertex-shader loading-fragment-shader ;
+ window-vertex-shader loading-fragment-shader
+ window-vertex ;
TUPLE: bunny-state
vertexes
TUPLE: bunny-world < wasd-world
bunny sobel loading ;
-VERTEX-FORMAT: bunny-vertex
- { "vertex" float-components 3 f }
- { f float-components 1 f }
- { "normal" float-components 3 f }
- { f float-components 1 f } ;
-
-STRUCT: bunny-vertex-struct
- { vertex float-4 }
- { normal float-4 } ;
-
SPECIALIZED-VECTOR: bunny-vertex-struct
UNIFORM-TUPLE: bunny-uniforms < mvp-uniforms
}
{ $description "Creates a new " { $link vertex-array } " to feed data to " { $snippet "program-instance" } " from the set of " { $link buffer } "s specified in " { $snippet "vertex-formats" } "." } ;
+HELP: feedback-format:
+{ $syntax "feedback-format: vertex-format" }
+{ $description "When used as part of a " { $link GLSL-PROGRAM: } " definition, this syntax specifies the " { $link vertex-format } " in which transform feedback output will be generated." } ;
+
HELP: GLSL-PROGRAM:
-{ $syntax "GLSL-PROGRAM: program-name shader shader ... shader [vertex-format] ;" }
-{ $description "Defines a new " { $link program } " named " { $snippet "program-name" } ". When the program is instantiated with " { $link <program-instance> } ", it will link together instances of all of the specified " { $link shader } "s to create the program instance. A single " { $link vertex-array } " may optionally be specified; if the program is used to collect transform feedback, this format will be used for the output." }
+{ $syntax "GLSL-PROGRAM: program-name shader shader ... [vertex-format vertex-format ...] [feedback-format: vertex-format] ;" }
+{ $description "Defines a new " { $link program } " named " { $snippet "program-name" } ". When the program is instantiated with " { $link <program-instance> } ", it will link together instances of all of the specified " { $link shader } "s to create the program instance. If any " { $link vertex-format } "s are specified, their attributes will be pre-assigned attribute indexes at link time, to ensure that their indexes remain constant if the program is refreshed with " { $link refresh-program } ". A trasform feedback vertex format may optionally be specified with " { $link feedback-format: } "; if the program is used to collect transform feedback, the given vertex format will be used for the output." }
{ $notes "Transform feedback requires OpenGL 3.0 or one of the " { $snippet "GL_EXT_transform_feedback" } " or " { $snippet "GL_ARB_transform_feedback" } " extensions." } ;
HELP: GLSL-SHADER-FILE:
USING: accessors alien alien.c-types alien.data alien.strings
arrays assocs byte-arrays classes.mixin classes.parser
classes.singleton classes.struct combinators combinators.short-circuit
-definitions destructors generic.parser gpu gpu.buffers hashtables
+definitions destructors fry generic.parser gpu gpu.buffers hashtables
images io.encodings.ascii io.files io.pathnames kernel lexer
literals locals math math.parser memoize multiline namespaces
opengl opengl.gl opengl.shaders parser quotations sequences
{ filename read-only }
{ line integer read-only }
{ shaders array read-only }
+ { vertex-formats array read-only }
{ feedback-format ?vertex-format read-only }
{ instances hashtable read-only } ;
MEMO: output-index ( program-instance output-name -- index )
[ handle>> ] dip glGetFragDataLocation ;
+: vertex-format-attributes ( vertex-format -- attributes )
+ "vertex-format-attributes" word-prop ; inline
+
<PRIVATE
TR: hyphens>underscores "-" "_" ;
M: f link-feedback-format
2drop ;
+: link-vertex-formats ( program-handle formats -- )
+ [ vertex-format-attributes [ name>> ] map sift ] map concat
+ swap '[ [ _ ] 2dip swap glBindAttribLocation ] each-index ;
+
GENERIC: (verify-feedback-format) ( program-instance format -- )
M: f (verify-feedback-format)
define-vertex-format ;
: define-vertex-struct ( class vertex-format -- )
- "vertex-format-attributes" word-prop [ vertex-attribute>struct-slot ] map
+ vertex-format-attributes [ vertex-attribute>struct-slot ] map
define-struct-class ;
SYNTAX: VERTEX-STRUCT:
[ compile-shader-error ] if ;
: (link-program) ( program shader-instances -- program-instance )
- [ [ handle>> ] map ] curry
- [ feedback-format>> [ link-feedback-format ] curry ] bi (gl-program)
+ '[ _ [ handle>> ] map ]
+ [
+ [ vertex-formats>> ] [ feedback-format>> ] bi
+ '[ [ _ link-vertex-formats ] [ _ link-feedback-format ] bi ]
+ ] bi (gl-program)
dup gl-program-ok? [
[ swap world get \ program-instance boa |dispose dup verify-feedback-format ]
with-destructors window-resource
world get over instances>> at*
[ nip ] [ drop link-program ] if ;
-: shaders-and-feedback-format ( words -- shaders feedback-format )
- [ vertex-format? ] partition swap
- [ [ def>> first ] map ] [
- dup length 1 <=
- [ [ f ] [ first ] if-empty ]
- [ too-many-feedback-formats-error ] if
- ] bi* ;
+TUPLE: feedback-format
+ { vertex-format ?vertex-format read-only } ;
+
+: validate-feedback-format ( sequence -- vertex-format/f )
+ dup length 1 <=
+ [ [ f ] [ first vertex-format>> ] if-empty ]
+ [ too-many-feedback-formats-error ] if ;
+
+: ?shader ( object -- shader/f )
+ dup word? [ def>> first dup shader? [ drop f ] unless ] [ drop f ] if ;
+
+: shaders-and-formats ( words -- shaders vertex-formats feedback-format )
+ [ [ ?shader ] map sift ]
+ [ [ vertex-format? ] filter ]
+ [ [ feedback-format? ] filter validate-feedback-format ] tri ;
PRIVATE>
+SYNTAX: feedback-format:
+ scan-object feedback-format boa suffix! ;
+
TYPED:: refresh-program ( program: program -- )
program shaders>> [ refresh-shader-source ] each
program instances>> [| world old-instance |
dup old-instances [
f
lexer get line>>
- \ ; parse-until >array shaders-and-feedback-format
+ \ ; parse-until >array shaders-and-formats
] dip
program boa
over reset-generic