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