BsGLTextureManager.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. SPtr<GLTextureCore> texPtr = bs_shared_ptr<GLTextureCore, GenAlloc>(tex);
  58. texPtr->_setThisPtr(texPtr);
  59. return texPtr;
  60. }
  61. SPtr<RenderTextureCore> GLTextureCoreManager::createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc)
  62. {
  63. SPtr<GLRenderTextureCore> texPtr = bs_shared_ptr<GLRenderTextureCore>(desc);
  64. texPtr->_setThisPtr(texPtr);
  65. return texPtr;
  66. }
  67. SPtr<MultiRenderTextureCore> GLTextureCoreManager::createMultiRenderTextureInternal(const MULTI_RENDER_TEXTURE_DESC& desc)
  68. {
  69. SPtr<GLMultiRenderTextureCore> texPtr = bs_shared_ptr<GLMultiRenderTextureCore>(desc);
  70. texPtr->_setThisPtr(texPtr);
  71. return texPtr;
  72. }
  73. }