BsGLTextureManager.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsGLTextureManager.h"
  4. #include "BsRenderAPI.h"
  5. #include "BsGLRenderTexture.h"
  6. #include "BsGLMultiRenderTexture.h"
  7. #include "BsGLPixelFormat.h"
  8. namespace BansheeEngine
  9. {
  10. GLTextureManager::GLTextureManager(GLSupport& support)
  11. :TextureManager(), mGLSupport(support)
  12. {
  13. }
  14. GLTextureManager::~GLTextureManager()
  15. {
  16. }
  17. SPtr<RenderTexture> GLTextureManager::createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc)
  18. {
  19. GLRenderTexture* tex = new (bs_alloc<GLRenderTexture>()) GLRenderTexture(desc);
  20. return bs_core_ptr<GLRenderTexture>(tex);
  21. }
  22. SPtr<MultiRenderTexture> GLTextureManager::createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc)
  23. {
  24. GLMultiRenderTexture* tex = new (bs_alloc<GLMultiRenderTexture>()) GLMultiRenderTexture(desc);
  25. return bs_core_ptr<GLMultiRenderTexture>(tex);
  26. }
  27. PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma)
  28. {
  29. // Adjust requested parameters to capabilities
  30. const RenderAPICapabilities& caps = RenderAPICore::instance().getCapabilities();
  31. // Check compressed texture support
  32. // If a compressed format not supported, revert to PF_A8R8G8B8
  33. if(PixelUtil::isCompressed(format) && !caps.hasCapability(RSC_TEXTURE_COMPRESSION_DXT))
  34. {
  35. return PF_A8R8G8B8;
  36. }
  37. // If floating point textures not supported, revert to PF_A8R8G8B8
  38. if(PixelUtil::isFloatingPoint(format) && !caps.hasCapability(RSC_TEXTURE_FLOAT))
  39. {
  40. return PF_A8R8G8B8;
  41. }
  42. // Check if this is a valid rendertarget format
  43. if( usage & TU_RENDERTARGET )
  44. {
  45. /// Get closest supported alternative
  46. /// If mFormat is supported it's returned
  47. return GLRTTManager::instance().getSupportedAlternative(format);
  48. }
  49. return GLPixelUtil::getClosestValidFormat(format);
  50. }
  51. GLTextureCoreManager::GLTextureCoreManager(GLSupport& support)
  52. :mGLSupport(support)
  53. { }
  54. SPtr<TextureCore> GLTextureCoreManager::createTextureInternal(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  55. int numMips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 multisampleCount, UINT32 numArraySlices, const SPtr<PixelData>& initialData)
  56. {
  57. GLTextureCore* tex = new (bs_alloc<GLTextureCore>()) GLTextureCore(mGLSupport, texType,
  58. width, height, depth, numMips, format, usage, hwGammaCorrection, multisampleCount, numArraySlices, initialData);
  59. SPtr<GLTextureCore> texPtr = bs_shared_ptr<GLTextureCore>(tex);
  60. texPtr->_setThisPtr(texPtr);
  61. return texPtr;
  62. }
  63. SPtr<RenderTextureCore> GLTextureCoreManager::createRenderTextureInternal(const RENDER_TEXTURE_CORE_DESC& desc)
  64. {
  65. SPtr<GLRenderTextureCore> texPtr = bs_shared_ptr_new<GLRenderTextureCore>(desc);
  66. texPtr->_setThisPtr(texPtr);
  67. return texPtr;
  68. }
  69. SPtr<MultiRenderTextureCore> GLTextureCoreManager::createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_CORE_DESC& desc)
  70. {
  71. SPtr<GLMultiRenderTextureCore> texPtr = bs_shared_ptr_new<GLMultiRenderTextureCore>(desc);
  72. texPtr->_setThisPtr(texPtr);
  73. return texPtr;
  74. }
  75. }