2
0

BsGLTextureManager.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. RenderTexturePtr GLTextureManager::createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc)
  16. {
  17. GLRenderTexture* tex = new (bs_alloc<GLRenderTexture, PoolAlloc>()) GLRenderTexture(desc);
  18. return bs_core_ptr<GLRenderTexture, PoolAlloc>(tex);
  19. }
  20. MultiRenderTexturePtr GLTextureManager::createMultiRenderTextureImpl(const MULTI_RENDER_TEXTURE_DESC& desc)
  21. {
  22. GLMultiRenderTexture* tex = new (bs_alloc<GLMultiRenderTexture, PoolAlloc>()) GLMultiRenderTexture(desc);
  23. return bs_core_ptr<GLMultiRenderTexture, PoolAlloc>(tex);
  24. }
  25. PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma)
  26. {
  27. // Adjust requested parameters to capabilities
  28. const RenderSystemCapabilities *caps = RenderSystem::instancePtr()->getCapabilities();
  29. // Check compressed texture support
  30. // If a compressed format not supported, revert to PF_A8R8G8B8
  31. if(PixelUtil::isCompressed(format) && !caps->hasCapability(RSC_TEXTURE_COMPRESSION_DXT))
  32. {
  33. return PF_A8R8G8B8;
  34. }
  35. // If floating point textures not supported, revert to PF_A8R8G8B8
  36. if(PixelUtil::isFloatingPoint(format) && !caps->hasCapability(RSC_TEXTURE_FLOAT))
  37. {
  38. return PF_A8R8G8B8;
  39. }
  40. // Check if this is a valid rendertarget format
  41. if( usage & TU_RENDERTARGET )
  42. {
  43. /// Get closest supported alternative
  44. /// If mFormat is supported it's returned
  45. return GLRTTManager::instance().getSupportedAlternative(format);
  46. }
  47. return GLPixelUtil::getClosestValidFormat(format);
  48. }
  49. GLTextureCoreManager::GLTextureCoreManager(GLSupport& support)
  50. :mGLSupport(support)
  51. { }
  52. SPtr<TextureCore> GLTextureCoreManager::createTextureInternal(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  53. int numMips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 multisampleCount)
  54. {
  55. GLTextureCore* tex = new (bs_alloc<GLTextureCore>()) GLTextureCore(mGLSupport, texType,
  56. width, height, depth, numMips, format, usage, hwGammaCorrection, multisampleCount);
  57. return bs_shared_ptr<GLTextureCore, GenAlloc>(tex);
  58. }
  59. SPtr<RenderTextureCore> GLTextureCoreManager::createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc)
  60. {
  61. return bs_shared_ptr<GLRenderTextureCore>(desc);
  62. }
  63. SPtr<MultiRenderTextureCore> GLTextureCoreManager::createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_DESC& desc)
  64. {
  65. return bs_shared_ptr<GLMultiRenderTextureCore>(desc);
  66. }
  67. }