]> gitweb.factorcode.org Git - factor.git/commitdiff
gpu.shaders: change around vertex-array construction a bit. rename <vertex-array...
authorJoe Groff <arcata@gmail.com>
Wed, 10 Feb 2010 23:27:57 +0000 (15:27 -0800)
committerJoe Groff <arcata@gmail.com>
Wed, 10 Feb 2010 23:27:57 +0000 (15:27 -0800)
extra/gpu/demos/bunny/bunny.factor
extra/gpu/shaders/shaders-docs.factor
extra/gpu/shaders/shaders.factor
extra/gpu/util/util.factor
extra/model-viewer/model-viewer.factor

index 332a33ff1e425cfcd3426b748a6b2691689f248e..987d3d15077a989892d4a8cabe5e59d654fce4c1 100644 (file)
@@ -163,7 +163,7 @@ CONSTANT: bunny-model-url "http://factorcode.org/bun_zipper.ply"
 
 : fill-bunny-state ( bunny-state -- )
     dup [ vertexes>> ] [ indexes>> ] bi <bunny-buffers>
-    [ bunny-program <program-instance> bunny-vertex buffer>vertex-array >>vertex-array ]
+    [ bunny-program <program-instance> <vertex-array> >>vertex-array ]
     [ 0 <buffer-ptr> ]
     [ uint-indexes <index-elements> >>index-elements ] tri*
     drop ;
@@ -180,7 +180,7 @@ CONSTANT: bunny-model-url "http://factorcode.org/bun_zipper.ply"
 
 : <sobel-state> ( window-vertex-buffer -- sobel-state )
     sobel-state new
