BsD3D9PixelBuffer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsD3D9Prerequisites.h"
  5. #include "BsPixelBuffer.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup D3D9
  9. * @{
  10. */
  11. /** DirectX9 implementation of a pixel buffer. Represents a hardware buffer containing a surface of pixels. */
  12. class BS_D3D9_EXPORT D3D9PixelBuffer : public PixelBuffer
  13. {
  14. protected:
  15. /** Internal DX9 buffer resources container. */
  16. struct BufferResources
  17. {
  18. IDirect3DSurface9* surface;
  19. IDirect3DVolume9* volume;
  20. IDirect3DSurface9* tempSurface;
  21. IDirect3DVolume9* tempVolume;
  22. IDirect3DBaseTexture9* mipTex;
  23. };
  24. public:
  25. D3D9PixelBuffer(GpuBufferUsage usage, D3D9TextureCore* ownerTexture);
  26. ~D3D9PixelBuffer();
  27. /**
  28. * Binds the specified surface object to this buffer. This needs to be called in order to initialize the pixel
  29. * buffer.
  30. *
  31. * @param[in] dev Device the surface was created on.
  32. * @param[in] surface DirectX 9 object representing the surface.
  33. * @param[in] mipTex Base texture that will be used for generating mipmaps. Usually the parent texture of
  34. * the surface.
  35. */
  36. void bind(IDirect3DDevice9* dev, IDirect3DSurface9* surface, IDirect3DBaseTexture9* mipTex);
  37. /**
  38. * Binds the specified volume object to this buffer. This needs to be called in order to initialize the pixel
  39. * buffer.
  40. *
  41. * @param[in] dev Device the volume was created on.
  42. * @param[in] volume DirectX 9 object representing the volume.
  43. * @param[in] mipTex Base texture that will be used for generating mipmaps. Usually the parent texture of
  44. * the volume.
  45. */
  46. void bind(IDirect3DDevice9* dev, IDirect3DVolume9* volume, IDirect3DBaseTexture9* mipTex);
  47. /**
  48. * Enables/disabled automatic mipmap generation on updates.
  49. *
  50. * @param[in] doMipmapGen If true, mipmaps will be regenerated whenever data is written to the buffer.
  51. * @param[in] HWMipmaps If true the mipmaps will be generated by the hardware, otherwise software (slower).
  52. */
  53. void setMipmapping(bool doMipmapGen, bool HWMipmaps);
  54. /** Returns internal DirectX 9 surface object for this buffer. */
  55. IDirect3DSurface9* getSurface(IDirect3DDevice9* d3d9Device);
  56. /** Release all surface objects held by this buffer for the specified device. */
  57. void releaseSurfaces(IDirect3DDevice9* d3d9Device);
  58. /** Destroy all resources associated with the specified device. */
  59. void destroyBufferResources(IDirect3DDevice9* d3d9Device);
  60. /** Called when device state is changing. Access to any device should be locked. */
  61. static void lockDeviceAccess();
  62. /** Called when device state change completed. Access to any device is allowed. */
  63. static void unlockDeviceAccess();
  64. /** Initializes the provided pixel data buffer with information provided in the D3D9 locked rectangle. */
  65. static void initPixelDataFromD3DLock(PixelData& pixelData, const D3DLOCKED_RECT& lrect);
  66. /** Initializes the provided pixel data buffer with information provided in the D3D9 locked box. */
  67. static void initPixelDataFromD3DLock(PixelData& pixelData, const D3DLOCKED_BOX& lrect);
  68. protected:
  69. /** @copydoc PixelBuffer::lockImpl */
  70. PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options) override;
  71. /** @copydoc PixelBuffer::unlockImpl */
  72. void unlockImpl() override;
  73. /**
  74. * Locks the specified volume of the provided buffer objects and returns a data buffer that you may use to access
  75. * it.
  76. */
  77. PixelData lockBuffer(BufferResources* bufferResources, const PixelVolume& lockBox, DWORD flags);
  78. /** Unlocks the specified buffer objects. */
  79. void unlockBuffer(BufferResources* bufferResources);
  80. /** Generates mip-map chain for the specified texture. */
  81. void genMipmaps(IDirect3DBaseTexture9* mipTex);
  82. /** Retrieves buffer resources for the specified device, or null if they do not exist. */
  83. BufferResources* getBufferResources(IDirect3DDevice9* d3d9Device);
  84. /** Creates a new empty set of buffer resources. */
  85. BufferResources* createBufferResources();
  86. protected:
  87. Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
  88. bool mDoMipmapGen;
  89. bool mHWMipmaps;
  90. D3D9TextureCore* mOwnerTexture;
  91. DWORD mLockFlags;
  92. };
  93. /** @} */
  94. };