From e5e226919d7a5a704e07390ddaa756e66c3457cc Mon Sep 17 00:00:00 2001 From: Martin Schultz <Martin.Schultz@RWTH-Aachen.de> Date: Wed, 28 May 2014 23:43:09 +0200 Subject: [PATCH] * further performance enhancements --- .../OpenGL/Data/GeometryDataLoadStoreOBJ.cc | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/ACGL/OpenGL/Data/GeometryDataLoadStoreOBJ.cc b/src/ACGL/OpenGL/Data/GeometryDataLoadStoreOBJ.cc index 81b4d767..d1cb9e22 100644 --- a/src/ACGL/OpenGL/Data/GeometryDataLoadStoreOBJ.cc +++ b/src/ACGL/OpenGL/Data/GeometryDataLoadStoreOBJ.cc @@ -89,6 +89,7 @@ namespace std::vector<IndexTuple> parseIndices(const char* _start, const char* _end) { std::vector<IndexTuple> indices; + indices.reserve(5); const char* it = _start; if (*it == ' ') //skip starting whitespace @@ -96,8 +97,6 @@ namespace const char* vsit; const char* vsend; const char* foundSlash; - std::string vertexString; - std::string component; int componentIndex; int index; while (it < _end) @@ -106,19 +105,18 @@ namespace vsend = std::find(it, _end, ' '); componentIndex = 0; IndexTuple indexTuple; - indices.push_back(indexTuple); //process the string now meaning we split by / while (vsit < vsend) { foundSlash = std::find(vsit, vsend, '/'); index = std::atoi(vsit); - if (componentIndex == 0) indices.back().position = index - 1; - if (componentIndex == 1) indices.back().texCoord = index - 1; - if (componentIndex == 2) indices.back().normal = index - 1; + if (componentIndex == 0) indexTuple.position = index - 1; + if (componentIndex == 1) indexTuple.texCoord = index - 1; + if (componentIndex == 2) indexTuple.normal = index - 1; componentIndex++; vsit = foundSlash == vsend ? vsend : foundSlash + 1; } - //indices.push_back(indexTuple); + indices.push_back(indexTuple); it = vsend == _end ? _end : vsend + 1; } return indices; @@ -157,7 +155,8 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c std::vector<IndexTuple> indices; - std::string keyword; + const char* keyword; + size_t keywordLength; const char* parameters[2]; while (pchBuf < pchEnd) { @@ -173,11 +172,12 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c // Otherwise, extract the first word and the remainder const char* pchKey = std::find(pchBuf, pchEnd, ' '); - keyword = std::string(pchBuf, pchKey); + keyword = pchBuf; + keywordLength = pchKey - pchBuf;//std::string(pchBuf, pchKey); parameters[0] = pchKey + 1; parameters[1] = pchEOL; - if(keyword == "v") // vertex position + if(strncmp(keyword,"v",keywordLength) == 0) // vertex position { glm::vec4 position; int dimension; @@ -192,7 +192,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c positionData.push_back(position); } - else if(keyword == "vt") // vertex tex coord + else if (strncmp(keyword, "vt", keywordLength) == 0) // vertex tex coord { glm::vec3 texCoord; int dimension; @@ -210,7 +210,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c texCoordData.push_back(texCoord); } - else if(keyword == "vn") // vertex normal + else if (strncmp(keyword, "vn", keywordLength) == 0) // vertex normal { glm::vec3 normal; int dimension; @@ -226,7 +226,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c normalData.push_back(normal); } - else if(keyword == "p") // point + else if (strncmp(keyword, "p", keywordLength) == 0) // point { if(primitiveType == GL_INVALID_ENUM) primitiveType = GL_POINTS; @@ -243,7 +243,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c indices.push_back(pointIndices[i]); } } - else if(keyword == "l") // line + else if (strncmp(keyword, "l", keywordLength) == 0) // line { if(primitiveType == GL_INVALID_ENUM) primitiveType = GL_LINES; @@ -261,7 +261,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c indices.push_back(lineIndices[i+1]); } } - else if(keyword == "f") // face + else if (strncmp(keyword, "f", keywordLength) == 0) // face { if(primitiveType == GL_INVALID_ENUM) primitiveType = GL_TRIANGLES; @@ -280,24 +280,24 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c indices.push_back(faceIndices[i+1]); } } - else if(keyword == "bevel" || keyword == "bmat" - || keyword == "bsp" || keyword == "bzp" - || keyword == "c_interp" || keyword == "cdc" - || keyword == "cdp" || keyword == "con" - || keyword == "cstype" || keyword == "ctech" - || keyword == "curv" || keyword == "curv2" - || keyword == "d_interp" || keyword == "deg" - || keyword == "end" || keyword == "g" - || keyword == "hole" || keyword == "lod" - || keyword == "maplib" || keyword == "mg" - || keyword == "mtllib" || keyword == "o" - || keyword == "parm" || keyword == "res" - || keyword == "s" || keyword == "scrv" - || keyword == "shadow_obj" || keyword == "sp" - || keyword == "stech" || keyword == "step" - || keyword == "surf" || keyword == "trace_obj" - || keyword == "trim" || keyword == "usemap" - || keyword == "usemtl" || keyword == "vp") + else if (strncmp(keyword, "bevel", keywordLength) == 0 || strncmp(keyword, "bmat", keywordLength) == 0 + || strncmp(keyword, "bsp", keywordLength) == 0 || strncmp(keyword, "bzp", keywordLength) == 0 + || strncmp(keyword, "c_interp", keywordLength) == 0 || strncmp(keyword, "cdc", keywordLength) == 0 + || strncmp(keyword, "cdp", keywordLength) == 0 || strncmp(keyword, "con", keywordLength) == 0 + || strncmp(keyword, "cstype", keywordLength) == 0 || strncmp(keyword, "ctech", keywordLength) == 0 + || strncmp(keyword, "curv", keywordLength) == 0 || strncmp(keyword, "curv2", keywordLength) == 0 + || strncmp(keyword, "d_interp", keywordLength) == 0 || strncmp(keyword, "deg", keywordLength) == 0 + || strncmp(keyword, "end", keywordLength) == 0 || strncmp(keyword, "g", keywordLength) == 0 + || strncmp(keyword, "hole", keywordLength) == 0 || strncmp(keyword, "lod", keywordLength) == 0 + || strncmp(keyword, "maplib", keywordLength) == 0 || strncmp(keyword, "mg", keywordLength) == 0 + || strncmp(keyword, "mtllib", keywordLength) == 0 || strncmp(keyword, "o", keywordLength) == 0 + || strncmp(keyword, "parm", keywordLength) == 0 || strncmp(keyword, "res", keywordLength) == 0 + || strncmp(keyword, "s", keywordLength) == 0 || strncmp(keyword, "scrv", keywordLength) == 0 + || strncmp(keyword, "shadow_obj", keywordLength) == 0 || strncmp(keyword, "sp", keywordLength) == 0 + || strncmp(keyword, "stech", keywordLength) == 0 || strncmp(keyword, "step", keywordLength) == 0 + || strncmp(keyword, "surf", keywordLength) == 0 || strncmp(keyword, "trace_obj", keywordLength) == 0 + || strncmp(keyword, "trim", keywordLength) == 0 || strncmp(keyword, "usemap", keywordLength) == 0 + || strncmp(keyword, "usemtl", keywordLength) == 0 || strncmp(keyword, "vp", keywordLength) == 0) { // part of the OBJ specification (i.e. non-polygonal geometry, object groups, etc.) // is not supported and is silently ignored -- GitLab