GrManagerImpl.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Gr/gl/GrManagerImpl.h>
  6. #include <AnKi/Gr/GrManager.h>
  7. #include <AnKi/Gr/gl/RenderingThread.h>
  8. #include <AnKi/Gr/gl/GlState.h>
  9. #include <AnKi/Core/Config.h>
  10. #include <AnKi/Core/NativeWindow.h>
  11. namespace anki
  12. {
  13. GrManagerImpl::GrManagerImpl()
  14. {
  15. }
  16. GrManagerImpl::~GrManagerImpl()
  17. {
  18. m_fakeDefaultFb.reset(nullptr);
  19. m_fakeFbTex.reset(nullptr);
  20. if(m_thread)
  21. {
  22. m_thread->stop();
  23. m_alloc.deleteInstance(m_thread);
  24. m_thread = nullptr;
  25. }
  26. if(m_state)
  27. {
  28. m_alloc.deleteInstance(m_state);
  29. }
  30. destroyBackend();
  31. }
  32. Error GrManagerImpl::init(GrManagerInitInfo& init, GrAllocator<U8> alloc)
  33. {
  34. m_alloc = alloc;
  35. m_cacheDir.create(m_alloc, init.m_cacheDirectory);
  36. m_debugMarkers = init.m_config->getNumber("gr_debugMarkers");
  37. // Init the backend of the backend
  38. ANKI_CHECK(createBackend(init));
  39. // First create the state
  40. m_state = m_alloc.newInstance<GlState>(this);
  41. m_state->initMainThread(*init.m_config);
  42. // Create thread
  43. m_thread = m_alloc.newInstance<RenderingThread>(this);
  44. // Start it
  45. m_thread->start();
  46. m_thread->syncClientServer();
  47. // Misc
  48. m_capabilities.m_gpuVendor = m_state->m_gpu;
  49. m_capabilities.m_uniformBufferBindOffsetAlignment = m_state->m_uboAlignment;
  50. m_capabilities.m_uniformBufferMaxRange = m_state->m_uniBlockMaxSize;
  51. m_capabilities.m_storageBufferBindOffsetAlignment = m_state->m_ssboAlignment;
  52. m_capabilities.m_storageBufferMaxRange = m_state->m_storageBlockMaxSize;
  53. m_capabilities.m_textureBufferBindOffsetAlignment = m_state->m_tboAlignment;
  54. m_capabilities.m_textureBufferMaxRange = m_state->m_tboMaxRange;
  55. m_capabilities.m_majorApiVersion = U(init.m_config->getNumber("gr.glmajor"));
  56. m_capabilities.m_minorApiVersion = U(init.m_config->getNumber("gr.glmajor"));
  57. initFakeDefaultFb(init);
  58. return Error::NONE;
  59. }
  60. void GrManagerImpl::initFakeDefaultFb(GrManagerInitInfo& init)
  61. {
  62. U32 defaultFbWidth = init.m_window->getWidth();
  63. U32 defaultFbHeight = init.m_window->getHeight();
  64. TextureInitInfo texinit("FB Tex");
  65. texinit.m_width = defaultFbWidth;
  66. texinit.m_height = defaultFbHeight;
  67. texinit.m_format = Format::R8G8B8A8_UNORM;
  68. texinit.m_usage =
  69. TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE | TextureUsageBit::IMAGE_COMPUTE_WRITE | TextureUsageBit::PRESENT;
  70. m_fakeFbTex = newTexture(texinit);
  71. TextureViewPtr view = newTextureView(TextureViewInitInfo(m_fakeFbTex, "FB view"));
  72. FramebufferInitInfo fbinit("Dflt FB");
  73. fbinit.m_colorAttachmentCount = 1;
  74. fbinit.m_colorAttachments[0].m_textureView = view;
  75. m_fakeDefaultFb = newFramebuffer(fbinit);
  76. }
  77. } // end namespace anki