BsD3D9RenderTexture.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "BsD3D9RenderTexture.h"
  2. #include "BsD3D9Texture.h"
  3. #include "BsD3D9PixelBuffer.h"
  4. #include "BsD3D9RenderSystem.h"
  5. #include "BsTextureView.h"
  6. namespace BansheeEngine
  7. {
  8. D3D9RenderTextureCore::D3D9RenderTextureCore(D3D9RenderTexture* parent, RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
  9. const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
  10. :RenderTextureCore(parent, properties, colorSurfaceDesc, depthStencilSurfaceDesc), mDX9ColorSurface(nullptr),
  11. mDX9DepthStencilSurface(nullptr), mIsBindableToShader(false)
  12. { }
  13. D3D9RenderTextureCore::~D3D9RenderTextureCore()
  14. { }
  15. void D3D9RenderTextureCore::initialize()
  16. {
  17. RenderTextureCore::initialize();
  18. initializeSurfaces();
  19. }
  20. void D3D9RenderTextureCore::initializeSurfaces()
  21. {
  22. D3D9Texture* d3d9texture = static_cast<D3D9Texture*>(mColorSurface->getTexture().get());
  23. D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
  24. d3d9texture->getBuffer(mColorSurface->getFirstArraySlice(), mColorSurface->getMostDetailedMip()).get());
  25. mDX9ColorSurface = pixelBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
  26. D3D9Texture* d3d9DepthStencil = static_cast<D3D9Texture*>(mDepthStencilSurface->getTexture().get());
  27. D3D9PixelBuffer* depthStencilBuffer = static_cast<D3D9PixelBuffer*>(
  28. d3d9DepthStencil->getBuffer(mDepthStencilSurface->getFirstArraySlice(), mDepthStencilSurface->getMostDetailedMip()).get());
  29. mDX9DepthStencilSurface = depthStencilBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
  30. }
  31. void D3D9RenderTextureCore::releaseSurfaces()
  32. {
  33. // All actual releasing happens in the color and depth textures.
  34. mDX9ColorSurface = nullptr;
  35. mDX9DepthStencilSurface = nullptr;
  36. }
  37. void D3D9RenderTextureCore::getCustomAttribute(const String& name, void* pData) const
  38. {
  39. if(name == "DDBACKBUFFER")
  40. {
  41. IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
  42. *pSurf = mDX9ColorSurface;
  43. return;
  44. }
  45. else if(name == "D3DZBUFFER")
  46. {
  47. IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
  48. *pSurf = mDX9DepthStencilSurface;
  49. return;
  50. }
  51. else if(name == "HWND")
  52. {
  53. HWND *pHwnd = (HWND*)pData;
  54. *pHwnd = NULL;
  55. return;
  56. }
  57. }
  58. void D3D9RenderTextureCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
  59. {
  60. initializeSurfaces();
  61. }
  62. void D3D9RenderTextureCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
  63. {
  64. releaseSurfaces();
  65. }
  66. void D3D9RenderTextureCore::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
  67. {
  68. releaseSurfaces();
  69. }
  70. void D3D9RenderTextureCore::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
  71. {
  72. initializeSurfaces();
  73. }
  74. RenderTargetProperties* D3D9RenderTexture::createProperties() const
  75. {
  76. return bs_new<RenderTextureProperties>();
  77. }
  78. SPtr<CoreObjectCore> D3D9RenderTexture::createCore() const
  79. {
  80. RenderTextureProperties* coreProperties = bs_new<RenderTextureProperties>();
  81. RenderTextureProperties* myProperties = static_cast<RenderTextureProperties*>(mProperties);
  82. *coreProperties = *myProperties;
  83. return bs_shared_ptr<D3D9RenderTextureCore>(const_cast<D3D9RenderTexture*>(this),
  84. coreProperties, mColorSurfaceDesc, mDepthStencilSurfaceDesc);
  85. }
  86. }