Skip to content
Snippets Groups Projects
Commit 5fdd877d authored by Jonas Johan Solsvik's avatar Jonas Johan Solsvik
Browse files

onlyVertex 90ms, onlyTriangle 21ms, makeModel 140ms total

parent ad244ce7
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ project(cube) ...@@ -2,7 +2,7 @@ project(cube)
cmake_minimum_required (VERSION 3.8 FATAL_ERROR) cmake_minimum_required (VERSION 3.8 FATAL_ERROR)
# Set global variables # Set global variables
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE RelWithDebInfo)
# Aliases # Aliases
set(SRCDIR ${CMAKE_SOURCE_DIR}) set(SRCDIR ${CMAKE_SOURCE_DIR})
......
...@@ -22,7 +22,7 @@ auto Parser::nextLine() -> std::string_view ...@@ -22,7 +22,7 @@ auto Parser::nextLine() -> std::string_view
// which means "not found". // which means "not found".
for (;;) { for (;;) {
this->lineCount += 1; lineCount += 1;
// After every iteration startofLine is set to the current value of endofLine +1. // After every iteration startofLine is set to the current value of endofLine +1.
startofLine = endofLine + 1; startofLine = endofLine + 1;
if (startofLine >= strview.size()) { if (startofLine >= strview.size()) {
...@@ -306,7 +306,8 @@ auto Parser::onlyVertex() -> Vertex ...@@ -306,7 +306,8 @@ auto Parser::onlyVertex() -> Vertex
// The function concerns performance only. // The function concerns performance only.
// This function replaces strtof() - which is a much more correct implemetation, but was a performance bottleneck loading // This function replaces strtof() - which is a much more correct implemetation, but was a performance bottleneck loading
// bigger models - JSolsvik 06.05.2018 // bigger models - JSolsvik 06.05.2018
auto naiveStringToFloat = [](const char *p, const char **end) -> float // @optmization Function will only work here. Not genral at all
auto __OPTMIZED__StringToFloat = [](const char *p, const char **end) -> float
{ {
float res = 0.0f; float res = 0.0f;
// Eat spaces // Eat spaces
...@@ -349,83 +350,109 @@ auto Parser::onlyVertex() -> Vertex ...@@ -349,83 +350,109 @@ auto Parser::onlyVertex() -> Vertex
return res; return res;
}; };
const auto line = nextLine();
const char* it = line.data();
const char* end;
auto[key, vertexString, err] = keyString(); // Find the separtor, the plus 1
if (err) while(*it != ':') ++it;
LOG_ERROR("VERTICES IN MODEL FILE IS CORRUPT"); ++it;
Vertex vert{};
float u, v;
float nx, ny, nz;
const char* it = vertexString.data();
const char* end_;
char* end;
// Position // Position
vert.x = naiveStringToFloat(it, &end_); const float x = __OPTMIZED__StringToFloat(it, &end);
it = end_; it = end;
vert.y = naiveStringToFloat(it, &end_); const float y = __OPTMIZED__StringToFloat(it, &end);
it = end_; it = end;
vert.z = naiveStringToFloat(it, &end_); const float z = __OPTMIZED__StringToFloat(it, &end);
it = end_; it = end;
// Normal // Normal
nx = naiveStringToFloat(it, &end_); const float nx = __OPTMIZED__StringToFloat(it, &end);
it = end_; it = end;
ny = naiveStringToFloat(it, &end_); const float ny = __OPTMIZED__StringToFloat(it, &end);
it = end_; it = end;
nz = naiveStringToFloat(it, &end_); const float nz = __OPTMIZED__StringToFloat(it, &end);
it = end_; it = end;
const GLint n = Util::packNormal(nx,ny,nz);
// uv // uv
u = naiveStringToFloat(it, &end_); const GLushort u = 65535U * __OPTMIZED__StringToFloat(it, &end);
it = end_; it = end;
v = naiveStringToFloat(it, &end_); const GLushort v = 65535U * __OPTMIZED__StringToFloat(it, &end);
it = end_; it = end;
// @optmization Function will only work here. Not genral at all
auto __OPTIMIZED__StringToGLubyte = [](const char *p, const char **end) -> GLubyte
{
while (*p == ' ') ++p;
GLubyte x = 0;
while (*p >= '0' && *p <= '9') {
x = (x*10) + (*p - '0');
++p;
}
*end = p;
return x;
};
// Colors // Colors
vert.r = (GLubyte)strtoul(it, &end, 10); const GLubyte r = __OPTIMIZED__StringToGLubyte(it, &end);
it = end;
vert.g = (GLubyte)strtoul(it, &end, 10);
it = end; it = end;
vert.b = (GLubyte)strtoul(it, &end, 10); const GLubyte g = __OPTIMIZED__StringToGLubyte(it, &end);
it = end; it = end;
vert.a = (GLubyte)strtoul(it, &end, 10); const GLubyte b = __OPTIMIZED__StringToGLubyte(it, &end);
it = end; it = end;
const GLubyte a = __OPTIMIZED__StringToGLubyte(it, &end);
// Packing and normalizing return Vertex {
vert.n = Util::packNormal(nx, ny, nz); x,y,z, n, u,v, r,g,b,a
vert.u = 65535U * u;//vert.uv = Util::packUV(u, v); };
vert.v = 65535U * v;
return vert;
} }
// //
// t: <GLuint> <GLuint> <GLuint> // t: <GLuint> <GLuint> <GLuint>
// //
auto Parser::onlyTriangle() -> Triangle auto Parser::onlyTriangle() -> Triangle
{ {
auto[key, triangleString, err] = keyString();
if (err)
LOG_ERROR("TRIANGLES IN MODEL FILE IS CORRUPT");
Triangle tri{}; // @optmization Function will only work here. Not genral at all
auto __OPTIMIZED__StringToGLuint = [](const char *p, const char **end) -> GLuint
{
while (*p == ' ') ++p;
GLuint x = 0;
while (*p >= '0' && *p <= '9') {
x = (x*10) + (*p - '0');
++p;
}
*end = p;
return x;
};
const char* it = triangleString.data();
char* end;
tri.a = strtol(it, &end, 10);
const auto line = nextLine();
const char* it = line.data();
const char* end;
// Find the separtor, the plus 1
while(*it != ':') ++it;
++it;
Triangle tri{};
tri.a = __OPTIMIZED__StringToGLuint(it, &end);
it = end; it = end;
tri.b = strtol(it, &end, 10); tri.b = __OPTIMIZED__StringToGLuint(it, &end);
it = end; it = end;
tri.c = strtol(it, &end, 10); tri.c = __OPTIMIZED__StringToGLuint(it, &end);
return tri; return tri;
} }
......
...@@ -76,7 +76,6 @@ int main(int argc, char** args) ...@@ -76,7 +76,6 @@ int main(int argc, char** args)
} }
// exit(0); // for performance analysis
float oldT = 0, t = 0, dt = 0; float oldT = 0, t = 0, dt = 0;
for(;;) for(;;)
...@@ -101,6 +100,8 @@ int main(int argc, char** args) ...@@ -101,6 +100,8 @@ int main(int argc, char** args)
glfwPollEvents(); glfwPollEvents();
oldT = t; oldT = t;
//break;
} }
Scene::clean(); Scene::clean();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment