2
0

Texture.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/Texture.h>
  6. #include <AnKi/Gr/gl/TextureImpl.h>
  7. #include <AnKi/Gr/gl/CommandBufferImpl.h>
  8. #include <AnKi/Gr/GrManager.h>
  9. namespace anki {
  10. Texture* Texture::newInstance(GrManager* manager, const TextureInitInfo& init)
  11. {
  12. class CreateTextureCommand final : public GlCommand
  13. {
  14. public:
  15. TexturePtr m_tex;
  16. TextureInitInfo m_init;
  17. CreateTextureCommand(Texture* tex, const TextureInitInfo& init)
  18. : m_tex(tex)
  19. , m_init(init)
  20. {
  21. }
  22. Error operator()(GlState&)
  23. {
  24. TextureImpl& impl = static_cast<TextureImpl&>(*m_tex);
  25. impl.init(m_init);
  26. GlObject::State oldState = impl.setStateAtomically(GlObject::State::CREATED);
  27. ANKI_ASSERT(oldState == GlObject::State::TO_BE_CREATED);
  28. (void)oldState;
  29. return Error::NONE;
  30. }
  31. };
  32. TextureImpl* impl = manager->getAllocator().newInstance<TextureImpl>(manager, init.getName());
  33. impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
  34. // Need to pre-init because some funcs ask for members and we don't want to serialize
  35. impl->preInit(init);
  36. CommandBufferPtr cmdb = manager->newCommandBuffer(CommandBufferInitInfo());
  37. static_cast<CommandBufferImpl&>(*cmdb).pushBackNewCommand<CreateTextureCommand>(impl, init);
  38. static_cast<CommandBufferImpl&>(*cmdb).flush();
  39. return impl;
  40. }
  41. } // end namespace anki