Browse Source

Graphics objects docs;

bjorn 5 years ago
parent
commit
ca593f95cd

+ 6 - 6
api/lovr/graphics/Canvas/init.lua

@@ -13,10 +13,10 @@ return {
   notes = [[
     Up to four textures can be attached to a Canvas and anything rendered to the Canvas will be
     broadcast to all attached Textures.  If you want to do render different things to different
-    textures, add a `#define MULTICANVAS` line to the top of your fragment shader and implement the
-    `void colors` function instead of the usual `vec4 color` function.  You can then assign
-    different output colors to `lovrCanvas[0]`, `lovrCanvas[1]`, etc. instead of returning a single
-    color.
+    textures, use the `multicanvas` shader flag when creating your shader and implement the `void
+    colors` function instead of the usual `vec4 color` function.  You can then assign different
+    output colors to `lovrCanvas[0]`, `lovrCanvas[1]`, etc. instead of returning a single color.
+    Each color written to the array will end up in the corresponding texture attached to the Canvas.
   ]],
   example = {
     description = 'Apply a postprocessing effect (wave) using a Canvas and a fragment shader.',
@@ -43,7 +43,7 @@ return {
         wave:send('time', lovr.timer.getTime())
       end
 
-      function lovr.draw(eye)
+      function lovr.draw()
         -- Render the scene to the canvas instead of the headset.
         canvas:renderTo(function()
           lovr.graphics.clear()
@@ -62,7 +62,7 @@ return {
         -- Render the canvas to the headset using a shader.
         lovr.graphics.setColor(1, 1, 1)
         lovr.graphics.setShader(wave)
-        lovr.graphics.plane(canvas)
+        lovr.graphics.fill(canvas:getTexture())
         lovr.graphics.setShader()
       end
     ]=]

+ 1 - 2
api/lovr/graphics/Font/getHeight.lua

@@ -1,8 +1,7 @@
 return {
   summary = 'Get the height of a line of text.',
   description = [[
-    Returns the height of a line of text, in meters.  Units are in meters, see
-    `Font:setPixelDensity`.
+    Returns the height of a line of text.  Units are in meters, see `Font:setPixelDensity`.
   ]],
   arguments = {},
   returns = {

+ 2 - 1
api/lovr/graphics/Font/getLineHeight.lua

@@ -1,6 +1,6 @@
 return {
   summary = 'Get the line height of the Font.',
-  description = 'Returns the current line height of the Font.  The default is 1.0.',
+  description = 'Returns the current line height multiplier of the Font.  The default is 1.0.',
   arguments = {},
   returns = {
     {
@@ -10,6 +10,7 @@ return {
     }
   },
   related = {
+    'Font:getHeight',
     'Rasterizer:getLineHeight'
   }
 }

+ 3 - 3
api/lovr/graphics/Font/getWidth.lua

@@ -1,8 +1,8 @@
 return {
-  summary = 'Get the width of a line of text.',
+  summary = 'Measure a line of text.',
   description = [[
-    Returns the width and line count of a string when rendered using the font, with an optional
-    wrap.
+    Returns the width and line count of a string when rendered using the font, taking into account
+    an optional wrap limit.
   ]],
   arguments = {
     {

+ 1 - 1
api/lovr/graphics/Font/hasGlyphs.lua

@@ -21,7 +21,7 @@ return {
   },
   notes = [[
     It is a good idea to use this function when you're rendering an unknown or user-supplied string
-    to avoid embarrassing crashes.
+    to avoid utterly embarrassing crashes.
   ]],
   related = {
     'Rasterizer:hasGlyphs'

+ 1 - 1
api/lovr/graphics/Font/init.lua

@@ -1,5 +1,5 @@
 return {
-  summary = 'A loaded font used to render text.',
+  summary = 'A font used to render text.',
   description = [[
     A Font is an object created from a TTF file.  It can be used to render text with
     `lovr.graphics.print`.

+ 1 - 0
api/lovr/graphics/Font/setLineHeight.lua

@@ -13,6 +13,7 @@ return {
   },
   returns = {},
   related = {
+    'Font:getHeight',
     'Rasterizer:getLineHeight'
   }
 }

+ 1 - 1
api/lovr/graphics/Material/getColor.lua

@@ -2,7 +2,7 @@ return {
   summary = 'Get a color property of the Material.',
   description = [[
     Returns a color property for a Material.  Different types of colors are supported for different
-    lighting parameters.  Colors default to white and are gamma corrected as necessary.
+    lighting parameters.  Colors default to `(1.0, 1.0, 1.0, 1.0)` and are gamma corrected.
   ]],
   arguments = {
     {

+ 1 - 3
api/lovr/graphics/Material/getScalar.lua

@@ -1,8 +1,6 @@
 return {
   summary = 'Get a scalar property of the Material.',
-  description = [[
-    Returns a numeric property of a Material.  Scalar properties default to 1.0.
-  ]],
+  description = 'Returns a numeric property of a Material.  Scalar properties default to 1.0.',
   arguments = {
     {
       name = 'scalarType',

+ 2 - 2
api/lovr/graphics/Material/getTexture.lua

@@ -1,8 +1,8 @@
 return {
   summary = 'Get a texture for the Material.',
   description = [[
-    Returns a texture for a Material.  Different types of textures are supported for different
-    lighting parameters.  If unset, textures default to a blank white texture.
+    Returns a texture for a Material.  Several predefined `MaterialTexture`s are supported.  Any
+    texture that is `nil` will use a single white pixel as a fallback.
   ]],
   arguments = {
     {

+ 6 - 1
api/lovr/graphics/Material/getTransform.lua

@@ -28,5 +28,10 @@ return {
       type = 'number',
       description = 'The texture coordinate rotation, in radians.'
     }
-  }
+  },
+  notes = [[
+    Although texture coordinates will automatically be transformed by the Material's transform, the
+    material transform is exposed as the `mat3 lovrMaterialTransform` uniform variable in shaders,
+    allowing it to be used for other purposes.
+  ]]
 }

+ 1 - 1
api/lovr/graphics/Material/setColor.lua

@@ -2,7 +2,7 @@ return {
   summary = 'Set a color property of the Material.',
   description = [[
     Sets a color property for a Material.  Different types of colors are supported for different
-    lighting parameters.  Colors default to white and are gamma corrected as necessary.
+    lighting parameters.  Colors default to `(1.0, 1.0, 1.0, 1.0)` and are gamma corrected.
   ]],
   arguments = {
     colorType = {

+ 2 - 4
api/lovr/graphics/Material/setScalar.lua

@@ -1,13 +1,11 @@
 return {
   summary = 'Set a scalar property of the Material.',
-  description = [[
-    Sets a numeric property of a Material.  Scalar properties default to 1.0.
-  ]],
+  description = 'Sets a numeric property of a Material.  Scalar properties default to 1.0.',
   arguments = {
     {
       name = 'scalarType',
       type = 'MaterialScalar',
-      description = 'The type of property to get.'
+      description = 'The type of property to set.'
     },
     {
       name = 'x',

+ 3 - 15
api/lovr/graphics/Material/setTexture.lua

@@ -1,22 +1,18 @@
 return {
   summary = 'Set a texture for the Material.',
   description = [[
-    Sets a texture for a Material.  Different types of textures are supported for different
-    lighting parameters.  If set to `nil`, textures default to a blank white texture.
+    Sets a texture for a Material.  Several predefined `MaterialTexture`s are supported.  Any
+    texture that is `nil` will use a single white pixel as a fallback.
   ]],
   arguments = {
     textureType = {
       type = 'MaterialTexture',
       default = [['diffuse']],
-      description = 'The type of texture to get.'
+      description = 'The type of texture to set.'
     },
     texture = {
       type = 'Texture',
       description = 'The texture to apply, or `nil` to use the default.'
-    },
-    canvas = {
-      type = 'Canvas',
-      description = 'A Canvas.  The first Texture attached to the Canvas will be used.'
     }
   },
   returns = {},
@@ -28,14 +24,6 @@ return {
     {
       arguments = { 'texture' },
       returns = {}
-    },
-    {
-      arguments = { 'textureType', 'canvas' },
-      returns = {}
-    },
-    {
-      arguments = { 'canvas' },
-      returns = {}
     }
   },
   related = {

+ 6 - 1
api/lovr/graphics/Material/setTransform.lua

@@ -31,5 +31,10 @@ return {
       description = 'The texture coordinate rotation, in radians.'
     }
   },
-  returns = {}
+  returns = {},
+  notes = [[
+    Although texture coordinates will automatically be transformed by the Material's transform, the
+    material transform is exposed as the `mat3 lovrMaterialTransform` uniform variable in shaders,
+    allowing it to be used for other purposes.
+  ]]
 }

+ 25 - 2
api/lovr/graphics/Shader/send.lua

@@ -15,12 +15,35 @@ return {
   },
   returns = {},
   notes = [[
-    The shader does not need to be active to update its uniforms.  However, the types must match up.
+    The shader does not need to be active to update its uniforms.
+
+    The following type combinations are supported:
+
+    <table>
+      <thead>
+        <tr>
+          <td>Uniform type</td>
+          <td>LÖVR type</td>
+        </tr>
+      </thead>
+      <tbody>
+        <tr>
+          <td>`float`, `int`</td>
+          <td>`number`</td>
+        </tr>
+        <tr>
+          <td>TODO</td>
+          <td>SORRY</td>
+        </tr>
+      </tbody>
+    </table>
+
     Uniform variables declared as `float`s must be sent a single number, whereas uniforms declared
     as `vec4`s must be sent a table containing 4 numbers, etc.  Note that uniforms declared as mat4s
     can be sent a `mat4` object.
 
-    An error is thrown if the uniform does not exist or is not used in the shader.
+    An error is thrown if the uniform does not exist or is not used in the shader.  The
+    `Shader:hasUniform` function can be used to check if a uniform variable exists.
 
     `Blob`s can be used to pass arbitrary binary data to Shader variables.
   ]],

+ 6 - 1
api/lovr/graphics/newCanvas.lua

@@ -98,7 +98,12 @@ return {
       returns = { 'canvas' }
     }
   },
-  notes = 'Textures created by this function will have `clamp` as their `TextureWrap`.',
+  notes = [[
+    Textures created by this function will have `clamp` as their `TextureWrap`.
+
+    Stereo Canvases will either have their width doubled or use array textures for their
+    attachments, depending on their implementation.
+  ]],
   related = {
     'lovr.graphics.setCanvas',
     'lovr.graphics.getCanvas',