1
0

CIndexBuffer.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include <vector>
  6. #include "IIndexBuffer.h"
  7. // Define to receive warnings when violating the hw mapping hints
  8. //#define INDEXBUFFER_HINT_DEBUG
  9. #ifdef INDEXBUFFER_HINT_DEBUG
  10. #include "../src/os.h"
  11. #endif
  12. namespace irr
  13. {
  14. namespace scene
  15. {
  16. //! Template implementation of the IIndexBuffer interface
  17. template <class T>
  18. class CIndexBuffer final : public IIndexBuffer
  19. {
  20. public:
  21. //! Default constructor for empty buffer
  22. CIndexBuffer()
  23. {
  24. #ifdef _DEBUG
  25. setDebugName("CIndexBuffer");
  26. #endif
  27. }
  28. video::E_INDEX_TYPE getType() const override
  29. {
  30. static_assert(sizeof(T) == 2 || sizeof(T) == 4, "invalid index type");
  31. return sizeof(T) == 2 ? video::EIT_16BIT : video::EIT_32BIT;
  32. }
  33. const void *getData() const override
  34. {
  35. return Data.data();
  36. }
  37. void *getData() override
  38. {
  39. return Data.data();
  40. }
  41. u32 getCount() const override
  42. {
  43. return static_cast<u32>(Data.size());
  44. }
  45. E_HARDWARE_MAPPING getHardwareMappingHint() const override
  46. {
  47. return MappingHint;
  48. }
  49. void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint) override
  50. {
  51. MappingHint = NewMappingHint;
  52. }
  53. void setDirty() override
  54. {
  55. ++ChangedID;
  56. #ifdef INDEXBUFFER_HINT_DEBUG
  57. if (MappingHint == EHM_STATIC && HWBuffer) {
  58. char buf[100];
  59. snprintf_irr(buf, sizeof(buf), "CIndexBuffer @ %p modified, but it has a static hint", this);
  60. os::Printer::log(buf, ELL_WARNING);
  61. }
  62. #endif
  63. }
  64. u32 getChangedID() const override { return ChangedID; }
  65. void setHWBuffer(void *ptr) const override
  66. {
  67. HWBuffer = ptr;
  68. }
  69. void *getHWBuffer() const override
  70. {
  71. return HWBuffer;
  72. }
  73. u32 ChangedID = 1;
  74. //! hardware mapping hint
  75. E_HARDWARE_MAPPING MappingHint = EHM_NEVER;
  76. mutable void *HWBuffer = nullptr;
  77. //! Indices of this buffer
  78. std::vector<T> Data;
  79. };
  80. //! Standard 16-bit buffer
  81. typedef CIndexBuffer<u16> SIndexBuffer;
  82. } // end namespace scene
  83. } // end namespace irr