conftest.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if buffer is None:
  51. pytest.skip("GraphicsPipe cannot make offscreen buffers")
  52. yield buffer.gsg
  53. if buffer is not None:
  54. graphics_engine.remove_window(buffer)