OpenGLContextTest.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "pch.h"
  2. #include "GraphicsDeviceContainer.h"
  3. #include "GraphicsDevice/OpenGL/OpenGLContext.h"
  4. #include "rtc_base/thread.h"
  5. namespace unity
  6. {
  7. namespace webrtc
  8. {
  9. class OpenGLContextTest : public testing::TestWithParam<UnityGfxRenderer>
  10. {
  11. };
  12. TEST_P(OpenGLContextTest, CurrentContext)
  13. {
  14. std::unique_ptr<GraphicsDeviceContainer> container = CreateGraphicsDeviceContainer(GetParam());
  15. std::unique_ptr<OpenGLContext> context = OpenGLContext::CurrentContext();
  16. ASSERT_NE(context, nullptr);
  17. }
  18. TEST_P(OpenGLContextTest, CurrentContextOnOtherThread)
  19. {
  20. std::unique_ptr<GraphicsDeviceContainer> container = CreateGraphicsDeviceContainer(GetParam());
  21. std::unique_ptr<rtc::Thread> thread = rtc::Thread::CreateWithSocketServer();
  22. thread->Start();
  23. std::unique_ptr<OpenGLContext> context = thread->Invoke<std::unique_ptr<OpenGLContext>>(
  24. RTC_FROM_HERE,
  25. [&]()
  26. {
  27. return OpenGLContext::CurrentContext();
  28. });
  29. ASSERT_EQ(context, nullptr);
  30. }
  31. TEST_P(OpenGLContextTest, CreateContextOnOtherThread)
  32. {
  33. std::unique_ptr<GraphicsDeviceContainer> container = CreateGraphicsDeviceContainer(GetParam());
  34. std::unique_ptr<rtc::Thread> thread = rtc::Thread::CreateWithSocketServer();
  35. thread->Start();
  36. std::unique_ptr<OpenGLContext> context = OpenGLContext::CurrentContext();
  37. std::unique_ptr<OpenGLContext> context2 = thread->Invoke<std::unique_ptr<OpenGLContext>>(
  38. RTC_FROM_HERE,
  39. [&]()
  40. {
  41. return OpenGLContext::CreateGLContext(context.get());
  42. });
  43. ASSERT_NE(context2, nullptr);
  44. }
  45. static UnityGfxRenderer supportedOpenGL[] =
  46. {
  47. #if SUPPORT_OPENGL_CORE & UNITY_LINUX
  48. kUnityGfxRendererOpenGLCore,
  49. #endif // SUPPORT_OPENGL_UNIFIED
  50. #if SUPPORT_OPENGL_ES
  51. kUnityGfxRendererOpenGLES30,
  52. #endif // SUPPORT_OPENGL_ES
  53. };
  54. INSTANTIATE_TEST_SUITE_P(OpenGLDevice, OpenGLContextTest, testing::ValuesIn(supportedOpenGL));
  55. } // end namespace webrtc
  56. } // end namespace unity