From c87d6dec3d6779a36120fe32a5ec8b90a4085541 Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 10 Dec 2019 13:15:12 -0800 Subject: [PATCH] lovrPlatformGetProcAddress; Seems nicer than a global and allows for logging/hooks; --- src/core/platform.h | 5 +---- src/core/platform_android.c.h | 10 ++++++---- src/core/platform_glfw.c.h | 6 ++++-- src/modules/graphics/graphics.c | 2 +- src/modules/graphics/graphics.h | 2 +- src/modules/graphics/opengl.c | 2 +- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/core/platform.h b/src/core/platform.h index 07abe810..5784b8e5 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -53,10 +53,6 @@ typedef void (*windowResizeCallback)(int width, int height); typedef void (*mouseButtonCallback)(MouseButton button, ButtonAction action); typedef void (*keyboardCallback)(KeyCode key, ButtonAction action); -typedef void (*gpuProc)(void); -typedef gpuProc (*getProcAddressProc)(const char*); -extern getProcAddressProc lovrGetProcAddress; - bool lovrPlatformInit(void); void lovrPlatformDestroy(void); const char* lovrPlatformGetName(void); @@ -70,6 +66,7 @@ void lovrPlatformGetWindowSize(int* width, int* height); void lovrPlatformGetFramebufferSize(int* width, int* height); void lovrPlatformSetSwapInterval(int interval); void lovrPlatformSwapBuffers(void); +void* lovrPlatformGetProcAddress(const char* function); void lovrPlatformOnWindowClose(windowCloseCallback callback); void lovrPlatformOnWindowResize(windowResizeCallback callback); void lovrPlatformOnMouseButton(mouseButtonCallback callback); diff --git a/src/core/platform_android.c.h b/src/core/platform_android.c.h index 03a55bf9..6928f112 100644 --- a/src/core/platform_android.c.h +++ b/src/core/platform_android.c.h @@ -1,6 +1,8 @@ #include "platform.h" #include #include +#include +#include bool lovrPlatformInit() { return true; @@ -51,6 +53,10 @@ void lovrPlatformSwapBuffers() { // } +void* lovrPlatformGetProcAddress(const char* function) { + return (void*) eglGetProcAddress(function) +} + void lovrPlatformOnWindowClose(windowCloseCallback callback) { // } @@ -86,7 +92,3 @@ bool lovrPlatformIsKeyDown(KeyCode key) { void lovrPlatformSleep(double seconds) { usleep((unsigned int) (seconds * 1000000)); } - -#include -#include -getProcAddressProc lovrGetProcAddress = eglGetProcAddress; diff --git a/src/core/platform_glfw.c.h b/src/core/platform_glfw.c.h index c7ad7fa8..00f7624a 100644 --- a/src/core/platform_glfw.c.h +++ b/src/core/platform_glfw.c.h @@ -12,8 +12,6 @@ #include #endif -getProcAddressProc lovrGetProcAddress = glfwGetProcAddress; - static struct { GLFWwindow* window; windowCloseCallback onWindowClose; @@ -202,6 +200,10 @@ void lovrPlatformSwapBuffers() { glfwSwapBuffers(state.window); } +void* lovrPlatformGetProcAddress(const char* function) { + return (void*) glfwGetProcAddress(function); +} + void lovrPlatformOnWindowClose(windowCloseCallback callback) { state.onWindowClose = callback; } diff --git a/src/modules/graphics/graphics.c b/src/modules/graphics/graphics.c index dcdc0810..abe94fde 100644 --- a/src/modules/graphics/graphics.c +++ b/src/modules/graphics/graphics.c @@ -224,7 +224,7 @@ void lovrGraphicsCreateWindow(WindowFlags* flags) { lovrPlatformOnWindowClose(onCloseWindow); lovrPlatformOnWindowResize(onResizeWindow); lovrPlatformGetFramebufferSize(&state.width, &state.height); - lovrGpuInit(lovrGetProcAddress); + lovrGpuInit(lovrPlatformGetProcAddress); state.defaultCanvas = lovrCanvasCreateFromHandle(state.width, state.height, (CanvasFlags) { .stereo = false }, 0, 0, 0, 1, true); diff --git a/src/modules/graphics/graphics.h b/src/modules/graphics/graphics.h index 4107f74d..f2a4b5e8 100644 --- a/src/modules/graphics/graphics.h +++ b/src/modules/graphics/graphics.h @@ -211,7 +211,7 @@ typedef struct { uint32_t instances; } DrawCommand; -void lovrGpuInit(getProcAddressProc getProcAddress); +void lovrGpuInit(void* (*getProcAddress)(const char*)); void lovrGpuDestroy(void); void lovrGpuClear(struct Canvas* canvas, Color* color, float* depth, int* stencil); void lovrGpuCompute(struct Shader* shader, int x, int y, int z); diff --git a/src/modules/graphics/opengl.c b/src/modules/graphics/opengl.c index 37f40fba..46001d06 100644 --- a/src/modules/graphics/opengl.c +++ b/src/modules/graphics/opengl.c @@ -1011,7 +1011,7 @@ static void lovrGpuSetViewports(float* viewport, uint32_t count) { // GPU -void lovrGpuInit(getProcAddressProc getProcAddress) { +void lovrGpuInit(void* (*getProcAddress)(const char*)) { #ifdef LOVR_GL gladLoadGLLoader((GLADloadproc) getProcAddress); #elif defined(LOVR_GLES)