Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
glfw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pirvi-public
glfw
Commits
e2f9340a
Commit
e2f9340a
authored
5 months ago
by
Doug Binks
Browse files
Options
Downloads
Patches
Plain Diff
Improved usercontext test with threading
parent
58aad6c1
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
tests/CMakeLists.txt
+1
-1
1 addition, 1 deletion
tests/CMakeLists.txt
tests/usercontext.c
+107
-3
107 additions, 3 deletions
tests/usercontext.c
with
108 additions
and
4 deletions
tests/CMakeLists.txt
+
1
−
1
View file @
e2f9340a
...
@@ -28,7 +28,7 @@ add_executable(iconify iconify.c ${GETOPT} ${GLAD_GL})
...
@@ -28,7 +28,7 @@ add_executable(iconify iconify.c ${GETOPT} ${GLAD_GL})
add_executable
(
monitors monitors.c
${
GETOPT
}
${
GLAD_GL
}
)
add_executable
(
monitors monitors.c
${
GETOPT
}
${
GLAD_GL
}
)
add_executable
(
reopen reopen.c
${
GLAD_GL
}
)
add_executable
(
reopen reopen.c
${
GLAD_GL
}
)
add_executable
(
cursor cursor.c
${
GLAD_GL
}
)
add_executable
(
cursor cursor.c
${
GLAD_GL
}
)
add_executable
(
usercontext usercontext.c
${
GLAD_GL
}
)
add_executable
(
usercontext usercontext.c
${
TINYCTHREAD
}
${
GLAD_GL
}
)
add_executable
(
empty WIN32 MACOSX_BUNDLE empty.c
${
TINYCTHREAD
}
${
GLAD_GL
}
)
add_executable
(
empty WIN32 MACOSX_BUNDLE empty.c
${
TINYCTHREAD
}
${
GLAD_GL
}
)
add_executable
(
gamma WIN32 MACOSX_BUNDLE gamma.c
${
GLAD_GL
}
)
add_executable
(
gamma WIN32 MACOSX_BUNDLE gamma.c
${
GLAD_GL
}
)
...
...
This diff is collapsed.
Click to expand it.
tests/usercontext.c
+
107
−
3
View file @
e2f9340a
//========================================================================
// User context test
// Copyright (c) Camilla Löwy <elmindreda@glfw.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test is intended to verify whether the OpenGL user context part of
// the GLFW API is able to be used from multiple threads
//
//========================================================================
#include
"tinycthread.h"
#define GLAD_GL_IMPLEMENTATION
#define GLAD_GL_IMPLEMENTATION
#include
<glad/gl.h>
#include
<glad/gl.h>
#define GLFW_INCLUDE_NONE
#define GLFW_INCLUDE_NONE
...
@@ -9,10 +41,44 @@ static void error_callback(int error, const char* description)
...
@@ -9,10 +41,44 @@ static void error_callback(int error, const char* description)
fprintf
(
stderr
,
"Error: %s
\n
"
,
description
);
fprintf
(
stderr
,
"Error: %s
\n
"
,
description
);
}
}
static
int
thread_main
(
void
*
data
)
{
GLFWusercontext
*
usercontext
=
(
GLFWusercontext
*
)
data
;
/* set the user context current */
glfwMakeUserContextCurrent
(
usercontext
);
if
(
glfwGetCurrentContext
()
!=
NULL
)
{
fprintf
(
stderr
,
"Current glfw window context not NULL after glfwMakeUserContextCurrent
\n
"
);
glfwTerminate
();
return
-
1
;
}
if
(
glfwGetCurrentUserContext
()
!=
usercontext
)
{
fprintf
(
stderr
,
"Current user context not correct after glfwMakeUserContextCurrent
\n
"
);
glfwTerminate
();
return
-
1
;
}
/* set the user context to NULL */
glfwMakeUserContextCurrent
(
NULL
);
if
(
glfwGetCurrentUserContext
()
!=
NULL
)
{
fprintf
(
stderr
,
"Current user context not NULL after glfwMakeContextCurrent
\n
"
);
glfwTerminate
();
return
-
1
;
}
return
0
;
}
int
main
(
void
)
int
main
(
void
)
{
{
GLFWwindow
*
window
;
GLFWwindow
*
window
;
GLFWusercontext
*
usercontext
;
GLFWusercontext
*
usercontext
;
thrd_t
thread_id
;
int
result
,
count
;
glfwSetErrorCallback
(
error_callback
);
glfwSetErrorCallback
(
error_callback
);
...
@@ -41,7 +107,6 @@ int main(void)
...
@@ -41,7 +107,6 @@ int main(void)
return
-
1
;
return
-
1
;
}
}
/* set the user context current */
/* set the user context current */
glfwMakeUserContextCurrent
(
usercontext
);
glfwMakeUserContextCurrent
(
usercontext
);
...
@@ -76,9 +141,19 @@ int main(void)
...
@@ -76,9 +141,19 @@ int main(void)
glClearColor
(
0
.
4
f
,
0
.
3
f
,
0
.
4
f
,
1
.
0
f
);
glClearColor
(
0
.
4
f
,
0
.
3
f
,
0
.
4
f
,
1
.
0
f
);
// Launch a thread which should create and use the usercontext
if
(
thrd_create
(
&
thread_id
,
thread_main
,
usercontext
)
!=
thrd_success
)
{
fprintf
(
stderr
,
"Failed to create secondary thread
\n
"
);
glfwTerminate
();
exit
(
EXIT_FAILURE
);
}
/* Loop until the user closes the window */
/* Loop 60 times or until the user closes the window */
while
(
!
glfwWindowShouldClose
(
window
))
count
=
0
;
while
(
!
glfwWindowShouldClose
(
window
)
&&
count
++
<
60
)
{
{
/* Render here */
/* Render here */
glClear
(
GL_COLOR_BUFFER_BIT
);
glClear
(
GL_COLOR_BUFFER_BIT
);
...
@@ -90,6 +165,35 @@ int main(void)
...
@@ -90,6 +165,35 @@ int main(void)
glfwPollEvents
();
glfwPollEvents
();
}
}
thrd_join
(
thread_id
,
&
result
);
/* One more test now the thread has joined */
/* set the user context current */
glfwMakeUserContextCurrent
(
usercontext
);
if
(
glfwGetCurrentContext
()
!=
NULL
)
{
fprintf
(
stderr
,
"Current glfw window context not NULL after glfwMakeUserContextCurrent
\n
"
);
glfwTerminate
();
return
-
1
;
}
if
(
glfwGetCurrentUserContext
()
!=
usercontext
)
{
fprintf
(
stderr
,
"Current user context not correct after glfwMakeUserContextCurrent
\n
"
);
glfwTerminate
();
return
-
1
;
}
/* set the user context to NULL */
glfwMakeUserContextCurrent
(
NULL
);
if
(
glfwGetCurrentUserContext
()
!=
NULL
)
{
fprintf
(
stderr
,
"Current user context not NULL after glfwMakeContextCurrent
\n
"
);
glfwTerminate
();
return
-
1
;
}
glfwDestroyUserContext
(
usercontext
);
glfwDestroyUserContext
(
usercontext
);
glfwTerminate
();
glfwTerminate
();
return
0
;
return
0
;
...
...
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