GrManager.cpp 3.0 KB

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