Browse Source

Add simple compute shader example;

bjorn 6 years ago
parent
commit
80793ee13a
2 changed files with 22 additions and 0 deletions
  1. 5 0
      api/init.lua
  2. 17 0
      api/lovr/graphics/newComputeShader.lua

+ 5 - 0
api/init.lua

@@ -8129,6 +8129,11 @@ return {
             "lovr.graphics.setShader",
             "lovr.graphics.getShader"
           },
+          examples = {
+            {
+              code = "function lovr.load()\n  computer = lovr.graphics.newComputeShader([[\n    layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n\n    void compute() {\n      // compute things!\n    }\n  ]])\n\n  -- Run the shader 4 times\n  local width, height, depth = 4, 1, 1\n\n  -- Dispatch the compute operation\n  lovr.graphics.compute(computer, width, height, depth)\nend"
+            }
+          },
           notes = "Compute shaders are not supported on all hardware, use `lovr.graphics.getSupported` to check if they're available on the current system.\n\nThe source code for a compute shader needs to implement the `void compute();` GLSL function. This function doesn't return anything, but the compute shader is able to write data out to `Texture`s or `ShaderBlock`s.\n\nThe GLSL version used for compute shaders is GLSL 430."
         },
         {

+ 17 - 0
api/lovr/graphics/newComputeShader.lua

@@ -28,6 +28,23 @@ return {
 
     The GLSL version used for compute shaders is GLSL 430.
   ]],
+  example = [=[
+    function lovr.load()
+      computer = lovr.graphics.newComputeShader([[
+        layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+
+        void compute() {
+          // compute things!
+        }
+      ]])
+
+      -- Run the shader 4 times
+      local width, height, depth = 4, 1, 1
+
+      -- Dispatch the compute operation
+      lovr.graphics.compute(computer, width, height, depth)
+    end
+  ]=],
   related = {
     'lovr.graphics.compute',
     'lovr.graphics.newShader',