Skip to content
Snippets Groups Projects
Verified Commit 238fafa1 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

[#89] Cleanup of window extensions

parent 328844c0
No related branches found
No related tags found
1 merge request!90Resolve "Mehrere Fenster, Abhängigkeiten von Core zu Fenster+Swapchain etc"
Pipeline #26980 failed
......@@ -78,6 +78,12 @@ namespace vkcv {
* polls all events on the GLFWwindow
*/
static void pollEvents();
/**
*
* @return
*/
static const std::vector<std::string>& getExtensions();
/**
* basic events of the window
......
#include <GLFW/glfw3.h>
#include "vkcv/Context.hpp"
#include "vkcv/Window.hpp"
namespace vkcv
{
......@@ -175,15 +174,13 @@ namespace vkcv
return true;
}
std::vector<const char*> getRequiredExtensions() {
glfwInit();
uint32_t glfwExtensionCount = 0;
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);
glfwTerminate();
std::vector<std::string> getRequiredExtensions() {
std::vector<std::string> extensions = Window::getExtensions();
#ifndef NDEBUG
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
extensions.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
#endif
return extensions;
}
......@@ -225,7 +222,13 @@ namespace vkcv
}
// for GLFW: get all required extensions
std::vector<const char*> requiredExtensions = getRequiredExtensions();
auto requiredStrings = getRequiredExtensions();
std::vector<const char*> requiredExtensions;
for (const auto& extension : requiredStrings) {
requiredExtensions.push_back(extension.c_str());
}
requiredExtensions.insert(requiredExtensions.end(), instanceExtensions.begin(), instanceExtensions.end());
if (!checkSupport(supportedExtensions, requiredExtensions)) {
......
......@@ -145,61 +145,6 @@ namespace vkcv {
}
}
/*void Window::destroyWindow() {
Window::e_mouseButton.unlock();
Window::e_mouseMove.unlock();
Window::e_mouseScroll.unlock();
Window::e_resize.unlock();
Window::e_key.unlock();
Window::e_char.unlock();
Window::e_gamepad.unlock();
if (m_window) {
s_Windows.erase(std::find(s_Windows.begin(), s_Windows.end(), m_window));
glfwDestroyWindow(m_window);
}
}*/
/*Window::Window(const Window &other) :
m_title(other.getTitle()),
m_resizable(other.isResizable()),
m_window(createGLFWWindow(
other.getTitle().c_str(),
other.getWidth(),
other.getHeight(),
other.isResizable()
)),
e_mouseButton(true),
e_mouseMove(true),
e_mouseScroll(true),
e_resize(true),
e_key(true),
e_char(true),
e_gamepad(true)
{
bindGLFWWindow(m_window, this);
}
Window &Window::operator=(const Window &other) {
if (m_window) {
s_Windows.erase(std::find(s_Windows.begin(), s_Windows.end(), m_window));
glfwDestroyWindow(m_window);
}
m_title = other.getTitle();
m_resizable = other.isResizable();
m_window = createGLFWWindow(
m_title.c_str(),
other.getWidth(),
other.getHeight(),
m_resizable
);
bindGLFWWindow(m_window, this);
return *this;
}*/
bool Window::hasOpenWindow() {
for (auto glfwWindow : s_Windows) {
auto window = static_cast<Window *>(glfwGetWindowUserPointer(glfwWindow));
......@@ -253,6 +198,29 @@ namespace vkcv {
window->m_shouldClose |= glfwWindowShouldClose(glfwWindow);
}
}
const std::vector<std::string>& Window::getExtensions() {
static std::vector<std::string> extensions;
if (extensions.empty()) {
if(s_Windows.empty()) {
glfwInit();
}
uint32_t glfwExtensionCount = 0;
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
for (uint32_t i = 0; i < glfwExtensionCount; i++) {
extensions.emplace_back(glfwExtensions[i]);
}
if (s_Windows.empty()) {
glfwTerminate();
}
}
return extensions;
}
bool Window::isOpen() const {
if (!m_window) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment