CVertexBuffer.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 "IVertexBuffer.h"
  7. // Define to receive warnings when violating the hw mapping hints
  8. //#define VERTEXBUFFER_HINT_DEBUG
  9. #ifdef VERTEXBUFFER_HINT_DEBUG
  10. #include "../src/os.h"
  11. #endif
  12. namespace irr
  13. {
  14. namespace scene
  15. {
  16. //! Template implementation of the IVertexBuffer interface
  17. template <class T>
  18. class CVertexBuffer final : public IVertexBuffer
  19. {
  20. public:
  21. //! Default constructor for empty buffer
  22. CVertexBuffer() {}
  23. const void *getData() const override
  24. {
  25. return Data.data();
  26. }
  27. void *getData() override
  28. {
  29. return Data.data();
  30. }
  31. u32 getCount() const override
  32. {
  33. return static_cast<u32>(Data.size());
  34. }
  35. video::E_VERTEX_TYPE getType() const override
  36. {
  37. return T::getType();
  38. }
  39. const core::vector3df &getPosition(u32 i) const override
  40. {
  41. return Data[i].Pos;
  42. }
  43. core::vector3df &getPosition(u32 i) override
  44. {
  45. return Data[i].Pos;
  46. }
  47. const core::vector3df &getNormal(u32 i) const override
  48. {
  49. return Data[i].Normal;
  50. }
  51. core::vector3df &getNormal(u32 i) override
  52. {
  53. return Data[i].Normal;
  54. }
  55. const core::vector2df &getTCoords(u32 i) const override
  56. {
  57. return Data[i].TCoords;
  58. }
  59. core::vector2df &getTCoords(u32 i) override
  60. {
  61. return Data[i].TCoords;
  62. }
  63. E_HARDWARE_MAPPING getHardwareMappingHint() const override
  64. {
  65. return MappingHint;
  66. }
  67. void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint) override
  68. {
  69. MappingHint = NewMappingHint;
  70. }
  71. void setDirty() override
  72. {
  73. ++ChangedID;
  74. #ifdef VERTEXBUFFER_HINT_DEBUG
  75. if (MappingHint == EHM_STATIC && HWBuffer) {
  76. char buf[100];
  77. snprintf_irr(buf, sizeof(buf), "CVertexBuffer @ %p modified, but it has a static hint", this);
  78. os::Printer::log(buf, ELL_WARNING);
  79. }
  80. #endif
  81. }
  82. u32 getChangedID() const override { return ChangedID; }
  83. void setHWBuffer(void *ptr) const override
  84. {
  85. HWBuffer = ptr;
  86. }
  87. void *getHWBuffer() const override
  88. {
  89. return HWBuffer;
  90. }
  91. u32 ChangedID = 1;
  92. //! hardware mapping hint
  93. E_HARDWARE_MAPPING MappingHint = EHM_NEVER;
  94. mutable void *HWBuffer = nullptr;
  95. //! Vertices of this buffer
  96. std::vector<T> Data;
  97. };
  98. //! Standard buffer
  99. typedef CVertexBuffer<video::S3DVertex> SVertexBuffer;
  100. //! Buffer with two texture coords per vertex, e.g. for lightmaps
  101. typedef CVertexBuffer<video::S3DVertex2TCoords> SVertexBufferLightMap;
  102. //! Buffer with vertices having tangents stored, e.g. for normal mapping
  103. typedef CVertexBuffer<video::S3DVertexTangents> SVertexBufferTangents;
  104. } // end namespace scene
  105. } // end namespace irr