Browse Source

Fix Shader:getBufferFormat;

bjorn 1 year ago
parent
commit
14ecc4020d
2 changed files with 29 additions and 33 deletions
  1. 3 3
      api/init.lua
  2. 26 30
      api/lovr/graphics/Shader/getBufferFormat.lua

+ 3 - 3
api/init.lua

@@ -21097,7 +21097,7 @@ return {
             {
               name = "getBufferFormat",
               summary = "Get the format of a buffer in the Shader.",
-              description = "Returns the format of a uniform or storage buffer in the shader.  This matches the same syntax used by `lovr.graphics.newBuffer`, so it can be passed there to quickly create a Buffer that matches a variable in a Shader.",
+              description = "Returns the format of a uniform or storage buffer in the shader.  The return type matches the same syntax used by `lovr.graphics.newBuffer`, so it can be passed there to quickly create a Buffer that matches a variable in a Shader.",
               key = "Shader:getBufferFormat",
               module = "lovr.graphics",
               examples = {
@@ -21105,7 +21105,7 @@ return {
                   code = "shader = lovr.graphics.newShader([[\n  layout(set = 2, binding = 0) uniform Transforms {\n    mat4 transforms[32];\n  };\n\n  vec4 lovrmain() {\n    return Projection * View * transforms[InstanceIndex] * VertexPosition;\n  }\n]], 'unlit')\n\nlocal format, length = shader:getBufferFormat('Transforms')\nprint(length) --> 32\nprint(format[1].name) --> 'transforms'\nprint(format[1].type) --> 'mat4'\n\n-- Can pass the 2 results directly to newBuffer:\ntransforms = lovr.graphics.newBuffer(shader:getBufferFormat('Transforms'))\n\n-- Or override the length with some initial data:\ntransforms = lovr.graphics.newBuffer(shader:getBufferFormat('Transforms'), objects)"
                 }
               },
-              notes = "If the buffer only has a single array field, the format will be \"unwrapped\" to an array instead of a single-field struct with an array in it.  Example:\n\n``` shader = lovr.graphics.newShader([[\n  layout(set = 0, binding = 0) buffer Numbers {\n    uint numbers[64];\n  };\n\n  void lovrmain(){} ]])\n\nshader:getBufferFormat('Numbers')\n-- returns {{ name = 'numbers', type = 'u32' }}, 64\n-- not     {{ name = 'numbers', type = 'u32', length = 64 }}, 1 ```\n\nSimilarly, if the buffer only has a single struct field, the format will be \"unwrapped\" to the inner struct.  This lets you use a struct for a Buffer's data without having to wrap everything in an extra namespace.  Example:\n\n``` shader = lovr.graphics.newShader([[\n  struct HandParams {\n    vec3 position;\n    float trigger;\n  };\n\n  layout(set = 0, binding = 0) buffer Hand {\n    HandParams params;\n  };\n\n  void lovrmain(){} ]])\n\nshader:getBufferFormat('Hand')\n-- returns {{ name = 'position', type = 'vec3' }, { name = 'trigger', type = 'float' }}, 1\n-- not     {{ name = 'params', type = {...}}}, 1 ```",
+              notes = "If the buffer only has a single array field, the format will be \"unwrapped\" to an array instead of a single-field struct with an array in it.  Example:\n\n    shader = lovr.graphics.newShader([[\n      layout(set = 0, binding = 0) buffer Numbers {\n        uint numbers[64];\n      };\n\n      void lovrmain(){}\n    ]])\n\n    shader:getBufferFormat('Numbers')\n    -- returns {{ name = 'numbers', type = 'u32' }}, 64\n    -- not     {{ name = 'numbers', type = 'u32', length = 64 }}, 1\n\nSimilarly, if the buffer only has a single struct field, the format will be \"unwrapped\" to the inner struct.  This lets you use a struct for a Buffer's data without having to wrap everything in an extra namespace.  Example:\n\n    shader = lovr.graphics.newShader([[\n      struct HandParams {\n        vec3 position;\n        float trigger;\n      };\n\n      layout(set = 0, binding = 0) buffer Hand {\n        HandParams params;\n      };\n\n      void lovrmain(){}\n    ]])\n\n    shader:getBufferFormat('Hand')\n    -- returns {{ name = 'position', type = 'vec3' }, { name = 'trigger', type = 'float' }}, 1\n    -- not     {{ name = 'params', type = {...}}}, 1",
               related = {
                 "lovr.graphics.newBuffer",
                 "Buffer:getFormat"
@@ -21123,7 +21123,7 @@ return {
                     {
                       name = "format",
                       type = "table",
-                      description = "The x size of a workgroup."
+                      description = "A list of fields declared in the shader code for the buffer."
                     },
                     {
                       name = "length",

+ 26 - 30
api/lovr/graphics/Shader/getBufferFormat.lua

@@ -1,9 +1,9 @@
 return {
   summary = 'Get the format of a buffer in the Shader.',
   description = [[
-    Returns the format of a uniform or storage buffer in the shader.  This matches the same syntax
-    used by `lovr.graphics.newBuffer`, so it can be passed there to quickly create a Buffer that
-    matches a variable in a Shader.
+    Returns the format of a uniform or storage buffer in the shader.  The return type matches the
+    same syntax used by `lovr.graphics.newBuffer`, so it can be passed there to quickly create a
+    Buffer that matches a variable in a Shader.
   ]],
   arguments = {
     name = {
@@ -14,7 +14,7 @@ return {
   returns = {
     format = {
       type = 'table',
-      description = 'The x size of a workgroup.'
+      description = 'A list of fields declared in the shader code for the buffer.'
     },
     length = {
       type = 'number',
@@ -31,42 +31,38 @@ return {
     If the buffer only has a single array field, the format will be "unwrapped" to an array instead
     of a single-field struct with an array in it.  Example:
 
-    ```
-    shader = lovr.graphics.newShader([[
-      layout(set = 0, binding = 0) buffer Numbers {
-        uint numbers[64];
-      };
+        shader = lovr.graphics.newShader([[
+          layout(set = 0, binding = 0) buffer Numbers {
+            uint numbers[64];
+          };
 
-      void lovrmain(){}
-    ]])
+          void lovrmain(){}
+        ]])
 
-    shader:getBufferFormat('Numbers')
-    -- returns {{ name = 'numbers', type = 'u32' }}, 64
-    -- not     {{ name = 'numbers', type = 'u32', length = 64 }}, 1
-    ```
+        shader:getBufferFormat('Numbers')
+        -- returns {{ name = 'numbers', type = 'u32' }}, 64
+        -- not     {{ name = 'numbers', type = 'u32', length = 64 }}, 1
 
     Similarly, if the buffer only has a single struct field, the format will be "unwrapped" to the
     inner struct.  This lets you use a struct for a Buffer's data without having to wrap everything
     in an extra namespace.  Example:
 
-    ```
-    shader = lovr.graphics.newShader([[
-      struct HandParams {
-        vec3 position;
-        float trigger;
-      };
+        shader = lovr.graphics.newShader([[
+          struct HandParams {
+            vec3 position;
+            float trigger;
+          };
 
-      layout(set = 0, binding = 0) buffer Hand {
-        HandParams params;
-      };
+          layout(set = 0, binding = 0) buffer Hand {
+            HandParams params;
+          };
 
-      void lovrmain(){}
-    ]])
+          void lovrmain(){}
+        ]])
 
-    shader:getBufferFormat('Hand')
-    -- returns {{ name = 'position', type = 'vec3' }, { name = 'trigger', type = 'float' }}, 1
-    -- not     {{ name = 'params', type = {...}}}, 1
-    ```
+        shader:getBufferFormat('Hand')
+        -- returns {{ name = 'position', type = 'vec3' }, { name = 'trigger', type = 'float' }}, 1
+        -- not     {{ name = 'params', type = {...}}}, 1
   ]=],
   example = [=[
     shader = lovr.graphics.newShader([[