CmD3D9HardwareIndexBuffer.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __D3D9HARDWAREINDEXBUFFER_H__
  25. #define __D3D9HARDWAREINDEXBUFFER_H__
  26. #include "CmD3D9Prerequisites.h"
  27. #include "CmHardwareIndexBuffer.h"
  28. #include "CmD3D9Resource.h"
  29. namespace CamelotEngine {
  30. class _OgreD3D9Export D3D9HardwareIndexBuffer : public HardwareIndexBuffer, public D3D9Resource
  31. {
  32. public:
  33. D3D9HardwareIndexBuffer(HardwareBufferManagerBase* mgr, IndexType idxType, size_t numIndexes,
  34. HardwareBuffer::Usage usage, bool useSystemMem, bool useShadowBuffer);
  35. ~D3D9HardwareIndexBuffer();
  36. /** See HardwareBuffer. */
  37. void readData(size_t offset, size_t length, void* pDest);
  38. /** See HardwareBuffer. */
  39. void writeData(size_t offset, size_t length, const void* pSource,
  40. bool discardWholeBuffer = false);
  41. // Called immediately after the Direct3D device has been created.
  42. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  43. // Called before the Direct3D device is going to be destroyed.
  44. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  45. // Called immediately after the Direct3D device has entered a lost state.
  46. virtual void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device);
  47. // Called immediately after the Direct3D device has been reset
  48. virtual void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
  49. // Create the actual index buffer.
  50. void createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool);
  51. /// Get the D3D-specific index buffer
  52. IDirect3DIndexBuffer9* getD3DIndexBuffer(void);
  53. protected:
  54. struct BufferResources
  55. {
  56. IDirect3DIndexBuffer9* mBuffer;
  57. bool mOutOfDate;
  58. size_t mLockOffset;
  59. size_t mLockLength;
  60. LockOptions mLockOptions;
  61. UINT32 mLastUsedFrame;
  62. };
  63. protected:
  64. /** See HardwareBuffer. */
  65. void* lockImpl(size_t offset, size_t length, LockOptions options);
  66. /** See HardwareBuffer. */
  67. void unlockImpl(void);
  68. // updates buffer resources from system memory buffer.
  69. bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);
  70. protected:
  71. typedef map<IDirect3DDevice9*, BufferResources*>::type DeviceToBufferResourcesMap;
  72. typedef DeviceToBufferResourcesMap::iterator DeviceToBufferResourcesIterator;
  73. DeviceToBufferResourcesMap mMapDeviceToBufferResources; // Map between device to buffer resources.
  74. D3DINDEXBUFFER_DESC mBufferDesc; // Buffer description.
  75. char* mSystemMemoryBuffer; // Consistent system memory buffer for multiple devices support.
  76. };
  77. }
  78. #endif