BsD3D9MultiRenderTexture.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "BsD3D9MultiRenderTexture.h"
  2. #include "BsD3D9Texture.h"
  3. #include "BsD3D9RenderSystem.h"
  4. namespace BansheeEngine
  5. {
  6. D3D9MultiRenderTextureCore::D3D9MultiRenderTextureCore(D3D9MultiRenderTexture* parent, MultiRenderTextureProperties* properties, const MULTI_RENDER_TEXTURE_DESC& desc)
  7. :MultiRenderTextureCore(parent, properties, desc), mDX9DepthStencilSurface(nullptr)
  8. { }
  9. D3D9MultiRenderTextureCore::~D3D9MultiRenderTextureCore()
  10. { }
  11. void D3D9MultiRenderTextureCore::initialize()
  12. {
  13. MultiRenderTextureCore::initialize();
  14. mDX9ColorSurfaces.resize(mColorSurfaces.size());
  15. for (size_t i = 0; i < mColorSurfaces.size(); i++)
  16. {
  17. if (mColorSurfaces[i] != nullptr)
  18. {
  19. D3D9Texture* d3d9texture = static_cast<D3D9Texture*>(mColorSurfaces[i]->getTexture().get());
  20. if (d3d9texture->getTextureType() != TEX_TYPE_3D)
  21. {
  22. D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
  23. d3d9texture->getBuffer(mColorSurfaces[i]->getDesc().firstArraySlice, mColorSurfaces[i]->getDesc().mostDetailMip).get());
  24. mDX9ColorSurfaces[i] = pixelBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
  25. }
  26. else
  27. mDX9ColorSurfaces[i] = nullptr;
  28. }
  29. else
  30. {
  31. mDX9ColorSurfaces[i] = nullptr;
  32. }
  33. }
  34. if (mDepthStencilSurface != nullptr)
  35. {
  36. D3D9Texture* d3d9DepthStencil = static_cast<D3D9Texture*>(mDepthStencilSurface->getTexture().get());
  37. if (d3d9DepthStencil->getTextureType() != TEX_TYPE_3D)
  38. {
  39. D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
  40. d3d9DepthStencil->getBuffer(mDepthStencilSurface->getDesc().firstArraySlice, mDepthStencilSurface->getDesc().mostDetailMip).get());
  41. mDX9DepthStencilSurface = pixelBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
  42. }
  43. else
  44. mDX9DepthStencilSurface = nullptr;
  45. }
  46. else
  47. {
  48. mDX9DepthStencilSurface = nullptr;
  49. }
  50. }
  51. void D3D9MultiRenderTextureCore::getCustomAttribute(const String& name, void* pData) const
  52. {
  53. if(name == "DDBACKBUFFER")
  54. {
  55. IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
  56. for(size_t x = 0; x < mDX9ColorSurfaces.size(); ++x)
  57. pSurf[x] = mDX9ColorSurfaces[x];
  58. return;
  59. }
  60. else if(name == "D3DZBUFFER")
  61. {
  62. IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
  63. *pSurf = mDX9DepthStencilSurface;
  64. return;
  65. }
  66. else if(name == "HWND")
  67. {
  68. HWND *pHwnd = (HWND*)pData;
  69. *pHwnd = NULL;
  70. return;
  71. }
  72. }
  73. RenderTargetProperties* D3D9MultiRenderTexture::createProperties() const
  74. {
  75. return bs_new<MultiRenderTextureProperties>();
  76. }
  77. CoreObjectCore* D3D9MultiRenderTexture::createCore() const
  78. {
  79. MultiRenderTextureProperties* coreProperties = bs_new<MultiRenderTextureProperties>();
  80. MultiRenderTextureProperties* myProperties = static_cast<MultiRenderTextureProperties*>(mProperties);
  81. *coreProperties = *myProperties;
  82. return bs_new<D3D9MultiRenderTextureCore>(const_cast<D3D9MultiRenderTexture*>(this),
  83. coreProperties, mDesc);
  84. }
  85. }