D3DShader.cpp 997 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (C) 2009-present, 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/D3D/D3DShader.h>
  6. namespace anki {
  7. Shader* Shader::newInstance(const ShaderInitInfo& init)
  8. {
  9. ShaderImpl* impl = anki::newInstance<ShaderImpl>(GrMemoryPool::getSingleton(), init.getName());
  10. const Error err = impl->init(init);
  11. if(err)
  12. {
  13. deleteInstance(GrMemoryPool::getSingleton(), impl);
  14. impl = nullptr;
  15. }
  16. return impl;
  17. }
  18. ShaderImpl::~ShaderImpl()
  19. {
  20. }
  21. Error ShaderImpl::init(const ShaderInitInfo& inf)
  22. {
  23. m_shaderType = inf.m_shaderType;
  24. m_shaderBinarySize = U32(inf.m_binary.getSizeInBytes());
  25. m_hasDiscard = inf.m_reflection.m_fragment.m_discards;
  26. m_reflection = inf.m_reflection;
  27. m_reflection.validate();
  28. m_binary.resize(m_shaderBinarySize);
  29. memcpy(m_binary.getBegin(), inf.m_binary.getBegin(), inf.m_binary.getSizeInBytes());
  30. return Error::kNone;
  31. }
  32. } // end namespace anki