Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
imt2531-exam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Halvor Bakken Smedås
imt2531-exam
Commits
5fdd877d
Commit
5fdd877d
authored
May 6, 2018
by
Jonas Johan Solsvik
Browse files
Options
Downloads
Patches
Plain Diff
onlyVertex 90ms, onlyTriangle 21ms, makeModel 140ms total
parent
ad244ce7
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+1
-1
1 addition, 1 deletion
CMakeLists.txt
src/Parser.cpp
+77
-50
77 additions, 50 deletions
src/Parser.cpp
src/main.cpp
+2
-1
2 additions, 1 deletion
src/main.cpp
with
80 additions
and
52 deletions
CMakeLists.txt
+
1
−
1
View file @
5fdd877d
...
@@ -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
}
)
...
...
This diff is collapsed.
Click to expand it.
src/Parser.cpp
+
77
−
50
View file @
5fdd877d
...
@@ -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
=
naive
StringToFloat
(
it
,
&
end
_
);
const
float
x
=
__OPTMIZED__
StringToFloat
(
it
,
&
end
);
it
=
end
_
;
it
=
end
;
vert
.
y
=
naive
StringToFloat
(
it
,
&
end
_
);
const
float
y
=
__OPTMIZED__
StringToFloat
(
it
,
&
end
);
it
=
end
_
;
it
=
end
;
vert
.
z
=
naive
StringToFloat
(
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
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
+
2
−
1
View file @
5fdd877d
...
@@ -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
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment