Skip to content

Commit 091804c

Browse files
committed
UPBGE: Use RAS_VertexFormatType to specify format in RAS_VertexData template.
Instead using two parameters to intanciate the RAS_VertexData template class, one struct is used: RAS_VertexFormatType, this struct also include the enum for the uv and color size.
1 parent 2cc0d9e commit 091804c

File tree

6 files changed

+22
-45
lines changed

6 files changed

+22
-45
lines changed

source/gameengine/Rasterizer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ set(SRC
126126
RAS_TextUser.h
127127
RAS_Vertex.h
128128
RAS_VertexData.h
129+
RAS_VertexFormat.h
129130
)
130131

131132
data_to_c_simple(RAS_OpenGLFilters/RAS_Blur2DFilter.glsl SRC)

source/gameengine/Rasterizer/RAS_IBatchDisplayArray.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RAS_IBatchDisplayArray::~RAS_IBatchDisplayArray()
3838

3939
#define NEW_DISPLAY_ARRAY_UV(vertformat, uv, color, primtype) \
4040
if (vertformat.uvSize == uv && vertformat.colorSize == color) { \
41-
return new RAS_BatchDisplayArray<RAS_VertexData<uv, color> >(primtype, vertformat); \
41+
return new RAS_BatchDisplayArray<RAS_VertexData<RAS_VertexFormatType<uv, color> > >(primtype, vertformat); \
4242
}
4343

4444
#define NEW_DISPLAY_ARRAY_COLOR(vertformat, color, primtype) \

source/gameengine/Rasterizer/RAS_IDisplayArray.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ RAS_IDisplayArray::~RAS_IDisplayArray()
8484

8585
#define NEW_DISPLAY_ARRAY_UV(vertformat, uv, color, primtype) \
8686
if (vertformat.uvSize == uv && vertformat.colorSize == color) { \
87-
return new RAS_DisplayArray<RAS_VertexData<uv, color> >(primtype, vertformat); \
87+
return new RAS_DisplayArray<RAS_VertexData<RAS_VertexFormatType<uv, color> > >(primtype, vertformat); \
8888
}
8989

9090
#define NEW_DISPLAY_ARRAY_COLOR(vertformat, color, primtype) \

source/gameengine/Rasterizer/RAS_Vertex.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@
3131

3232
#include "RAS_Vertex.h"
3333

34-
bool operator== (const RAS_VertexFormat& format1, const RAS_VertexFormat& format2)
35-
{
36-
return (format1.uvSize == format2.uvSize && format1.colorSize == format2.colorSize);
37-
}
38-
39-
bool operator!= (const RAS_VertexFormat& format1, const RAS_VertexFormat& format2)
40-
{
41-
return !(format1 == format2);
42-
}
43-
4434
RAS_VertexInfo::RAS_VertexInfo(unsigned int origindex, bool flat)
4535
:m_origindex(origindex)
4636
{

source/gameengine/Rasterizer/RAS_Vertex.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,6 @@
3333

3434
#include "BLI_math_vector.h"
3535

36-
/// Struct used to pass the vertex format to functions.
37-
struct RAS_VertexFormat
38-
{
39-
uint8_t uvSize;
40-
uint8_t colorSize;
41-
};
42-
43-
/// Operators used to compare the contents (uv size, color size, ...) of two vertex formats.
44-
bool operator== (const RAS_VertexFormat& format1, const RAS_VertexFormat& format2);
45-
bool operator!= (const RAS_VertexFormat& format1, const RAS_VertexFormat& format2);
46-
4736
class RAS_VertexInfo
4837
{
4938
public:

source/gameengine/Rasterizer/RAS_VertexData.h

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "mathfu.h"
55

6+
#include "RAS_VertexFormat.h"
7+
68
#include "BLI_math_vector.h"
79

810
struct RAS_VertexDataBasic
@@ -28,32 +30,32 @@ struct RAS_VertexDataBasic
2830
}
2931
};
3032

31-
template <unsigned short uvSize, unsigned short colorSize>
33+
template <class Format>
3234
struct RAS_VertexDataExtra
3335
{
34-
float uvs[uvSize][2];
35-
unsigned int colors[colorSize];
36+
float uvs[Format::UvSize][2];
37+
unsigned int colors[Format::ColorSize];
3638

3739
inline RAS_VertexDataExtra() = default;
3840

39-
inline RAS_VertexDataExtra(const mt::vec2 _uvs[uvSize], const unsigned int _colors[colorSize])
41+
inline RAS_VertexDataExtra(const mt::vec2 _uvs[Format::UvSize], const unsigned int _colors[Format::ColorSize])
4042
{
41-
for (unsigned short i = 0; i < uvSize; ++i) {
43+
for (unsigned short i = 0; i < Format::UvSize; ++i) {
4244
_uvs[i].Pack(uvs[i]);
4345
}
4446

45-
for (unsigned short i = 0; i < colorSize; ++i) {
47+
for (unsigned short i = 0; i < Format::ColorSize; ++i) {
4648
colors[i] = _colors[i];
4749
}
4850
}
4951

50-
inline RAS_VertexDataExtra(const float _uvs[uvSize][2], const unsigned int _colors[colorSize])
52+
inline RAS_VertexDataExtra(const float _uvs[Format::UvSize][2], const unsigned int _colors[Format::ColorSize])
5153
{
52-
for (unsigned short i = 0; i < uvSize; ++i) {
54+
for (unsigned short i = 0; i < Format::UvSize; ++i) {
5355
copy_v2_v2(uvs[i], _uvs[i]);
5456
}
5557

56-
for (unsigned short i = 0; i < colorSize; ++i) {
58+
for (unsigned short i = 0; i < Format::ColorSize; ++i) {
5759
colors[i] = _colors[i];
5860
}
5961
}
@@ -86,33 +88,28 @@ struct RAS_VertexDataMemoryFormat
8688
uint8_t size;
8789
};
8890

89-
template <unsigned short uvSize, unsigned short colorSize>
90-
struct RAS_VertexData : RAS_IVertexData, RAS_VertexDataExtra<uvSize, colorSize>
91+
template <class Format>
92+
struct RAS_VertexData : RAS_IVertexData, RAS_VertexDataExtra<Format>
9193
{
92-
enum {
93-
UvSize = uvSize,
94-
ColorSize = colorSize
95-
};
96-
9794
inline RAS_VertexData() = default;
9895

9996
inline RAS_VertexData(const mt::vec3& _position,
100-
const mt::vec2 _uvs[uvSize],
97+
const mt::vec2 _uvs[Format::UvSize],
10198
const mt::vec4& _tangent,
102-
const unsigned int _colors[colorSize],
99+
const unsigned int _colors[Format::ColorSize],
103100
const mt::vec3& _normal)
104101
:RAS_IVertexData(_position, _normal, _tangent),
105-
RAS_VertexDataExtra<uvSize, colorSize>(_uvs, _colors)
102+
RAS_VertexDataExtra<Format>(_uvs, _colors)
106103
{
107104
}
108105

109106
inline RAS_VertexData(const float _position[3],
110-
const float _uvs[uvSize][2],
107+
const float _uvs[Format::UvSize][2],
111108
const float _tangent[4],
112-
const unsigned int _colors[colorSize],
109+
const unsigned int _colors[Format::ColorSize],
113110
const float _normal[3])
114111
:RAS_IVertexData(_position, _normal, _tangent),
115-
RAS_VertexDataExtra<uvSize, colorSize>(_uvs, _colors)
112+
RAS_VertexDataExtra<Format>(_uvs, _colors)
116113
{
117114
}
118115

0 commit comments

Comments
 (0)