2
0

conftest.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import sys
  2. import pytest
  3. from panda3d import core
  4. from direct.showbase.ShowBase import ShowBase
  5. @pytest.fixture
  6. def base():
  7. base = ShowBase(windowType='none')
  8. yield base
  9. base.destroy()
  10. @pytest.fixture
  11. def tk_toplevel():
  12. tk = pytest.importorskip('tkinter')
  13. if sys.platform == 'darwin' and not core.ConfigVariableBool('want-tk', False):
  14. pytest.skip('"want-tk" must be true to use tkinter with Panda3D on macOS')
  15. try:
  16. root = tk.Toplevel()
  17. except tk.TclError as e:
  18. pytest.skip(str(e))
  19. yield root
  20. root.destroy()
  21. @pytest.fixture(scope='session')
  22. def graphics_pipe():
  23. from panda3d.core import GraphicsPipeSelection
  24. pipe = GraphicsPipeSelection.get_global_ptr().make_default_pipe()
  25. if pipe is None or not pipe.is_valid():
  26. pytest.skip("GraphicsPipe is invalid")
  27. yield pipe
  28. @pytest.fixture(scope='session')
  29. def graphics_engine():
  30. from panda3d.core import GraphicsEngine
  31. engine = GraphicsEngine.get_global_ptr()
  32. yield engine
  33. # This causes GraphicsEngine to also terminate the render threads.
  34. engine.remove_all_windows()
  35. @pytest.fixture
  36. def window(graphics_pipe, graphics_engine):
  37. from panda3d.core import GraphicsPipe, FrameBufferProperties, WindowProperties
  38. fbprops = FrameBufferProperties.get_default()
  39. winprops = WindowProperties.get_default()
  40. win = graphics_engine.make_output(
  41. graphics_pipe,
  42. 'window',
  43. 0,
  44. fbprops,
  45. winprops,
  46. GraphicsPipe.BF_require_window
  47. )
  48. graphics_engine.open_windows()
  49. if win is None:
  50. pytest.skip("GraphicsPipe cannot make windows")
  51. yield win
  52. if win is not None:
  53. graphics_engine.remove_window(win)
  54. @pytest.fixture(scope='module')
  55. def gsg(graphics_pipe, graphics_engine):
  56. "Returns a windowless GSG that can be used for offscreen rendering."
  57. from panda3d.core import GraphicsPipe, FrameBufferProperties, WindowProperties
  58. fbprops = FrameBufferProperties()
  59. fbprops.force_hardware = True
  60. buffer = graphics_engine.make_output(
  61. graphics_pipe,
  62. 'buffer',
  63. 0,
  64. fbprops,
  65. WindowProperties.size(32, 32),
  66. GraphicsPipe.BF_refuse_window
  67. )
  68. graphics_engine.open_windows()
  69. if buffer is None:
  70. pytest.skip("GraphicsPipe cannot make offscreen buffers")
  71. yield buffer.gsg
  72. if buffer is not None:
  73. graphics_engine.remove_window(buffer)