BsD3D9RenderTexture.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. initializeSurfaces();
  14. }
  15. D3D9RenderTextureCore::~D3D9RenderTextureCore()
  16. {
  17. }
  18. void D3D9RenderTextureCore::initializeSurfaces()
  19. {
  20. D3D9Texture* d3d9texture = static_cast<D3D9Texture*>(mColorSurface->getTexture().get());
  21. D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
  22. d3d9texture->getBuffer(mColorSurface->getFirstArraySlice(), mColorSurface->getMostDetailedMip()).get());
  23. mDX9ColorSurface = pixelBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
  24. D3D9Texture* d3d9DepthStencil = static_cast<D3D9Texture*>(mDepthStencilSurface->getTexture().get());
  25. D3D9PixelBuffer* depthStencilBuffer = static_cast<D3D9PixelBuffer*>(
  26. d3d9DepthStencil->getBuffer(mDepthStencilSurface->getFirstArraySlice(), mDepthStencilSurface->getMostDetailedMip()).get());
  27. mDX9DepthStencilSurface = depthStencilBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
  28. }
  29. void D3D9RenderTextureCore::releaseSurfaces()
  30. {
  31. // All actual releasing happens in the color and depth textures.
  32. mDX9ColorSurface = nullptr;
  33. mDX9DepthStencilSurface = nullptr;
  34. }
  35. void D3D9RenderTextureCore::getCustomAttribute(const String& name, void* pData) const
  36. {
  37. if(name == "DDBACKBUFFER")
  38. {
  39. IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
  40. *pSurf = mDX9ColorSurface;
  41. return;
  42. }
  43. else if(name == "D3DZBUFFER")
  44. {
  45. IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
  46. *pSurf = mDX9DepthStencilSurface;
  47. return;
  48. }
  49. else if(name == "HWND")
  50. {
  51. HWND *pHwnd = (HWND*)pData;
  52. *pHwnd = NULL;
  53. return;
  54. }
  55. }
  56. void D3D9RenderTextureCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
  57. {
  58. initializeSurfaces();
  59. }
  60. void D3D9RenderTextureCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
  61. {
  62. releaseSurfaces();
  63. }
  64. void D3D9RenderTextureCore::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
  65. {
  66. releaseSurfaces();
  67. }
  68. void D3D9RenderTextureCore::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
  69. {
  70. initializeSurfaces();
  71. }
  72. RenderTargetProperties* D3D9RenderTexture::createProperties() const
  73. {
  74. return bs_new<RenderTextureProperties>();
  75. }
  76. RenderTextureCore* D3D9RenderTexture::createCore(RenderTextureProperties* properties, const RENDER_SURFACE_DESC& colorSurfaceDesc,
  77. const RENDER_SURFACE_DESC& depthStencilSurfaceDesc)
  78. {
  79. return bs_new<D3D9RenderTextureCore>(this, properties, colorSurfaceDesc, depthStencilSurfaceDesc);
  80. }
  81. }