BsD3D9RenderTexture.cpp 2.6 KB

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