Browse Source

Fix some ShaderBlock docs;

bjorn 5 years ago
parent
commit
1de2a7a773
3 changed files with 34 additions and 13 deletions
  1. 21 5
      api/init.lua
  2. 1 1
      api/lovr/graphics/ShaderBlock/send.lua
  3. 12 7
      api/lovr/graphics/newShaderBlock.lua

+ 21 - 5
api/init.lua

@@ -8470,6 +8470,11 @@ return {
           variants = {
             {
               arguments = {
+                {
+                  name = "type",
+                  type = "BlockType",
+                  description = "Whether the block will be used for read-only uniform data or compute shaders."
+                },
                 {
                   name = "uniforms",
                   type = "table",
@@ -8488,9 +8493,9 @@ return {
                       default = "dynamic"
                     },
                     {
-                      name = "writable",
+                      name = "readable",
                       type = "boolean",
-                      description = "Whether Shaders can write to the data in the block.",
+                      description = "Whether the data in the block can be read using `ShaderBlock:read`.",
                       default = "false"
                     }
                   }
@@ -8512,10 +8517,10 @@ return {
           examples = {
             {
               description = "Create a ShaderBlock to hold a block of useful shader data.",
-              code = "function lovr.load()\n  block = lovr.graphics.newShaderBlock({\n    time = 'float',\n    lightCount = 'int',\n    lightPositions = { 'vec3', 16 },\n    lightColors = { 'vec3', 16 },\n    objectCount = 'int',\n    objectTransforms = { 'mat4', 256 }\n  })\n\n  shader = lovr.graphics.newShader(\n    block:getShaderCode('Block') .. -- Define the block in the shader\n    [[\n      vec4 position(mat4 projection, mat4 transform, vec4 vertex) {\n        // ...use the object transforms from the block\n        return projection * transform * vertex;\n      }\n    ]],\n\n    block:getShaderCode('Block') ..\n    [[\n      vec4 color(vec4 gColor, sampler2D image, vec2 uv) {\n        // ...use the lights from the block\n        return gColor * texture(image, uv);\n      }\n    ]]\n  )\n\n  -- Bind the block to the shader\n  shader:sendBlock('Block', block)\nend\n\n-- Update the data in the block every frame\nfunction lovr.update(dt)\n  block:send('time', lovr.timer.getTime())\n  block:send('lightCount', lightCount)\n  block:send('lightPositions', { { x, y, z}, { x, y, z } })\n  -- etc.\nend"
+              code = "function lovr.load()\n  block = lovr.graphics.newShaderBlock('uniform', {\n    time = 'float',\n    lightCount = 'int',\n    lightPositions = { 'vec3', 16 },\n    lightColors = { 'vec3', 16 },\n    objectCount = 'int',\n    objectTransforms = { 'mat4', 256 }\n  })\n\n  shader = lovr.graphics.newShader(\n    block:getShaderCode('Block') .. -- Define the block in the shader\n    [[\n      vec4 position(mat4 projection, mat4 transform, vec4 vertex) {\n        // ...use the object transforms from the block\n        return projection * transform * vertex;\n      }\n    ]],\n\n    block:getShaderCode('Block') ..\n    [[\n      vec4 color(vec4 gColor, sampler2D image, vec2 uv) {\n        // ...use the lights from the block\n        return gColor * texture(image, uv);\n      }\n    ]]\n  )\n\n  -- Bind the block to the shader\n  shader:sendBlock('Block', block)\nend\n\n-- Update the data in the block every frame\nfunction lovr.update(dt)\n  block:send('time', lovr.timer.getTime())\n  block:send('lightCount', lightCount)\n  block:send('lightPositions', { { x, y, z}, { x, y, z } })\n  -- etc.\nend"
             }
           },
-          notes = "The writable flag can only be true if compute shaders are supported, see `lovr.graphics.getFeatures`.  Writable blocks may be slightly slower than non-writable blocks, but they can also be much, much larger.  Non-writable blocks are usually limited to around 16 kilobytes in size, depending on hardware."
+          notes = "`compute` blocks can only be true if compute shaders are supported, see `lovr.graphics.getFeatures`.  Compute blocks may be slightly slower than uniform blocks, but they can also be much, much larger.  Uniform blocks are usually limited to around 16 kilobytes in size, depending on hardware."
         },
         {
           name = "newTexture",
@@ -12942,7 +12947,18 @@ return {
               },
               variants = {
                 {
-                  arguments = {},
+                  arguments = {
+                    {
+                      name = "variable",
+                      type = "string",
+                      description = "The name of the variable to update."
+                    },
+                    {
+                      name = "value",
+                      type = "*",
+                      description = "The new value of the uniform."
+                    }
+                  },
                   returns = {}
                 },
                 {

+ 1 - 1
api/lovr/graphics/ShaderBlock/send.lua

@@ -23,7 +23,7 @@ return {
   },
   variants = {
     {
-      arguments = { 'string', '*' },
+      arguments = { 'variable', 'value' },
       returns = {}
     },
     {

+ 12 - 7
api/lovr/graphics/newShaderBlock.lua

@@ -5,6 +5,11 @@ return {
     Creates a new ShaderBlock from a table of variable definitions with their names and types.
   ]],
   arguments = {
+    {
+      name = 'type',
+      type = 'BlockType',
+      description = 'Whether the block will be used for read-only uniform data or compute shaders.'
+    },
     {
       name = 'uniforms',
       type = 'table',
@@ -27,10 +32,10 @@ return {
           description = 'How the data in the block will be updated.'
         },
         {
-          name = 'writable',
+          name = 'readable',
           type = 'boolean',
           default = 'false',
-          description = 'Whether Shaders can write to the data in the block.'
+          description = 'Whether the data in the block can be read using `ShaderBlock:read`.'
         }
       }
     }
@@ -43,16 +48,16 @@ return {
     }
   },
   notes = [[
-    The writable flag can only be true if compute shaders are supported, see
-    `lovr.graphics.getFeatures`.  Writable blocks may be slightly slower than non-writable blocks,
-    but they can also be much, much larger.  Non-writable blocks are usually limited to around 16
-    kilobytes in size, depending on hardware.
+    `compute` blocks can only be true if compute shaders are supported, see
+    `lovr.graphics.getFeatures`.  Compute blocks may be slightly slower than uniform blocks, but
+    they can also be much, much larger.  Uniform blocks are usually limited to around 16 kilobytes
+    in size, depending on hardware.
   ]],
   example = {
     description = 'Create a ShaderBlock to hold a block of useful shader data.',
     code = [=[
       function lovr.load()
-        block = lovr.graphics.newShaderBlock({
+        block = lovr.graphics.newShaderBlock('uniform', {
           time = 'float',
           lightCount = 'int',
           lightPositions = { 'vec3', 16 },