GrManager.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/GrManager.h>
  6. #include <AnKi/Gr/gl/GrManagerImpl.h>
  7. #include <AnKi/Gr/gl/RenderingThread.h>
  8. #include <AnKi/Gr/gl/TextureImpl.h>
  9. #include <AnKi/Gr/gl/GlState.h>
  10. #include <AnKi/Gr/Buffer.h>
  11. #include <AnKi/Gr/Texture.h>
  12. #include <AnKi/Gr/Sampler.h>
  13. #include <AnKi/Gr/Shader.h>
  14. #include <AnKi/Gr/ShaderProgram.h>
  15. #include <AnKi/Gr/CommandBuffer.h>
  16. #include <AnKi/Gr/Framebuffer.h>
  17. #include <AnKi/Gr/OcclusionQuery.h>
  18. #include <AnKi/Gr/RenderGraph.h>
  19. #include <cstring>
  20. namespace anki {
  21. GrManager::GrManager()
  22. {
  23. }
  24. GrManager::~GrManager()
  25. {
  26. // Destroy in reverse order
  27. m_cacheDir.destroy(m_alloc);
  28. }
  29. Error GrManager::newInstance(GrManagerInitInfo& init, GrManager*& gr)
  30. {
  31. auto alloc = GrAllocator<U8>(init.m_allocCallback, init.m_allocCallbackUserData);
  32. GrManagerImpl* impl = alloc.newInstance<GrManagerImpl>();
  33. Error err = impl->init(init, alloc);
  34. if(err)
  35. {
  36. alloc.deleteInstance(impl);
  37. gr = nullptr;
  38. }
  39. else
  40. {
  41. gr = impl;
  42. }
  43. return err;
  44. }
  45. void GrManager::deleteInstance(GrManager* gr)
  46. {
  47. if(gr == nullptr)
  48. {
  49. return;
  50. }
  51. auto alloc = gr->m_alloc;
  52. gr->~GrManager();
  53. alloc.deallocate(gr, 1);
  54. }
  55. TexturePtr GrManager::acquireNextPresentableTexture()
  56. {
  57. ANKI_GL_SELF(GrManagerImpl);
  58. return self.m_fakeFbTex;
  59. }
  60. void GrManager::swapBuffers()
  61. {
  62. ANKI_GL_SELF(GrManagerImpl);
  63. self.getRenderingThread().swapBuffers();
  64. }
  65. void GrManager::finish()
  66. {
  67. ANKI_GL_SELF(GrManagerImpl);
  68. self.getRenderingThread().syncClientServer();
  69. }
  70. #define ANKI_SAFE_CONSTRUCT(class_) \
  71. class_* out = class_::newInstance(this, init); \
  72. class_##Ptr ptr(out); \
  73. out->getRefcount().fetchSub(1); \
  74. return ptr
  75. BufferPtr GrManager::newBuffer(const BufferInitInfo& init)
  76. {
  77. ANKI_SAFE_CONSTRUCT(Buffer);
  78. }
  79. TexturePtr GrManager::newTexture(const TextureInitInfo& init)
  80. {
  81. ANKI_SAFE_CONSTRUCT(Texture);
  82. }
  83. TextureViewPtr GrManager::newTextureView(const TextureViewInitInfo& init)
  84. {
  85. ANKI_SAFE_CONSTRUCT(TextureView);
  86. }
  87. SamplerPtr GrManager::newSampler(const SamplerInitInfo& init)
  88. {
  89. ANKI_SAFE_CONSTRUCT(Sampler);
  90. }
  91. ShaderPtr GrManager::newShader(const ShaderInitInfo& init)
  92. {
  93. ANKI_SAFE_CONSTRUCT(Shader);
  94. }
  95. ShaderProgramPtr GrManager::newShaderProgram(const ShaderProgramInitInfo& init)
  96. {
  97. ANKI_SAFE_CONSTRUCT(ShaderProgram);
  98. }
  99. CommandBufferPtr GrManager::newCommandBuffer(const CommandBufferInitInfo& init)
  100. {
  101. return CommandBufferPtr(CommandBuffer::newInstance(this, init));
  102. }
  103. FramebufferPtr GrManager::newFramebuffer(const FramebufferInitInfo& init)
  104. {
  105. ANKI_SAFE_CONSTRUCT(Framebuffer);
  106. }
  107. OcclusionQueryPtr GrManager::newOcclusionQuery()
  108. {
  109. OcclusionQuery* out = OcclusionQuery::newInstance(this);
  110. OcclusionQueryPtr ptr(out);
  111. out->getRefcount().fetchSub(1);
  112. return ptr;
  113. }
  114. RenderGraphPtr GrManager::newRenderGraph()
  115. {
  116. return RenderGraphPtr(RenderGraph::newInstance(this));
  117. }
  118. #undef ANKI_SAFE_CONSTRUCT
  119. GrManagerStats GrManager::getStats() const
  120. {
  121. return GrManagerStats();
  122. }
  123. } // end namespace anki