CmHardwareBufferManager.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 __HardwareBufferManager__
  25. #define __HardwareBufferManager__
  26. // Precompiler options
  27. #include "CmPrerequisites.h"
  28. #include "CmModule.h"
  29. #include "CmVertexBuffer.h"
  30. #include "CmIndexBuffer.h"
  31. #include "CmGpuParamBlock.h"
  32. namespace CamelotFramework {
  33. /** \addtogroup Core
  34. * @{
  35. */
  36. /** \addtogroup RenderSystem
  37. * @{
  38. */
  39. /** Base definition of a hardware buffer manager.
  40. */
  41. class CM_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
  42. {
  43. public:
  44. HardwareBufferManager();
  45. virtual ~HardwareBufferManager();
  46. /** Create a hardware vertex buffer.
  47. @remarks
  48. This method creates a new vertex buffer; this will act as a source of geometry
  49. data for rendering objects. Note that because the meaning of the contents of
  50. the vertex buffer depends on the usage, this method does not specify a
  51. vertex format; the user of this buffer can actually insert whatever data
  52. they wish, in any format. However, in order to use this with a RenderOperation,
  53. the data in this vertex buffer will have to be associated with a semantic element
  54. of the rendering pipeline, e.g. a position, or texture coordinates. This is done
  55. using the VertexDeclaration class, which itself contains VertexElement structures
  56. referring to the source data.
  57. @remarks Note that because vertex buffers can be shared, they are reference
  58. counted so you do not need to worry about destroying themm this will be done
  59. automatically.
  60. @param vertexSize The size in bytes of each vertex in this buffer; you must calculate
  61. this based on the kind of data you expect to populate this buffer with.
  62. @param numVerts The number of vertices in this buffer.
  63. @param usage One or more members of the HardwareBuffer::Usage enumeration; you are
  64. strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to
  65. update regularly, consider HBU_DYNAMIC_WRITE_ONLY and useShadowBuffer=true.
  66. @param streamOut Whether the vertex buffer will be used for steam out operations of the
  67. geometry shader.
  68. */
  69. virtual VertexBufferPtr
  70. createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
  71. /** Create a hardware index buffer.
  72. @remarks Note that because buffers can be shared, they are reference
  73. counted so you do not need to worry about destroying them this will be done
  74. automatically.
  75. @param itype The type in index, either 16- or 32-bit, depending on how many vertices
  76. you need to be able to address
  77. @param numIndexes The number of indexes in the buffer
  78. @param usage One or more members of the HardwareBuffer::Usage enumeration.
  79. */
  80. virtual IndexBufferPtr
  81. createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
  82. /**
  83. * @brief Creates an GPU parameter block that you can use for setting parameters
  84. * for GPU programs.
  85. *
  86. * @return The new GPU parameter block.
  87. */
  88. virtual GpuParamBlockBufferPtr createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  89. /**
  90. * @brief Creates a generic buffer that can be passed as a parameter to a shader.
  91. *
  92. * @param elementCount Number of elements in the buffer.
  93. * @param elementSize Size of each individual element in the buffer, in bytes.
  94. * @param type Type of the buffer.
  95. * @param usage Determines how will the buffer be used.
  96. * @param randomGpuWrite (optional) Allows the GPU to write to the resource.
  97. * @param useCounter (optional) Binds a counter that can be used from a shader to the buffer.
  98. *
  99. * Be aware that some of these settings cannot be used together, and you will receive an assert if in debug mode.
  100. */
  101. virtual GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize,
  102. GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
  103. /** Creates a new vertex declaration. */
  104. virtual VertexDeclarationPtr createVertexDeclaration();
  105. protected:
  106. virtual VertexDeclarationPtr createVertexDeclarationImpl();
  107. virtual VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
  108. virtual IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
  109. virtual GpuParamBlockBufferPtr createGpuParamBlockBufferImpl() = 0;
  110. virtual GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage,
  111. bool randomGpuWrite = false, bool useCounter = false) = 0;
  112. };
  113. /** @} */
  114. /** @} */
  115. }
  116. #endif