BsD3D9RenderTexture.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. D3D9RenderTexture::D3D9RenderTexture()
  9. :mDX9ColorSurface(nullptr), mDX9DepthStencilSurface(nullptr), mIsBindableToShader(false)
  10. {
  11. }
  12. D3D9RenderTexture::~D3D9RenderTexture()
  13. {
  14. }
  15. void D3D9RenderTexture::initialize_internal()
  16. {
  17. initializeSurfaces();
  18. RenderTexture::initialize_internal();
  19. }
  20. void D3D9RenderTexture::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 D3D9RenderTexture::releaseSurfaces()
  32. {
  33. // All actual releasing happens in the color and depth textures.
  34. mDX9ColorSurface = nullptr;
  35. mDX9DepthStencilSurface = nullptr;
  36. }
  37. void D3D9RenderTexture::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 D3D9RenderTexture::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
  59. {
  60. initializeSurfaces();
  61. }
  62. void D3D9RenderTexture::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
  63. {
  64. releaseSurfaces();
  65. }
  66. void D3D9RenderTexture::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
  67. {
  68. releaseSurfaces();
  69. }
  70. void D3D9RenderTexture::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
  71. {
  72. initializeSurfaces();
  73. }
  74. }