Sampler.cpp 1.4 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/Sampler.h>
  6. #include <AnKi/Gr/gl/SamplerImpl.h>
  7. #include <AnKi/Gr/gl/CommandBufferImpl.h>
  8. #include <AnKi/Gr/GrManager.h>
  9. namespace anki
  10. {
  11. Sampler* Sampler::newInstance(GrManager* manager, const SamplerInitInfo& init)
  12. {
  13. class CreateSamplerCommand : public GlCommand
  14. {
  15. public:
  16. SamplerPtr m_sampler;
  17. SamplerInitInfo m_init;
  18. CreateSamplerCommand(Sampler* sampler, const SamplerInitInfo& init)
  19. : m_sampler(sampler)
  20. , m_init(init)
  21. {
  22. }
  23. Error operator()(GlState&)
  24. {
  25. SamplerImpl& impl = static_cast<SamplerImpl&>(*m_sampler);
  26. impl.init(m_init);
  27. GlObject::State oldState = impl.setStateAtomically(GlObject::State::CREATED);
  28. (void)oldState;
  29. ANKI_ASSERT(oldState == GlObject::State::TO_BE_CREATED);
  30. return Error::NONE;
  31. }
  32. };
  33. SamplerImpl* impl = manager->getAllocator().newInstance<SamplerImpl>(manager, init.getName());
  34. impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
  35. CommandBufferPtr cmdb = manager->newCommandBuffer(CommandBufferInitInfo());
  36. static_cast<CommandBufferImpl&>(*cmdb).pushBackNewCommand<CreateSamplerCommand>(impl, init);
  37. static_cast<CommandBufferImpl&>(*cmdb).flush();
  38. return impl;
  39. }
  40. } // end namespace anki