Oxygine  1
2g game engine
vertex.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include "math/Vector2.h"
4 
5 namespace oxygine
6 {
7  enum VertexFormatFlags
8  {
9  VERTEX_POSITION = 0x0001,
10  VERTEX_COLOR = 0x0002,
11 
12  VERTEX_LAST_BIT = 8,
13 
14  USER_DATA_SIZE_BIT = VERTEX_LAST_BIT + 4,
15  NUM_TEX_COORD_BIT = VERTEX_LAST_BIT + 7,
16  TEX_COORD_SIZE_BIT = VERTEX_LAST_BIT + 10,
17 
18  USER_DATA_SIZE_MASK = (0x7 << USER_DATA_SIZE_BIT),
19  NUM_TEX_COORD_MASK = (0x7 << NUM_TEX_COORD_BIT),
20  TEX_COORD_SIZE_MASK = (0x7 << TEX_COORD_SIZE_BIT),
21  };
22 
23 #define VERTEX_USERDATA_SIZE(_n) ((_n) << USER_DATA_SIZE_BIT)
24 #define VERTEX_NUM_TEXCOORDS(_n) ((_n) << NUM_TEX_COORD_BIT)
25 #define VERTEX_TEXCOORD_SIZE(_stage, _n) ((_n) << (TEX_COORD_SIZE_BIT + (3*_stage)))
26 
27  typedef unsigned int bvertex_format;
28 
29  inline int vertexFlags(bvertex_format vertexFormat)
30  {
31  return vertexFormat & ((1 << (VERTEX_LAST_BIT + 1)) - 1);
32  }
33 
34  inline int numTextureCoordinates(bvertex_format vertexFormat)
35  {
36  return (vertexFormat >> NUM_TEX_COORD_BIT) & 0x7;
37  }
38 
39  inline int userDataSize(bvertex_format vertexFormat)
40  {
41  return (vertexFormat >> USER_DATA_SIZE_BIT) & 0x7;
42  }
43 
44  inline int texCoordSize(int stage, bvertex_format vertexFormat)
45  {
46  return (vertexFormat >> (TEX_COORD_SIZE_BIT + 3 * stage)) & 0x7;
47  }
48 
49 
50 
51  inline unsigned int getVertexSize(bvertex_format fmt)
52  {
53  int offset = 0;
54 
55  if (fmt & VERTEX_POSITION)
56  {
57  offset += sizeof(float) * 3;
58  }
59 
60  if (fmt & VERTEX_COLOR)
61  {
62  offset += 4;
63  }
64 
65  int numTexCoords = numTextureCoordinates(fmt);
66  for (int j = 0; j < numTexCoords; ++j)
67  {
68  int coordSize = texCoordSize(j, fmt);
69  offset += sizeof(float) * coordSize;
70  }
71 
72  int ds = userDataSize(fmt);
73  if (ds > 0)
74  {
75  offset += sizeof(float) * ds;
76  }
77  return offset;
78  }
79 
80  struct vertexPT2
81  {
82  enum { FORMAT = VERTEX_POSITION | VERTEX_NUM_TEXCOORDS(1) | VERTEX_TEXCOORD_SIZE(0, 2) };
83  float x, y, z;
84  float u, v;
85  };
86 
87  struct vertexP2C
88  {
89  float x, y;
90  unsigned int color;
91 
92  Vector2& getPos() {return *((Vector2*)&x);}
93  };
94 
95  struct vertexPCT2
96  {
97  enum { FORMAT = VERTEX_POSITION | VERTEX_COLOR | VERTEX_NUM_TEXCOORDS(1) | VERTEX_TEXCOORD_SIZE(0, 2) };
98  float x, y, z;
99  unsigned int color;
100  float u, v;
101  };
102 
103  struct vertexPCT2T2 : public vertexPCT2
104  {
105  enum { FORMAT = VERTEX_POSITION | VERTEX_COLOR | VERTEX_NUM_TEXCOORDS(2) | VERTEX_TEXCOORD_SIZE(0, 2) | VERTEX_TEXCOORD_SIZE(1, 2) };
106  float u2, v2;
107  };
108 
109  struct vertexPCT2T2T2 : public vertexPCT2T2
110  {
111  enum { FORMAT = VERTEX_POSITION | VERTEX_COLOR | VERTEX_NUM_TEXCOORDS(3) | VERTEX_TEXCOORD_SIZE(0, 2) | VERTEX_TEXCOORD_SIZE(1, 2) | VERTEX_TEXCOORD_SIZE(2, 2) };
112  float u3, v3;
113  };
114 
115 #define VERTEX_PCT2 vertexPCT2::FORMAT
116 #define VERTEX_PCT2T2 vertexPCT2T2::FORMAT
117 
118 }
Definition: vertex.h:87
Definition: vertex.h:103
–oxgl-end–!
Definition: Actor.h:14
Definition: vertex.h:109
Definition: vertex.h:95
Definition: vertex.h:80