Skip to content
Snippets Groups Projects
Commit c1de6145 authored by Sebastian Gaida's avatar Sebastian Gaida
Browse files

Merge branch 'develop' into 7-context-functionality

# Conflicts:
#	projects/first_triangle/src/main.cpp
parents 9beed6c5 ae7d8fad
No related branches found
No related tags found
1 merge request!2Resolve "Context Functionality"
.project
.cproject
.vs/
.vscode/
.idea/
.editorconfig
......
......@@ -2,4 +2,8 @@
set(vkcv_sources
${vkcv_source}/vkcv/Context.hpp
${vkcv_source}/vkcv/Context.cpp
${vkcv_source}/vkcv/Window.hpp
${vkcv_source}/vkcv/Window.cpp
${vkcv_source}/vkcv/CoreManager.hpp
${vkcv_source}/vkcv/CoreManager.cpp
)
#include <iostream>
#include <vkcv/Context.hpp>
#include <vkcv/Window.hpp>
int main(int argc, const char** argv) {
const char* applicationName = "First Triangle";
vkcv::Window window = vkcv::Window::create(
applicationName,
800,
600,
false
);
vkcv::Context context = vkcv::Context::create(
"First Triangle",
applicationName,
VK_MAKE_VERSION(0, 0, 1),
20,
{vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eTransfer}
......@@ -24,5 +32,8 @@ int main(int argc, const char** argv) {
default: std::cout << "Unknown GPU vendor?! Either you're on an exotic system or your driver is broken..." << std::endl;
}
while (window.isWindowOpen()) {
window.pollEvents();
}
return 0;
}
#define GLFW_INCLUDE_VULKAN
#include "CoreManager.hpp"
namespace vkcv {
int glfwCounter = 0;
void initGLFW() {
if (glfwCounter == 0) {
int glfwSuccess = glfwInit();
if (glfwSuccess == GLFW_FALSE) {
throw std::runtime_error("Could not initialize GLFW");
}
}
glfwCounter++;
}
void terminateGLFW() {
if (glfwCounter == 1) {
glfwTerminate();
}
glfwCounter--;
}
}
\ No newline at end of file
#ifndef VKCV_COREMANAGER_HPP
#define VKCV_COREMANAGER_HPP
#include <GLFW/glfw3.h>
#include <stdexcept>
namespace vkcv {
/**
* initialize GLFW if not initialized
*/
void initGLFW();
/**
* terminate GLFW
*/
void terminateGLFW();
}
#endif //VKCV_COREMANAGER_HPP
#include "Window.hpp"
#include "CoreManager.hpp"
namespace vkcv {
Window::Window(GLFWwindow *window)
: m_window(window) {
}
Window::~Window() {
glfwDestroyWindow(m_window);
vkcv::terminateGLFW();
}
Window Window::create(const char *windowTitle, int width, int height, bool resizable) {
vkcv::initGLFW();
width = std::max(width, 1);
height = std::max(height, 1);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, resizable ? GLFW_TRUE : GLFW_FALSE);
GLFWwindow *window;
window = glfwCreateWindow(width, height, windowTitle, nullptr, nullptr);
return Window(window);
}
bool Window::isWindowOpen() const {
return !glfwWindowShouldClose(m_window);
}
void Window::pollEvents() {
glfwPollEvents();
}
GLFWwindow *Window::getWindow() const {
return m_window;
}
int Window::getWidth() const {
int width;
glfwGetWindowSize(m_window, &width, nullptr);
return width;
}
int Window::getHeight() const {
int height;
glfwGetWindowSize(m_window, nullptr, &height);
return height;
}
}
\ No newline at end of file
#pragma once
#include <vulkan/vulkan.hpp>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
namespace vkcv {
class Window final {
private:
explicit Window(GLFWwindow *window);
GLFWwindow *m_window;
public:
static Window create(const char *windowTitle, int width = -1, int height = -1, bool resizable = false);
[[nodiscard]]
bool isWindowOpen() const;
static void pollEvents();
[[nodiscard]]
GLFWwindow *getWindow() const;
[[nodiscard]]
int getWidth() const;
[[nodiscard]]
int getHeight() const;
Window &operator=(const Window &other) = delete;
Window &operator=(Window &&other) = default;
virtual ~Window();
};
}
\ No newline at end of file
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