Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
graphite/engine/platform/glfw/gfx.cpp

46 lines
1.3 KiB
C++
Raw Normal View History

2024-01-03 16:05:02 -05:00
#include "gfx.hpp"
#include <GLFW/glfw3.h>
#include "platform.hpp"
int oldWindowX = 0, oldWindowY = 0;
void GFX::MakeContextCurrent()
{
glfwMakeContextCurrent(static_cast<GLFWwindow*>(Platform::GetUserData()));
glfwSwapInterval(1);
}
void GFX::SwapBuffers()
{
glfwSwapBuffers(static_cast<GLFWwindow*>(Platform::GetUserData()));
}
void GFX::GoFullscreen()
{
GLFWwindow* window = static_cast<GLFWwindow*>(Platform::GetUserData());
glfwGetWindowPos(window, &oldWindowX, &oldWindowY); //save window pos for later
const GLFWvidmode* videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0, videoMode->width, videoMode->height, videoMode->refreshRate);
}
void GFX::ExitFullscreen()
{
GLFWwindow* window = static_cast<GLFWwindow*>(Platform::GetUserData());
if(oldWindowX == 0 || oldWindowY == 0)
glfwGetWindowPos(window, &oldWindowX, &oldWindowY); //save window pos
glfwSetWindowMonitor(window, nullptr, oldWindowX, oldWindowY, 1600, 900, GLFW_DONT_CARE);
}
VkSurfaceKHR GFX::CreateVulkanSurface(VkInstance instance)
{
VkSurfaceKHR surface;
glfwCreateWindowSurface(instance, static_cast<GLFWwindow*>(Platform::GetUserData()), nullptr, &surface);
return surface;
}