BsD3D9PixelBuffer.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #pragma once
  2. #include "BsD3D9Prerequisites.h"
  3. #include "BsPixelBuffer.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief DirectX9 implementation of a pixel buffer. Represents a hardware buffer
  8. * containing a surface of pixels.
  9. */
  10. class BS_D3D9_EXPORT D3D9PixelBuffer : public PixelBuffer
  11. {
  12. protected:
  13. /**
  14. * @brief Internal DX9 buffer resources container.
  15. */
  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. * @brief Binds the specified surface object to this buffer. This needs to be called in order
  29. * to initialize the pixel buffer.
  30. *
  31. * @param dev Device the surface was created on.
  32. * @param surface DirectX 9 object representing the surface.
  33. * @param mipTex Base texture that will be used for generating mipmaps. Usually
  34. * the parent texture of the surface.
  35. */
  36. void bind(IDirect3DDevice9* dev, IDirect3DSurface9* surface, IDirect3DBaseTexture9* mipTex);
  37. /**
  38. * @brief Binds the specified volume object to this buffer. This needs to be called in order
  39. * to initialize the pixel buffer.
  40. *
  41. * @param dev Device the volume was created on.
  42. * @param surface DirectX 9 object representing the volume.
  43. * @param mipTex Base texture that will be used for generating mipmaps. Usually
  44. * the parent texture of the volume.
  45. */
  46. void bind(IDirect3DDevice9* dev, IDirect3DVolume9* volume, IDirect3DBaseTexture9* mipTex);
  47. /**
  48. * @brief Enables/disabled automatic mipmap generation on updates.
  49. *
  50. * @param doMipmapGen If true, mipmaps will be regenerated whenever data is written to the buffer.
  51. * @param HWMipmaps If true the mipmaps will be generated by the hardware, otherwise software (slower).
  52. */
  53. void setMipmapping(bool doMipmapGen, bool HWMipmaps);
  54. /**
  55. * @brief Returns internal DirectX 9 surface object for this buffer.
  56. */
  57. IDirect3DSurface9* getSurface(IDirect3DDevice9* d3d9Device);
  58. /**
  59. * @brief Release all surface objects held by this buffer for the specified device.
  60. */
  61. void releaseSurfaces(IDirect3DDevice9* d3d9Device);
  62. /**
  63. * @brief Destroy all resources associated with the specified device.
  64. */
  65. void destroyBufferResources(IDirect3DDevice9* d3d9Device);
  66. /**
  67. * @brief Called when device state is changing. Access to any device should be locked.
  68. */
  69. static void lockDeviceAccess();
  70. /**
  71. * @brief Called when device state change completed. Access to any device is allowed.
  72. */
  73. static void unlockDeviceAccess();
  74. /**
  75. * @brief Initializes the provided pixel data buffer with information provided in the D3D9 locked rectangle.
  76. */
  77. static void initPixelDataFromD3DLock(PixelData& pixelData, const D3DLOCKED_RECT& lrect);
  78. /**
  79. * @brief Initializes the provided pixel data buffer with information provided in the D3D9 locked box.
  80. */
  81. static void initPixelDataFromD3DLock(PixelData& pixelData, const D3DLOCKED_BOX& lrect);
  82. protected:
  83. /**
  84. * @copydoc PixelBuffer::lockImpl
  85. */
  86. PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options);
  87. /**
  88. * @copydoc PixelBuffer::unlockImpl
  89. */
  90. void unlockImpl();
  91. /**
  92. * @brief Locks the specified volume of the provided buffer objects and
  93. * returns a data buffer that you may use to access it.
  94. */
  95. PixelData lockBuffer(BufferResources* bufferResources, const PixelVolume& lockBox, DWORD flags);
  96. /**
  97. * @brief Unlocks the specified buffer objects.
  98. */
  99. void unlockBuffer(BufferResources* bufferResources);
  100. /**
  101. * @brief Generates mip-map chain for the specified texture.
  102. */
  103. void genMipmaps(IDirect3DBaseTexture9* mipTex);
  104. /**
  105. * @brief Retrieves buffer resources for the specified device, or null if they
  106. * do not exist.
  107. */
  108. BufferResources* getBufferResources(IDirect3DDevice9* d3d9Device);
  109. /**
  110. * @brief Creates a new empty set of buffer resources.
  111. */
  112. BufferResources* createBufferResources();
  113. protected:
  114. Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
  115. bool mDoMipmapGen;
  116. bool mHWMipmaps;
  117. D3D9TextureCore* mOwnerTexture;
  118. DWORD mLockFlags;
  119. };
  120. };