BsTextureManager.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, GenAlloc>(tex);
  13. ret->_setThisPtr(ret);
  14. ret->initialize();
  15. return ret;
  16. }
  17. TexturePtr TextureManager::_createEmpty()
  18. {
  19. Texture* tex = new (bs_alloc<Texture>()) Texture();
  20. TexturePtr texture = bs_core_ptr<Texture, GenAlloc>(tex);
  21. texture->_setThisPtr(texture);
  22. return texture;
  23. }
  24. RenderTexturePtr TextureManager::createRenderTexture(TextureType textureType, UINT32 width, UINT32 height,
  25. PixelFormat format, bool hwGamma, UINT32 multisampleCount,
  26. bool createDepth, PixelFormat depthStencilFormat)
  27. {
  28. TexturePtr texture = createTexture(textureType, width, height, 0, format, TU_RENDERTARGET, hwGamma, multisampleCount);
  29. TexturePtr depthStencil = nullptr;
  30. if(createDepth)
  31. {
  32. depthStencil = createTexture(TEX_TYPE_2D, width, height, 0, depthStencilFormat, TU_DEPTHSTENCIL, false, multisampleCount);
  33. }
  34. RENDER_TEXTURE_DESC desc;
  35. desc.colorSurface.texture = texture;
  36. desc.colorSurface.face = 0;
  37. desc.colorSurface.mipLevel = 0;
  38. desc.depthStencilSurface.texture = depthStencil;
  39. desc.depthStencilSurface.face = 0;
  40. desc.depthStencilSurface.mipLevel = 0;
  41. RenderTexturePtr newRT = createRenderTexture(desc);
  42. return newRT;
  43. }
  44. RenderTexturePtr TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC& desc)
  45. {
  46. RenderTexturePtr newRT = createRenderTextureImpl(desc);
  47. newRT->_setThisPtr(newRT);
  48. newRT->initialize();
  49. return newRT;
  50. }
  51. MultiRenderTexturePtr TextureManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
  52. {
  53. MultiRenderTexturePtr newRT = createMultiRenderTextureImpl(desc);
  54. newRT->_setThisPtr(newRT);
  55. newRT->initialize();
  56. return newRT;
  57. }
  58. SPtr<TextureCore> TextureCoreManager::createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
  59. int numMips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 multisampleCount)
  60. {
  61. SPtr<TextureCore> newRT = createTextureInternal(texType, width, height, depth, numMips, format, usage, hwGammaCorrection, multisampleCount);
  62. newRT->initialize();
  63. return newRT;
  64. }
  65. SPtr<RenderTextureCore> TextureCoreManager::createRenderTexture(const RENDER_TEXTURE_DESC& desc)
  66. {
  67. SPtr<RenderTextureCore> newRT = createRenderTextureInternal(desc);
  68. newRT->initialize();
  69. return newRT;
  70. }
  71. SPtr<MultiRenderTextureCore> TextureCoreManager::createMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
  72. {
  73. SPtr<MultiRenderTextureCore> newRT = createMultiRenderTextureInternal(desc);
  74. newRT->initialize();
  75. return newRT;
  76. }
  77. }