IndexBuffer.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  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. #pragma once
  24. #include "GPUObject.h"
  25. #include "Object.h"
  26. #include "GraphicsDefs.h"
  27. #include "SharedArrayPtr.h"
  28. /// Hardware index buffer
  29. class IndexBuffer : public Object, public GPUObject
  30. {
  31. OBJECT(IndexBuffer);
  32. public:
  33. /// Construct with graphics subsystem pointer and whether is dynamic or not
  34. IndexBuffer(Context* context);
  35. /// Destruct
  36. virtual ~IndexBuffer();
  37. /// Release default pool resources
  38. virtual void OnDeviceLost();
  39. /// Recreate default pool resources
  40. virtual void OnDeviceReset();
  41. /// Release buffer
  42. virtual void Release();
  43. /// Set buffer size and dynamic mode. Previous data will be lost
  44. bool SetSize(unsigned indexCount, bool largeIndices, bool dynamic = false);
  45. /// Set buffer size and dynamic mode. Previous data will be lost
  46. bool SetSize(unsigned indexCount, unsigned indexSize, bool dynamic = false);
  47. /// Set all data in the buffer,
  48. bool SetData(const void* data);
  49. /// Set a data range in the buffer
  50. bool SetDataRange(const void* data, unsigned start, unsigned count);
  51. /// Lock a data range in the buffer. Return pointer to locked data if successful
  52. void* Lock(unsigned start, unsigned count, LockMode mode);
  53. /// Unlock buffer
  54. void Unlock();
  55. /// Clear data lost flag
  56. void ClearDataLost();
  57. /// Return whether is dynamic
  58. bool IsDynamic() const;
  59. /// Return whether default pool data lost
  60. bool IsDataLost() const { return dataLost_; }
  61. /// Return number of indices
  62. unsigned GetIndexCount() const {return indexCount_; }
  63. /// Return index size
  64. unsigned GetIndexSize() const { return indexSize_; }
  65. /// Return used vertex range from index range
  66. bool GetUsedVertexRange(unsigned start, unsigned count, unsigned& minVertex, unsigned& vertexCount);
  67. private:
  68. /// Create buffer
  69. bool Create();
  70. /// Fallback data when operating with a null graphics
  71. SharedArrayPtr<unsigned char> fallbackData_;
  72. /// Memory pool
  73. unsigned pool_;
  74. /// Usage type
  75. unsigned usage_;
  76. /// Number of indices
  77. unsigned indexCount_;
  78. /// Index size
  79. unsigned indexSize_;
  80. /// Buffer locked flag
  81. bool locked_;
  82. /// Default pool data lost flag
  83. bool dataLost_;
  84. };