Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Vulkan Workshop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
JetBrains YouTrack
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
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
KSZK
DevTeam
Vulkan Workshop
Commits
ee64a065
Commit
ee64a065
authored
10 months ago
by
n0F4x
Browse files
Options
Downloads
Patches
Plain Diff
Refactor GLFW initialization
parent
e771735a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Window.cpp
+25
-13
25 additions, 13 deletions
src/Window.cpp
with
25 additions
and
13 deletions
src/Window.cpp
+
25
−
13
View file @
ee64a065
...
@@ -3,21 +3,35 @@
...
@@ -3,21 +3,35 @@
#include
<format>
#include
<format>
#include
<stdexcept>
#include
<stdexcept>
[[
nodiscard
]]
static
auto
init_glfw
()
->
void
static
auto
create_window
(
const
uint16_t
width
,
const
uint16_t
height
,
const
std
::
string
&
title
)
->
GLFWwindow
*
{
{
if
(
const
auto
error_code
{
glfwInit
()
};
error_code
!=
GLFW_TRUE
)
{
if
(
const
int
success
{
glfwInit
()
};
success
!=
GLFW_TRUE
)
{
const
char
*
description
{};
const
int
error_code
{
glfwGetError
(
&
description
)
};
if
(
description
==
nullptr
)
{
throw
std
::
runtime_error
{
throw
std
::
runtime_error
{
std
::
format
(
"glfwInit failed with error code {}"
,
error_code
)
std
::
format
(
"glfwInit failed with error code {}"
,
error_code
)
};
};
}
}
if
(
const
auto
result
{
std
::
atexit
(
glfwTerminate
)
};
result
!=
0
)
{
throw
std
::
runtime_error
{
std
::
format
(
"glfwInit failed with error code {} - '{}'"
,
error_code
,
description
)
};
}
if
(
const
int
result
{
std
::
atexit
(
glfwTerminate
)
};
result
!=
0
)
{
throw
std
::
runtime_error
{
throw
std
::
runtime_error
{
std
::
format
(
"std::atexit
(glfwTerminate)
failed with error code {}"
,
result
)
std
::
format
(
"std::atexit failed with error code {}"
,
result
)
};
};
}
}
}
[[
nodiscard
]]
static
auto
create_window
(
const
uint16_t
width
,
const
uint16_t
height
,
const
std
::
string
&
title
)
->
GLFWwindow
*
{
init_glfw
();
glfwDefaultWindowHints
();
glfwDefaultWindowHints
();
glfwWindowHint
(
GLFW_CLIENT_API
,
GLFW_NO_API
);
glfwWindowHint
(
GLFW_CLIENT_API
,
GLFW_NO_API
);
...
@@ -34,9 +48,7 @@ static auto
...
@@ -34,9 +48,7 @@ static auto
auto
Window
::
vulkan_instance_extensions
()
->
std
::
span
<
const
char
*
const
>
auto
Window
::
vulkan_instance_extensions
()
->
std
::
span
<
const
char
*
const
>
{
{
static
const
std
::
vector
s_extension_names
{
[]()
->
std
::
vector
<
const
char
*>
{
static
const
std
::
vector
s_extension_names
{
[]()
->
std
::
vector
<
const
char
*>
{
if
(
glfwInit
()
!=
GLFW_TRUE
)
{
init_glfw
();
return
{};
}
uint32_t
count
{};
uint32_t
count
{};
const
char
**
glfw_extension_names
{
glfwGetRequiredInstanceExtensions
(
&
count
)
};
const
char
**
glfw_extension_names
{
glfwGetRequiredInstanceExtensions
(
&
count
)
};
...
...
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