2
0

CmGLHardwareBufferManager.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 __GLHARWAREBUFFERMANAGER_H__
  25. #define __GLHARWAREBUFFERMANAGER_H__
  26. #include "CmGLPrerequisites.h"
  27. #include "CmHardwareBufferManager.h"
  28. namespace CamelotFramework {
  29. // Default threshold at which glMapBuffer becomes more efficient than glBufferSubData (32k?)
  30. # define CM_GL_DEFAULT_MAP_BUFFER_THRESHOLD (1024 * 32)
  31. /** Implementation of HardwareBufferManager for OpenGL. */
  32. class CM_RSGL_EXPORT GLHardwareBufferManager : public HardwareBufferManager
  33. {
  34. public:
  35. GLHardwareBufferManager();
  36. ~GLHardwareBufferManager();
  37. /// Utility function to get the correct GL usage based on HBU's
  38. static GLenum getGLUsage(unsigned int usage);
  39. /// Utility function to get the correct GL type based on VET's
  40. static GLenum getGLType(unsigned int type);
  41. /** Allocator method to allow us to use a pool of memory as a scratch
  42. area for hardware buffers. This is because glMapBuffer is incredibly
  43. inefficient, seemingly no matter what options we give it. So for the
  44. period of lock/unlock, we will instead allocate a section of a local
  45. memory pool, and use glBufferSubDataARB / glGetBufferSubDataARB
  46. instead.
  47. */
  48. void* allocateScratch(UINT32 size);
  49. /// @see allocateScratch
  50. void deallocateScratch(void* ptr);
  51. /** Threshold after which glMapBuffer is used and not glBufferSubData
  52. */
  53. const UINT32 getGLMapBufferThreshold() const;
  54. void setGLMapBufferThreshold( const UINT32 value );
  55. protected:
  56. char* mScratchBufferPool;
  57. CM_MUTEX(mScratchMutex);
  58. UINT32 mMapBufferThreshold;
  59. /**
  60. * @copydoc HardwareBufferManager::createVertexBufferImpl
  61. */
  62. VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize,
  63. UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
  64. /**
  65. * @copydoc HardwareBufferManager::createIndexBufferImpl
  66. */
  67. IndexBufferPtr createIndexBufferImpl(
  68. IndexBuffer::IndexType itype, UINT32 numIndexes,
  69. GpuBufferUsage usage);
  70. /** @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl */
  71. GpuParamBlockBufferPtr createGpuParamBlockBufferImpl();
  72. /**
  73. * @copydoc HardwareBufferManager::createGenericBufferImpl
  74. *
  75. * OpenGL does not support generic buffers so this method will return a dummy instance.
  76. */
  77. GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize,
  78. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
  79. };
  80. }
  81. #endif // __GLHARWAREBUFFERMANAGER_H__