BsGLTextureManager.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #include "BsGLTextureManager.h"
  5. #include "BsRenderSystem.h"
  6. #include "BsGLRenderTexture.h"
  7. #include "BsGLMultiRenderTexture.h"
  8. #include "BsGLPixelFormat.h"
  9. namespace BansheeEngine
  10. {
  11. GLTextureManager::GLTextureManager( GLSupport& support)
  12. :TextureManager(), mGLSupport(support)
  13. {
  14. }
  15. GLTextureManager::~GLTextureManager()
  16. {
  17. }
  18. TexturePtr GLTextureManager::createTextureImpl()
  19. {
  20. GLTexture* tex = new (bs_alloc<GLTexture, PoolAlloc>()) GLTexture(mGLSupport);
  21. return bs_core_ptr<GLTexture, PoolAlloc>(tex);
  22. }
  23. RenderTexturePtr GLTextureManager::createRenderTextureImpl()
  24. {
  25. GLRenderTexture* tex = new (bs_alloc<GLRenderTexture, PoolAlloc>()) GLRenderTexture();
  26. return bs_core_ptr<GLRenderTexture, PoolAlloc>(tex);
  27. }
  28. MultiRenderTexturePtr GLTextureManager::createMultiRenderTextureImpl()
  29. {
  30. GLMultiRenderTexture* tex = new (bs_alloc<GLMultiRenderTexture, PoolAlloc>()) GLMultiRenderTexture();
  31. return bs_core_ptr<GLMultiRenderTexture, PoolAlloc>(tex);
  32. }
  33. PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma)
  34. {
  35. // Adjust requested parameters to capabilities
  36. const RenderSystemCapabilities *caps = RenderSystem::instancePtr()->getCapabilities();
  37. // Check compressed texture support
  38. // If a compressed format not supported, revert to PF_A8R8G8B8
  39. if(PixelUtil::isCompressed(format) && !caps->hasCapability(RSC_TEXTURE_COMPRESSION_DXT))
  40. {
  41. return PF_A8R8G8B8;
  42. }
  43. // If floating point textures not supported, revert to PF_A8R8G8B8
  44. if(PixelUtil::isFloatingPoint(format) && !caps->hasCapability(RSC_TEXTURE_FLOAT))
  45. {
  46. return PF_A8R8G8B8;
  47. }
  48. // Check if this is a valid rendertarget format
  49. if( usage & TU_RENDERTARGET )
  50. {
  51. /// Get closest supported alternative
  52. /// If mFormat is supported it's returned
  53. return GLRTTManager::instance().getSupportedAlternative(format);
  54. }
  55. return GLPixelUtil::getClosestValidFormat(format);
  56. }
  57. }