]> gitweb.factorcode.org Git - factor.git/commitdiff
gpu.buffers: grow-buffer helper word
authorJoe Groff <arcata@gmail.com>
Tue, 25 May 2010 05:12:49 +0000 (22:12 -0700)
committerJoe Groff <arcata@gmail.com>
Tue, 25 May 2010 05:13:15 +0000 (22:13 -0700)
extra/gpu/buffers/buffers-docs.factor
extra/gpu/buffers/buffers.factor

index 1487fbf4c7f82c2553b3fdc88a70cf16fdfc68ba..4440fc1d88020a747f07787563a9d6320203d9ac 100644 (file)
@@ -149,6 +149,10 @@ HELP: dynamic-upload
 HELP: gpu-data-ptr
 { $class-description "This class is a union of the " { $link c-ptr } " and " { $link buffer-ptr } " classes. It represents a value that can be supplied either from CPU or GPU memory." } ;
 
+HELP: grow-buffer
+{ $values { "buffer" buffer } { "target-size" integer } }
+{ $description "If the " { $link buffer-size } " of the given " { $link buffer } " is less than " { $snippet "target-size" } ", reallocates the buffer to a size large enough to accommodate " { $snippet "target-size" } " bytes. If the buffer is reallocated, the original contents are lost." } ;
+
 HELP: index-buffer
 { $class-description "This " { $link buffer-kind } " declares that a " { $link buffer } "'s primary use will be to index vertex arrays." } ;
 
@@ -243,6 +247,7 @@ ARTICLE: "gpu.buffers" "Buffer objects"
 { $subsections
     allocate-buffer
     allocate-byte-array
+    grow-buffer
     update-buffer
     read-buffer
     copy-buffer
index 86d51b46ce229176ca39d6120637c29943cd9ccf..6172c8ad8ce616dd789e1fddf8babdd0c9e719c4 100644 (file)
@@ -132,6 +132,13 @@ TYPED:: copy-buffer ( to-buffer-ptr: buffer-ptr from-buffer-ptr: buffer-ptr size
     from-buffer-ptr offset>> to-buffer-ptr offset>>
     size glCopyBufferSubData ;
 
+: (grow-buffer-size) ( target-size old-size -- new-size )
+    [ 2dup > ] [ 2 * ] while nip ; inline
+
+TYPED: grow-buffer ( buffer: buffer target-size: integer -- )
+    over buffer-size 2dup >
+    [ (grow-buffer-size) f allocate-buffer ] [ 3drop ] if ; inline
+
 :: with-mapped-buffer ( ..a buffer access quot: ( ..a alien -- ..b ) -- ..b )
     buffer bind-buffer :> target
     target access gl-access glMapBuffer