Skip to content

Commit

Permalink
UPBGE: Use RAS_VertexFormatType to specify format in RAS_VertexData t…
Browse files Browse the repository at this point in the history
…emplate.

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.
  • Loading branch information
panzergame committed Dec 14, 2017
1 parent 2cc0d9e commit 091804c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 45 deletions.
1 change: 1 addition & 0 deletions source/gameengine/Rasterizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ set(SRC
RAS_TextUser.h
RAS_Vertex.h
RAS_VertexData.h
RAS_VertexFormat.h
)

data_to_c_simple(RAS_OpenGLFilters/RAS_Blur2DFilter.glsl SRC)
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Rasterizer/RAS_IBatchDisplayArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RAS_IBatchDisplayArray::~RAS_IBatchDisplayArray()

#define NEW_DISPLAY_ARRAY_UV(vertformat, uv, color, primtype) \
if (vertformat.uvSize == uv && vertformat.colorSize == color) { \
return new RAS_BatchDisplayArray<RAS_VertexData<uv, color> >(primtype, vertformat); \
return new RAS_BatchDisplayArray<RAS_VertexData<RAS_VertexFormatType<uv, color> > >(primtype, vertformat); \
}

#define NEW_DISPLAY_ARRAY_COLOR(vertformat, color, primtype) \
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Rasterizer/RAS_IDisplayArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ RAS_IDisplayArray::~RAS_IDisplayArray()

#define NEW_DISPLAY_ARRAY_UV(vertformat, uv, color, primtype) \
if (vertformat.uvSize == uv && vertformat.colorSize == color) { \
return new RAS_DisplayArray<RAS_VertexData<uv, color> >(primtype, vertformat); \
return new RAS_DisplayArray<RAS_VertexData<RAS_VertexFormatType<uv, color> > >(primtype, vertformat); \
}

#define NEW_DISPLAY_ARRAY_COLOR(vertformat, color, primtype) \
Expand Down
10 changes: 0 additions & 10 deletions source/gameengine/Rasterizer/RAS_Vertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@

#include "RAS_Vertex.h"

bool operator== (const RAS_VertexFormat& format1, const RAS_VertexFormat& format2)
{
return (format1.uvSize == format2.uvSize && format1.colorSize == format2.colorSize);
}

bool operator!= (const RAS_VertexFormat& format1, const RAS_VertexFormat& format2)
{
return !(format1 == format2);
}

RAS_VertexInfo::RAS_VertexInfo(unsigned int origindex, bool flat)
:m_origindex(origindex)
{
Expand Down
11 changes: 0 additions & 11 deletions source/gameengine/Rasterizer/RAS_Vertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@

#include "BLI_math_vector.h"

/// Struct used to pass the vertex format to functions.
struct RAS_VertexFormat
{
uint8_t uvSize;
uint8_t colorSize;
};

/// Operators used to compare the contents (uv size, color size, ...) of two vertex formats.
bool operator== (const RAS_VertexFormat& format1, const RAS_VertexFormat& format2);
bool operator!= (const RAS_VertexFormat& format1, const RAS_VertexFormat& format2);

class RAS_VertexInfo
{
public:
Expand Down
41 changes: 19 additions & 22 deletions source/gameengine/Rasterizer/RAS_VertexData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "mathfu.h"

#include "RAS_VertexFormat.h"

#include "BLI_math_vector.h"

struct RAS_VertexDataBasic
Expand All @@ -28,32 +30,32 @@ struct RAS_VertexDataBasic
}
};

template <unsigned short uvSize, unsigned short colorSize>
template <class Format>
struct RAS_VertexDataExtra
{
float uvs[uvSize][2];
unsigned int colors[colorSize];
float uvs[Format::UvSize][2];
unsigned int colors[Format::ColorSize];

inline RAS_VertexDataExtra() = default;

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

for (unsigned short i = 0; i < colorSize; ++i) {
for (unsigned short i = 0; i < Format::ColorSize; ++i) {
colors[i] = _colors[i];
}
}

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

for (unsigned short i = 0; i < colorSize; ++i) {
for (unsigned short i = 0; i < Format::ColorSize; ++i) {
colors[i] = _colors[i];
}
}
Expand Down Expand Up @@ -86,33 +88,28 @@ struct RAS_VertexDataMemoryFormat
uint8_t size;
};

template <unsigned short uvSize, unsigned short colorSize>
struct RAS_VertexData : RAS_IVertexData, RAS_VertexDataExtra<uvSize, colorSize>
template <class Format>
struct RAS_VertexData : RAS_IVertexData, RAS_VertexDataExtra<Format>
{
enum {
UvSize = uvSize,
ColorSize = colorSize
};

inline RAS_VertexData() = default;

inline RAS_VertexData(const mt::vec3& _position,
const mt::vec2 _uvs[uvSize],
const mt::vec2 _uvs[Format::UvSize],
const mt::vec4& _tangent,
const unsigned int _colors[colorSize],
const unsigned int _colors[Format::ColorSize],
const mt::vec3& _normal)
:RAS_IVertexData(_position, _normal, _tangent),
RAS_VertexDataExtra<uvSize, colorSize>(_uvs, _colors)
RAS_VertexDataExtra<Format>(_uvs, _colors)
{
}

inline RAS_VertexData(const float _position[3],
const float _uvs[uvSize][2],
const float _uvs[Format::UvSize][2],
const float _tangent[4],
const unsigned int _colors[colorSize],
const unsigned int _colors[Format::ColorSize],
const float _normal[3])
:RAS_IVertexData(_position, _normal, _tangent),
RAS_VertexDataExtra<uvSize, colorSize>(_uvs, _colors)
RAS_VertexDataExtra<Format>(_uvs, _colors)
{
}

Expand Down

0 comments on commit 091804c

Please sign in to comment.