mirror of https://github.com/bjornbytes/lovr.git
Headset module can be restarted;
This commit is contained in:
parent
8fb3421658
commit
9ca743dc1a
|
@ -24,6 +24,10 @@ void lovrEventAddPump(EventPump pump) {
|
|||
vec_push(&state.pumps, pump);
|
||||
}
|
||||
|
||||
void lovrEventRemovePump(EventPump pump) {
|
||||
vec_remove(&state.pumps, pump);
|
||||
}
|
||||
|
||||
void lovrEventPump() {
|
||||
int i; EventPump pump;
|
||||
vec_foreach(&state.pumps, pump, i) {
|
||||
|
|
|
@ -75,7 +75,8 @@ typedef struct {
|
|||
|
||||
void lovrEventInit();
|
||||
void lovrEventDestroy();
|
||||
void lovrEventAddPump(void (*pump)(void));
|
||||
void lovrEventAddPump(EventPump pump);
|
||||
void lovrEventRemovePump(EventPump pump);
|
||||
void lovrEventPump();
|
||||
void lovrEventPush(Event event);
|
||||
bool lovrEventPoll(Event* event);
|
||||
|
|
|
@ -190,52 +190,48 @@ void lovrGraphicsPrepare(Material* material, float* pose) {
|
|||
void lovrGraphicsCreateWindow(int w, int h, bool fullscreen, int msaa, const char* title, const char* icon) {
|
||||
lovrAssert(!state.window, "Window is already created");
|
||||
|
||||
if (!state.initialized && (state.window = glfwGetCurrentContext()) != NULL) {
|
||||
lovrGraphicsReset();
|
||||
state.initialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((state.window = glfwGetCurrentContext()) == NULL) {
|
||||
#ifdef EMSCRIPTEN
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
glfwWindowHint(GLFW_SAMPLES, msaa);
|
||||
glfwWindowHint(GLFW_SRGB_CAPABLE, state.gammaCorrect);
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
glfwWindowHint(GLFW_SAMPLES, msaa);
|
||||
glfwWindowHint(GLFW_SRGB_CAPABLE, state.gammaCorrect);
|
||||
#else
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
glfwWindowHint(GLFW_SAMPLES, msaa);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
glfwWindowHint(GLFW_SRGB_CAPABLE, state.gammaCorrect);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
glfwWindowHint(GLFW_SAMPLES, msaa);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
glfwWindowHint(GLFW_SRGB_CAPABLE, state.gammaCorrect);
|
||||
#endif
|
||||
|
||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||
if (fullscreen) {
|
||||
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
|
||||
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
|
||||
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
|
||||
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
|
||||
}
|
||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||
if (fullscreen) {
|
||||
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
|
||||
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
|
||||
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
|
||||
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
|
||||
}
|
||||
|
||||
state.window = glfwCreateWindow(w ? w : mode->width, h ? h : mode->height, title, fullscreen ? monitor : NULL, NULL);
|
||||
if (!state.window) {
|
||||
glfwTerminate();
|
||||
lovrThrow("Could not create window");
|
||||
}
|
||||
state.window = glfwCreateWindow(w ? w : mode->width, h ? h : mode->height, title, fullscreen ? monitor : NULL, NULL);
|
||||
if (!state.window) {
|
||||
glfwTerminate();
|
||||
lovrThrow("Could not create window");
|
||||
}
|
||||
|
||||
if (icon) {
|
||||
GLFWimage image;
|
||||
image.pixels = stbi_load(icon, &image.width, &image.height, NULL, 3);
|
||||
glfwSetWindowIcon(state.window, 1, &image);
|
||||
free(image.pixels);
|
||||
}
|
||||
if (icon) {
|
||||
GLFWimage image;
|
||||
image.pixels = stbi_load(icon, &image.width, &image.height, NULL, 3);
|
||||
glfwSetWindowIcon(state.window, 1, &image);
|
||||
free(image.pixels);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(state.window);
|
||||
glfwSetWindowCloseCallback(state.window, onCloseWindow);
|
||||
glfwMakeContextCurrent(state.window);
|
||||
glfwSetWindowCloseCallback(state.window, onCloseWindow);
|
||||
}
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
|
|
|
@ -7,9 +7,12 @@ void lovrControllerDestroy(const Ref* ref) {
|
|||
}
|
||||
|
||||
static HeadsetInterface* headset = NULL;
|
||||
static bool headsetAlreadyInit = false;
|
||||
static bool initialized = false;
|
||||
|
||||
void lovrHeadsetInit(HeadsetDriver* drivers, int count) {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
HeadsetInterface* interface = NULL;
|
||||
|
||||
|
@ -29,14 +32,15 @@ void lovrHeadsetInit(HeadsetDriver* drivers, int count) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!headsetAlreadyInit && headset) {
|
||||
if (headset) {
|
||||
headset->init();
|
||||
atexit(lovrHeadsetDestroy);
|
||||
headsetAlreadyInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
void lovrHeadsetDestroy() {
|
||||
if (!initialized) return;
|
||||
initialized = false;
|
||||
|
||||
if (headset) {
|
||||
headset->destroy();
|
||||
headset = NULL;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
// From openvr_capi.h
|
||||
extern intptr_t VR_InitInternal(EVRInitError *peError, EVRApplicationType eType);
|
||||
extern void VR_ShutdownInternal();
|
||||
extern bool VR_IsHmdPresent();
|
||||
extern intptr_t VR_GetGenericInterface(const char* pchInterfaceVersion, EVRInitError* peError);
|
||||
extern bool VR_IsRuntimeInstalled();
|
||||
|
@ -151,6 +152,7 @@ static void initializeCanvas() {
|
|||
}
|
||||
|
||||
static void openvrInit() {
|
||||
if (state.isInitialized) return;
|
||||
state.isInitialized = false;
|
||||
state.isRendering = false;
|
||||
state.isMirrored = true;
|
||||
|
@ -229,6 +231,7 @@ static void openvrInit() {
|
|||
}
|
||||
|
||||
static void openvrDestroy() {
|
||||
if (!state.isInitialized) return;
|
||||
state.isInitialized = false;
|
||||
if (state.canvas) {
|
||||
lovrRelease(&state.canvas->texture.ref);
|
||||
|
@ -245,6 +248,9 @@ static void openvrDestroy() {
|
|||
lovrRelease(&controller->ref);
|
||||
}
|
||||
vec_deinit(&state.controllers);
|
||||
lovrEventRemovePump(openvrPoll);
|
||||
VR_ShutdownInternal();
|
||||
memset(&state, 0, sizeof(HeadsetState));
|
||||
}
|
||||
|
||||
static void openvrPoll() {
|
||||
|
|
|
@ -12,6 +12,7 @@ void lovrDestroy() {
|
|||
lovrEventDestroy();
|
||||
lovrFilesystemDestroy();
|
||||
lovrGraphicsDestroy();
|
||||
lovrHeadsetDestroy();
|
||||
lovrMathDestroy();
|
||||
lovrPhysicsDestroy();
|
||||
lovrTimerDestroy();
|
||||
|
|
Loading…
Reference in New Issue