BsTextureManager.cpp 3.6 KB

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