From 091804c1eafc3273f737690931b93d4601ecfaff Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Thu, 14 Dec 2017 22:45:10 +0100 Subject: [PATCH] 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. --- source/gameengine/Rasterizer/CMakeLists.txt | 1 + .../Rasterizer/RAS_IBatchDisplayArray.cpp | 2 +- .../Rasterizer/RAS_IDisplayArray.cpp | 2 +- source/gameengine/Rasterizer/RAS_Vertex.cpp | 10 ----- source/gameengine/Rasterizer/RAS_Vertex.h | 11 ----- source/gameengine/Rasterizer/RAS_VertexData.h | 41 +++++++++---------- 6 files changed, 22 insertions(+), 45 deletions(-) diff --git a/source/gameengine/Rasterizer/CMakeLists.txt b/source/gameengine/Rasterizer/CMakeLists.txt index ac9765968efe..088e2d764859 100644 --- a/source/gameengine/Rasterizer/CMakeLists.txt +++ b/source/gameengine/Rasterizer/CMakeLists.txt @@ -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) diff --git a/source/gameengine/Rasterizer/RAS_IBatchDisplayArray.cpp b/source/gameengine/Rasterizer/RAS_IBatchDisplayArray.cpp index 26f2ebea7b5a..789b337b8f02 100644 --- a/source/gameengine/Rasterizer/RAS_IBatchDisplayArray.cpp +++ b/source/gameengine/Rasterizer/RAS_IBatchDisplayArray.cpp @@ -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 >(primtype, vertformat); \ + return new RAS_BatchDisplayArray > >(primtype, vertformat); \ } #define NEW_DISPLAY_ARRAY_COLOR(vertformat, color, primtype) \ diff --git a/source/gameengine/Rasterizer/RAS_IDisplayArray.cpp b/source/gameengine/Rasterizer/RAS_IDisplayArray.cpp index c216b473bcfb..30030ea0e798 100644 --- a/source/gameengine/Rasterizer/RAS_IDisplayArray.cpp +++ b/source/gameengine/Rasterizer/RAS_IDisplayArray.cpp @@ -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 >(primtype, vertformat); \ + return new RAS_DisplayArray > >(primtype, vertformat); \ } #define NEW_DISPLAY_ARRAY_COLOR(vertformat, color, primtype) \ diff --git a/source/gameengine/Rasterizer/RAS_Vertex.cpp b/source/gameengine/Rasterizer/RAS_Vertex.cpp index 2eef031e3b81..438c3c4cb7f0 100644 --- a/source/gameengine/Rasterizer/RAS_Vertex.cpp +++ b/source/gameengine/Rasterizer/RAS_Vertex.cpp @@ -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) { diff --git a/source/gameengine/Rasterizer/RAS_Vertex.h b/source/gameengine/Rasterizer/RAS_Vertex.h index ee391995b7ff..721b3dcaaa40 100644 --- a/source/gameengine/Rasterizer/RAS_Vertex.h +++ b/source/gameengine/Rasterizer/RAS_Vertex.h @@ -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: diff --git a/source/gameengine/Rasterizer/RAS_VertexData.h b/source/gameengine/Rasterizer/RAS_VertexData.h index a1bbf291eafc..e612b3375c32 100644 --- a/source/gameengine/Rasterizer/RAS_VertexData.h +++ b/source/gameengine/Rasterizer/RAS_VertexData.h @@ -3,6 +3,8 @@ #include "mathfu.h" +#include "RAS_VertexFormat.h" + #include "BLI_math_vector.h" struct RAS_VertexDataBasic @@ -28,32 +30,32 @@ struct RAS_VertexDataBasic } }; -template +template 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]; } } @@ -86,33 +88,28 @@ struct RAS_VertexDataMemoryFormat uint8_t size; }; -template -struct RAS_VertexData : RAS_IVertexData, RAS_VertexDataExtra +template +struct RAS_VertexData : RAS_IVertexData, RAS_VertexDataExtra { - 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(_uvs, _colors) + RAS_VertexDataExtra(_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(_uvs, _colors) + RAS_VertexDataExtra(_uvs, _colors) { }