Sampler.cpp 1.4 KB

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