opengl_draw_tests.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python3
  2. # Apache License, Version 2.0
  3. import argparse
  4. import os
  5. import subprocess
  6. import sys
  7. def screenshot():
  8. import bpy
  9. output_path = sys.argv[-1]
  10. # Force redraw and take screenshot.
  11. bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
  12. bpy.ops.screen.screenshot(filepath=output_path, full=True)
  13. bpy.ops.wm.quit_blender()
  14. # When run from inside Blender, take screenshot and exit.
  15. try:
  16. import bpy
  17. inside_blender = True
  18. except ImportError:
  19. inside_blender = False
  20. if inside_blender:
  21. screenshot()
  22. sys.exit(0)
  23. def get_arguments(filepath, output_filepath):
  24. return [
  25. "--no-window-focus",
  26. "--window-geometry",
  27. "0", "0", "1024", "768",
  28. "-noaudio",
  29. "--factory-startup",
  30. "--enable-autoexec",
  31. filepath,
  32. "-P",
  33. os.path.realpath(__file__),
  34. "--",
  35. output_filepath + '0001.png']
  36. def create_argparse():
  37. parser = argparse.ArgumentParser()
  38. parser.add_argument("-blender", nargs="+")
  39. parser.add_argument("-testdir", nargs=1)
  40. parser.add_argument("-outdir", nargs=1)
  41. parser.add_argument("-idiff", nargs=1)
  42. return parser
  43. def main():
  44. parser = create_argparse()
  45. args = parser.parse_args()
  46. blender = args.blender[0]
  47. test_dir = args.testdir[0]
  48. idiff = args.idiff[0]
  49. output_dir = args.outdir[0]
  50. from modules import render_report
  51. report = render_report.Report("OpenGL Draw", output_dir, idiff)
  52. ok = report.run(test_dir, blender, get_arguments)
  53. sys.exit(not ok)
  54. if __name__ == "__main__":
  55. main()