Pioneer
GeoPatchContext.h
Go to the documentation of this file.
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 {
24  };
25 
26  GeoPatchContext(const int _edgeLen)
27  {
28  m_edgeLen = _edgeLen + 2; // +2 for the skirt
29  Init();
30  }
31 
32  static void Refresh()
33  {
34  Init();
35  }
36 
37  static void Init();
38 
39  static inline Graphics::IndexBuffer *GetIndexBuffer() { return m_indices.Get(); }
40 
41  static inline int NUMVERTICES() { return m_edgeLen * m_edgeLen; }
42 
43  static inline int GetEdgeLen() { return m_edgeLen; }
44  static inline int GetNumTris() { return m_numTris; }
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 
53  static inline int VBO_COUNT_HI_EDGE() { return 3 * (m_edgeLen - 1); }
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 
57  static inline int IDX_VBO_LO_OFFSET(const int i) { return i * sizeof(Uint32) * 3 * (m_edgeLen / 2); }
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 */
Definition: GeoPatchContext.h:17
GeoPatchContext(const int _edgeLen)
Definition: GeoPatchContext.h:26
static int NUMVERTICES()
Definition: GeoPatchContext.h:41
static void Refresh()
Definition: GeoPatchContext.h:32
static int GetEdgeLen()
Definition: GeoPatchContext.h:43
static int GetNumTris()
Definition: GeoPatchContext.h:44
static void Init()
Definition: GeoPatchContext.cpp:82
static Graphics::IndexBuffer * GetIndexBuffer()
Definition: GeoPatchContext.h:39
static double GetFrac()
Definition: GeoPatchContext.h:45
Definition: VertexBuffer.h:114
Definition: RefCounted.h:11
T * Get() const
Definition: SmartPtr.h:37
Definition: Color.h:66
Definition: GeoPatchContext.h:19
vector3f norm
Definition: GeoPatchContext.h:21
vector2f uv
Definition: GeoPatchContext.h:23
Color4ub col
Definition: GeoPatchContext.h:22
vector3f pos
Definition: GeoPatchContext.h:20