TextureView.cpp 1.5 KB

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