-        swap sobel-program <program-instance> window-vertex buffer>vertex-array >>vertex-array
+        swap sobel-program <program-instance> <vertex-array> >>vertex-array
 
         RGBA half-components T{ texture-parameters
             { wrap clamp-texcoord-to-edge }
@@ -207,7 +207,7 @@ CONSTANT: bunny-model-url "http://factorcode.org/bun_zipper.ply"
 : <loading-state> ( window-vertex-buffer -- loading-state )
     loading-state new
         swap
-        loading-program <program-instance> window-vertex buffer>vertex-array >>vertex-array
+        loading-program <program-instance> <vertex-array> >>vertex-array
 
         RGBA ubyte-components T{ texture-parameters
             { wrap clamp-texcoord-to-edge }
index fde011dc12a0cfbef261bc76d22a2e230781c1f3..fa3fbd6aa444de4100b5343db7fbfeb7a7a8ecfd 100644 (file)
@@ -19,10 +19,11 @@ HELP: <shader-instance>
 
 HELP: <multi-vertex-array>
 { $values
-    { "program-instance" program-instance } { "vertex-formats" "a list of " { $link buffer-ptr } "/" { $link vertex-format } " pairs" }
+    { "vertex-formats" "a list of " { $link buffer-ptr } "/" { $link vertex-format } " pairs" }
+    { "program-instance" program-instance } 
     { "vertex-array" vertex-array }
 }
-{ $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" } "." } ;
+{ $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" } ". The first element of each pair in " { $snippet "vertex-formats" } " can be either a " { $link buffer-ptr } " or a " { $link buffer } "; in the latter case, vertex data in the associated format is read from the beginning of the buffer." } ;
 
 HELP: feedback-format:
 { $syntax "feedback-format: vertex-format" }
@@ -66,14 +67,21 @@ HELP: attribute-index
 }
 { $description "Returns the numeric index of the vertex attribute named " { $snippet "attribute-name" } " in " { $snippet "program-instance" } "." } ;
 
+HELP: <vertex-array>
+{ $values
+    { "vertex-buffer" "a " { $link buffer } " or " { $link buffer-ptr } } { "program-instance" program-instance }
+    { "vertex-array" vertex-array }
+}
+{ $description "Creates a new " { $link vertex-array } " from the entire contents of a single " { $link buffer } " for use with a " { $link program-instance } ". The data in " { $snippet "buffer" } " is taken in the first " { $link vertex-format } " specified in the program instance's originating " { $link POSTPONE: GLSL-PROGRAM: } " definition. If the program has no associated vertex formats, an error will be thrown. To specify a different vertex format, use " { $link <vertex-array*> } "." } ;
+
 HELP: <vertex-array*>
 { $values
-    { "vertex-buffer" buffer } { "program-instance" program-instance } { "format" vertex-format }
+    { "vertex-buffer" "a " { $link buffer } " or " { $link buffer-ptr } } { "program-instance" program-instance } { "format" vertex-format }
     { "vertex-array" vertex-array }
 }
-{ $description "Creates a new " { $link vertex-array } " from the entire contents of a single " { $link buffer } " in a single " { $link vertex-format } " for use with " { $snippet "program-instance" } "." } ;
+{ $description "Creates a new " { $link vertex-array } " from the entire contents of a single " { $link buffer } " for use with a " { $link program-instance } ". The data in " { $snippet "buffer" } " is taken in the specified " { $link vertex-format } "." } ;
 
-{ vertex-array <multi-vertex-array> <vertex-array*> } related-words
+{ vertex-array <multi-vertex-array> <vertex-array> <vertex-array*> } related-words
 
 HELP: compile-shader-error
 { $class-description "An error compiling the source for a " { $link shader } "."
index e68586331d9c198bc9ecc91d4d718a4f6e7eeb4a..0401584f7cb261d15cc1577f4f7962b647443d60 100644 (file)
@@ -326,19 +326,28 @@ TUPLE: vertex-array < gpu-object
 M: vertex-array dispose
     [ [ delete-vertex-array ] when* f ] change-handle drop ;
 
-: <vertex-array> ( program-instance vertex-formats -- vertex-array )
-    gen-vertex-array
-    [ glBindVertexArray [ first2 bind-vertex-format ] with each ]
-    [ -rot [ first buffer>> ] map vertex-array boa ] 3bi
-    window-resource ; inline
-
-TYPED: buffer>vertex-array ( vertex-buffer: buffer
-                             program-instance: program-instance
-                             format: vertex-format
-                             --
-                             vertex-array: vertex-array )
-    [ swap ] dip
-    [ 0 <buffer-ptr> ] dip 2array 1array <vertex-array> ; inline
+: ?>buffer-ptr ( buffer/ptr -- buffer-ptr )
+    dup buffer-ptr? [ 0 <buffer-ptr> ] unless ; inline
+: ?>buffer ( buffer/ptr -- buffer )
+    dup buffer? [ buffer>> ] unless ; inline
+
+:: <multi-vertex-array> ( vertex-formats program-instance -- vertex-array )
+    gen-vertex-array :> handle
+    handle glBindVertexArray
+
+    vertex-formats [ program-instance swap first2 [ ?>buffer-ptr ] dip bind-vertex-format ] each
+    handle program-instance vertex-formats [ first ?>buffer ] map
+    vertex-array boa window-resource ; inline
+
+:: <vertex-array*> ( vertex-buffer program-instance format -- vertex-array )
+    gen-vertex-array :> handle
+    handle glBindVertexArray
+    program-instance vertex-buffer ?>buffer-ptr format bind-vertex-format
+    handle program-instance vertex-buffer ?>buffer 1array
+    vertex-array boa window-resource ; inline
+
+: <vertex-array> ( vertex-buffer program-instance -- vertex-array )
+    dup program>> vertex-formats>> first <vertex-array*> ; inline
 
 TYPED: vertex-array-buffer ( vertex-array: vertex-array -- vertex-buffer: buffer )
     vertex-buffers>> first ;
@@ -424,7 +433,7 @@ TUPLE: feedback-format
 
 : shaders-and-formats ( words -- shaders vertex-formats feedback-format )
     [ [ ?shader ] map sift ]
-    [ [ vertex-format? ] filter ]
+    [ [ vertex-format-attributes ] filter ]
     [ [ feedback-format? ] filter validate-feedback-format ] tri ;
 
 PRIVATE>
index ccabd3d3087ed0aea81b56fb604aee0d263a887d..d33fcf8c09799f8a99d3b50a4c2b4b40a8db35e1 100644 (file)
@@ -62,4 +62,4 @@ CONSTANT: window-vertexes
     byte-array>buffer ; inline
 
 : <window-vertex-array> ( program-instance -- vertex-array )
-    [ <window-vertex-buffer> ] dip window-vertex buffer>vertex-array ; inline
+    [ <window-vertex-buffer> ] dip window-vertex <vertex-array*> ; inline
index 22a80a136e6bdbe3c60cbf0793e71d545080c4c8..061ce07d1e515d5f5a482f40c08d4d2097234e8f 100644 (file)
@@ -130,7 +130,7 @@ TUPLE: vbo
         [
             [
                 [ vertex-buffer>> obj-program <program-instance> ]
-                [ vertex-format>> ] bi buffer>vertex-array
+                [ vertex-format>> ] bi <vertex-array*>
             ] map >>vertex-arrays drop
         ]
         [