1 // Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details 2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt 3 4 #ifndef _GEOPATCHCONTEXT_H 5 #define _GEOPATCHCONTEXT_H 6 7 #include <SDL_stdinc.h> 8 9 #include "vector3.h" 10 #include "graphics/VertexBuffer.h" 11 12 #include <deque> 13 14 // maximumpatch depth 15 #define GEOPATCH_MAX_DEPTH 15 16 17 class GeoPatchContext : public RefCounted { 18 public: 19 struct VBOVertex { 20 vector3f pos; 21 vector3f norm; 22 Color4ub col; 23 vector2f uv; 24 }; 25 GeoPatchContext(const int _edgeLen)26 GeoPatchContext(const int _edgeLen) 27 { 28 m_edgeLen = _edgeLen + 2; // +2 for the skirt 29 Init(); 30 } 31 Refresh()32 static void Refresh() 33 { 34 Init(); 35 } 36 37 static void Init(); 38 GetIndexBuffer()39 static inline Graphics::IndexBuffer *GetIndexBuffer() { return m_indices.Get(); } 40 NUMVERTICES()41 static inline int NUMVERTICES() { return m_edgeLen * m_edgeLen; } 42 GetEdgeLen()43 static inline int GetEdgeLen() { return m_edgeLen; } GetNumTris()44 static inline int GetNumTris() { return m_numTris; } GetFrac()45 static inline double GetFrac() { return m_frac; } 46 47 private: 48 static int m_edgeLen; 49 static int m_numTris; 50 51 static double m_frac; 52 VBO_COUNT_HI_EDGE()53 static inline int VBO_COUNT_HI_EDGE() { return 3 * (m_edgeLen - 1); } VBO_COUNT_MID_IDX()54 static inline int VBO_COUNT_MID_IDX() { return (4 * 3 * (m_edgeLen - 3)) + 2 * (m_edgeLen - 3) * (m_edgeLen - 3) * 3; } 55 // ^^ serrated teeth bit ^^^ square inner bit 56 IDX_VBO_LO_OFFSET(const int i)57 static inline int IDX_VBO_LO_OFFSET(const int i) { return i * sizeof(Uint32) * 3 * (m_edgeLen / 2); } IDX_VBO_HI_OFFSET(const int i)58 static inline int IDX_VBO_HI_OFFSET(const int i) { return (i * sizeof(Uint32) * VBO_COUNT_HI_EDGE()) + IDX_VBO_LO_OFFSET(4); } 59 60 static RefCountedPtr<Graphics::IndexBuffer> m_indices; 61 static int m_prevEdgeLen; 62 63 static void GenerateIndices(); 64 65 }; 66 67 #endif /* _GEOPATCHCONTEXT_H */ 68