conftest.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. props = WindowProperties.size(32, 32)
  61. buffer = graphics_engine.make_output(
  62. graphics_pipe,
  63. 'buffer',
  64. 0,
  65. fbprops,
  66. props,
  67. GraphicsPipe.BF_refuse_window
  68. )
  69. graphics_engine.open_windows()
  70. if buffer is None:
  71. # Try making a window instead, putting it in the background so it
  72. # disrupts the desktop as little as possible
  73. props.minimized = True
  74. props.foreground = False
  75. props.z_order = WindowProperties.Z_bottom
  76. buffer = graphics_engine.make_output(
  77. graphics_pipe,
  78. 'buffer',
  79. 0,
  80. fbprops,
  81. props,
  82. GraphicsPipe.BF_require_window
  83. )
  84. if buffer is None:
  85. pytest.skip("GraphicsPipe cannot make offscreen buffers or windows")
  86. yield buffer.gsg
  87. if buffer is not None:
  88. graphics_engine.remove_window(buffer)