Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
glow-extras
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonathan Kunstwald
glow-extras
Commits
0267a3df
Commit
0267a3df
authored
7 years ago
by
Philip Trettner
Browse files
Options
Downloads
Patches
Plain Diff
modularized main loop
parent
9c9bdc80
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
glfw/glow-extras/glfw/GlfwApp.cc
+50
-29
50 additions, 29 deletions
glfw/glow-extras/glfw/GlfwApp.cc
glfw/glow-extras/glfw/GlfwApp.hh
+13
-0
13 additions, 0 deletions
glfw/glow-extras/glfw/GlfwApp.hh
with
63 additions
and
29 deletions
glfw/glow-extras/glfw/GlfwApp.cc
+
50
−
29
View file @
0267a3df
...
...
@@ -7,9 +7,10 @@
#include
<cassert>
#include
<chrono>
#include
<iostream>
#include
<thread>
#include
<chrono>
#include
<glow/gl.hh>
#include
<GLFW/glfw3.h>
...
...
@@ -322,28 +323,7 @@ void GlfwApp::mainLoop()
double
cpuTime
=
0
;
while
(
!
shouldClose
())
{
// update cursor mode
switch
(
mCursorMode
)
{
case
CursorMode
::
Normal
:
glfwSetInputMode
(
mWindow
,
GLFW_CURSOR
,
GLFW_CURSOR_NORMAL
);
break
;
case
CursorMode
::
Hidden
:
glfwSetInputMode
(
mWindow
,
GLFW_CURSOR
,
GLFW_CURSOR_HIDDEN
);
break
;
case
CursorMode
::
Disabled
:
glfwSetInputMode
(
mWindow
,
GLFW_CURSOR
,
GLFW_CURSOR_DISABLED
);
break
;
}
// vsync
glfwSwapInterval
(
mVSync
?
1
:
0
);
// Poll for and process events
glfwPollEvents
();
// viewport
glViewport
(
0
,
0
,
mWindowWidth
,
mWindowHeight
);
updateInput
();
// Update
auto
maxTicks
=
mMaxFrameSkip
;
...
...
@@ -364,6 +344,8 @@ void GlfwApp::mainLoop()
mCurrentTime
+=
dt
;
}
beginRender
();
// Render here
{
if
(
mQueryStats
&&
mPrimitiveQuery
)
...
...
@@ -384,12 +366,7 @@ void GlfwApp::mainLoop()
}
}
// draw the tweak bar(s)
if
(
mDrawTweakbars
)
TwDraw
();
// Swap front and back buffers
glfwSwapBuffers
(
mWindow
);
endRender
();
// timing
auto
now
=
glfwGetTime
();
...
...
@@ -442,6 +419,50 @@ void GlfwApp::internalOnMouseButton(double x, double y, int button, int action,
onMouseButton
(
x
,
y
,
button
,
action
,
mods
,
mClickCount
);
}
void
GlfwApp
::
updateInput
()
{
// update cursor mode
switch
(
mCursorMode
)
{
case
CursorMode
::
Normal
:
glfwSetInputMode
(
mWindow
,
GLFW_CURSOR
,
GLFW_CURSOR_NORMAL
);
break
;
case
CursorMode
::
Hidden
:
glfwSetInputMode
(
mWindow
,
GLFW_CURSOR
,
GLFW_CURSOR_HIDDEN
);
break
;
case
CursorMode
::
Disabled
:
glfwSetInputMode
(
mWindow
,
GLFW_CURSOR
,
GLFW_CURSOR_DISABLED
);
break
;
}
// Poll for and process events
glfwPollEvents
();
}
void
GlfwApp
::
beginRender
()
{
// vsync
glfwSwapInterval
(
mVSync
?
1
:
0
);
// viewport
glViewport
(
0
,
0
,
mWindowWidth
,
mWindowHeight
);
}
void
GlfwApp
::
endRender
()
{
// draw the tweak bar(s)
if
(
mDrawTweakbars
)
TwDraw
();
// Swap front and back buffers
glfwSwapBuffers
(
mWindow
);
}
void
GlfwApp
::
sleepSeconds
(
double
seconds
)
const
{
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
((
int
)(
seconds
*
1000
)));
}
int
GlfwApp
::
run
(
int
argc
,
char
*
argv
[])
{
static
GlfwApp
*
currApp
=
nullptr
;
...
...
This diff is collapsed.
Click to expand it.
glfw/glow-extras/glfw/GlfwApp.hh
+
13
−
0
View file @
0267a3df
...
...
@@ -228,6 +228,19 @@ protected:
private
:
void
internalOnMouseButton
(
double
x
,
double
y
,
int
button
,
int
action
,
int
mods
);
protected
:
/// performs glfw polling
void
updateInput
();
/// should be called before rendering
void
beginRender
();
/// should be called after rendering
/// calls swapBuffers
void
endRender
();
/// Blocks the thread for a given number of milliseconds
void
sleepSeconds
(
double
seconds
)
const
;
public
:
/// Initializes GLFW and GLOW, and runs until window is closed
int
run
(
int
argc
,
char
*
argv
[]);
...
...
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