CmD3D9PixelBuffer.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include "CmD3D9Prerequisites.h"
  3. #include "CmPixelBuffer.h"
  4. namespace BansheeEngine
  5. {
  6. class BS_D3D9_EXPORT D3D9PixelBuffer : public PixelBuffer
  7. {
  8. protected:
  9. struct BufferResources
  10. {
  11. /// Surface abstracted by this buffer
  12. IDirect3DSurface9* surface;
  13. /// Volume abstracted by this buffer
  14. IDirect3DVolume9* volume;
  15. /// Temporary surface in main memory if direct locking of mSurface is not possible
  16. IDirect3DSurface9* tempSurface;
  17. /// Temporary volume in main memory if direct locking of mVolume is not possible
  18. IDirect3DVolume9* tempVolume;
  19. /// Mip map texture.
  20. IDirect3DBaseTexture9 *mipTex;
  21. };
  22. public:
  23. D3D9PixelBuffer(GpuBufferUsage usage, D3D9Texture* ownerTexture);
  24. ~D3D9PixelBuffer();
  25. /// Call this to associate a D3D surface or volume with this pixel buffer
  26. void bind(IDirect3DDevice9* dev, IDirect3DSurface9* mSurface,
  27. bool writeGamma, UINT32 multisampleCount, const String& srcName, IDirect3DBaseTexture9* mipTex);
  28. void bind(IDirect3DDevice9* dev, IDirect3DVolume9* mVolume, IDirect3DBaseTexture9* mipTex);
  29. /// Internal function to update mipmaps on update of level 0
  30. void genMipmaps(IDirect3DBaseTexture9* mipTex);
  31. /// Function to set mipmap generation
  32. void setMipmapping(bool doMipmapGen, bool HWMipmaps);
  33. /// Accessor for surface
  34. IDirect3DSurface9 *getSurface(IDirect3DDevice9* d3d9Device);
  35. /// Release surfaces held by this pixel buffer.
  36. void releaseSurfaces(IDirect3DDevice9* d3d9Device);
  37. /// Destroy resources associated with the given device.
  38. void destroyBufferResources(IDirect3DDevice9* d3d9Device);
  39. // Called when device state is changing. Access to any device should be locked.
  40. // Relevant for multi thread application.
  41. static void lockDeviceAccess();
  42. // Called when device state change completed. Access to any device is allowed.
  43. // Relevant for multi thread application.
  44. static void unlockDeviceAccess();
  45. protected:
  46. /// Lock a box
  47. PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options);
  48. PixelData lockBuffer(BufferResources* bufferResources, const PixelVolume& lockBox, DWORD flags);
  49. /// Unlock a box
  50. void unlockImpl();
  51. void unlockBuffer(BufferResources* bufferResources);
  52. BufferResources* getBufferResources(IDirect3DDevice9* d3d9Device);
  53. BufferResources* createBufferResources();
  54. void blit(IDirect3DDevice9* d3d9Device, const PixelBufferPtr& src, const PixelVolume& srcBox, const PixelVolume& dstBox,
  55. BufferResources* srcBufferResources, BufferResources* dstBufferResources);
  56. void blitFromMemory(const PixelData& src, const PixelVolume& dstBox, BufferResources* dstBufferResources);
  57. void blitToMemory(const PixelVolume& srcBox, const PixelData& dst, BufferResources* srcBufferResources, IDirect3DDevice9* d3d9Device);
  58. protected:
  59. /// Map between device to buffer resources.
  60. Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
  61. /// Mipmapping
  62. bool mDoMipmapGen;
  63. bool mHWMipmaps;
  64. // The owner texture if exists.
  65. D3D9Texture* mOwnerTexture;
  66. // The current lock flags of this surface.
  67. DWORD mLockFlags;
  68. };
  69. };