BsGLHardwareBufferManager.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include "BsGLPrerequisites.h"
  3. #include "BsHardwareBufferManager.h"
  4. namespace BansheeEngine {
  5. // Default threshold at which glMapBuffer becomes more efficient than glBufferSubData (32k?)
  6. # define BS_GL_DEFAULT_MAP_BUFFER_THRESHOLD (1024 * 32)
  7. /** Implementation of HardwareBufferManager for OpenGL. */
  8. class BS_RSGL_EXPORT GLHardwareBufferManager : public HardwareBufferManager
  9. {
  10. public:
  11. GLHardwareBufferManager();
  12. ~GLHardwareBufferManager();
  13. /// Utility function to get the correct GL usage based on HBU's
  14. static GLenum getGLUsage(unsigned int usage);
  15. /// Utility function to get the correct GL type based on VET's
  16. static GLenum getGLType(unsigned int type);
  17. /** Allocator method to allow us to use a pool of memory as a scratch
  18. area for hardware buffers. This is because glMapBuffer is incredibly
  19. inefficient, seemingly no matter what options we give it. So for the
  20. period of lock/unlock, we will instead allocate a section of a local
  21. memory pool, and use glBufferSubDataARB / glGetBufferSubDataARB
  22. instead.
  23. */
  24. void* allocateScratch(UINT32 size);
  25. /// @see allocateScratch
  26. void deallocateScratch(void* ptr);
  27. /** Threshold after which glMapBuffer is used and not glBufferSubData
  28. */
  29. const UINT32 getGLMapBufferThreshold() const;
  30. void setGLMapBufferThreshold( const UINT32 value );
  31. protected:
  32. char* mScratchBufferPool;
  33. BS_MUTEX(mScratchMutex);
  34. UINT32 mMapBufferThreshold;
  35. /**
  36. * @copydoc HardwareBufferManager::createVertexBufferImpl
  37. */
  38. VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize,
  39. UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
  40. /**
  41. * @copydoc HardwareBufferManager::createIndexBufferImpl
  42. */
  43. IndexBufferPtr createIndexBufferImpl(
  44. IndexBuffer::IndexType itype, UINT32 numIndexes,
  45. GpuBufferUsage usage);
  46. /** @copydoc HardwareBufferManager::createGpuParamBlockBufferImpl */
  47. GpuParamBlockBufferPtr createGpuParamBlockBufferImpl();
  48. /**
  49. * @copydoc HardwareBufferManager::createGenericBufferImpl
  50. *
  51. * OpenGL does not support generic buffers so this method will return a dummy instance.
  52. */
  53. GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize,
  54. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
  55. };
  56. }