CmGLDefaultHardwareBufferManager.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 __GLDefaultHardwareBufferManager_H__
  25. #define __GLDefaultHardwareBufferManager_H__
  26. #include "CmGLPrerequisites.h"
  27. #include "CmHardwareBufferManager.h"
  28. #include "CmHardwareVertexBuffer.h"
  29. #include "CmHardwareIndexBuffer.h"
  30. namespace CamelotEngine {
  31. /// Specialisation of HardwareVertexBuffer for emulation
  32. class CM_RSGL_EXPORT GLDefaultHardwareVertexBuffer : public HardwareVertexBuffer
  33. {
  34. protected:
  35. unsigned char* mpData;
  36. /// @copydoc HardwareBuffer::lock
  37. void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
  38. /// @copydoc HardwareBuffer::unlock
  39. void unlockImpl(void);
  40. public:
  41. GLDefaultHardwareVertexBuffer(UINT32 vertexSize, UINT32 numVertices, HardwareBuffer::Usage usage);
  42. GLDefaultHardwareVertexBuffer(HardwareBufferManagerBase* mgr, UINT32 vertexSize, UINT32 numVertices,
  43. HardwareBuffer::Usage usage);
  44. ~GLDefaultHardwareVertexBuffer();
  45. /// @copydoc HardwareBuffer::readData
  46. void readData(UINT32 offset, UINT32 length, void* pDest);
  47. /// @copydoc HardwareBuffer::writeData
  48. void writeData(UINT32 offset, UINT32 length, const void* pSource,
  49. bool discardWholeBuffer = false);
  50. /** Override HardwareBuffer to turn off all shadowing. */
  51. void* lock(UINT32 offset, UINT32 length, LockOptions options);
  52. /** Override HardwareBuffer to turn off all shadowing. */
  53. void unlock(void);
  54. //void* getDataPtr(void) const { return (void*)mpData; }
  55. void* getDataPtr(UINT32 offset) const { return (void*)(mpData + offset); }
  56. };
  57. /// Specialisation of HardwareIndexBuffer for emulation
  58. class CM_RSGL_EXPORT GLDefaultHardwareIndexBuffer : public HardwareIndexBuffer
  59. {
  60. protected:
  61. unsigned char* mpData;
  62. /// @copydoc HardwareBuffer::lock
  63. void* lockImpl(UINT32 offset, UINT32 length, LockOptions options);
  64. /// @copydoc HardwareBuffer::unlock
  65. void unlockImpl(void);
  66. public:
  67. GLDefaultHardwareIndexBuffer(IndexType idxType, UINT32 numIndexes, HardwareBuffer::Usage usage);
  68. ~GLDefaultHardwareIndexBuffer();
  69. /// @copydoc HardwareBuffer::readData
  70. void readData(UINT32 offset, UINT32 length, void* pDest);
  71. /// @copydoc HardwareBuffer::writeData
  72. void writeData(UINT32 offset, UINT32 length, const void* pSource,
  73. bool discardWholeBuffer = false);
  74. /** Override HardwareBuffer to turn off all shadowing. */
  75. void* lock(UINT32 offset, UINT32 length, LockOptions options);
  76. /** Override HardwareBuffer to turn off all shadowing. */
  77. void unlock(void);
  78. void* getDataPtr(UINT32 offset) const { return (void*)(mpData + offset); }
  79. };
  80. /** Specialisation of HardwareBufferManager to emulate hardware buffers.
  81. @remarks
  82. You might want to instantiate this class if you want to utilise
  83. classes like MeshSerializer without having initialised the
  84. rendering system (which is required to create a 'real' hardware
  85. buffer manager.
  86. */
  87. class CM_RSGL_EXPORT GLDefaultHardwareBufferManagerBase : public HardwareBufferManagerBase
  88. {
  89. public:
  90. GLDefaultHardwareBufferManagerBase();
  91. ~GLDefaultHardwareBufferManagerBase();
  92. /**
  93. * @copydoc HardwareBufferManagerBase::createVertexBuffer
  94. */
  95. HardwareVertexBufferPtr
  96. createVertexBuffer(UINT32 vertexSize, UINT32 numVerts,
  97. HardwareBuffer::Usage usage, bool streamOut = false);
  98. /**
  99. * @copydoc HardwareBufferManagerBase::createIndexBuffer
  100. */
  101. HardwareIndexBufferPtr
  102. createIndexBuffer(HardwareIndexBuffer::IndexType itype, UINT32 numIndexes,
  103. HardwareBuffer::Usage usage);
  104. /**
  105. * @copydoc HardwareBufferManagerBase::createConstantBuffer
  106. */
  107. HardwareConstantBufferPtr createConstantBuffer(UINT32 sizeBytes, HardwareBuffer::Usage usage);
  108. };
  109. /// GLDefaultHardwareBufferManagerBase as a Singleton
  110. class CM_RSGL_EXPORT GLDefaultHardwareBufferManager : public HardwareBufferManager
  111. {
  112. public:
  113. GLDefaultHardwareBufferManager()
  114. : HardwareBufferManager(new GLDefaultHardwareBufferManagerBase())
  115. {
  116. }
  117. ~GLDefaultHardwareBufferManager()
  118. {
  119. delete mImpl;
  120. }
  121. };
  122. }
  123. #endif