BsGLTextureManager.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(const RENDER_TEXTURE_DESC& desc)
  21. {
  22. GLRenderTexture* tex = new (bs_alloc<GLRenderTexture, PoolAlloc>()) GLRenderTexture(desc);
  23. return bs_core_ptr<GLRenderTexture, PoolAlloc>(tex);
  24. }
  25. MultiRenderTexturePtr GLTextureManager::createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc)
  26. {
  27. GLMultiRenderTexture* tex = new (bs_alloc<GLMultiRenderTexture, PoolAlloc>()) GLMultiRenderTexture(desc);
  28. return bs_core_ptr<GLMultiRenderTexture, PoolAlloc>(tex);
  29. }
  30. PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma)
  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. GLTextureCoreManager::GLTextureCoreManager(GLSupport& support)
  55. :mGLSupport(support)
  56. { }
  57. SPtr<RenderTextureCore> GLTextureCoreManager::createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc)
  58. {
  59. return bs_shared_ptr<GLRenderTextureCore>(desc);
  60. }
  61. SPtr<MultiRenderTextureCore> GLTextureCoreManager::createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_DESC& desc)
  62. {
  63. return bs_shared_ptr<GLMultiRenderTextureCore>(desc);
  64. }
  65. }