]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <arcata@gmail.com>
Sat, 6 Feb 2010 04:13:45 +0000 (20:13 -0800)
committerJoe Groff <arcata@gmail.com>
Sat, 6 Feb 2010 04:13:45 +0000 (20:13 -0800)
basis/json/json.factor
extra/gpu/buffers/buffers-docs.factor
extra/gpu/buffers/buffers.factor

index d7cfc0e5bc1eaf794c5a86f053e151a71c677881..790e85d610c827d57fc83453d5fff0cd5c246ecb 100644 (file)
@@ -1,7 +1,15 @@
+USING: kernel vocabs.loader ;
 IN: json
-USE: vocabs.loader
 
 SINGLETON: json-null
 
+: if-json-null ( x if-null else -- )
+    [ dup json-null? ]
+    [ [ drop ] prepose ]
+    [ ] tri* if ; inline
+
+: when-json-null ( x if-null -- ) [ ] if-json-null ; inline
+: unless-json-null ( x else -- ) [ ] swap if-json-null ; inline
+
 "json.reader" require
 "json.writer" require
index 7f685be11625d11470372541f5f592d88f812bc3..9ca1093000dd6309983b999d30a6e0c06f728374 100644 (file)
@@ -34,6 +34,12 @@ HELP: allocate-buffer
 }
 { $description "Discards any memory currently held by " { $snippet "buffer" } " and reallocates a new memory block of " { $snippet "size" } " bytes for it. If " { $snippet "initial-data" } " is not " { $link f } ", " { $snippet "size" } " bytes are copied from " { $snippet "initial-data" } " into the buffer to initialize it; otherwise, the buffer content is left uninitialized." } ;
 
+HELP: allocate-byte-array
+{ $values
+    { "buffer" buffer } { "byte-array" byte-array }
+}
+{ $description "Discards any memory currently held by " { $snippet "buffer" } " and reallocates a new memory block large enough to store " { $snippet "byte-array" } ". The contents of " { $snippet "byte-array" } " are then copied into the buffer." } ;
+
 HELP: buffer
 { $class-description "Objects of this class represent GPU-accessible memory buffers. Buffer objects can be used to store vertex data and to update or read pixel data from textures and framebuffers without CPU involvement. The data inside buffer objects may be resident in main memory or different parts of GPU memory; the graphics driver will choose a location for a buffer based on usage hints specified when the buffer object is constructed with " { $link <buffer> } " or " { $link byte-array>buffer } ":"
 { $list
@@ -201,7 +207,7 @@ HELP: with-mapped-buffer
 }
 { $description "Maps " { $snippet "buffer" } " into CPU address space with " { $snippet "access" } " for the dynamic extent of " { $snippet "quot" } ". " { $snippet "quot" } " is called with a pointer to the mapped memory on top of the stack." } ;
 
-{ allocate-buffer buffer-size update-buffer read-buffer copy-buffer with-mapped-buffer } related-words
+{ allocate-buffer allocate-byte-array buffer-size update-buffer read-buffer copy-buffer with-mapped-buffer } related-words
 
 HELP: write-access
 { $class-description "This " { $link buffer-access-mode } " value requests write-only access when mapping a buffer object through " { $link with-mapped-buffer } "." } ;
@@ -229,6 +235,7 @@ ARTICLE: "gpu.buffers" "Buffer objects"
 "Manipulating buffer data:"
 { $subsections
     allocate-buffer
+    allocate-byte-array
     update-buffer
     read-buffer
     copy-buffer
index c29d9f2f102d14822cd2a7f7fd6d918066d685be..bc6f089db95885871aec1796b5e83a71caafd2a4 100644 (file)
@@ -86,9 +86,12 @@ TYPED: buffer-size ( buffer: buffer -- size: integer )
     2dup [ buffer-size ] dip -
     buffer-range boa ; inline
 
-TYPED:: allocate-buffer ( buffer: buffer size: integer initial-data -- )
+:: allocate-buffer ( buffer size initial-data -- )
     buffer bind-buffer :> target
-    target size initial-data buffer gl-buffer-usage glBufferData ;
+    target size initial-data buffer gl-buffer-usage glBufferData ; inline
+
+: allocate-byte-array ( buffer byte-array -- )
+    [ byte-length ] [ ] bi allocate-buffer ; inline
 
 TYPED: <buffer> ( upload: buffer-upload-pattern
                   usage: buffer-usage-pattern