TextureView.cpp 1.5 KB

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