MeshPart.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef MESHPART_H_
  2. #define MESHPART_H_
  3. #include "Base.h"
  4. #include "Object.h"
  5. #include "Vertex.h"
  6. namespace gameplay
  7. {
  8. class MeshPart : public Object
  9. {
  10. public:
  11. enum PrimitiveType
  12. {
  13. TRIANGLES = 4, // GL_TRIANGLES
  14. TRIANGLE_STRIP = 5, // GL_TRIANGLE_STRIP
  15. LINES = 1, // GL_LINES
  16. LINE_STRIP = 3, // GL_LINE_STRIP
  17. POINTS = 0 // GL_POINTS
  18. };
  19. enum IndexFormat
  20. {
  21. INDEX16 = 0x1403, // GL_UNSIGNED_SHORT
  22. INDEX32 = 0x1405 // GL_UNSIGNED_INT
  23. };
  24. /**
  25. * Constructor.
  26. */
  27. MeshPart(void);
  28. /**
  29. * Destructor.
  30. */
  31. virtual ~MeshPart(void);
  32. virtual unsigned int getTypeId(void) const;
  33. virtual const char* getElementName(void) const;
  34. virtual void writeBinary(FILE* file);
  35. virtual void writeText(FILE* file);
  36. /**
  37. * Adds an index to the list of indices.
  38. */
  39. void addIndex(unsigned int index);
  40. /**
  41. * Returns the number of indices.
  42. */
  43. size_t getIndicesCount() const;
  44. /**
  45. * Returns the index format.
  46. */
  47. IndexFormat getIndexFormat() const;
  48. /**
  49. * Gets the value of the index at the specificied location.
  50. */
  51. unsigned int getIndex(unsigned int i) const;
  52. private:
  53. /**
  54. * Returns the size of the indices array in bytes.
  55. */
  56. unsigned int indicesByteSize() const;
  57. /**
  58. * Returns the size of an index.
  59. */
  60. unsigned int indexFormatSize() const;
  61. /**
  62. * Updates the index format if newIndex is larger than 256 or 65536.
  63. */
  64. void updateIndexFormat(unsigned int newIndex);
  65. /**
  66. * Writes the index to the binary file stream.
  67. * The number of bytes written depends on indexFormat.
  68. */
  69. void writeBinaryIndex(unsigned int index, FILE* file);
  70. private:
  71. unsigned int _primitiveType;
  72. IndexFormat _indexFormat;
  73. std::vector<unsigned int> _indices;
  74. };
  75. }
  76. #endif