BsGLTextureManager.cpp 2.0 KB

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