main.lua 875 B

12345678910111213141516171819202122232425262728293031323334
  1. function lovr.load()
  2. stats = { 0, 0, 0, 0 }
  3. tally = lovr.graphics.newTally('shader', 1, 1)
  4. readbacks = {}
  5. end
  6. function lovr.update(dt)
  7. while readbacks[1] and readbacks[1]:isComplete() do
  8. stats = readbacks[1]:getData()
  9. table.remove(readbacks, 1)
  10. end
  11. end
  12. function lovr.draw(pass)
  13. -- Track metrics in the Tally when drawing the cube
  14. pass:tick(tally, 1)
  15. pass:cube(0, 0.7, -1, .5, lovr.headset.getTime())
  16. pass:tock(tally, 1)
  17. -- Read back the tally data
  18. local tx = lovr.graphics.getPass('transfer')
  19. local readback = tx:read(tally, 1)
  20. table.insert(readbacks, readback)
  21. -- Render latest tally results
  22. pass:text(('%s: %s\n%s: %s\n%s: %s\n%s: %s'):format(
  23. 'vertices', stats[1],
  24. 'vertexshader', stats[2],
  25. 'visibletriangles', stats[3],
  26. 'fragmentshader', stats[4]
  27. ), 0, 1.7, -1, .1)
  28. return lovr.graphics.submit(pass, tx)
  29. end