conftest.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import pytest
  2. @pytest.fixture(scope='session')
  3. def graphics_pipe():
  4. from panda3d.core import GraphicsPipeSelection
  5. pipe = GraphicsPipeSelection.get_global_ptr().make_default_pipe()
  6. if pipe is None or not pipe.is_valid():
  7. pytest.skip("GraphicsPipe is invalid")
  8. yield pipe
  9. @pytest.fixture(scope='session')
  10. def graphics_engine():
  11. from panda3d.core import GraphicsEngine
  12. engine = GraphicsEngine.get_global_ptr()
  13. yield engine
  14. # This causes GraphicsEngine to also terminate the render threads.
  15. engine.remove_all_windows()
  16. @pytest.fixture
  17. def window(graphics_pipe, graphics_engine):
  18. from panda3d.core import GraphicsPipe, FrameBufferProperties, WindowProperties
  19. fbprops = FrameBufferProperties.get_default()
  20. winprops = WindowProperties.get_default()
  21. win = graphics_engine.make_output(
  22. graphics_pipe,
  23. 'window',
  24. 0,
  25. fbprops,
  26. winprops,
  27. GraphicsPipe.BF_require_window
  28. )
  29. graphics_engine.open_windows()
  30. if win is None:
  31. pytest.skip("GraphicsPipe cannot make windows")
  32. yield win
  33. if win is not None:
  34. graphics_engine.remove_window(win)
  35. @pytest.fixture(scope='module')
  36. def gsg(graphics_pipe, graphics_engine):
  37. "Returns a windowless GSG that can be used for offscreen rendering."
  38. from panda3d.core import GraphicsPipe, FrameBufferProperties, WindowProperties
  39. fbprops = FrameBufferProperties()
  40. fbprops.force_hardware = True
  41. buffer = graphics_engine.make_output(
  42. graphics_pipe,
  43. 'buffer',
  44. 0,
  45. fbprops,
  46. WindowProperties.size(32, 32),
  47. GraphicsPipe.BF_refuse_window
  48. )
  49. graphics_engine.open_windows()
  50. assert buffer is not None
  51. yield buffer.gsg
  52. if buffer is not None:
  53. graphics_engine.remove_window(buffer)