Commit e5e22691 authored by Martin Schultz's avatar Martin Schultz

* further performance enhancements

parent 211adda7
...@@ -89,6 +89,7 @@ namespace ...@@ -89,6 +89,7 @@ namespace
std::vector<IndexTuple> parseIndices(const char* _start, const char* _end) std::vector<IndexTuple> parseIndices(const char* _start, const char* _end)
{ {
std::vector<IndexTuple> indices; std::vector<IndexTuple> indices;
indices.reserve(5);
const char* it = _start; const char* it = _start;
if (*it == ' ') //skip starting whitespace if (*it == ' ') //skip starting whitespace
...@@ -96,8 +97,6 @@ namespace ...@@ -96,8 +97,6 @@ namespace
const char* vsit; const char* vsit;
const char* vsend; const char* vsend;
const char* foundSlash; const char* foundSlash;
std::string vertexString;
std::string component;
int componentIndex; int componentIndex;
int index; int index;
while (it < _end) while (it < _end)
...@@ -106,19 +105,18 @@ namespace ...@@ -106,19 +105,18 @@ namespace
vsend = std::find(it, _end, ' '); vsend = std::find(it, _end, ' ');
componentIndex = 0; componentIndex = 0;
IndexTuple indexTuple; IndexTuple indexTuple;
indices.push_back(indexTuple);
//process the string now meaning we split by / //process the string now meaning we split by /
while (vsit < vsend) while (vsit < vsend)
{ {
foundSlash = std::find(vsit, vsend, '/'); foundSlash = std::find(vsit, vsend, '/');
index = std::atoi(vsit); index = std::atoi(vsit);
if (componentIndex == 0) indices.back().position = index - 1; if (componentIndex == 0) indexTuple.position = index - 1;
if (componentIndex == 1) indices.back().texCoord = index - 1; if (componentIndex == 1) indexTuple.texCoord = index - 1;
if (componentIndex == 2) indices.back().normal = index - 1; if (componentIndex == 2) indexTuple.normal = index - 1;
componentIndex++; componentIndex++;
vsit = foundSlash == vsend ? vsend : foundSlash + 1; vsit = foundSlash == vsend ? vsend : foundSlash + 1;
} }
//indices.push_back(indexTuple); indices.push_back(indexTuple);
it = vsend == _end ? _end : vsend + 1; it = vsend == _end ? _end : vsend + 1;
} }
return indices; return indices;
...@@ -157,7 +155,8 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c ...@@ -157,7 +155,8 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c
std::vector<IndexTuple> indices; std::vector<IndexTuple> indices;
std::string keyword; const char* keyword;
size_t keywordLength;
const char* parameters[2]; const char* parameters[2];
while (pchBuf < pchEnd) while (pchBuf < pchEnd)
{ {
...@@ -173,11 +172,12 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c ...@@ -173,11 +172,12 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c
// Otherwise, extract the first word and the remainder // Otherwise, extract the first word and the remainder
const char* pchKey = std::find(pchBuf, pchEnd, ' '); 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[0] = pchKey + 1;
parameters[1] = pchEOL; parameters[1] = pchEOL;
if(keyword == "v") // vertex position if(strncmp(keyword,"v",keywordLength) == 0) // vertex position
{ {
glm::vec4 position; glm::vec4 position;
int dimension; int dimension;
...@@ -192,7 +192,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c ...@@ -192,7 +192,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c
positionData.push_back(position); positionData.push_back(position);
} }
else if(keyword == "vt") // vertex tex coord else if (strncmp(keyword, "vt", keywordLength) == 0) // vertex tex coord
{ {
glm::vec3 texCoord; glm::vec3 texCoord;
int dimension; int dimension;
...@@ -210,7 +210,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c ...@@ -210,7 +210,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c
texCoordData.push_back(texCoord); texCoordData.push_back(texCoord);
} }
else if(keyword == "vn") // vertex normal else if (strncmp(keyword, "vn", keywordLength) == 0) // vertex normal
{ {
glm::vec3 normal; glm::vec3 normal;
int dimension; int dimension;
...@@ -226,7 +226,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c ...@@ -226,7 +226,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c
normalData.push_back(normal); normalData.push_back(normal);
} }
else if(keyword == "p") // point else if (strncmp(keyword, "p", keywordLength) == 0) // point
{ {
if(primitiveType == GL_INVALID_ENUM) if(primitiveType == GL_INVALID_ENUM)
primitiveType = GL_POINTS; primitiveType = GL_POINTS;
...@@ -243,7 +243,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c ...@@ -243,7 +243,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c
indices.push_back(pointIndices[i]); indices.push_back(pointIndices[i]);
} }
} }
else if(keyword == "l") // line else if (strncmp(keyword, "l", keywordLength) == 0) // line
{ {
if(primitiveType == GL_INVALID_ENUM) if(primitiveType == GL_INVALID_ENUM)
primitiveType = GL_LINES; primitiveType = GL_LINES;
...@@ -261,7 +261,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c ...@@ -261,7 +261,7 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c
indices.push_back(lineIndices[i+1]); indices.push_back(lineIndices[i+1]);
} }
} }
else if(keyword == "f") // face else if (strncmp(keyword, "f", keywordLength) == 0) // face
{ {
if(primitiveType == GL_INVALID_ENUM) if(primitiveType == GL_INVALID_ENUM)
primitiveType = GL_TRIANGLES; primitiveType = GL_TRIANGLES;
...@@ -280,24 +280,24 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c ...@@ -280,24 +280,24 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c
indices.push_back(faceIndices[i+1]); indices.push_back(faceIndices[i+1]);
} }
} }
else if(keyword == "bevel" || keyword == "bmat" else if (strncmp(keyword, "bevel", keywordLength) == 0 || strncmp(keyword, "bmat", keywordLength) == 0
|| keyword == "bsp" || keyword == "bzp" || strncmp(keyword, "bsp", keywordLength) == 0 || strncmp(keyword, "bzp", keywordLength) == 0
|| keyword == "c_interp" || keyword == "cdc" || strncmp(keyword, "c_interp", keywordLength) == 0 || strncmp(keyword, "cdc", keywordLength) == 0
|| keyword == "cdp" || keyword == "con" || strncmp(keyword, "cdp", keywordLength) == 0 || strncmp(keyword, "con", keywordLength) == 0
|| keyword == "cstype" || keyword == "ctech" || strncmp(keyword, "cstype", keywordLength) == 0 || strncmp(keyword, "ctech", keywordLength) == 0
|| keyword == "curv" || keyword == "curv2" || strncmp(keyword, "curv", keywordLength) == 0 || strncmp(keyword, "curv2", keywordLength) == 0
|| keyword == "d_interp" || keyword == "deg" || strncmp(keyword, "d_interp", keywordLength) == 0 || strncmp(keyword, "deg", keywordLength) == 0
|| keyword == "end" || keyword == "g" || strncmp(keyword, "end", keywordLength) == 0 || strncmp(keyword, "g", keywordLength) == 0
|| keyword == "hole" || keyword == "lod" || strncmp(keyword, "hole", keywordLength) == 0 || strncmp(keyword, "lod", keywordLength) == 0
|| keyword == "maplib" || keyword == "mg" || strncmp(keyword, "maplib", keywordLength) == 0 || strncmp(keyword, "mg", keywordLength) == 0
|| keyword == "mtllib" || keyword == "o" || strncmp(keyword, "mtllib", keywordLength) == 0 || strncmp(keyword, "o", keywordLength) == 0
|| keyword == "parm" || keyword == "res" || strncmp(keyword, "parm", keywordLength) == 0 || strncmp(keyword, "res", keywordLength) == 0
|| keyword == "s" || keyword == "scrv" || strncmp(keyword, "s", keywordLength) == 0 || strncmp(keyword, "scrv", keywordLength) == 0
|| keyword == "shadow_obj" || keyword == "sp" || strncmp(keyword, "shadow_obj", keywordLength) == 0 || strncmp(keyword, "sp", keywordLength) == 0
|| keyword == "stech" || keyword == "step" || strncmp(keyword, "stech", keywordLength) == 0 || strncmp(keyword, "step", keywordLength) == 0
|| keyword == "surf" || keyword == "trace_obj" || strncmp(keyword, "surf", keywordLength) == 0 || strncmp(keyword, "trace_obj", keywordLength) == 0
|| keyword == "trim" || keyword == "usemap" || strncmp(keyword, "trim", keywordLength) == 0 || strncmp(keyword, "usemap", keywordLength) == 0
|| keyword == "usemtl" || keyword == "vp") || strncmp(keyword, "usemtl", keywordLength) == 0 || strncmp(keyword, "vp", keywordLength) == 0)
{ {
// part of the OBJ specification (i.e. non-polygonal geometry, object groups, etc.) // part of the OBJ specification (i.e. non-polygonal geometry, object groups, etc.)
// is not supported and is silently ignored // is not supported and is silently ignored
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment