BsD3D9RenderTexture.cpp 2.7 KB

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