BsD3D9RenderTexture.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsD3D9RenderTexture.h"
  4. #include "BsD3D9Texture.h"
  5. #include "BsD3D9PixelBuffer.h"
  6. #include "BsD3D9RenderAPI.h"
  7. #include "BsTextureView.h"
  8. namespace BansheeEngine
  9. {
  10. D3D9RenderTextureCore::D3D9RenderTextureCore(const RENDER_TEXTURE_CORE_DESC& desc)
  11. :RenderTextureCore(desc), mProperties(desc, false), mDX9ColorSurface(nullptr),
  12. mDX9DepthStencilSurface(nullptr), mIsBindableToShader(false)
  13. { }
  14. D3D9RenderTextureCore::~D3D9RenderTextureCore()
  15. { }
  16. void D3D9RenderTextureCore::initialize()
  17. {
  18. RenderTextureCore::initialize();
  19. initializeSurfaces();
  20. }
  21. void D3D9RenderTextureCore::initializeSurfaces()
  22. {
  23. D3D9TextureCore* d3d9texture = static_cast<D3D9TextureCore*>(mColorSurface->getTexture().get());
  24. D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
  25. d3d9texture->getBuffer(mColorSurface->getFirstArraySlice(), mColorSurface->getMostDetailedMip()).get());
  26. mDX9ColorSurface = pixelBuffer->getSurface(D3D9RenderAPI::getActiveD3D9Device());
  27. D3D9TextureCore* d3d9DepthStencil = static_cast<D3D9TextureCore*>(mDepthStencilSurface->getTexture().get());
  28. D3D9PixelBuffer* depthStencilBuffer = static_cast<D3D9PixelBuffer*>(
  29. d3d9DepthStencil->getBuffer(mDepthStencilSurface->getFirstArraySlice(), mDepthStencilSurface->getMostDetailedMip()).get());
  30. mDX9DepthStencilSurface = depthStencilBuffer->getSurface(D3D9RenderAPI::getActiveD3D9Device());
  31. }
  32. void D3D9RenderTextureCore::releaseSurfaces()
  33. {
  34. // All actual releasing happens in the color and depth textures.
  35. mDX9ColorSurface = nullptr;
  36. mDX9DepthStencilSurface = nullptr;
  37. }
  38. void D3D9RenderTextureCore::getCustomAttribute(const String& name, void* pData) const
  39. {
  40. if(name == "DDBACKBUFFER")
  41. {
  42. IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
  43. *pSurf = mDX9ColorSurface;
  44. return;
  45. }
  46. else if(name == "D3DZBUFFER")
  47. {
  48. IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
  49. *pSurf = mDX9DepthStencilSurface;
  50. return;
  51. }
  52. else if(name == "HWND")
  53. {
  54. HWND *pHwnd = (HWND*)pData;
  55. *pHwnd = NULL;
  56. return;
  57. }
  58. }
  59. void D3D9RenderTextureCore::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
  60. {
  61. initializeSurfaces();
  62. }
  63. void D3D9RenderTextureCore::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
  64. {
  65. releaseSurfaces();
  66. }
  67. void D3D9RenderTextureCore::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
  68. {
  69. releaseSurfaces();
  70. }
  71. void D3D9RenderTextureCore::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
  72. {
  73. initializeSurfaces();
  74. }
  75. D3D9RenderTexture::D3D9RenderTexture(const RENDER_TEXTURE_DESC& desc)
  76. :RenderTexture(desc), mProperties(desc, false)
  77. {
  78. }
  79. }