D3D9IndexBuffer.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 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 "ArrayPtr.h"
  28. /// Hardware index buffer.
  29. class IndexBuffer : public Object, public GPUObject
  30. {
  31. OBJECT(IndexBuffer);
  32. public:
  33. /// Construct.
  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 all data in the buffer.
  46. bool SetData(const void* data);
  47. /// %Set a data range in the buffer.
  48. bool SetDataRange(const void* data, unsigned start, unsigned count);
  49. /// Lock a data range in the buffer. Return pointer to locked data if successful.
  50. void* Lock(unsigned start, unsigned count, LockMode mode);
  51. /// Unlock buffer.
  52. void Unlock();
  53. /// Clear data lost flag.
  54. void ClearDataLost();
  55. /// Return whether is dynamic.
  56. bool IsDynamic() const;
  57. /// Return whether default pool data lost.
  58. bool IsDataLost() const { return dataLost_; }
  59. /// Return number of indices.
  60. unsigned GetIndexCount() const {return indexCount_; }
  61. /// Return index size.
  62. unsigned GetIndexSize() const { return indexSize_; }
  63. /// Return used vertex range from index range.
  64. bool GetUsedVertexRange(unsigned start, unsigned count, unsigned& minVertex, unsigned& vertexCount);
  65. private:
  66. /// Create buffer.
  67. bool Create();
  68. /// Fallback data when operating with a null graphics subsystem.
  69. SharedArrayPtr<unsigned char> fallbackData_;
  70. /// Memory pool.
  71. unsigned pool_;
  72. /// Usage type.
  73. unsigned usage_;
  74. /// Number of indices.
  75. unsigned indexCount_;
  76. /// Index size.
  77. unsigned indexSize_;
  78. /// Buffer locked flag.
  79. bool locked_;
  80. /// Default pool data lost flag.
  81. bool dataLost_;
  82. };