BsTextureManager.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "BsTextureManager.h"
  2. #include "BsException.h"
  3. #include "BsPixelUtil.h"
  4. #include "BsMultiRenderTexture.h"
  5. #include "BsRenderAPI.h"
  6. namespace BansheeEngine
  7. {
  8. TexturePtr TextureManager::createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
  9. PixelFormat format, int usage, bool hwGamma, UINT32 multisampleCount)
  10. {
  11. Texture* tex = new (bs_alloc<Texture>()) Texture(texType, width, height, depth, numMipmaps, format, usage, hwGamma, multisampleCount);
  12. TexturePtr ret = bs_core_ptr<Texture>(tex);
  13. ret->_setThisPtr(ret);
  14. ret->initialize();
  15. return ret;
  16. }
  17. TexturePtr TextureManager::createTexture(const PixelDataPtr& pixelData, int usage , bool hwGammaCorrection)
  18. {
  19. Texture* tex = new (bs_alloc<Texture>()) Texture(pixelData, usage, hwGammaCorrection);
  20. TexturePtr ret = bs_core_ptr<Texture>(tex);
  21. ret->_setThisPtr(ret);
  22. ret->initialize();
  23. return ret;
  24. }
  25. TexturePtr TextureManager::_createEmpty()
  26. {
  27. Texture* tex = new (bs_alloc<Texture>()) Texture();
  28. TexturePtr texture = bs_core_ptr<Texture>(tex);
  29. texture->_setThisPtr(texture);
  30. return texture;
  31. }
  32. RenderTexturePtr TextureManager::createRenderTexture(TextureType textureType, UINT32 width, UINT32 height,
  33. PixelFormat format, bool hwGamma, UINT32 multisampleCount,
  34. bool createDepth, PixelFormat depthStencilFormat)
  35. {
  36. HTexture texture = Texture::create(textureType, width, height, 0, format, TU_RENDERTARGET, hwGamma, multisampleCount);
  37. HTexture depthStencil;
  38. if(createDepth)
  39. {
  40. depthStencil = Texture::create(TEX_TYPE_2D, width, height, 0, depthStencilFormat, TU_DEPTHSTENCIL, false, multisampleCount);
  41. }
  42. RENDER_TEXTURE_DESC desc;
  43. desc.colorSurface.texture = texture;
  44. desc.colorSurface.face = 0;
  45. desc.colorSurface.mipLevel = 0;
  46. desc.depthStencilSurface.texture = depthStencil;
  47. desc.depthStencilSurface.face = 0;
  48. desc.depthStencilSurface.mipLevel = 0;
  49. RenderTexturePtr newRT = createRenderTexture(desc);
  50. return newRT;
  51. }
  52. RenderTexturePtr TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC& desc)
  53. {
  54. RenderTexturePtr newRT = createRenderTextureImpl(desc);
  55. newRT->_setThisPtr(newRT);
  56. newRT->initialize();
  57. return newRT;
  58. }
  59. MultiRenderTexturePtr TextureManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
  60. {
  61. MultiRenderTexturePtr newRT = createMultiRenderTextureImpl(desc);
  62. newRT->_setThisPtr(newRT);
  63. newRT->initialize();
  64. return newRT;
  65. }
  66. SPtr<TextureCore> TextureCoreManager::createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  67. int numMips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 multisampleCount)
  68. {
  69. SPtr<TextureCore> newRT = createTextureInternal(texType, width, height, depth, numMips, format, usage, hwGammaCorrection, multisampleCount);
  70. newRT->initialize();
  71. return newRT;
  72. }
  73. SPtr<RenderTextureCore> TextureCoreManager::createRenderTexture(const RENDER_TEXTURE_CORE_DESC& desc)
  74. {
  75. SPtr<RenderTextureCore> newRT = createRenderTextureInternal(desc);
  76. newRT->initialize();
  77. return newRT;
  78. }
  79. SPtr<MultiRenderTextureCore> TextureCoreManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_CORE_DESC& desc)
  80. {
  81. SPtr<MultiRenderTextureCore> newRT = createMultiRenderTextureInternal(desc);
  82. newRT->initialize();
  83. return newRT;
  84. }
  85. }