BsGLTextureManager.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "BsGLPixelFormat.h"
  7. namespace BansheeEngine
  8. {
  9. GLTextureManager::GLTextureManager(GLSupport& support)
  10. :TextureManager(), mGLSupport(support)
  11. {
  12. }
  13. GLTextureManager::~GLTextureManager()
  14. {
  15. }
  16. SPtr<RenderTexture> GLTextureManager::createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc)
  17. {
  18. GLRenderTexture* tex = new (bs_alloc<GLRenderTexture>()) GLRenderTexture(desc);
  19. return bs_core_ptr<GLRenderTexture>(tex);
  20. }
  21. PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma)
  22. {
  23. // Adjust requested parameters to capabilities
  24. const RenderAPICapabilities& caps = RenderAPICore::instance().getCapabilities();
  25. // Check compressed texture support
  26. // If a compressed format not supported, revert to PF_A8R8G8B8
  27. if(PixelUtil::isCompressed(format) && !caps.hasCapability(RSC_TEXTURE_COMPRESSION_DXT))
  28. {
  29. return PF_A8R8G8B8;
  30. }
  31. // If floating point textures not supported, revert to PF_A8R8G8B8
  32. if(PixelUtil::isFloatingPoint(format) && !caps.hasCapability(RSC_TEXTURE_FLOAT))
  33. {
  34. return PF_A8R8G8B8;
  35. }
  36. // Check if this is a valid rendertarget format
  37. if(usage & TU_RENDERTARGET)
  38. {
  39. /// Get closest supported alternative
  40. /// If mFormat is supported it's returned
  41. return GLRTTManager::instance().getSupportedAlternative(format);
  42. }
  43. return GLPixelUtil::getClosestValidFormat(format);
  44. }
  45. GLTextureCoreManager::GLTextureCoreManager(GLSupport& support)
  46. :mGLSupport(support)
  47. { }
  48. SPtr<TextureCore> GLTextureCoreManager::createTextureInternal(const TEXTURE_DESC& desc,
  49. const SPtr<PixelData>& initialData, GpuDeviceFlags deviceMask)
  50. {
  51. GLTextureCore* tex = new (bs_alloc<GLTextureCore>()) GLTextureCore(mGLSupport, desc, initialData, deviceMask);
  52. SPtr<GLTextureCore> texPtr = bs_shared_ptr<GLTextureCore>(tex);
  53. texPtr->_setThisPtr(texPtr);
  54. return texPtr;
  55. }
  56. SPtr<RenderTextureCore> GLTextureCoreManager::createRenderTextureInternal(const RENDER_TEXTURE_DESC_CORE& desc,
  57. GpuDeviceFlags deviceMask)
  58. {
  59. SPtr<GLRenderTextureCore> texPtr = bs_shared_ptr_new<GLRenderTextureCore>(desc, deviceMask);
  60. texPtr->_setThisPtr(texPtr);
  61. return texPtr;
  62. }
  63. }