CIndexBuffer.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. video::E_INDEX_TYPE getType() const override
  24. {
  25. static_assert(sizeof(T) == 2 || sizeof(T) == 4, "invalid index type");
  26. return sizeof(T) == 2 ? video::EIT_16BIT : video::EIT_32BIT;
  27. }
  28. const void *getData() const override
  29. {
  30. return Data.data();
  31. }
  32. void *getData() override
  33. {
  34. return Data.data();
  35. }
  36. u32 getCount() const override
  37. {
  38. return static_cast<u32>(Data.size());
  39. }
  40. E_HARDWARE_MAPPING getHardwareMappingHint() const override
  41. {
  42. return MappingHint;
  43. }
  44. void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint) override
  45. {
  46. MappingHint = NewMappingHint;
  47. }
  48. void setDirty() override
  49. {
  50. ++ChangedID;
  51. #ifdef INDEXBUFFER_HINT_DEBUG
  52. if (MappingHint == EHM_STATIC && HWBuffer) {
  53. char buf[100];
  54. snprintf_irr(buf, sizeof(buf), "CIndexBuffer @ %p modified, but it has a static hint", this);
  55. os::Printer::log(buf, ELL_WARNING);
  56. }
  57. #endif
  58. }
  59. u32 getChangedID() const override { return ChangedID; }
  60. void setHWBuffer(void *ptr) const override
  61. {
  62. HWBuffer = ptr;
  63. }
  64. void *getHWBuffer() const override
  65. {
  66. return HWBuffer;
  67. }
  68. u32 ChangedID = 1;
  69. //! hardware mapping hint
  70. E_HARDWARE_MAPPING MappingHint = EHM_NEVER;
  71. mutable void *HWBuffer = nullptr;
  72. //! Indices of this buffer
  73. std::vector<T> Data;
  74. };
  75. //! Standard 16-bit buffer
  76. typedef CIndexBuffer<u16> SIndexBuffer;
  77. } // end namespace scene
  78. } // end namespace irr