BsD3D9RenderTexture.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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* data) const
  39. {
  40. if(name == "DDBACKBUFFER")
  41. {
  42. IDirect3DSurface9** surf = (IDirect3DSurface9**)data;
  43. *surf = mDX9ColorSurface;
  44. }
  45. else if(name == "D3DZBUFFER")
  46. {
  47. IDirect3DSurface9** surf = (IDirect3DSurface9**)data;
  48. *surf = mDX9DepthStencilSurface;
  49. }
  50. else if(name == "HWND")
  51. {
  52. HWND* hWnd = (HWND*)data;
  53. *hWnd = nullptr;
  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. D3D9RenderTexture::D3D9RenderTexture(const RENDER_TEXTURE_DESC& desc)
  73. :RenderTexture(desc), mProperties(desc, false)
  74. {
  75. }
  76. }