CmGLDefaultHardwareBufferManager.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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(size_t offset, size_t length, LockOptions options);
  38. /// @copydoc HardwareBuffer::unlock
  39. void unlockImpl(void);
  40. public:
  41. GLDefaultHardwareVertexBuffer(size_t vertexSize, size_t numVertices, HardwareBuffer::Usage usage);
  42. GLDefaultHardwareVertexBuffer(HardwareBufferManagerBase* mgr, size_t vertexSize, size_t numVertices,
  43. HardwareBuffer::Usage usage);
  44. ~GLDefaultHardwareVertexBuffer();
  45. /// @copydoc HardwareBuffer::readData
  46. void readData(size_t offset, size_t length, void* pDest);
  47. /// @copydoc HardwareBuffer::writeData
  48. void writeData(size_t offset, size_t length, const void* pSource,
  49. bool discardWholeBuffer = false);
  50. /** Override HardwareBuffer to turn off all shadowing. */
  51. void* lock(size_t offset, size_t 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(size_t 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(size_t offset, size_t length, LockOptions options);
  64. /// @copydoc HardwareBuffer::unlock
  65. void unlockImpl(void);
  66. public:
  67. GLDefaultHardwareIndexBuffer(IndexType idxType, size_t numIndexes, HardwareBuffer::Usage usage);
  68. ~GLDefaultHardwareIndexBuffer();
  69. /// @copydoc HardwareBuffer::readData
  70. void readData(size_t offset, size_t length, void* pDest);
  71. /// @copydoc HardwareBuffer::writeData
  72. void writeData(size_t offset, size_t length, const void* pSource,
  73. bool discardWholeBuffer = false);
  74. /** Override HardwareBuffer to turn off all shadowing. */
  75. void* lock(size_t offset, size_t length, LockOptions options);
  76. /** Override HardwareBuffer to turn off all shadowing. */
  77. void unlock(void);
  78. void* getDataPtr(size_t 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. /// Creates a vertex buffer
  93. HardwareVertexBufferPtr
  94. createVertexBuffer(size_t vertexSize, size_t numVerts,
  95. HardwareBuffer::Usage usage, bool useShadowBuffer = false);
  96. /// Create a hardware vertex buffer
  97. HardwareIndexBufferPtr
  98. createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes,
  99. HardwareBuffer::Usage usage, bool useShadowBuffer = false);
  100. };
  101. /// GLDefaultHardwareBufferManagerBase as a Singleton
  102. class CM_RSGL_EXPORT GLDefaultHardwareBufferManager : public HardwareBufferManager
  103. {
  104. public:
  105. GLDefaultHardwareBufferManager()
  106. : HardwareBufferManager(new GLDefaultHardwareBufferManagerBase())
  107. {
  108. }
  109. ~GLDefaultHardwareBufferManager()
  110. {
  111. delete mImpl;
  112. }
  113. };
  114. }
  115. #endif