Răsfoiți Sursa

Fix some ShaderBlock docs;

bjorn 5 ani în urmă
părinte
comite
d91606f2e2

+ 21 - 5
api/init.lua

@@ -8656,6 +8656,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",
@@ -8674,9 +8679,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"
                     }
                   }
@@ -8698,10 +8703,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  }, 'uniform')\n\n  shader = lovr.graphics.newShader(\n    block:getShaderCode('Block') .. -- Define the block in the shader\n    [[\n      vec4 lovrMain() {\n        // ...use the object transforms from the block\n        return lovrProjection * lovrTransform * lovrVertex;\n      }\n    ]],\n\n    block:getShaderCode('Block') ..\n    [[\n      vec4 lovrMain() {\n        // ...use the lights from the block\n        return lovrGraphicsColor * texture(lovrDiffuseTexture, lovrTexCoord);\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  }, 'uniform')\n\n  shader = lovr.graphics.newShader(\n    block:getShaderCode('Block') .. -- Define the block in the shader\n    [[\n      vec4 lovrMain() {\n        // ...use the object transforms from the block\n        return lovrProjection * lovrTransform * lovrVertex;\n      }\n    ]],\n\n    block:getShaderCode('Block') ..\n    [[\n      vec4 lovrMain() {\n        // ...use the lights from the block\n        return lovrGraphicsColor * texture(lovrDiffuseTexture, lovrTexCoord);\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",
@@ -13128,7 +13133,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 },