conftest.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. assert win is not None
  31. yield win
  32. if win is not None:
  33. graphics_engine.remove_window(win)
  34. @pytest.fixture(scope='module')
  35. def gsg(graphics_pipe, graphics_engine):
  36. "Returns a windowless GSG that can be used for offscreen rendering."
  37. from panda3d.core import GraphicsPipe, FrameBufferProperties, WindowProperties
  38. fbprops = FrameBufferProperties()
  39. fbprops.force_hardware = True
  40. buffer = graphics_engine.make_output(
  41. graphics_pipe,
  42. 'buffer',
  43. 0,
  44. fbprops,
  45. WindowProperties.size(32, 32),
  46. GraphicsPipe.BF_refuse_window
  47. )
  48. graphics_engine.open_windows()
  49. assert buffer is not None
  50. yield buffer.gsg
  51. if buffer is not None:
  52. graphics_engine.remove_window(buffer)